private boolean hasStaticImport(String typeName, String memberName, boolean extension) { for (String string : implicitlyImportedPackages) { if (typeName.startsWith(string)) { return typeName.substring(string.length()).lastIndexOf('.') == 0; } } Map<JvmDeclaredType, Set<String>> imports = staticImports; if (extension) { imports = staticExtensionImports; } for (JvmDeclaredType type : imports.keySet()) { if (typeName.equals(type.getIdentifier())) { Set<String> members = imports.get(type); return members != null && ((members.contains(memberName) || members.contains(null))); } } for (XImportDeclaration importDeclr : addedImportDeclarations) { String identifier = importDeclr.getImportedTypeName(); if (importDeclr.isStatic() && typeName.equals(identifier)) { if (Objects.equal(importDeclr.getMemberName(), memberName) || importDeclr.isWildcard() || "*".equals(importDeclr.getMemberName())) { return true; } } } return false; }
public RewritableImportSection( XtextResource resource, IImportsConfiguration importsConfiguration, XImportSection originalImportSection, String lineSeparator, ImportSectionRegionUtil regionUtil, IValueConverter<String> nameConverter) { this.importsConfiguration = importsConfiguration; this.resource = resource; this.lineSeparator = lineSeparator; this.regionUtil = regionUtil; this.nameValueConverter = nameConverter; this.implicitlyImportedPackages = importsConfiguration.getImplicitlyImportedPackages(resource); this.importRegion = regionUtil.computeRegion(resource); if (originalImportSection != null) { for (XImportDeclaration originalImportDeclaration : originalImportSection.getImportDeclarations()) { this.originalImportDeclarations.add(originalImportDeclaration); JvmDeclaredType importedType = originalImportDeclaration.getImportedType(); if (originalImportDeclaration.isStatic()) { String memberName = originalImportDeclaration.getMemberName(); if (originalImportDeclaration.isExtension()) { Maps2.putIntoSetMap(importedType, memberName, staticExtensionImports); } else { Maps2.putIntoSetMap(importedType, memberName, staticImports); } } else if (importedType != null) { Maps2.putIntoListMap(importedType.getSimpleName(), importedType, plainImports); } } } }
protected List<XImportDeclaration> findOriginalImports( JvmDeclaredType type, String memberName, Collection<XImportDeclaration> list, boolean isStatic, boolean isExtension) { List<XImportDeclaration> result = newArrayList(); for (XImportDeclaration importDeclaration : list) { if (!(isStatic ^ importDeclaration.isStatic()) && !(isExtension ^ importDeclaration.isExtension()) && importDeclaration.getImportedType() == type && (memberName == null || memberName.equals(importDeclaration.getMemberName()))) { result.add(importDeclaration); } } return result; }
protected void appendImport(StringBuilder builder, XImportDeclaration newImportDeclaration) { builder.append("import "); if (newImportDeclaration.isStatic()) { builder.append("static "); if (newImportDeclaration.isExtension()) { builder.append("extension "); } } String qualifiedTypeName = newImportDeclaration.getImportedNamespace(); if (newImportDeclaration.getImportedType() != null) { qualifiedTypeName = serializeType(newImportDeclaration.getImportedType()); } String escapedTypeName = nameValueConverter.toString(qualifiedTypeName); builder.append(escapedTypeName); if (newImportDeclaration.isStatic()) { builder.append("."); if (newImportDeclaration.isWildcard()) { builder.append("*"); } else { builder.append(newImportDeclaration.getMemberName()); } } builder.append(lineSeparator); }