protected void recomputeAndCheckIdentifiers(Resource resource) { Iterator<JvmMember> iter = Iterators.filter(EcoreUtil.getAllContents(resource, false), JvmMember.class); while (iter.hasNext()) { JvmMember member = iter.next(); String identifier = member.getIdentifier(); member.internalSetIdentifier(null); String computed = member.getIdentifier(); assertNotNull(String.valueOf(member), computed); assertEquals(identifier, computed); checkDeprecatedBitSet(member); } Iterator<JvmFormalParameter> params = Iterators.filter(EcoreUtil.getAllContents(resource, false), JvmFormalParameter.class); while (params.hasNext()) { JvmFormalParameter parameter = params.next(); assertNotNull(parameter.eContainer().toString(), parameter.getName()); } }
protected void doTestInnerType_WrappedIterator_02(JvmGenericType wrappedIterator) { assertEquals(3, Iterables.size(wrappedIterator.getDeclaredConstructors())); JvmConstructor constructor = (JvmConstructor) Iterables.find(wrappedIterator.getMembers(), new Predicate<JvmMember>() { @Override public boolean apply(JvmMember input) { return (input instanceof JvmConstructor) && input.getSimpleName().equals("WrappedIterator") && ((JvmConstructor) input).getParameters().size() == 3; } }); assertNotNull(constructor); JvmFormalParameter firstParameter = constructor.getParameters().get(0); assertEquals(1, firstParameter.getAnnotations().size()); assertEquals("java.lang.String", firstParameter.getParameterType().getIdentifier()); assertEquals(TestAnnotationWithDefaults.class.getName(), firstParameter.getAnnotations().get(0).getAnnotation().getQualifiedName()); JvmFormalParameter secondParameter = constructor.getParameters().get(1); assertEquals(0, secondParameter.getAnnotations().size()); assertEquals("int", secondParameter.getParameterType().getIdentifier()); JvmFormalParameter thirdParameter = constructor.getParameters().get(2); assertEquals(1, thirdParameter.getAnnotations().size()); assertEquals("java.util.Iterator<V>", thirdParameter.getParameterType().getIdentifier()); assertEquals(TestAnnotation.NestedAnnotation.class.getName(), thirdParameter.getAnnotations().get(0).getAnnotation().getQualifiedName()); }
public void setVisibility(int accessFlags, JvmMember result) { switch (accessFlags & (ACC_PRIVATE | ACC_PROTECTED | ACC_PUBLIC)) { case ACC_PRIVATE: result.setVisibility(JvmVisibility.PRIVATE); return; case ACC_PROTECTED: result.setVisibility(JvmVisibility.PROTECTED); return; case ACC_PUBLIC: result.setVisibility(JvmVisibility.PUBLIC); return; default: result.setVisibility(JvmVisibility.DEFAULT); return; } }
protected JvmTypeReference createComputedTypeReference( Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmMember member, /* @Nullable */ InferredTypeIndicator indicator, boolean returnType) { XComputedTypeReference result = getServices().getXtypeFactory().createXComputedTypeReference(); if (indicator == null || indicator.getExpression() == null) result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, returnType)); else result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, indicator.getExpression(), returnType)); // TODO do we need a lightweight computed type reference? // resolvedTypes.setType(member, result); return result; }
@Test public void testBug426073() { try { final XExpression expression = this.expression("org.eclipse.emf.common.util.URI.createURI(\"dummy\")"); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmField> _function_1 = (JvmField it_1) -> { this.builder.setInitializer(it_1, expression); }; JvmField _field = this.builder.toField(expression, "URI", this.typeRef(expression, URI.class), _function_1); this.builder.<JvmField>operator_add(_members, _field); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); this.compile(expression.eResource(), clazz); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testEnum_04() throws Exception { String typeName = TestEnum.class.getName(); JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); boolean constructorFound = false; for (JvmMember member : members) { if (member instanceof JvmConstructor) { assertFalse(constructorFound); constructorFound = true; List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters(); assertEquals(1, parameters.size()); // synthetic parameters are not returned } } assertTrue(constructorFound); }
protected SignatureHashBuilder appendMemberSignatures(JvmDeclaredType type, boolean innerTypesOnly) { Iterable<? extends JvmMember> members = type.getMembers(); if(innerTypesOnly) members = filter(members, JvmDeclaredType.class); for (JvmMember member : members) { if (member.getSimpleName() != null) { appendAnnotationReferences(member); if (member instanceof JvmOperation) appendSignature((JvmOperation) member); else if (member instanceof JvmConstructor) appendSignature((JvmConstructor) member); else if (member instanceof JvmField) appendSignature((JvmField) member); else if (member instanceof JvmDeclaredType) { append(member.getQualifiedName()); appendMemberSignatures((JvmDeclaredType) member, true); } append("\n"); } } return this; }
/** * Detaches any existing bodies from the {@link JvmMember}. * A body could be a logically container {@link XExpression} or a * black box compilation strategy. * * @param member the member to remove the body from */ public void removeExistingBody(/* @Nullable */ JvmMember member) { if (member != null) { // We have to be careful how to remove existing adapters due to an EMF bug: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=462451 Object[] adapters = member.eAdapters().toArray(); for (int i = 0, j = 0; i < adapters.length; i++) { if (adapters[i] instanceof CompilationStrategyAdapter || adapters[i] instanceof CompilationTemplateAdapter) { member.eAdapters().remove(j); } else { j++; } } associator.removeLogicalChildAssociation(member); } }
@Test public void testNestedAnnotationType() { try { final XExpression expression = this.expression("42"); final JvmGenericType outerClass = this.builder.toClass(expression, "my.outer.Clazz"); EList<JvmMember> _members = outerClass.getMembers(); final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> { EList<JvmMember> _members_1 = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); }; JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1); this.builder.<JvmOperation>operator_add(_members_1, _method); }; JvmAnnotationType _annotationType = this.builder.toAnnotationType(expression, "MyAnnotation", _function); this.builder.<JvmAnnotationType>operator_add(_members, _annotationType); final Class<?> compiled = IterableExtensions.<Class<?>>head(((Iterable<Class<?>>)Conversions.doWrapArray(this.compile(expression.eResource(), outerClass).getDeclaredClasses()))); Assert.assertEquals("my.outer.Clazz.MyAnnotation", compiled.getCanonicalName()); Assert.assertEquals(Integer.valueOf(42), IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiled.getDeclaredMethods()))).getDefaultValue()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Override public EList<JvmMember> getMembers() { checkPendingInitialization(); if (members == null) { members = new EObjectContainmentWithInverseEList<JvmMember>(JvmMember.class, this, TypesPackage.JVM_DECLARED_TYPE__MEMBERS, TypesPackage.JVM_MEMBER__DECLARING_TYPE) { private static final long serialVersionUID = 1L; @Override protected void didChange() { literals = null; super.didChange(); } }; } return members; }
@Override public EList<JvmEnumerationLiteral> getLiterals() { checkPendingInitialization(); if (literals == null) { @SuppressWarnings("serial") EObjectResolvingEList<JvmEnumerationLiteral> list = new EObjectResolvingEList<JvmEnumerationLiteral>( JvmEnumerationLiteral.class, this, TypesPackage.JVM_ENUMERATION_TYPE__LITERALS) { @Override protected boolean isNotificationRequired() { return false; } }; for (JvmMember member : getMembers()) { if (member instanceof JvmEnumerationLiteral) list.add((JvmEnumerationLiteral) member); } literals = new DelegatingEcoreEList.UnmodifiableEList<JvmEnumerationLiteral>(this, TypesPackage.Literals.JVM_ENUMERATION_TYPE__LITERALS, list); } return literals; }
@Test public void testCompilationStrategy() { try { final XExpression expression = this.expression("null", false); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); JvmField _field = this.builder.toField(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmField>operator_add(_members, _field); EList<JvmMember> _members_1 = it.getMembers(); JvmOperation _getter = this.builder.toGetter(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmOperation>operator_add(_members_1, _getter); EList<JvmMember> _members_2 = it.getMembers(); JvmOperation _setter = this.builder.toSetter(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmOperation>operator_add(_members_2, _setter); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); final Class<?> compiled = this.compile(expression.eResource(), clazz); final Object inst = compiled.newInstance(); final Method getter = compiled.getMethod("getX"); final Method setter = compiled.getMethod("setX", String.class); setter.invoke(inst, "FOO"); Assert.assertEquals("FOO", getter.invoke(inst)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected void collectStaticImportsFrom(XExpression expression, JvmIdentifiableElement feature) { if (expression instanceof XAbstractFeatureCall) { if (feature instanceof JvmEnumerationLiteral && expression instanceof XFeatureCall) { if (isEnumLiteralImplicitelyImported(expression, (JvmEnumerationLiteral) feature)) { return; } } XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expression; if ((feature instanceof JvmOperation || feature instanceof JvmField) && featureCall.isStatic()) { if (featureCall.isExtension()) { acceptStaticExtensionImport((JvmMember) feature); } else { acceptStaticImport((JvmMember) feature); } } } }
@Test public void testNestedEnum_04() throws Exception { String typeName = TestEnum.Nested.class.getName(); JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); boolean constructorFound = false; for (JvmMember member : members) { if (member instanceof JvmConstructor) { assertFalse(constructorFound); constructorFound = true; List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters(); assertEquals(0, parameters.size()); // synthetic parameters are not returned } } assertTrue(constructorFound); }
protected void process(JvmMember context, Map<String, JvmIdentifiableElement> result) { if (context instanceof JvmDeclaredType) { if (!result.containsKey(context.getSimpleName())) result.put(context.getSimpleName(), context); JvmDeclaredType contextType = (JvmDeclaredType) context; ContextualVisibilityHelper visibilityHelper = new ContextualVisibilityHelper(this.visibilityHelper, contextType); addInnerTypes(contextType, "", visibilityHelper, result); Set<JvmType> superTypes = rawSuperTypes.collect(contextType); for (JvmType superType : superTypes) { if (superType instanceof JvmDeclaredType) addInnerTypes((JvmDeclaredType) superType, "", visibilityHelper, result); } } if (context instanceof JvmTypeParameterDeclarator) addTypeParameters((JvmTypeParameterDeclarator) context, result); JvmDeclaredType declaringType = context.getDeclaringType(); if (declaringType != null) process(declaringType, result); }
@Test public void testLinkToParameter() { try { final XExpression expr = this.expression("x", false); final Resource resource = expr.eResource(); resource.eSetDeliver(false); EList<EObject> _contents = resource.getContents(); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { EList<JvmFormalParameter> _parameters = it_1.getParameters(); JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(expr, "x", this.stringType(expr)); this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter); this._jvmTypesBuilder.setBody(it_1, expr); }; JvmOperation _method = this._jvmTypesBuilder.toMethod(expr, "doStuff", this.stringType(expr), _function_1); this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method); }; JvmGenericType _class = this._jvmTypesBuilder.toClass(expr, "Foo", _function); this._jvmTypesBuilder.<JvmGenericType>operator_add(_contents, _class); this._validationTestHelper.assertNoErrors(expr); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testEnumerationWithCompleter() { try { final XExpression expression = this.expression("null", false); final Procedure1<JvmEnumerationType> _function = (JvmEnumerationType it) -> { EList<JvmMember> _members = it.getMembers(); JvmEnumerationLiteral _enumerationLiteral = this.builder.toEnumerationLiteral(expression, "BAR"); this.builder.<JvmEnumerationLiteral>operator_add(_members, _enumerationLiteral); EList<JvmMember> _members_1 = it.getMembers(); JvmEnumerationLiteral _enumerationLiteral_1 = this.builder.toEnumerationLiteral(expression, "BAZ"); this.builder.<JvmEnumerationLiteral>operator_add(_members_1, _enumerationLiteral_1); }; final JvmEnumerationType enumeration = this.builder.toEnumerationType(expression, "my.test.Foo", _function); expression.eResource().getContents().add(enumeration); this.completer.complete(enumeration); final Class<?> compiled = this.compile(expression.eResource(), enumeration); final Method valuesMethod = compiled.getMethod("values"); Object _invoke = valuesMethod.invoke(null); final Object[] values = ((Object[]) _invoke); Assert.assertEquals("BAR", values[0].toString()); Assert.assertEquals("BAZ", values[1].toString()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
public ITreeAppendable generateModifier(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) { if (it instanceof JvmConstructor) { return _generateModifier((JvmConstructor)it, appendable, config); } else if (it instanceof JvmOperation) { return _generateModifier((JvmOperation)it, appendable, config); } else if (it instanceof JvmField) { return _generateModifier((JvmField)it, appendable, config); } else if (it instanceof JvmGenericType) { return _generateModifier((JvmGenericType)it, appendable, config); } else if (it instanceof JvmDeclaredType) { return _generateModifier((JvmDeclaredType)it, appendable, config); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, appendable, config).toString()); } }
public ITreeAppendable generateMember(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) { if (it instanceof JvmConstructor) { return _generateMember((JvmConstructor)it, appendable, config); } else if (it instanceof JvmOperation) { return _generateMember((JvmOperation)it, appendable, config); } else if (it instanceof JvmField) { return _generateMember((JvmField)it, appendable, config); } else if (it instanceof JvmDeclaredType) { return _generateMember((JvmDeclaredType)it, appendable, config); } else if (it != null) { return _generateMember(it, appendable, config); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, appendable, config).toString()); } }
@Test public void test_staticNestedTypes_constructor() { String typeName = Bug347739.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); for (JvmMember member : members) { if (member instanceof JvmGenericType) { if ("StackItem".equals(member.getSimpleName())) { JvmGenericType stackItem = (JvmGenericType) member; Iterable<JvmConstructor> constructors = stackItem.getDeclaredConstructors(); for (JvmConstructor constructor : constructors) { assertEquals(2, constructor.getParameters().size()); } return; } } } fail("could not find inner class"); }
protected void _infer(final Model m, final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) { final XBlockExpression e = m.getBlock(); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { EList<JvmTypeReference> _exceptions = it_1.getExceptions(); JvmTypeReference _typeRef = this._typeReferenceBuilder.typeRef(Throwable.class); this._jvmTypesBuilder.<JvmTypeReference>operator_add(_exceptions, _typeRef); this._jvmTypesBuilder.setBody(it_1, e); }; JvmOperation _method = this._jvmTypesBuilder.toMethod(e, "myMethod", this._jvmTypesBuilder.inferredType(), _function_1); this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method); }; acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(e, this.name(e.eResource())), _function); }
public static boolean isDeprecatedMember(JvmMember member) { if (member.isSetDeprecated()) { return member.isDeprecated(); } List<JvmAnnotationReference> annotations = member.getAnnotations(); for(JvmAnnotationReference annotation: annotations) { JvmAnnotationType annotationType = annotation.getAnnotation(); if (annotationType != null && Deprecated.class.getName().equals(annotationType.getIdentifier())) { return true; } } return false; }
protected void assertMembers(String typeName, Set<String> memberNames) { JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertEquals(memberNames.size(), type.getMembers().size()); for (org.eclipse.xtext.common.types.JvmMember member : type.getMembers()) { assertTrue(member.getIdentifier(), member instanceof JvmOperation); JvmOperation op = (JvmOperation) member; assertTrue(op.getSimpleName(), memberNames.remove(op.getSimpleName())); } assertTrue(memberNames.isEmpty()); }
@Test public void testBug380754() { try { final XExpression expression = this.expression("null"); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); final JvmAnnotationReference annotation = this.builder.toAnnotation(expression, TestAnnotations.class); final JvmAnnotationAnnotationValue annotationAnnotationValue = this.typesFactory.createJvmAnnotationAnnotationValue(); EList<JvmAnnotationReference> _values = annotationAnnotationValue.getValues(); JvmAnnotationReference _annotation = this.builder.toAnnotation(expression, TestAnnotation.class); this.builder.<JvmAnnotationReference>operator_add(_values, _annotation); EList<JvmAnnotationReference> _values_1 = annotationAnnotationValue.getValues(); JvmAnnotationReference _annotation_1 = this.builder.toAnnotation(expression, TestAnnotation.class); this.builder.<JvmAnnotationReference>operator_add(_values_1, _annotation_1); EList<JvmAnnotationReference> _values_2 = annotationAnnotationValue.getValues(); JvmAnnotationReference _annotation_2 = this.builder.toAnnotation(expression, TestAnnotation.class); this.builder.<JvmAnnotationReference>operator_add(_values_2, _annotation_2); EList<JvmAnnotationValue> _explicitValues = annotation.getExplicitValues(); this.builder.<JvmAnnotationAnnotationValue>operator_add(_explicitValues, annotationAnnotationValue); EList<JvmAnnotationReference> _annotations = it_1.getAnnotations(); this.builder.<JvmAnnotationReference>operator_add(_annotations, annotation); }; JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1); this.builder.<JvmOperation>operator_add(_members, _method); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); this.compile(expression.eResource(), clazz); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testLinkToParameter_1() { try { XExpression _expression = this.expression("x", false); final XFeatureCall expr = ((XFeatureCall) _expression); final Resource resource = expr.eResource(); resource.eSetDeliver(false); EList<EObject> _contents = resource.getContents(); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); JvmField _field = this._jvmTypesBuilder.toField(expr, "x", this.stringType(expr)); this._jvmTypesBuilder.<JvmField>operator_add(_members, _field); EList<JvmMember> _members_1 = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { EList<JvmFormalParameter> _parameters = it_1.getParameters(); JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(expr, "x", this.stringType(expr)); this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter); this._jvmTypesBuilder.setBody(it_1, expr); }; JvmOperation _method = this._jvmTypesBuilder.toMethod(expr, "doStuff", this.stringType(expr), _function_1); this._jvmTypesBuilder.<JvmOperation>operator_add(_members_1, _method); }; JvmGenericType _class = this._jvmTypesBuilder.toClass(expr, "Foo", _function); this._jvmTypesBuilder.<JvmGenericType>operator_add(_contents, _class); this._validationTestHelper.assertNoErrors(expr); JvmIdentifiableElement _feature = expr.getFeature(); Assert.assertTrue((_feature instanceof JvmFormalParameter)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<JvmMember> getMembers() { if (members == null) { members = new EObjectContainmentWithInverseEList<JvmMember>(JvmMember.class, this, TypesPackage.JVM_DECLARED_TYPE__MEMBERS, TypesPackage.JVM_MEMBER__DECLARING_TYPE); } return members; }
@SuppressWarnings("deprecation") @Test public void testDeprecatedBit_01() { String typeName = org.eclipse.xtext.common.types.testSetups.DeprecatedClass.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertTrue(type.isSetDeprecated()); assertTrue(type.isDeprecated()); for (JvmMember member : type.getMembers()) { assertTrue(member.isSetDeprecated()); assertFalse(member.isDeprecated()); } }
@Test public void testDeprecatedBit_02() { String typeName = DeprecatedMembers.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertTrue(type.isSetDeprecated()); assertFalse(type.isDeprecated()); for (JvmMember member : type.getMembers()) { assertTrue(member.isSetDeprecated()); assertTrue(member.isDeprecated()); } }
@Check public void checkNoForwardReferences(XExpression fieldInitializer) { JvmIdentifiableElement container = logicalContainerProvider.getLogicalContainer(fieldInitializer); if (container instanceof JvmField) { JvmField field = (JvmField) container; boolean staticField = field.isStatic(); JvmDeclaredType declaredType = field.getDeclaringType(); if (declaredType == null) { return; } Collection<JvmField> illegalFields = Sets.newHashSet(); for(int i = declaredType.getMembers().size() - 1; i>=0; i--) { JvmMember member = declaredType.getMembers().get(i); if (member instanceof JvmField) { if (((JvmField) member).isStatic() == staticField) { illegalFields.add((JvmField) member); } } if (member == field) break; } TreeIterator<EObject> iterator = EcoreUtil2.eAll(fieldInitializer); while(iterator.hasNext()) { EObject object = iterator.next(); if (object instanceof XFeatureCall) { JvmIdentifiableElement feature = ((XFeatureCall) object).getFeature(); if (illegalFields.contains(((XFeatureCall) object).getFeature())) { error("Cannot reference the field '" + feature.getSimpleName() + "' before it is defined", object, null, INSIGNIFICANT_INDEX, ILLEGAL_FORWARD_REFERENCE); } } else if (isLocalClassSemantics(object)) { iterator.prune(); } } } }
private boolean isNestedTypeOf(JvmType child, JvmDeclaredType parent) { if (child instanceof JvmMember) { JvmMember member = (JvmMember) child; return member.getDeclaringType() == parent; } return false; }
@Test public void testLinkToField() { try { XExpression _expression = this.expression("x", false); final XFeatureCall expr = ((XFeatureCall) _expression); final Resource resource = expr.eResource(); resource.eSetDeliver(false); EList<EObject> _contents = resource.getContents(); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); JvmField _field = this._jvmTypesBuilder.toField(expr, "x", this.stringType(expr)); this._jvmTypesBuilder.<JvmField>operator_add(_members, _field); EList<JvmMember> _members_1 = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { EList<JvmFormalParameter> _parameters = it_1.getParameters(); JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(expr, "y", this.stringType(expr)); this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter); this._jvmTypesBuilder.setBody(it_1, expr); }; JvmOperation _method = this._jvmTypesBuilder.toMethod(expr, "doStuff", this.stringType(expr), _function_1); this._jvmTypesBuilder.<JvmOperation>operator_add(_members_1, _method); }; JvmGenericType _class = this._jvmTypesBuilder.toClass(expr, "Foo", _function); this._jvmTypesBuilder.<JvmGenericType>operator_add(_contents, _class); this._validationTestHelper.assertNoErrors(expr); JvmIdentifiableElement _feature = expr.getFeature(); Assert.assertTrue((_feature instanceof JvmField)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Override public void doAddImports(ITypeImporter importer) { for (JvmMember member : enumType.getMembers()) { if (member instanceof JvmEnumerationLiteral) { importer.importStatic(enumType, member.getSimpleName()); } } }
@Test public void testGetMethod_2() throws Exception { JvmDeclaredType type = getType(X.class); JvmMember addMethod = Iterables.find(type.getMembers(), new Predicate<JvmMember>() { @Override public boolean apply(JvmMember input) { if (input instanceof JvmOperation) { return input.getSimpleName().equals("a"); } return false; } }); Method method = X.class.getDeclaredMethod("a", Comparable.class, CharSequence.class); assertEquals(method, getJavaReflectAccess().getMethod((JvmOperation)addMethod)); }
public DemandTypeReferenceProvider( JvmMember member, XExpression expression, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, ResolvedTypes resolvedTypes, IFeatureScopeSession session, boolean returnType) { this.member = member; this.expression = expression; this.resolvedTypesByContext = resolvedTypesByContext; this.resolvedTypes = resolvedTypes; this.session = session; this.returnType = returnType; }
protected void _recordExpressions(JvmDeclaredType type) { List<JvmMember> members = type.getMembers(); for(int i = 0, size = members.size(); i < size; i++) { recordExpressions(members.get(i)); } recordAnnotationExpressions(type); }
protected AbstractReentrantTypeReferenceProvider createTypeProvider( Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmMember member, /* @Nullable */ XExpression expression, boolean returnType) { if (expression != null) { markToBeInferred(resolvedTypes, expression); return new DemandTypeReferenceProvider(member, expression, resolvedTypesByContext, resolvedTypes, featureScopeSession, returnType); } return new AnyTypeReferenceProvider(member, resolvedTypes, this); }
protected void computeMemberTypes(Map<JvmIdentifiableElement, ResolvedTypes> preparedResolvedTypes, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmDeclaredType type) { IFeatureScopeSession childSession = addExtensionsToMemberSession(resolvedTypes, featureScopeSession, type); List<JvmMember> members = type.getMembers(); for(int i = 0; i < members.size(); i++) { computeTypes(preparedResolvedTypes, resolvedTypes, childSession, members.get(i)); } }
@Override /* @Nullable */ protected LightweightTypeReference getExpectedTypeForAssociatedExpression(JvmMember member, XExpression expression) { if (toBeInferredRootExpressions != null && toBeInferredRootExpressions.contains(expression)) { return null; } return getActualType(member); }