Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#getSuperTypes()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#getSuperTypes() . 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: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void addConstructorCandidates(ResolvedFeatures resolvedFeatures, IVisibilityHelper visibilityHelper,
		List<IResolvedExecutable> result) {
	LightweightTypeReference typeReference = resolvedFeatures.getType();
	List<LightweightTypeReference> superTypes = typeReference.getSuperTypes();
	for (LightweightTypeReference superType : superTypes) {
		if (!superType.isInterfaceType()) {
			List<IResolvedConstructor> declaredConstructors = resolvedFeatures.getDeclaredConstructors();
			Set<String> erasedSignatures = Sets.<String>newHashSet();
			for (IResolvedConstructor constructor : declaredConstructors) {
				erasedSignatures.add(constructor.getResolvedErasureSignature());
			}
			ResolvedFeatures superClass = overrideHelper.getResolvedFeatures(superType);
			for (IResolvedConstructor superclassConstructor : superClass.getDeclaredConstructors()) {
				IResolvedConstructor overriddenConstructor = new ResolvedConstructor(
						superclassConstructor.getDeclaration(), typeReference);
				if (isCandidate(typeReference, overriddenConstructor, visibilityHelper)) {
					if (erasedSignatures.add(superclassConstructor.getResolvedErasureSignature())) {
						result.add(overriddenConstructor);
					}
				}
			}
			return;
		}
	}
}
 
Example 2
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 3
Source File: SARLCodeMiningProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the inferred type for the given expression.
 *
 * @param expr the expression.
 * @return the type of the expression.
 */
protected LightweightTypeReference getLightweightType(XExpression expr) {
	final IResolvedTypes resolvedTypes = getResolvedTypes(expr);
	final LightweightTypeReference expressionType = resolvedTypes.getActualType(expr);
	if (expr instanceof AnonymousClass) {
		final List<LightweightTypeReference> superTypes = expressionType.getSuperTypes();
		if (superTypes.size() == 1) {
			return superTypes.get(0);
		}
	}
	return expressionType;
}
 
Example 4
Source File: SuperTypesTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<LightweightTypeReference> collectSuperTypes(final LightweightTypeReference reference) {
  return reference.getSuperTypes();
}