1.1 --- a/file/src/org/netbeans/modules/jackpot30/file/conditionapi/Context.java Sun Jan 23 16:49:34 2011 +0100
1.2 +++ b/file/src/org/netbeans/modules/jackpot30/file/conditionapi/Context.java Thu Jul 21 22:51:52 2011 +0200
1.3 @@ -39,6 +39,7 @@
1.4
1.5 package org.netbeans.modules.jackpot30.file.conditionapi;
1.6
1.7 +import com.sun.source.tree.CompilationUnitTree;
1.8 import com.sun.source.tree.Tree.Kind;
1.9 import com.sun.source.util.TreePath;
1.10 import java.util.ArrayList;
1.11 @@ -55,11 +56,13 @@
1.12 import javax.lang.model.element.Element;
1.13 import javax.lang.model.element.ElementKind;
1.14 import javax.lang.model.element.Modifier;
1.15 +import javax.lang.model.element.TypeElement;
1.16 import javax.lang.model.type.TypeKind;
1.17 import javax.lang.model.type.TypeMirror;
1.18 import org.netbeans.api.annotations.common.CheckForNull;
1.19 import org.netbeans.api.annotations.common.NonNull;
1.20 import org.netbeans.api.java.queries.SourceLevelQuery;
1.21 +import org.netbeans.api.java.source.TreeUtilities;
1.22 import org.netbeans.modules.jackpot30.file.APIAccessor;
1.23 import org.netbeans.modules.jackpot30.spi.Hacks;
1.24 import org.netbeans.modules.jackpot30.spi.HintContext;
1.25 @@ -250,6 +253,46 @@
1.26 APIAccessor.IMPL = new APIAccessorImpl();
1.27 }
1.28
1.29 + /**Returns canonical names of classes that enclose the {@link Variable}.
1.30 + * If the given {@link Variable} represents a class, its canonical name is also listed.
1.31 + * The names are given from the innermost class to the outermost class.
1.32 + *
1.33 + * @return the canonical names of the enclosing classes
1.34 + */
1.35 + public @NonNull Iterable<? extends String> enclosingClasses(Variable forVariable) {
1.36 + List<String> result = new ArrayList<String>();
1.37 + TreePath path = getSingleVariable(forVariable);
1.38 +
1.39 + while (path != null) {
1.40 + TreePath current = path;
1.41 +
1.42 + path = path.getParentPath();
1.43 +
1.44 + if (!TreeUtilities.CLASS_TREE_KINDS.contains(current.getLeaf().getKind())) continue;
1.45 +
1.46 + Element e = ctx.getInfo().getTrees().getElement(current);
1.47 +
1.48 + if (e == null) continue;
1.49 +
1.50 + if (e.getKind().isClass() || e.getKind().isInterface()) {
1.51 + result.add(((TypeElement) e).getQualifiedName().toString());
1.52 + }
1.53 + }
1.54 +
1.55 + return result;
1.56 + }
1.57 +
1.58 + /**Returns name of package in which the current file is located. Default package
1.59 + * is represented by an empty string.
1.60 + *
1.61 + * @return the name of the enclosing package
1.62 + */
1.63 + public @NonNull String enclosingPackage() {
1.64 + CompilationUnitTree cut = ctx.getInfo().getCompilationUnit();
1.65 +
1.66 + return cut.getPackageName() != null ? cut.getPackageName().toString() : "";
1.67 + }
1.68 +
1.69 static final class APIAccessorImpl extends APIAccessor {
1.70
1.71 @Override