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

The following examples show how to use org.eclipse.xtext.common.types.JvmDeclaredType#findAllFeaturesByName() . 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: AbstractResolvedOperation.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<JvmOperation> getOverriddenAndImplementedMethodCandidates() {
	if (overrideCandidates != null)
		return overrideCandidates;
	// here we are only interested in the raw type thus the declarator is not substituted
	// the found operation will be put in the right context by clients, e.g. #getOverriddenAndImplementedMethods
	ParameterizedTypeReference currentDeclarator = getContextType().getOwner().newParameterizedTypeReference(getDeclaration().getDeclaringType());
	List<LightweightTypeReference> superTypes = currentDeclarator.getSuperTypes();
	List<JvmOperation> result = Lists.newArrayListWithCapacity(5);
	for(LightweightTypeReference superType: superTypes) {
		if (superType.getType() instanceof JvmDeclaredType) {
			JvmDeclaredType declaredSuperType = (JvmDeclaredType) superType.getType();
			if (declaredSuperType != null) {
				Iterable<JvmFeature> equallyNamedFeatures = declaredSuperType.findAllFeaturesByName(getDeclaration().getSimpleName());
				for(JvmFeature equallyNamedFeature: equallyNamedFeatures) {
					if (equallyNamedFeature instanceof JvmOperation) {
						result.add((JvmOperation) equallyNamedFeature);
					}
				}
			}
		}
	}
	return overrideCandidates = Collections.unmodifiableList(result);
}
 
Example 2
Source File: RawResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void computeAllFeatures(
		JvmDeclaredType type,
		String name,
		Multimap<String, AbstractResolvedOperation> processedOperations,
		Set<String> processedFields,
		List<JvmFeature> result) {
	Iterable<JvmFeature> features = type.findAllFeaturesByName(name);
	for(JvmFeature feature: features) {
		if (feature instanceof JvmOperation) {
			JvmOperation operation = (JvmOperation) feature;
			String simpleName = operation.getSimpleName();
			if (processedOperations.containsKey(simpleName)) {
				if (isOverridden(operation, processedOperations.get(simpleName))) {
					continue;
				}
			}
			BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
			processedOperations.put(simpleName, resolvedOperation);
			result.add(operation);	
		} else if (feature instanceof JvmField && processedFields.add(feature.getSimpleName())) {
			result.add(feature);
		}
	}
}
 
Example 3
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug470767() {
	String typeName = Bug470767.class.getName();
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	diagnose(type);
	diagnose(type);
	Resource resource = type.eResource();
	getAndResolveAllFragments(resource);
	recomputeAndCheckIdentifiers(resource);
	Iterable<JvmFeature> methods = type.findAllFeaturesByName("paramIsAnnotated");
	JvmOperation method = (JvmOperation) Iterables.getOnlyElement(methods);
	JvmTypeReference paramType = method.getParameters().get(0).getParameterType();
	assertEquals("int", paramType.getSimpleName());
}
 
Example 4
Source File: OverrideHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmOperation findOverriddenOperation(JvmOperation operation, LightweightTypeReference declaringType,
		TypeParameterSubstitutor<?> substitutor, ITypeReferenceOwner owner, IVisibilityHelper visibilityHelper) {
	int parameterSize = operation.getParameters().size();
	List<LightweightTypeReference> superTypes = declaringType.getSuperTypes();
	for(LightweightTypeReference superType: superTypes) {
		if (superType.getType() instanceof JvmDeclaredType) {
			JvmDeclaredType declaredSuperType = (JvmDeclaredType) superType.getType();
			if (declaredSuperType != null) {
				Iterable<JvmFeature> equallyNamedFeatures = declaredSuperType.findAllFeaturesByName(operation.getSimpleName());
				for(JvmFeature feature: equallyNamedFeatures) {
					if (feature instanceof JvmOperation) {
						JvmOperation candidate = (JvmOperation) feature;
						if (parameterSize == candidate.getParameters().size()) {
							if (visibilityHelper.isVisible(feature)) {
								boolean matchesSignature = true;
								for(int i = 0; i < parameterSize && matchesSignature; i++) {
									JvmFormalParameter parameter = operation.getParameters().get(i);
									JvmFormalParameter candidateParameter = candidate.getParameters().get(i);
									matchesSignature = isMatchesSignature(parameter, candidateParameter, substitutor, owner);
								}
								if (matchesSignature) {
									return candidate;
								}
							}
						}
					}
				}
			}
		}
	}
	return null;
}
 
Example 5
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug470767() {
	String typeName = Bug470767.class.getName();
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	diagnose(type);
	diagnose(type);
	Resource resource = type.eResource();
	getAndResolveAllFragments(resource);
	recomputeAndCheckIdentifiers(resource);
	Iterable<JvmFeature> methods = type.findAllFeaturesByName("paramIsAnnotated");
	JvmOperation method = (JvmOperation) Iterables.getOnlyElement(methods);
	JvmTypeReference paramType = method.getParameters().get(0).getParameterType();
	assertEquals("int", paramType.getSimpleName());
}
 
Example 6
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug470767() {
	String typeName = Bug470767.class.getName();
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	diagnose(type);
	diagnose(type);
	Resource resource = type.eResource();
	getAndResolveAllFragments(resource);
	recomputeAndCheckIdentifiers(resource);
	Iterable<JvmFeature> methods = type.findAllFeaturesByName("paramIsAnnotated");
	JvmOperation method = (JvmOperation) Iterables.getOnlyElement(methods);
	JvmTypeReference paramType = method.getParameters().get(0).getParameterType();
	assertEquals("int", paramType.getSimpleName());
}
 
Example 7
Source File: XbaseQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void replaceOperator(XBinaryOperation operation, QualifiedName from, QualifiedName to) {
	JvmIdentifiableElement feature = operation.getFeature();
	String fromMethodName = operatorMapping.getMethodName(from).toString();
	if (fromMethodName.equals(feature.getSimpleName())) {
		JvmDeclaredType declaringType = ((JvmOperation) feature).getDeclaringType();
		String toMethodName = operatorMapping.getMethodName(to).toString();
		for (JvmFeature f : declaringType.findAllFeaturesByName(toMethodName)) {
			if (f instanceof JvmOperation) {
				operation.setFeature(f);
				break;
			}
		}
	}
}
 
Example 8
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public JvmOperation getDispatcherOperation(JvmDeclaredType type, DispatchSignature signature) {
	Iterable<JvmFeature> allByName = type.findAllFeaturesByName(signature.getSimpleName());
	for(JvmFeature feature: allByName) {
		if (feature instanceof JvmOperation && signature.getArity() == ((JvmOperation) feature).getParameters().size()) {
			return (JvmOperation) feature;
		}
	}
	return null;
}
 
Example 9
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected List<JvmOperation> getAllDispatchMethods(DispatchSignature signature, JvmDeclaredType type,
		ContextualVisibilityHelper contextualVisibilityHelper) {
	List<JvmOperation> allOperations = Lists.newArrayListWithExpectedSize(5);
	Iterable<JvmFeature> allFeatures = type.findAllFeaturesByName(signature.getDispatchCaseName());
	for(JvmFeature feature: allFeatures) {
		if (feature instanceof JvmOperation) {
			JvmOperation operationByName = (JvmOperation) feature;
			if (signature.isDispatchCase(operationByName) && contextualVisibilityHelper.isVisible(operationByName)) {
				allOperations.add(operationByName);
			}
		}
	}
	sort(allOperations);
	return allOperations;
}