public String getOrganizedImportSection(XtextResource xtextResource) { String lineSeparator = whitespaceInformationProvider .getLineSeparatorInformation(xtextResource.getURI()) .getLineSeparator(); StringBuilder importsSection = new StringBuilder(); ArrayList<QualifiedName> importedNames = newArrayList(getImportedNames(xtextResource)); Collections.sort(importedNames); if (!importedNames.isEmpty()) { importsSection.append(lineSeparator); IValueConverter<String> qualifiedNameValueConverter = valueConverterService.getQualifiedNameValueConverter(); for (QualifiedName qualifiedName : importedNames) { String qualifiedNameValue = qualifiedNameValueConverter.toString(nameConverter.toString(qualifiedName)); importsSection.append(lineSeparator).append("import ").append(qualifiedNameValue); } } return importsSection.toString(); }
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); }