Java Code Examples for org.eclipse.xtext.common.types.JvmType#eContainer()

The following examples show how to use org.eclipse.xtext.common.types.JvmType#eContainer() . 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: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected int doIsConformantOuter(LightweightTypeReference left, LightweightTypeReference right, int nestedResult, int flags) {
	if ((nestedResult & SUCCESS) != 0) {
		JvmType leftType = left.getType();
		EObject leftDeclarator = leftType.eContainer();
		if (leftDeclarator instanceof JvmDeclaredType) {
			JvmDeclaredType castedLeftDeclarator = (JvmDeclaredType) leftDeclarator;
			LightweightTypeReference leftOuter = left.getOuter().getSuperType(castedLeftDeclarator);
			if (leftOuter != null) {
				LightweightTypeReference rightOuter = right.getOuter().getSuperType(castedLeftDeclarator);
				if (rightOuter != null) {
					int outerResult = doIsConformant(leftOuter, rightOuter, flags);
					if ((outerResult & SUCCESS) == 0) {
						return outerResult;
					}
				}
			}
		}
	}
	return nestedResult;
}
 
Example 2
Source File: ParameterizedTypeReference.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public ParameterizedTypeReference(ITypeReferenceOwner owner, JvmType type) {
	super(owner);
	if (type == null) {
		throw new NullPointerException("type may not be null");
	}
	if (type instanceof JvmArrayType) {
		throw new IllegalArgumentException("type may not be an array type");
	}
	if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
		EObject container = type.eContainer();
		if (container instanceof JvmDeclaredType) {
			checkStaticFlag((JvmDeclaredType)type);
		}
	}
	this.type = type;
	this.resolved = !(type instanceof JvmTypeParameter);
}
 
Example 3
Source File: ParameterizedTypeReference.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isInner(JvmType type) {
	if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
		if (type.eContainer() instanceof JvmDeclaredType) {
			return !((JvmGenericType) type).isStatic();
		}
	}
	return false;
}
 
Example 4
Source File: LightweightTypeReferenceFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isInner(JvmType type) {
	if (type != null && type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
		if (type.eContainer() instanceof JvmDeclaredType) {
			return !((JvmGenericType) type).isStatic();
		}
	}
	return false;
}
 
Example 5
Source File: TypeScopeWithWildcardImports.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
	if (!(type instanceof JvmDeclaredType)) {
		return;
	}
	JvmDeclaredType declaredType = (JvmDeclaredType) type;
	String packageName = declaredType.getPackageName();
	if (!Strings.isEmpty(packageName)) {
		QualifiedName qualifiedPackageName = QualifiedName.create(Strings.split(packageName, '.'));
		QualifiedName withDot = null;
		String withDollar = null; 
		for(int i = 0; i < imports.length; i++) {
			ImportNormalizer[] chunk = imports[i];
			for(int j = 0; j < chunk.length; j++) {
				ImportNormalizer normalizer = chunk[j];
				QualifiedName namespacePrefix = normalizer.getImportedNamespacePrefix();
				if (namespacePrefix.equals(qualifiedPackageName)) {
					if (withDot == null) {
						withDot = QualifiedName.create(Strings.split(type.getQualifiedName('.'), '.'));
						withDollar = type.eContainer() instanceof JvmType ? type.getQualifiedName('$').substring(packageName.length() + 1) : null;
					}
					result.add(EObjectDescription.create(withDot.skipFirst(qualifiedPackageName.getSegmentCount()), type));
					if (withDollar != null) {
						result.add(EObjectDescription.create(withDollar, type));	
					}
				}
			}
		}
	}
	if (parent != null) {
		parent.doGetElements(type, result);
	} else {
		Iterables.addAll(result, typeScope.getElements(type));
	}
}
 
Example 6
Source File: KnownTypesScope.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doGetDescriptions(JvmType type, JvmType knownType, int index, List<IEObjectDescription> result) {
	if (type == knownType) {
		result.add(EObjectDescription.create(QualifiedName.create(type.getSimpleName()), type));
	} else if (type.eContainer() == knownType) {
		result.add(EObjectDescription.create(QualifiedName.create(knownType.getSimpleName(), type.getSimpleName()), type));
		result.add(EObjectDescription.create(QualifiedName.create(knownType.getSimpleName() + '$' + type.getSimpleName()), type));
	} else {
		String knownTypeName = knownType.getQualifiedName();
		String withDollar = type.getQualifiedName('$');
		String withDot = type.getQualifiedName('.');
		result.add(EObjectDescription.create(QualifiedName.create(Strings.split(withDot.substring(knownTypeName.length()), '.')), type));
		result.add(EObjectDescription.create(QualifiedName.create(withDollar.substring(knownTypeName.length())), type));
	}
}
 
Example 7
Source File: LegacyKnownTypesScope.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected JvmType findNestedType(JvmType result, int index, QualifiedName name) {
	if (result.eContainer() instanceof JvmDeclaredType && name.getSegmentCount() == 1) {
		QualifiedName importName = importNames.get(index);
		if (importName != null && importName.getLastSegment().equals(name.getFirstSegment())) {
			return result;
		}
	}
	return super.findNestedType(result, index, name);
}
 
Example 8
Source File: FeatureScopeSessionWithContext.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean isVisible(JvmMember member, /* @Nullable */ LightweightTypeReference receiverType, /* @Nullable */ JvmIdentifiableElement receiverFeature) {
	boolean result = isVisible(member);
	if (result && JvmVisibility.PROTECTED == member.getVisibility()) {
		if (receiverFeature != null) {
			// We bypass this check for qualified.this and qualified.super in the scope provider
			// they are considered to be always visible
			/*
			 * class A {
			 *   class B {
			 *     {
			 *       A.super.toString
			 *     }
			 *   }
			 * }
			 */
			if (isThisSuperOrTypeLiteral(receiverFeature)) {
				if (receiverType == null || !receiverType.isType(Class.class)) {
					return true;
				}
			}
		}
		JvmType contextType = visibilityHelper.getRawContextType();
		if (contextType instanceof JvmDeclaredType) {
			String packageName = visibilityHelper.getPackageName();
			JvmDeclaredType declaringType = member.getDeclaringType();
			String memberPackageName = declaringType.getPackageName();
			if (Strings.equal(packageName, memberPackageName)) {
				return true;
			}
		}
		if (receiverType != null) {
			if (receiverType.isSubtypeOf(contextType)) {
				return true;
			}
			EObject container = contextType.eContainer();
			while (container instanceof JvmType) {
				if (receiverType.isSubtypeOf((JvmType)container)) {
					return true;
				}
				container = container.eContainer();
			}
		}
		return false;
	}
	return result;
}