1 19 package org.netbeans.modules.java.source.builder; 20 21 import com.sun.tools.javac.code.*; 22 import com.sun.tools.javac.code.Symbol.*; 23 import com.sun.tools.javac.tree.JCTree; 24 import com.sun.tools.javac.tree.JCTree.*; 25 import com.sun.tools.javac.tree.TreeScanner; 26 import com.sun.tools.javac.util.Context; 27 import com.sun.tools.javac.util.List; 28 29 import java.util.HashSet ; 30 import javax.lang.model.element.Element; 31 import org.netbeans.api.java.source.*; 32 33 class MethodCharacterization { 34 final HashSet <? super Element> overridden = new HashSet <Element>(); 35 final HashSet <? super Element> overrides = new HashSet <Element>(); 36 37 public MethodCharacterization(final Types types, JCTree t) { 38 new TreeScanner() { 39 @Override 40 public void visitMethodDef(JCMethodDecl md) { 41 checkAll(md.sym, md.sym.owner.type); 42 } 43 private void checkAll(MethodSymbol m, Type c) { 44 if(c.tag==TypeTags.CLASS) { 45 if(c != m.owner.type) { 46 Scope.Entry e = c.tsym.members().lookup(m.name); 47 while (e.scope != null) { 48 if (m.overrides(e.sym, (TypeSymbol)m.owner, types, true)) { 49 overridden.add(e.sym); 50 overrides.add(m); 51 } 52 e = e.next(); 53 } 54 } 55 for(List<Type> i = types.interfaces(c.baseType()); i.nonEmpty(); i = i.tail) 56 checkAll(m, i.head); 57 checkAll(m,types.supertype(c.baseType())); 58 } 59 } 60 }.scan(t); 61 } 62 63 public boolean isOverridden(Element s) { 64 return overridden.contains(s); 65 } 66 67 public boolean overrides(Element s) { 68 return overrides.contains(s); 69 } 70 } 71 | Popular Tags |