KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > builder > MethodCharacterization


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
30 import javax.lang.model.element.Element;
31 import org.netbeans.api.java.source.*;
32
33 class MethodCharacterization {
34     final HashSet JavaDoc<? super Element> overridden = new HashSet JavaDoc<Element>();
35     final HashSet JavaDoc<? super Element> overrides = new HashSet JavaDoc<Element>();
36     
37     public MethodCharacterization(final Types types, JCTree t) {
38     new TreeScanner() {
39             @Override JavaDoc
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