use of org.eclipse.jdt.core.IPackageDeclaration in project bndtools by bndtools.
the class BaselineErrorHandler method findPackageInfoJavaVersionLocation.
ISourceRange findPackageInfoJavaVersionLocation(String packageName, ICompilationUnit compUnit) throws JavaModelException {
ISourceRange range = null;
IPackageDeclaration[] pkgDecls = compUnit.getPackageDeclarations();
if (pkgDecls != null) {
for (IPackageDeclaration pkgDecl : pkgDecls) {
if (packageName.equals(pkgDecl.getElementName())) {
IAnnotation[] annots = pkgDecl.getAnnotations();
for (IAnnotation annot : annots) {
String name = annot.getElementName();
if (ANNOTATION_VERSION_NO_PKG.equals(name) || ANNOTATION_VERSION_OSGI.equals(name) || ANNOTATION_VERSION_BND.equals(name)) {
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(compUnit);
parser.setResolveBindings(true);
CompilationUnit ast = (CompilationUnit) parser.createAST(null);
if (ast != null) {
MemberValuePairLocationRetriever mvpRetriever = new MemberValuePairLocationRetriever(annot, new Predicate<String>() {
@Override
public boolean test(String t) {
return ANNOTATION_VERSION_BND.equals(t) || ANNOTATION_VERSION_OSGI.equals(t);
}
}, "value");
ast.accept(mvpRetriever);
range = mvpRetriever.getMemberValuePairSourceRange();
}
}
}
}
}
}
return range;
}
Aggregations