org.eclipse.xtext.common.types.JvmMember Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmMember. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InferredJvmModelTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testInferredFunction_04() throws Exception {
		XtendFile xtendFile = file("class Foo { def Iterable<CharSequence> create result: newArrayList(s) newList(String s) {} }");
		JvmGenericType inferredType = getInferredType(xtendFile);
		XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
		EList<JvmMember> jvmMembers = inferredType.getMembers();
		assertEquals(4, jvmMembers.size());
		JvmMember jvmMember = jvmMembers.get(1);
		assertTrue(jvmMember instanceof JvmOperation);
		XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
		assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
		assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
		assertEquals("java.lang.Iterable<java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
		
		JvmField cacheVar = (JvmField) jvmMembers.get(2);
		assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
		assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
		assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
		
		JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
		assertEquals("_init_"+xtendFunction.getName(), privateInitializer.getSimpleName());
		assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
//		This used to be a bogus assertion since Iterable<CharSequence> is not assignable from ArrayList<String>
//		assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
		assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
		assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
	}
 
Example #2
Source File: Proxies.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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;
	}
}
 
Example #3
Source File: AbstractExtraLanguageGenerator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies the expression associated to the given object.
 * Usually, the expression is inside the given object.
 *
 * @param object the object.
 * @return the expression, or {@code null} if none.
 */
protected XExpression getAssociatedExpression(JvmMember object) {
	final XExpression expr = getTypeBuilder().getExpression(object);
	if (expr == null) {
		// The member may be a automatically generated code with dynamic code-building strategies
		final Procedure1<? super ITreeAppendable> strategy = getTypeExtensions().getCompilationStrategy(object);
		if (strategy != null) {
			//
		} else {
			final StringConcatenationClient template = getTypeExtensions().getCompilationTemplate(object);
			if (template != null) {
				//
			}
		}
	}
	return expr;
}
 
Example #4
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testBug377925No_Nullpointer() {
  try {
    final XExpression expression = this.expression("[Object o| 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);
      };
      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);
  }
}
 
Example #5
Source File: JvmEnumerationTypeImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: TypeUsageCollector.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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);
			}
		}
	}
}
 
Example #7
Source File: JvmEnumerationTypeImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: InferredJvmModelTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testXtendField_00() throws Exception {
	XtendFile xtendFile = file("class Foo { @Inject String string }");
	JvmGenericType type = getInferredType(xtendFile);
	Iterable<JvmField> iterable = type.getDeclaredFields();
	JvmField next = iterable.iterator().next();
	assertEquals("string",next.getSimpleName());
	assertEquals(JvmVisibility.PRIVATE, next.getVisibility());
	assertEquals("java.lang.String", next.getType().getIdentifier());
	for(JvmMember member: type.getMembers()) {
		if (member instanceof JvmExecutable) {
			assertEquals(JvmVisibility.PUBLIC, member.getVisibility());
		} else {
			assertEquals(JvmVisibility.PRIVATE, member.getVisibility());
		}
	}
}
 
