Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType#findAllNestedTypesByName()

The following examples show how to use org.eclipse.xtext.common.types.JvmDeclaredType#findAllNestedTypesByName() . 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: NestedTypesScope.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected IEObjectDescription doGetSingleElement(JvmDeclaredType declarator, QualifiedName name, String firstSegment, int dollarIndex) {
	if (declarator.isLocal()) {
		JvmTypeReference superTypeReference = Iterables.getLast(declarator.getSuperTypes());
		if (InferredTypeIndicator.isInferred(superTypeReference))
			return findNestedTypeInLocalTypeNonResolving(declarator, name, firstSegment, dollarIndex);
	}
	
	Iterable<JvmDeclaredType> nestedTypes = declarator.findAllNestedTypesByName(firstSegment);
	for(JvmDeclaredType nested: nestedTypes) {
		JvmType nestedType = findNestedType(nested, 0, name);
		if (nestedType != null) {
			return toDescription(name, nestedType, dollarIndex, 0);
		}
	}
	return null;
}
 
Example 2
Source File: NestedTypesScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
	List<JvmDeclaredType> nestedTypeDeclarators = session.getNestedTypeDeclarators();
	if (nestedTypeDeclarators.isEmpty())
		return Collections.emptyList();
	Iterator<JvmDeclaredType> iterator = nestedTypeDeclarators.iterator();
	String simpleName = name.getFirstSegment();
	List<IEObjectDescription> result = null;
	if (name.getSegmentCount() == 1) {
		Set<JvmDeclaredType> nestedTypesSet = new LinkedHashSet<>();
		while(iterator.hasNext()) {
			JvmDeclaredType declarator = iterator.next();
			Iterable<JvmDeclaredType> nestedTypes = declarator.findAllNestedTypesByName(simpleName);
			CollectionExtensions.addAll(nestedTypesSet, nestedTypes);
		}
		if (!nestedTypesSet.isEmpty()) {
			result = addDescriptions(name, 0, nestedTypesSet, result);
		}
	}
	if (result == null && name.getSegmentCount() == 1 && simpleName.indexOf('$') > 0) {
		QualifiedName splitted = QualifiedName.create(Strings.split(simpleName, '$'));
		return getLocalElementsByName(splitted);
	}
	if (result != null)
		return result;
	return Collections.emptyList();
}
 
Example 3
Source File: AbstractJvmTypeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmType findNestedType(JvmDeclaredType outer, List<String> segments, int i) {
	Iterable<JvmDeclaredType> nestedTypesByName = outer.findAllNestedTypesByName(segments.get(i));
	for(JvmDeclaredType nestedType: nestedTypesByName) {
		if (i == segments.size() - 1) {
			return nestedType;
		}
		JvmType result = findNestedType(nestedType, segments, i + 1);
		if (result != null) {
			return result;
		}
	}
	return null;
}