Search in sources :

Example 6 with IPackageDeclaration

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;
}
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

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 IPackageDeclaration (org.eclipse.jdt.core.IPackageDeclaration)6 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4 ISourceRange (org.eclipse.jdt.core.ISourceRange)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MemberValuePairLocationRetriever (org.bndtools.builder.utils.MemberValuePairLocationRetriever)1 Region (org.eclipse.che.ide.ext.java.shared.dto.Region)1 JavaProject (org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject)1 FindUsagesResponse (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAnnotation (org.eclipse.jdt.core.IAnnotation)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IMember (org.eclipse.jdt.core.IMember)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1