private JvmDeclaredType findDeclaringTypeBySimpleName(JvmDeclaredType referencedType, String outerSegment) { if (referencedType.getDeclaringType() == null || outerSegment.equals(referencedType.getSimpleName())) { return referencedType; } return findDeclaringTypeBySimpleName(referencedType.getDeclaringType(), outerSegment); }
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); }
public boolean needsImport(JvmDeclaredType type) { if (type.getDeclaringType() != null) return true; String packageName = type.getPackageName(); return packageName != null && !(implicitlyImportedPackages.contains(packageName)); }
protected void collectAllVisibleFields(final JvmDeclaredType type, final Map<String, JvmIdentifiableElement> result) { if ((type == null)) { return; } this.collectAllVisibleFields(type.getDeclaringType(), result); result.putAll(this.getAllVisibleFields(type)); }
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; }
protected boolean isStaticContext(EObject element) { if(element instanceof JvmConstructor) return false; if(element instanceof JvmFeature) return ((JvmFeature) element).isStatic(); if(element instanceof JvmDeclaredType) return ((JvmDeclaredType) element).isStatic() || ( ((JvmDeclaredType)element).getDeclaringType() == null && !isLocalType(element)); return false; }
@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); } } } }
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; } }
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); }
private String getConcreteSyntax(String name, JvmDeclaredType importedType, TypeUsage usage) { JvmDeclaredType usedType = usage.getUsedType(); if (usedType == null) { String typeName = usage.getUsedTypeName(); String suffix = getSuffix(usage); String fullTypeName = typeName + suffix; return nameValueConverter.toString(fullTypeName); } else { if (usedType != importedType) { List<String> segments = Lists.newLinkedList(); while (usedType != importedType) { segments.add(0, usedType.getSimpleName()); usedType = usedType.getDeclaringType(); } name = name + '.' + Joiner.on('.').join(segments); } else { String suffix = getSuffix(usage); name = name + suffix; } return nameValueConverter.toString(name); } }
@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); } } } } }
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); }
if (jvmType.getDeclaringType() == null) { GeneratorConfig generatorConfig = generatorConfigProvider.get(jvmType); boolean generateSuppressWarnings = !(jvmType instanceof JvmAnnotationType)
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) { if (call.isPackageFragment()) { if (type instanceof JvmDeclaredType) { int segmentIndex = countSegments(call); String packageName = ((JvmDeclaredType) type).getPackageName(); List<String> splitted = Strings.split(packageName, '.'); String segment = splitted.get(segmentIndex); return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE); } return IScope.NULLSCOPE; } else { if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } else { XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget(); if (target.isPackageFragment()) { String qualifiedName = type.getQualifiedName(); int dot = qualifiedName.lastIndexOf('.'); String simpleName = qualifiedName.substring(dot + 1); return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE); } else { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } } } }
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); }
if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() != null) { Resource resource = call.eResource(); if (resource instanceof XtextResource) {
JvmDeclaredType declaredType = (JvmDeclaredType) derivedJvmElement; QualifiedName jvmTypeName = getQualifiedNameOfLocalElement(declaredType); if (declaredType.getDeclaringType() == null && !Strings.isEmpty(declaredType.getPackageName())) { QualifiedName packageName = this.qualifiedNameConverter.toQualifiedName(declaredType.getPackageName()); ImportNormalizer normalizer = doCreateImportNormalizer(packageName, true, ignoreCase);
JvmDeclaredType declaredType = (JvmDeclaredType) derivedJvmElement; QualifiedName jvmTypeName = getQualifiedNameOfLocalElement(declaredType); if (declaredType.getDeclaringType() == null && !Strings.isEmpty(declaredType.getPackageName())) { QualifiedName packageName = this.qualifiedNameConverter.toQualifiedName(declaredType.getPackageName()); ImportNormalizer normalizer = doCreateImportNormalizer(packageName, true, ignoreCase);