Search in sources :

Example 1 with MemberValuePairLocationRetriever

use of org.bndtools.builder.utils.MemberValuePairLocationRetriever 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;
}
Also used : IAnnotation(org.eclipse.jdt.core.IAnnotation) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ASTParser(org.eclipse.jdt.core.dom.ASTParser) MemberValuePairLocationRetriever(org.bndtools.builder.utils.MemberValuePairLocationRetriever) IPackageDeclaration(org.eclipse.jdt.core.IPackageDeclaration) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

MemberValuePairLocationRetriever (org.bndtools.builder.utils.MemberValuePairLocationRetriever)1 IAnnotation (org.eclipse.jdt.core.IAnnotation)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageDeclaration (org.eclipse.jdt.core.IPackageDeclaration)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 ASTParser (org.eclipse.jdt.core.dom.ASTParser)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1