Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType#getMembers()
The following examples show how to use
org.eclipse.xtext.common.types.JvmDeclaredType#getMembers() .
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: JvmDeclaredTypeSignatureHashProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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; }
Example 2
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void createMethods(Class<?> clazz, JvmDeclaredType result) { try { Method[] declaredMethods = clazz.getDeclaredMethods(); if (declaredMethods.length != 0) { boolean intf = clazz.isInterface() && !clazz.isAnnotation(); InternalEList<JvmMember> members = (InternalEList<JvmMember>)result.getMembers(); for (Method method : declaredMethods) { if (!method.isSynthetic()) { JvmOperation operation = createOperation(method); if (clazz.isAnnotation()) { setDefaultValue(operation, method); } else if (intf && !operation.isAbstract() && !operation.isStatic()) { operation.setDefault(true); } members.addUnique(operation); } } } } catch (NoClassDefFoundError e) { logNoClassDefFoundError(e, clazz, "methods"); } }
Example 3
Source File: NestedTypesScope.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
/** * We have to be careful to keep the unresolved super type of a local type which may depend on type resolution. * Therefore these types are treated differently from other types. */ protected IEObjectDescription findNestedTypeInLocalTypeNonResolving(JvmDeclaredType localType, QualifiedName name, String firstSegment, int dollarIndex) { List<JvmMember> members = localType.getMembers(); for(int i = 0; i < members.size(); i++) { JvmMember member = members.get(i); if (member instanceof JvmDeclaredType) { JvmDeclaredType nestedType = (JvmDeclaredType) member; if (firstSegment.equals(nestedType.getSimpleName())) { JvmType candidate = findNestedType(nestedType, 0, name); if (candidate != null) { return toDescription(name, candidate, dollarIndex, 0); } } } } JvmDeclaredType superType = typeScopeProvider.getSuperTypeOfLocalTypeNonResolving(localType); if (superType == null) { return null; } return doGetSingleElement(superType, name, firstSegment, dollarIndex); }
Example 4
Source File: XtendImportedNamespaceScopeProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private void doGetAllDescriptions(JvmDeclaredType type, List<IEObjectDescription> descriptions) { descriptions.add(EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(type.getIdentifier()), type)); EList<JvmMember> members = null; if (type instanceof JvmDeclaredTypeImplCustom) { members = ((JvmDeclaredTypeImplCustom)type).basicGetMembers(); } else { members = type.getMembers(); } for(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 5
Source File: SARLOutlineTreeProvider.java From sarl with Apache License 2.0 | 5 votes |
private static JvmOperation findMethod(JvmDeclaredType container, String name) { for (final JvmMember member : container.getMembers()) { if (member instanceof JvmOperation) { final JvmOperation operation = (JvmOperation) member; if (Objects.equal(name, operation.getSimpleName())) { return operation; } } } return null; }
Example 6
Source File: AbstractXtendOutlineTreeBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void buildMembers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, @Extension final IXtendOutlineContext context) { EList<JvmMember> _members = inferredType.getMembers(); for (final JvmMember member : _members) { boolean _isProcessed = context.isProcessed(member); boolean _not = (!_isProcessed); if (_not) { if ((member instanceof JvmDeclaredType)) { boolean _isShowInherited = context.isShowInherited(); if (_isShowInherited) { final IXtendOutlineContext typeContext = context.newContext(); final EObject sourceElement = this._iXtendJvmAssociations.getPrimarySourceElement(member); if ((sourceElement instanceof XtendTypeDeclaration)) { this.buildType(sourceElement, typeContext); } else { this.buildJvmType(((JvmDeclaredType)member), typeContext); } } else { this.buildJvmType(((JvmDeclaredType)member), context); } } else { if ((member instanceof JvmFeature)) { boolean _skipFeature = this.skipFeature(((JvmFeature)member)); boolean _not_1 = (!_skipFeature); if (_not_1) { final IXtendOutlineContext featureContext = this.buildFeature(baseType, ((JvmFeature)member), member, context); final Consumer<JvmGenericType> _function = (JvmGenericType it) -> { this.buildJvmType(it, featureContext.newContext()); }; ((JvmFeature)member).getLocalClasses().forEach(_function); } } } context.markAsProcessed(member); } } boolean _isShowInherited_1 = context.isShowInherited(); if (_isShowInherited_1) { this.buildInheritedMembers(inferredType, context); } }
Example 7
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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()); } }
Example 8
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void createConstructors(Class<?> clazz, JvmDeclaredType result) { try { Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors(); if (declaredConstructors.length != 0) { InternalEList<JvmMember> members = (InternalEList<JvmMember>)result.getMembers(); for (Constructor<?> constructor : declaredConstructors) { if (!constructor.isSynthetic()) { members.addUnique(createConstructor(constructor)); } } } } catch (NoClassDefFoundError e) { logNoClassDefFoundError(e, clazz, "constructors"); } }
Example 9
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void createFields(Class<?> clazz, JvmDeclaredType result) { try { Field[] declaredFields = clazz.getDeclaredFields(); if (declaredFields.length != 0) { InternalEList<JvmMember> members = (InternalEList<JvmMember>)result.getMembers(); for (Field field : declaredFields) { if (!field.isSynthetic()) { members.addUnique(createField(field)); } } } } catch (NoClassDefFoundError e) { logNoClassDefFoundError(e, clazz, "fields"); } }
Example 10
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void createNestedTypes(Class<?> clazz, JvmDeclaredType result) { try { Class<?>[] declaredClasses = clazz.getDeclaredClasses(); if (declaredClasses.length != 0) { InternalEList<JvmMember> members = (InternalEList<JvmMember>)result.getMembers(); for (Class<?> declaredClass : declaredClasses) { if (!declaredClass.isAnonymousClass() && !declaredClass.isSynthetic()) { members.addUnique(createType(declaredClass)); } } } } catch(NoClassDefFoundError e) { logNoClassDefFoundError(e, clazz, "nested types"); } }
Example 11
Source File: AbstractTypeProviderPerformanceTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmDeclaredType loadAndResolve(String name, boolean accessMembers, boolean accessAnnotations, boolean accessTypeParams, boolean accessParameter, boolean accessParameterNames) { JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(name); EcoreUtil.resolveAll(type.eResource()); EcoreUtil.resolveAll(type.eResource().getResourceSet()); Assert.assertNotNull(name, type); if (accessAnnotations) { type.getAnnotations(); } if (accessMembers) { EList<JvmMember> members = type.getMembers(); for (JvmMember member : members) { if (accessAnnotations) { member.getAnnotations(); } if (member instanceof JvmExecutable) { JvmExecutable operation = (JvmExecutable) member; if (accessParameter) { EList<JvmFormalParameter> parameters = operation.getParameters(); for (JvmFormalParameter jvmFormalParameter : parameters) { if (accessAnnotations) { jvmFormalParameter.getAnnotations(); } if (accessParameterNames) { jvmFormalParameter.getName(); } } } } } } return type; }
Example 12
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override @Test public void testDeprecatedBit_02() { String typeName = DeprecatedMembers.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertFalse(type.isSetDeprecated()); for(JvmMember member: type.getMembers()) { assertFalse(member.isSetDeprecated()); } }
Example 13
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override @Test public void testDeprecatedBit_01() { String typeName = org.eclipse.xtext.common.types.testSetups.DeprecatedClass.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertFalse(type.isSetDeprecated()); for(JvmMember member: type.getMembers()) { assertFalse(member.isSetDeprecated()); } }
Example 14
Source File: NonOverridableTypesProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 15
Source File: DefaultImportsConfiguration.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addInnerTypes(JvmDeclaredType containerType, IAcceptor<? super JvmDeclaredType> result) { for (JvmMember member : containerType.getMembers()) { if (member instanceof JvmDeclaredType) { result.accept((JvmDeclaredType) member); addInnerTypes((JvmDeclaredType) member, result); } } }
Example 16
Source File: NestedTypeLiteralScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmType findNestedType(JvmDeclaredType outerType, Iterator<String> iterator) { String current = iterator.next(); for(JvmMember member: outerType.getMembers()) { if (member instanceof JvmDeclaredType && member.getSimpleName().equals(current)) { if (iterator.hasNext()) { return findNestedType((JvmDeclaredType) member, iterator); } return (JvmDeclaredType) member; } } return null; }
Example 17
Source File: DispatchHelper.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * Return the local cases that match the given signature (in no particular order, usually as defined in the file). */ public List<JvmOperation> getLocalDispatchCases(JvmDeclaredType type, DispatchSignature signature) { List<JvmOperation> result = Lists.newArrayListWithExpectedSize(5); for(JvmMember feature: type.getMembers()) { if (feature instanceof JvmOperation && signature.isDispatchCase((JvmOperation) feature)) { result.add((JvmOperation) feature); } } return result; }
Example 18
Source File: LogicalContainerAwareReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void prepareMembers(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmDeclaredType type, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByType) { IFeatureScopeSession childSession = addExtensionsToMemberSession(resolvedTypes, featureScopeSession, type); StackedResolvedTypes childResolvedTypes = declareTypeParameters(resolvedTypes, type, resolvedTypesByType); JvmTypeReference superType = getExtendedClass(type); ITypeReferenceOwner referenceOwner = childResolvedTypes.getReferenceOwner(); if (superType != null) { LightweightTypeReference lightweightSuperType = referenceOwner.toLightweightTypeReference(superType); childResolvedTypes.reassignTypeWithoutMerge(superType.getType(), lightweightSuperType); /* * We use reassignType to make sure that the following works: * * StringList extends AbstractList<String> { * NestedIntList extends AbstractList<Integer> { * } * SubType extends StringList {} * } */ } LightweightTypeReference lightweightThisType = referenceOwner.toLightweightTypeReference(type); childResolvedTypes.reassignTypeWithoutMerge(type, lightweightThisType); List<JvmMember> members = type.getMembers(); int size = members.size(); for(int i = 0; i < size; i++) { doPrepare(childResolvedTypes, childSession, members.get(i), resolvedTypesByType); } }
Example 19
Source File: ConstantExpressionsInterpreter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void collect(final JvmDeclaredType type, final Set<JvmType> seen, final Map<String, JvmIdentifiableElement> result) { boolean _add = seen.add(type); if (_add) { EList<JvmMember> _members = type.getMembers(); for (final JvmMember member : _members) { if ((member instanceof JvmField)) { if ((((JvmField)member).isFinal() && ((JvmField)member).isStatic())) { final JvmIdentifiableElement existing = result.put(((JvmField)member).getSimpleName(), member); if ((existing != null)) { result.put(existing.getSimpleName(), existing); } } } } EList<JvmTypeReference> _superTypes = type.getSuperTypes(); for (final JvmTypeReference superType : _superTypes) { { JvmType _type = null; if (superType!=null) { _type=superType.getType(); } final JvmType rawSuperType = _type; if (((rawSuperType instanceof JvmDeclaredType) && (!rawSuperType.eIsProxy()))) { this.collect(((JvmDeclaredType) rawSuperType), seen, result); } } } } }
Example 20
Source File: RegisterGlobalsContextImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void setNameAndAccept(final JvmDeclaredType newType, final String qualifiedName) { ConditionUtils.checkQualifiedName(qualifiedName, "qualifiedName"); JvmDeclaredType _findType = this.findType(qualifiedName); boolean _tripleEquals = (_findType == null); StringConcatenation _builder = new StringConcatenation(); _builder.append("The type \'"); _builder.append(qualifiedName); _builder.append("\' has already been registered."); Preconditions.checkArgument(_tripleEquals, _builder); this.compilationUnit.checkCanceled(); final Pair<String, String> namespaceAndName = this.getNameParts(qualifiedName); final String headerText = this.compilationUnit.getFileHeaderProvider().getFileHeader(this.compilationUnit.getXtendFile().eResource()); this.compilationUnit.getJvmTypesBuilder().setFileHeader(newType, headerText); String _key = namespaceAndName.getKey(); boolean _tripleNotEquals = (_key != null); if (_tripleNotEquals) { final JvmDeclaredType parentType = this.findType(namespaceAndName.getKey()); if ((parentType != null)) { EList<JvmMember> _members = parentType.getMembers(); _members.add(newType); newType.setStatic(true); } else { newType.setPackageName(namespaceAndName.getKey()); this.acceptor.<JvmDeclaredType>accept(newType); } } else { this.acceptor.<JvmDeclaredType>accept(newType); } newType.setSimpleName(namespaceAndName.getValue()); }