Example #9
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #11
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #12
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSimple() {
  try {
    final XExpression expression = this.expression("return s.toUpperCase", false);
    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.builder.toParameter(expression, "s", this.references.getTypeForName(String.class, expression));
        this.builder.<JvmFormalParameter>operator_add(_parameters, _parameter);
        this.builder.setBody(it_1, expression);
      };
      JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName(String.class, expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members, _method);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    final Class<?> compiledClass = this.compile(expression.eResource(), clazz);
    final Object instance = compiledClass.getDeclaredConstructor().newInstance();
    Assert.assertEquals("FOO", compiledClass.getMethod("doStuff", String.class).invoke(instance, "foo"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #13
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #14
Source File: DerivedMemberAwareEditorOpener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected EObject findEObjectByURI(URI uri, XtextResource resource) {
	if (uri.query() != null) {
		String identifier = uri.query();
		TreeIterator<EObject> contents = EcoreUtil.<EObject>getAllContents(resource, true);
		while(contents.hasNext()) {
			EObject content = contents.next();
			if (content instanceof JvmMember) {
				String identifierFromResource = ((JvmIdentifiableElement) content).getIdentifier();
				if (identifier.equals(identifierFromResource)) {
					EObject sourceElement = associations.getPrimarySourceElement(content);
					return sourceElement;
				}
			}
		}
	}
	return super.findEObjectByURI(uri, resource);
}
 
Example #15
Source File: SARLImportedNamespaceScopeProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
private void doGetAllDescriptions(JvmDeclaredType type, List<IEObjectDescription> descriptions) {
	descriptions.add(EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(type.getIdentifier()), type));
	final EList<JvmMember> members;
	if (type instanceof JvmDeclaredTypeImplCustom) {
		members = ((JvmDeclaredTypeImplCustom) type).basicGetMembers();
	} else {
		members = type.getMembers();
	}
	for (final JvmMember member: members) {
		if (member instanceof JvmDeclaredType) {
			// add nested types also with the dot delimiter
			descriptions.add(EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(
					member.getQualifiedName('.')), member));
			doGetAllDescriptions((JvmDeclaredType) member, descriptions);
		}
	}
}
 
Example #16
Source File: ImportedTypesCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void acceptType(JvmType type, JvmType usedType, ITextRegion refRegion) {
	JvmMember currentContext = getCurrentContext();
	if (currentContext == null) {
		return;
	}
	if (type == null || type.eIsProxy()) {
		throw new IllegalArgumentException();
	}
	if (type instanceof JvmDeclaredType && !isIgnored(type, refRegion)) {
		getTypeUsages().addTypeUsage((JvmDeclaredType) type, (JvmDeclaredType) usedType, refRegion, currentContext);
	}
}
 
Example #17
Source File: InferredJvmModelTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testInferredJvmConstructor() throws Exception {
	XtendFile xtendFile = file("class Foo { }");
	JvmGenericType inferredType = getInferredType(xtendFile);
	XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
	assertEquals(1, inferredType.getMembers().size());
	JvmMember inferredFirstMember = inferredType.getMembers().get(0);
	assertTrue(inferredFirstMember instanceof JvmConstructor);
	assertEquals(JvmVisibility.PUBLIC, inferredFirstMember.getVisibility());
	assertEquals(associations.getInferredConstructor(xtendClass), inferredFirstMember);
}
 
Example #18
Source File: DefaultFeatureCallValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
private boolean isPrivateAPICaller(JvmIdentifiableElement element) {
	JvmMember featureContainer = EcoreUtil2.getContainerOfType(element, JvmMember.class);
	while (featureContainer != null) {
		if (this.annotations.findAnnotation(featureContainer, PrivateAPI.class.getName()) != null) {
			return true;
		}
		featureContainer = EcoreUtil2.getContainerOfType(featureContainer.eContainer(), JvmMember.class);
	}
	return false;
}
 
Example #19
Source File: JvmDeclaredTypeImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case TypesPackage.JVM_DECLARED_TYPE__ARRAY_TYPE:
			setArrayType((JvmArrayType)newValue);
			return;
		case TypesPackage.JVM_DECLARED_TYPE__SUPER_TYPES:
			getSuperTypes().clear();
			getSuperTypes().addAll((Collection<? extends JvmTypeReference>)newValue);
			return;
		case TypesPackage.JVM_DECLARED_TYPE__MEMBERS:
			getMembers().clear();
			getMembers().addAll((Collection<? extends JvmMember>)newValue);
			return;
		case TypesPackage.JVM_DECLARED_TYPE__ABSTRACT:
			setAbstract((Boolean)newValue);
			return;
		case TypesPackage.JVM_DECLARED_TYPE__STATIC:
			setStatic((Boolean)newValue);
			return;
		case TypesPackage.JVM_DECLARED_TYPE__FINAL:
			setFinal((Boolean)newValue);
			return;
		case TypesPackage.JVM_DECLARED_TYPE__PACKAGE_NAME:
			setPackageName((String)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #20
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void doTestInnerType_WrappedIterator_03(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() == 4;
				}
			});
	assertNotNull(constructor);
	JvmFormalParameter firstParameter = constructor.getParameters().get(0);
	assertEquals(0, firstParameter.getAnnotations().size());
	assertEquals("int", firstParameter.getParameterType().getIdentifier());
	JvmFormalParameter secondParameter = constructor.getParameters().get(1);
	assertEquals(1, secondParameter.getAnnotations().size());
	assertEquals("java.lang.String", secondParameter.getParameterType().getIdentifier());
	assertEquals(TestAnnotationWithDefaults.class.getName(),
			secondParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
	JvmFormalParameter thirdParameter = constructor.getParameters().get(2);
	assertEquals(0, thirdParameter.getAnnotations().size());
	assertEquals("int", thirdParameter.getParameterType().getIdentifier());
	JvmFormalParameter forthParameter = constructor.getParameters().get(3);
	assertEquals(1, forthParameter.getAnnotations().size());
	assertEquals("java.lang.String", forthParameter.getParameterType().getIdentifier());
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			forthParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
}
 
Example #21
Source File: NonOverridableTypesProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void addInnerTypes(
		JvmDeclaredType type,
		String prefix,
		IVisibilityHelper visibilityHelper,
		Map<String, JvmIdentifiableElement> result) {
	for (JvmMember member : type.getMembers()) {
		if (member instanceof JvmDeclaredType && visibilityHelper.isVisible(member)) {
			String localName = prefix + member.getSimpleName();
			if (!result.containsKey(localName)) {
				result.put(localName, member);
			}
			addInnerTypes((JvmDeclaredType) member, prefix + member.getSimpleName() + ".", visibilityHelper, result);
		}
	}
}
 
Example #22
Source File: TypeUsages.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void addTypeUsage(
		JvmDeclaredType typeToImport,
		JvmDeclaredType usedType,
		ITextRegion textRegion,
		JvmMember context) {
	simpleName2types.put(typeToImport.getSimpleName(), typeToImport);
	types2usages.put(typeToImport, new TypeUsage(usedType, textRegion, context));
}
 
