Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType#getDeclaringType()
The following examples show how to use
org.eclipse.xtext.common.types.JvmDeclaredType#getDeclaringType() .
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: TypeLiteralLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected void preApply() { XAbstractFeatureCall expression = getExpression(); JvmType type = getType(); if (expression instanceof XMemberFeatureCall) { if (type instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) type; if (declaredType.getDeclaringType() == null) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } else { String queriedName = description.getName().toString(); // may be Map$Entry String qualifiedName = declaredType.getIdentifier(); String packageName = Strings.emptyIfNull(declaredType.getPackageName()); if (packageName.length() + 1 + queriedName.length() == qualifiedName.length()) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } } } } }
Example 2
Source File: ImportOrganizer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
private ReplaceRegion getReplaceRegion(String nameToUse, String packageLocalName, JvmDeclaredType type, TypeUsage usage, RewritableImportSection importSection) { // if the resource contains two types with the same simple name, we don't add any import // but we can still use the package local name within the same package. // Except for inner types if (equal(usage.getContextPackageName(), type.getPackageName()) && type.getDeclaringType() == null) { if (type.eContainer() != null) { String declarationLocalName = getLocalName(type, usage.getContext()); nameToUse = declarationLocalName; } else if (importSection.getImportedTypes(packageLocalName) == null) { nameToUse = packageLocalName; } } String textToUse = getConcreteSyntax(nameToUse, type, usage); return new ReplaceRegion(usage.getTextRegion(), textToUse); }
Example 3
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
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; }
Example 4
Source File: ResolvedTypeLiteral.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void preApply() { JvmType type = getType(); XAbstractFeatureCall expression = getExpression(); if (expression instanceof XMemberFeatureCall) { if (type instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) type; if (declaredType.getDeclaringType() == null) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } } } }
Example 5
Source File: ImportOrganizer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isUsedInLocalContextOnly(JvmDeclaredType type, Iterable<TypeUsage> usages, NonOverridableTypesProvider nonOverridableTypesProvider, String name) { for (TypeUsage usage : usages) { JvmIdentifiableElement visibleType = nonOverridableTypesProvider.getVisibleType(usage.getContext(), name); if (visibleType == null && ( !equal(usage.getContextPackageName(), type.getPackageName()) || (type.getDeclaringType() != null && usage.getContext().eResource() != type.getDeclaringType().eResource()) )) return false; } return true; }
Example 6
Source File: TypeUsageCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected PreferredType findPreferredType(JvmDeclaredType referencedType, String text) { if (referencedType != null && !referencedType.eIsProxy()) { if (referencedType.getDeclaringType() == null) { return new PreferredType(referencedType, referencedType); } String outerSegment = getFirstNameSegment(text); JvmType outerType = findDeclaringTypeBySimpleName(referencedType, outerSegment); if (outerType == null) { throw new IllegalStateException(); } return new PreferredType(outerType, referencedType); } String name = getFirstNameSegment(text); return new PreferredType(name); }
Example 7
Source File: ImportsCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _visit(final JvmDeclaredType jvmType, final INode originNode, final ImportsAcceptor acceptor) { JvmDeclaredType _declaringType = jvmType.getDeclaringType(); boolean _tripleEquals = (_declaringType == null); if (_tripleEquals) { this.collectTypeImportFrom(jvmType, acceptor); } final String text = NodeModelUtils.getTokenText(originNode); final String outerSegment = this.getFirstNameSegment(text); final JvmDeclaredType outerType = this.findDeclaringTypeBySimpleName(jvmType, outerSegment); if ((outerType == null)) { throw new IllegalStateException(); } this.collectTypeImportFrom(outerType, acceptor); }
Example 8
Source File: XbaseReferenceUpdater.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected String resolveNameConflict(EObject referringElement, EReference reference, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) { if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_IDENTIFIABLE_ELEMENT, reference.getEReferenceType())) { if (newTargetElement instanceof JvmType) { JvmType type = (JvmType) newTargetElement; if (canLinkJvmType(referringElement, type)) { return toString(qualifiedNameProvider.getFullyQualifiedName(type)); } } if (newTargetElement instanceof JvmFeature) { JvmFeature feature = (JvmFeature) newTargetElement; if (feature.isStatic() && !isStaticExtensionFeatureCall(referringElement, reference, newTargetElement)) { JvmDeclaredType declaringType = feature.getDeclaringType(); if (canLinkJvmType(referringElement, declaringType)) { JvmDeclaredType parentType = declaringType; List<String> segments = new LinkedList<String>(); segments.add(feature.getSimpleName()); segments.add(0, parentType.getSimpleName()); while (!hasImportedType(updateAcceptor, parentType)) { parentType = parentType.getDeclaringType(); if (parentType == null) { return toString(qualifiedNameProvider.getFullyQualifiedName(feature)); } segments.add(0, parentType.getSimpleName()); } return toString(QualifiedName.create(segments)); } } } } return super.resolveNameConflict(referringElement, reference, newTargetElement, updateAcceptor); }
Example 9
Source File: XbaseReferenceUpdater.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @return the currently imported type containing the newTargetType and the element's name relative to that import. */ protected Pair<JvmDeclaredType, QualifiedName> getImportedTypeAndRelativeName(JvmType newTargetType, RewritableImportSection section) { if (!(newTargetType instanceof JvmDeclaredType) || !section.isEnabled()) { return null; } JvmDeclaredType importedType = (JvmDeclaredType) newTargetType; StringBuffer relativeName = new StringBuffer(importedType.getSimpleName()); while(importedType.getDeclaringType() != null && !section.hasImportedType(importedType)) { importedType = importedType.getDeclaringType(); relativeName.insert(0, "."); relativeName.insert(0, importedType.getSimpleName()); } return Tuples.create(importedType, qualifiedNameConverter.toQualifiedName(relativeName.toString())); }
Example 10
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public boolean needsImport(JvmDeclaredType type) { if (type.getDeclaringType() != null) return true; String packageName = type.getPackageName(); return packageName != null && !(implicitlyImportedPackages.contains(packageName)); }
Example 11
Source File: TypeUsageCollector.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
private JvmDeclaredType findDeclaringTypeBySimpleName(JvmDeclaredType referencedType, String outerSegment) { if (referencedType.getDeclaringType() == null || outerSegment.equals(referencedType.getSimpleName())) { return referencedType; } return findDeclaringTypeBySimpleName(referencedType.getDeclaringType(), outerSegment); }
Example 12
Source File: ImportsCollector.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
private JvmDeclaredType findDeclaringTypeBySimpleName(final JvmDeclaredType referencedType, final String outerSegment) { if (((referencedType.getDeclaringType() == null) || outerSegment.equals(referencedType.getSimpleName()))) { return referencedType; } return this.findDeclaringTypeBySimpleName(referencedType.getDeclaringType(), outerSegment); }