use of org.eclipse.jdt.core.dom.PackageDeclaration in project bndtools by bndtools.
the class ImportPackageQuickFixProcessor method getCorrections.
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
Set<String> pkgs = new HashSet<>(locations.length * 2 + 1);
for (IProblemLocation location : locations) {
Name name;
switch(location.getProblemId()) {
case IProblem.IsClassPathCorrect:
name = getPackageFromIsClassPathCorrect(context, location);
break;
case IProblem.ImportNotFound:
name = getPackageFromImportNotFound(context, location);
break;
case IProblem.UndefinedType:
name = getPackageFromUndefinedType(context, location);
break;
default:
continue;
}
if (name == null) {
continue;
}
final String pkg = name.getFullyQualifiedName();
// Don't suggest adding a bundle to fix missing package in import if current Compilation Unit
// is already part of that package.
final PackageDeclaration ourPkg = context.getASTRoot().getPackage();
if (ourPkg != null && pkg.equals(ourPkg.getName().getFullyQualifiedName())) {
continue;
}
pkgs.add(pkg);
}
if (pkgs.isEmpty()) {
return null;
}
return getSuggestions(pkgs, context);
}
use of org.eclipse.jdt.core.dom.PackageDeclaration in project sts4 by spring-projects.
the class ImportRewrite method getAddedImportsInsertLocation.
/**
* Reads the positions of each existing import declaration along with any associated comments,
* and returns these in a list whose iteration order reflects the existing order of the imports
* in the compilation unit.
*/
private int getAddedImportsInsertLocation() {
List<ImportDeclaration> importDeclarations = astRoot.imports();
if (importDeclarations == null) {
importDeclarations = Collections.emptyList();
}
List<Comment> comments = astRoot.getCommentList();
int currentCommentIndex = 0;
// Skip over package and file header comments (see https://bugs.eclipse.org/121428).
ImportDeclaration firstImport = importDeclarations.get(0);
PackageDeclaration packageDeclaration = astRoot.getPackage();
int firstImportStartPosition = packageDeclaration == null ? firstImport.getStartPosition() : astRoot.getExtendedStartPosition(packageDeclaration) + astRoot.getExtendedLength(packageDeclaration);
while (currentCommentIndex < comments.size() && comments.get(currentCommentIndex).getStartPosition() < firstImportStartPosition) {
currentCommentIndex++;
}
int previousExtendedEndPosition = -1;
for (ImportDeclaration currentImport : importDeclarations) {
int extendedEndPosition = astRoot.getExtendedStartPosition(currentImport) + astRoot.getExtendedLength(currentImport);
int commentAfterImportIndex = currentCommentIndex;
while (commentAfterImportIndex < comments.size() && comments.get(commentAfterImportIndex).getStartPosition() < extendedEndPosition) {
commentAfterImportIndex++;
}
currentCommentIndex = commentAfterImportIndex;
previousExtendedEndPosition = extendedEndPosition;
}
return previousExtendedEndPosition;
}
Aggregations