Example #23
Source File: JavaElementFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
public IJavaElement getDeclaringTypeElement(JvmMember object) {
	if (object.getDeclaringType() != null) {
		IJavaElement typeElement = doSwitch(object.getDeclaringType());
		return typeElement;
	} 
	return null;
}
 
Example #24
Source File: BatchLinkableResource.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Recursively traverse the types in this resource to mark them as lazy initialized types. 
 */
private void markPendingInitialization(JvmDeclaredTypeImplCustom type) {
	type.setPendingInitialization(true);
	for (JvmMember member : type.basicGetMembers()) {
		if (member instanceof JvmDeclaredTypeImplCustom) {
			markPendingInitialization((JvmDeclaredTypeImplCustom) member);
		}
	}
}
 
Example #25
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String enrichWithDeclarator(String signature, EObject o) {
	if(o instanceof JvmMember && ((JvmMember) o).getDeclaringType() != null){
		String parentsName = getDeclaratorName((JvmMember) o);
		return parentsName + "." + signature;
	}
	return signature;
}
 
Example #26
Source File: MutableJvmAnnotationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends MutableAnnotationTypeElementDeclaration> getDeclaredAnnotationTypeElements() {
  final Function1<JvmMember, MemberDeclaration> _function = (JvmMember it) -> {
    return this.getCompilationUnit().toMemberDeclaration(it);
  };
  return Iterables.<MutableAnnotationTypeElementDeclaration>filter(ListExtensions.<JvmMember, MemberDeclaration>map(this.getDelegate().getMembers(), _function), MutableAnnotationTypeElementDeclaration.class);
}
 
Example #27
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void doTestInnerType_WrappedIterator_03(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() == 4;
				}
			});
	assertNotNull(constructor);
	JvmFormalParameter firstParameter = constructor.getParameters().get(0);
	assertEquals(0, firstParameter.getAnnotations().size());
	assertEquals("int", firstParameter.getParameterType().getIdentifier());
	JvmFormalParameter secondParameter = constructor.getParameters().get(1);
	assertEquals(1, secondParameter.getAnnotations().size());
	assertEquals("java.lang.String", secondParameter.getParameterType().getIdentifier());
	assertEquals(TestAnnotationWithDefaults.class.getName(),
			secondParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
	JvmFormalParameter thirdParameter = constructor.getParameters().get(2);
	assertEquals(0, thirdParameter.getAnnotations().size());
	assertEquals("int", thirdParameter.getParameterType().getIdentifier());
	JvmFormalParameter forthParameter = constructor.getParameters().get(3);
	assertEquals(1, forthParameter.getAnnotations().size());
	assertEquals("java.lang.String", forthParameter.getParameterType().getIdentifier());
	assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
			forthParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
}
 
Example #28
Source File: CachingResourceValidatorImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void addWarningForOrphanedJvmElement(final Resource resource, final JvmMember jvmElement, final Severity severity, final IAcceptor<Issue> acceptor) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("The generated ");
  String _uiString = this.getUiString(jvmElement);
  _builder.append(_uiString);
  _builder.append(" is not associated with a source element. The producing active annotation should use \'setPrimarySourceElement\'.");
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  this.issueFromXtextResourceDiagnostic(new DiagnosticOnFirstKeyword(severity, 
    IssueCodes.ORPHAN_ELEMENT, _builder.toString(), _head, 
    null), severity, acceptor);
}
 
Example #29
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public NamedElement toNamedElement(final JvmIdentifiableElement delegate) {
  final Function1<JvmIdentifiableElement, Declaration> _function = (JvmIdentifiableElement it) -> {
    Declaration _switchResult = null;
    boolean _matched = false;
    if (delegate instanceof JvmMember) {
      _matched=true;
      _switchResult = this.toMemberDeclaration(((JvmMember)delegate));
    }
    if (!_matched) {
      if (delegate instanceof JvmTypeParameter) {
        _matched=true;
        _switchResult = this.toTypeParameterDeclaration(((JvmTypeParameter)delegate));
      }
    }
    if (!_matched) {
      if (delegate instanceof JvmFormalParameter) {
        _matched=true;
        _switchResult = this.toParameterDeclaration(((JvmFormalParameter)delegate));
      }
    }
    if (!_matched) {
      throw new UnsupportedOperationException((("Couldn\'t translate \'" + delegate) + "\'"));
    }
    return _switchResult;
  };
  return this.<JvmIdentifiableElement, Declaration>getOrCreate(delegate, _function);
}
 
Example #30
Source File: JvmTypesBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void setCompilationStrategy(/* @Nullable */ JvmMember member, /* @Nullable */ Procedures.Procedure1<ITreeAppendable> strategy) {
	if(member == null || strategy == null)
		return;
	CompilationStrategyAdapter adapter = new CompilationStrategyAdapter();
	adapter.setCompilationStrategy(strategy);
	member.eAdapters().add(adapter);
}