use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method getResourceTypeScope.
private AbstractScope getResourceTypeScope(Resource resource, String packageName, AbstractScope parent) {
List<EObject> contents = resource.getContents();
List<JvmType> knownTypes = Lists.newArrayListWithExpectedSize(contents.size() - 1);
for (EObject content : contents) {
if (content instanceof JvmType) {
if (content instanceof JvmDeclaredType) {
if (Strings.equal(packageName, ((JvmDeclaredType) content).getPackageName())) {
knownTypes.add((JvmType) content);
}
} else {
knownTypes.add((JvmType) content);
}
}
}
if (knownTypes.isEmpty())
return parent;
return new KnownTypesScope(knownTypes, parent);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method doGetAllDescriptions.
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);
}
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method doPrepareLocalTypes.
protected void doPrepareLocalTypes(final ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmFeature container, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
List<JvmGenericType> localClasses = container.getLocalClasses();
for (final JvmGenericType localClass : localClasses) {
JvmTypeReference superType = localClass.getSuperTypes().get(0);
final IFeatureScopeSession nestedSession = featureScopeSession;
if (InferredTypeIndicator.isInferred(superType)) {
final XComputedTypeReference casted = (XComputedTypeReference) superType;
InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression();
XConstructorCall constructorCall = anonymousClass.getConstructorCall();
IScope typeScope = featureScopeSession.getScope(constructorCall, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
final JvmDeclaredType type = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
if (type == null) {
JvmUnknownTypeReference superTypeReference = TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {
@Override
public void accept(JvmTypeReference capturingTypeReference) {
casted.setEquivalent(capturingTypeReference);
inferAnonymousClassConstructor(anonymousClass, localClass);
}
});
} else {
final JvmParameterizedTypeReference superTypeReference = createSuperTypeReference(type, constructorCall);
requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {
@Override
@SuppressWarnings("deprecation")
public void accept(JvmTypeReference capturingTypeReference) {
casted.setEquivalent(capturingTypeReference);
IFeatureScopeSession mySession = addThisAndSuper(nestedSession, resolvedTypes.getReferenceOwner(), localClass, superTypeReference, false);
if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) type).isInterface()) {
localClass.getSuperTypes().add(0, typesBuilder.newTypeRef(localClass, Object.class));
inferAnonymousClassConstructor(anonymousClass, localClass);
} else {
for (JvmMember superMember : type.getMembers()) {
if (superMember instanceof JvmConstructor) {
JvmConstructor superTypeConstructor = (JvmConstructor) superMember;
boolean visible = mySession.isVisible(superTypeConstructor);
inferAnonymousClassConstructor(anonymousClass, localClass, superTypeConstructor, visible);
}
}
}
}
});
}
}
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendValidator method contributesToConflict.
/**
* Determine whether the given type contributes to the conflict caused by the given default interface implementation.
*/
private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) {
Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet();
involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType());
for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) {
involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType());
}
RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>();
if (rootType.isInterface()) {
int contributingCount = 0;
for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) {
JvmType rawType = typeRef.getType();
if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) {
contributingCount++;
}
}
return contributingCount >= 2;
} else {
return contributesToConflict(rootType, involvedInterfaces, recursionGuard);
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendValidator method hasCycleInHierarchy.
protected boolean hasCycleInHierarchy(JvmGenericType type, Set<JvmGenericType> processedSuperTypes) {
JvmDeclaredType container = type;
do {
if (processedSuperTypes.contains(container))
return true;
container = container.getDeclaringType();
} while (container != null);
processedSuperTypes.add(type);
for (JvmTypeReference superTypeRef : type.getSuperTypes()) {
if (superTypeRef.getType() instanceof JvmGenericType) {
if (hasCycleInHierarchy((JvmGenericType) superTypeRef.getType(), processedSuperTypes))
return true;
}
}
processedSuperTypes.remove(type);
return false;
}
Aggregations