1 19 package org.netbeans.modules.javacore.parser; 20 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.Set ; 24 import org.netbeans.jmi.javamodel.Resource; 25 import org.netbeans.lib.java.parser.ASTree; 26 import org.netbeans.lib.java.parser.ASTreeTypes; 27 import org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement; 28 import org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl; 29 import org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement; 30 31 35 public final class ResourceInfo extends ElementInfo { 36 public static final int RESOURCE_TYPE = ASTreeTypes.COMPILATION_UNIT; 37 38 public final ClassInfo[] classes; 39 public final ElementInfo[] imports; 40 41 private MDRParser hardRef; 42 private Set attributed; 43 private static final boolean DEBUG = false; 44 45 public ResourceInfo(ASTree tree, int infoType, Resource resource, ClassInfo[] classes, ElementInfo[] imports) { 46 super(tree, infoType, resource == null ? null : resource.getName()); 47 this.classes = classes == null ? EMPTY_FEATURES : classes; 48 this.imports = imports == null ? EMPTY_FEATURES : imports; 49 } 50 51 public void hardRefAST() { 52 hardRef = resource.getParser(); 53 } 54 55 public void doAttribution(MetadataElement parent) { 56 ASTree tree = parent.getASTree(); 57 if (tree != null) { 58 if (attributed == null) { 59 attributed = new HashSet (); 60 } 61 if (attributed.add(parent)) { 62 MDRParser parser = (MDRParser) tree.getASTContext(); 63 parser.prepareForAttribution(parent, tree); 64 } 65 } 66 } 67 68 public ASTree refreshASTree() { 69 MDRParser mdrParser = ((ResourceImpl) resource).createMDRParser(null, false); 70 if (DEBUG) System.err.println("Recreating AST for: " + mdrParser); 71 try { 72 resource.alreadyChecking = true; 73 resource.alreadyCheckingStackTrace = new RuntimeException (); 74 ResourceInfo resInfo = mdrParser.enterMembers(); 75 this.tree = resInfo.tree; 76 } finally { 77 resource.alreadyChecking = false; 78 } 79 80 if (attributed != null) { 81 for (Iterator it = attributed.iterator(); it.hasNext();) { 82 MetadataElement entry = (MetadataElement) it.next(); 83 mdrParser.prepareForAttribution(entry, entry.getASTree()); 84 } 85 } 86 87 return mdrParser.getASTree(); 88 } 89 90 public ASTree getTypeAST(SemiPersistentElement owner) { 91 ASTree tree = owner.getASTree(); 92 if (tree != null) { 93 ASTree pkg = tree.getSubTrees()[0]; 94 return pkg == null ? null : pkg.getSubTrees()[1]; 95 } 96 return null; 97 } 98 } 99 | Popular Tags |