@Override /* @Nullable */ protected JvmTypeReference doGetTypeReference(XComputedTypeReferenceImplCustom context) { try { resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.TOO_LITTLE_TYPE_INFORMATION, "Cannot infer type", typeResolver.getSourceElement(member), null, -1, null)); return TypesFactory.eINSTANCE.createJvmAnyTypeReference(); } finally { context.unsetTypeProviderWithoutNotification(); } }
protected void completeJvmGenericType(JvmGenericType element) { // if no super type add Object ensureSuperTypeObject(element); addAnnotations(element); if (!element.isInterface()) { // if no constructors have been added, add a default constructor if (isEmpty(element.getDeclaredConstructors())) { JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor(); constructor.setSimpleName(element.getSimpleName()); constructor.setVisibility(JvmVisibility.PUBLIC); typeExtensions.setSynthetic(constructor, true); EObject primarySourceElement = associations.getPrimarySourceElement(element); if (primarySourceElement != null) { associator.associate(primarySourceElement, constructor); } element.getMembers().add(constructor); } } }
protected JvmTypeReference getJavaLangObjectTypeRef(JvmType rawType, TypesFactory typesFactory) { ResourceSet rs = EcoreUtil2.getResourceSet(rawType); JvmParameterizedTypeReference refToObject = typesFactory.createJvmParameterizedTypeReference(); if (rs != null) { EObject javaLangObject = rs.getEObject(javaLangObjectURI, true); if (javaLangObject instanceof JvmType) { JvmType objectDeclaration = (JvmType) javaLangObject; refToObject.setType(objectDeclaration); return refToObject; } } JvmGenericType proxy = typesFactory.createJvmGenericType(); ((InternalEObject)proxy).eSetProxyURI(javaLangObjectURI); refToObject.setType(proxy); return refToObject; }
protected JvmTypeReference toTypeReference(final JvmType type, final int arrayDimensions) { if ((type == null)) { return null; } JvmParameterizedTypeReference _createJvmParameterizedTypeReference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); final Procedure1<JvmParameterizedTypeReference> _function = (JvmParameterizedTypeReference it) -> { it.setType(type); }; JvmTypeReference resultTypeRef = ObjectExtensions.<JvmParameterizedTypeReference>operator_doubleArrow(_createJvmParameterizedTypeReference, _function); ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, arrayDimensions, true); for (final Integer i : _doubleDotLessThan) { { final JvmGenericArrayTypeReference arrayRef = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference(); arrayRef.setComponentType(resultTypeRef); resultTypeRef = arrayRef; } } return resultTypeRef; }
@Test public void testJvmTypeSimple_Issue145() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName"); assertEquals(expected, actual); resource.getContents().remove(expected); ((InternalEObject)expected).eSetProxyURI(EcoreUtil.getURI(expected)); JvmGenericType expected2 = TypesFactory.eINSTANCE.createJvmGenericType(); expected2.setSimpleName("SimpleName"); expected2.setPackageName("package.name"); resource.getContents().add(expected2); JvmType actual2 = getTypeProvider().findTypeByName("package.name.SimpleName"); assertEquals(expected2, actual2); }
public JvmType createProxy(BinaryTypeSignature type, Map<String, JvmTypeParameter> typeParameters) { String variableName = type.getTypeVariableName(); if (variableName != null) { if (typeParameters == null) { throw new IllegalStateException(type.toString()); } JvmType result = typeParameters.get(variableName); if (result == null) { throw new IllegalStateException(type.toString()); } return result; } JvmType proxy = typeProxies.get(type); if (proxy == null) { proxy = TypesFactory.eINSTANCE.createJvmVoid(); URI uri = type.getURI(); ((InternalEObject) proxy).eSetProxyURI(uri); typeProxies.put(type, proxy); } return proxy; }
protected JvmEnumerationType createEnumerationType(Class<?> clazz) { JvmEnumerationType result = TypesFactory.eINSTANCE.createJvmEnumerationType(); result.internalSetIdentifier(clazz.getName()); result.setSimpleName(clazz.getSimpleName()); if (clazz.getDeclaringClass() == null && clazz.getPackage() != null) result.setPackageName(clazz.getPackage().getName()); setVisibility(clazz, result); setTypeModifiers(clazz, result); createNestedTypes(clazz, result); createMethods(clazz, result); createFields(clazz, result); createConstructors(clazz, result); setSuperTypes(clazz, result); createAnnotationValues(clazz, result); return result; }
protected JvmFormalParameter createFormalParameter(Type parameterType, String paramName, JvmMember container, GenericDeclaration member, Annotation[] annotations) { JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter(); result.setName(paramName); if (isLocal(parameterType, member)) { result.setParameterType(createLocalTypeReference(parameterType, (JvmTypeParameterDeclarator) container, member)); } else { result.setParameterType(createTypeReference(parameterType)); } if (annotations.length != 0) { InternalEList<JvmAnnotationReference> annotationsReferences = (InternalEList<JvmAnnotationReference>)result.getAnnotations(); for (Annotation annotation : annotations) { annotationsReferences.addUnique(createAnnotationReference(annotation)); } } return result; }
/** * {@inheritDoc} * * Returns the value of the 'Type' reference. If there is no type set, * a reference to <code>java.lang.Object</code> is assumed as soon as there is more * than one contained reference. * If there is only one contained reference, its type is returned. */ @Override public JvmType getType() { if (references != null && !references.isEmpty()) { if (references.size() == 1) { return references.get(0).getType(); } if (type == null) { JvmGenericType objectType = TypesFactory.eINSTANCE.createJvmGenericType(); String objectClassName = Object.class.getName(); ((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName)); type = objectType; } } return super.getType(); }
/** * Translates a single {@link XAnnotation} to {@link JvmAnnotationReference} that can be added to a {@link JvmAnnotationTarget}. * * @param anno the source annotation * * @return a {@link JvmAnnotationReference} that can be attached to some {@link JvmAnnotationTarget} */ /* @Nullable */ public JvmAnnotationReference getJvmAnnotationReference(/* @Nullable */ XAnnotation anno) { if(anno == null) return null; JvmAnnotationReference reference = typesFactory.createJvmAnnotationReference(); final JvmType annotation = (JvmType) anno.eGet( XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false); if (annotation.eIsProxy()) { JvmAnnotationType copiedProxy = TypesFactory.eINSTANCE.createJvmAnnotationType(); ((InternalEObject)copiedProxy).eSetProxyURI(EcoreUtil.getURI(annotation)); reference.setAnnotation(copiedProxy); } else if (annotation instanceof JvmAnnotationType){ reference.setAnnotation((JvmAnnotationType) annotation); } for (XAnnotationElementValuePair val : anno.getElementValuePairs()) { XExpression valueExpression = val.getValue(); JvmAnnotationValue annotationValue = toJvmAnnotationValue(valueExpression); if (annotationValue != null) { JvmOperation op = (JvmOperation) val.eGet( XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT, false); annotationValue.setOperation(op); reference.getExplicitValues().add(annotationValue); } } if (anno.getValue() != null) { JvmAnnotationValue value = toJvmAnnotationValue(anno.getValue()); if (value != null) { reference.getExplicitValues().add(value); } } associate(anno, reference); return reference; }
@Override public JvmTypeReference getEquivalent() { if (equivalent == null) { IJvmTypeReferenceProvider provider = getTypeProvider(); if (provider != null) { JvmTypeReference result = provider.getTypeReference(this); if (equivalent == null || equivalent != result) { if (result != null && (result.eResource() != null || result.eContainer() != null)) { JvmDelegateTypeReference delegate = TypesFactory.eINSTANCE.createJvmDelegateTypeReference(); delegate.setDelegate(result); result = delegate; } if (result != null) { boolean wasDeliver = eDeliver(); try { eSetDeliver(false); setEquivalent(result); } finally { eSetDeliver(wasDeliver); } } } } else { equivalent = null; } } return equivalent; }
public static JvmType getType(final Class<?> clazz, final EObject context) { JvmType _xblockexpression = null; { JvmVoid _createJvmVoid = TypesFactory.eINSTANCE.createJvmVoid(); final InternalEObject proxy = ((InternalEObject) _createJvmVoid); proxy.eSetProxyURI(XFunctionTypeRefs.computeTypeUri(clazz)); EObject _resolve = EcoreUtil.resolve(proxy, context); _xblockexpression = ((JvmType) _resolve); } return _xblockexpression; }
@Test public void testGetElementByInstance_01() { JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor(); JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType(); type.setPackageName("java.lang"); type.setSimpleName("Object"); constructor.setSimpleName("Object"); type.getMembers().add(constructor); IEObjectDescription element = getConstructorScope().getSingleElement(constructor); assertNotNull(element); assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getName()); assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getQualifiedName()); }
@Test public void testJvmTypeSimple() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName"); assertEquals(expected, actual); }
@Test public void testJvmTypeNoPackage() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("SimpleName"); assertEquals(expected, actual); }
@Test public void testJvmTypeNestedClass() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType(); container.setSimpleName("SimpleName"); container.setPackageName("package.name"); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("Child"); container.getMembers().add(expected); resource.getContents().add(container); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName$Child"); assertEquals(expected, actual); }
@Test public void testJvmTypeNestedClassWithDot_01() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType(); container.setSimpleName("SimpleName"); container.setPackageName("package.name"); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("Child"); container.getMembers().add(expected); resource.getContents().add(container); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", false); assertEquals(expected, actual); }
@Test public void testJvmTypeNestedClassWithDot_02() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType(); container.setSimpleName("SimpleName"); container.setPackageName("package.name"); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("Child"); container.getMembers().add(expected); resource.getContents().add(container); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", true); assertNull(actual); }
@Test public void testJvmTypeArray() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName[]"); assertTrue(actual instanceof JvmArrayType); assertEquals(expected, ((JvmArrayType) actual).getComponentType()); }
public JvmParameterizedTypeReferenceConstructor(JvmType jvmType, TypesFactory typesFactory, IJvmTypeProvider typesProvider, JvmParameterizedTypeReferenceConstructor parent) { this.reference = typesFactory.createJvmParameterizedTypeReference(); reference.setType(jvmType); this.typesFactory = typesFactory; this.typesProvider = typesProvider; this.parent = parent; }
protected JvmOperation createMethodProxy(BinaryTypeSignature type, String methodName) { BinarySimpleMemberSignature method = type.appendMethod(methodName); JvmOperation proxy = operationProxies.get(method); if (proxy == null) { proxy = TypesFactory.eINSTANCE.createJvmOperation(); URI uri = method.getURI(); ((InternalEObject) proxy).eSetProxyURI(uri); operationProxies.put(method, proxy); } return proxy; }
protected JvmEnumerationLiteral createEnumLiteral(String literalName, BinaryTypeSignature typeName) { JvmEnumerationLiteral enumLiteralProxy = TypesFactory.eINSTANCE.createJvmEnumerationLiteral(); InternalEObject internalEObject = (InternalEObject) enumLiteralProxy; BinarySimpleMemberSignature fieldSignature = typeName.appendField(literalName); URI uri = fieldSignature.getURI(); internalEObject.eSetProxyURI(uri); return enumLiteralProxy; }
@Override public void visitEnum(String name, String desc, String value) { if (name != null) { throw new IllegalStateException(); } if (result == null) { result = TypesFactory.eINSTANCE.createJvmEnumAnnotationValue(); } JvmEnumerationLiteral enumLiteralProxy = proxies.createEnumLiteral(value, desc); ((InternalEList<JvmEnumerationLiteral>) ((JvmEnumAnnotationValue) result).getValues()).addUnique(enumLiteralProxy); }
@Override public AnnotationVisitor visitAnnotation(String name, String desc) { if (name != null) { throw new IllegalStateException(); } if (result == null) { result = TypesFactory.eINSTANCE.createJvmAnnotationAnnotationValue(); } InternalEList<JvmAnnotationReference> nestedValues = (InternalEList<JvmAnnotationReference>) ((JvmAnnotationAnnotationValue) result).getValues(); JvmAnnotationReferenceBuilder annotation = new JvmAnnotationReferenceBuilder(nestedValues, desc, proxies); return annotation; }
public JvmAnnotationReferenceBuilder(InternalEList<JvmAnnotationReference> target, String desc, Proxies proxies) { super(Opcodes.ASM5); this.proxies = proxies; this.target = target; this.annotationType = BinarySignatures.createTypeSignature(desc); result = TypesFactory.eINSTANCE.createJvmAnnotationReference(); result.setAnnotation(proxies.createAnnotationProxy(annotationType)); values = (InternalEList<JvmAnnotationValue>) result.getExplicitValues(); }
@Override public void visitEnum(final String name, final String desc, final String value) { JvmEnumAnnotationValue result = TypesFactory.eINSTANCE.createJvmEnumAnnotationValue(); JvmEnumerationLiteral enumLiteralProxy = proxies.createEnumLiteral(value, desc); ((InternalEList<JvmEnumerationLiteral>) result.getValues()).addUnique(enumLiteralProxy); result.setOperation(proxies.createMethodProxy(annotationType, name)); values.addUnique(result); }
@Override public AnnotationVisitor visitAnnotation(final String name, final String desc) { JvmAnnotationAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmAnnotationAnnotationValue(); InternalEList<JvmAnnotationReference> nestedValues = (InternalEList<JvmAnnotationReference>) annotationValue .getValues(); annotationValue.setOperation(proxies.createMethodProxy(annotationType, name)); JvmAnnotationReferenceBuilder annotation = new JvmAnnotationReferenceBuilder(nestedValues, desc, proxies); values.addUnique(annotationValue); return annotation; }
@Override public AnnotationVisitor visitArray(final String name) { return new JvmAnnotationValueBuilder(proxies) { @Override public void visitEnd() { if (result == null) { result = TypesFactory.eINSTANCE.createJvmCustomAnnotationValue(); } result.setOperation(proxies.createMethodProxy(annotationType, name)); values.addUnique(result); } }; }
protected JvmFormalParameter createFormalParameter(BinaryTypeSignature parameterType, String paramName, JvmMember container, Map<String, JvmTypeParameter> typeParameters) { JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter(); result.setName(paramName); result.setParameterType(proxies.createTypeReference(parameterType, typeParameters)); return result; }
protected JvmEnumerationLiteral createEnumLiteralProxy(Enum<?> e) { JvmEnumerationLiteral enumLiteralProxy = TypesFactory.eINSTANCE.createJvmEnumerationLiteral(); InternalEObject internalEObject = (InternalEObject) enumLiteralProxy; Class<?> type = e.getDeclaringClass(); try { Field field = type.getDeclaredField(e.name()); internalEObject.eSetProxyURI(uriHelper.getFullURI(field)); } catch (Exception exception) { log.error(exception.getMessage(), exception); return null; } return enumLiteralProxy; }
protected EStructuralFeature.Setting createAnnotationValue(Class<?> type) { if (String.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmStringAnnotationValue().getValues(); } else if (Class.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmTypeAnnotationValue().getValues(); } else if (boolean.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmBooleanAnnotationValue().getValues(); } else if (int.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmIntAnnotationValue().getValues(); } else if (type.isAnnotation()) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmAnnotationAnnotationValue().getValues(); } else if (type.isEnum()) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmEnumAnnotationValue().getValues(); } else if (long.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmLongAnnotationValue().getValues(); } else if (short.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmShortAnnotationValue().getValues(); } else if (float.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmFloatAnnotationValue().getValues(); } else if (double.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmDoubleAnnotationValue().getValues(); } else if (char.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmCharAnnotationValue().getValues(); } else if (byte.class == type) { return (EStructuralFeature.Setting)TypesFactory.eINSTANCE.createJvmByteAnnotationValue().getValues(); } else throw new IllegalArgumentException("Unexpected type: " + type.getCanonicalName()); }
protected JvmAnnotationType createAnnotationProxy(Class<? extends Annotation> type) { JvmAnnotationType proxy = annotationProxies.get(type); if (proxy == null) { proxy = TypesFactory.eINSTANCE.createJvmAnnotationType(); URI uri = uriHelper.getFullURI(type); ((InternalEObject)proxy).eSetProxyURI(uri); annotationProxies.put(type, proxy); } return proxy; }
protected JvmOperation createMethodProxy(Method method) { JvmOperation proxy = operationProxies.get(method); if (proxy == null) { proxy = TypesFactory.eINSTANCE.createJvmOperation(); URI uri = uriHelper.getFullURI(method); ((InternalEObject)proxy).eSetProxyURI(uri); operationProxies.put(method, proxy); } return proxy; }
protected JvmAnnotationType createAnnotationType(Class<?> clazz) { JvmAnnotationType result = TypesFactory.eINSTANCE.createJvmAnnotationType(); result.internalSetIdentifier(clazz.getName()); result.setSimpleName(clazz.getSimpleName()); if (clazz.getDeclaringClass() == null && clazz.getPackage() != null) result.setPackageName(clazz.getPackage().getName()); setVisibility(clazz, result); setTypeModifiers(clazz, result); createNestedTypes(clazz, result); createMethods(clazz, result); createFields(clazz, result); setSuperTypes(clazz, result); createAnnotationValues(clazz, result); return result; }