methoddecl.java

来自「JDK1.4编译器前端」· Java 代码 · 共 1,272 行 · 第 1/4 页

JAVA
1,272
字号

package AST;
import java.util.HashSet;import java.util.LinkedHashSet;import java.io.FileNotFoundException;import java.io.File;import java.util.*;import beaver.*;import java.util.ArrayList;import java.util.zip.*;import java.io.*;public class MethodDecl extends MemberDecl implements Cloneable, SimpleSet, Iterator {
    public void flushCache() {        super.flushCache();        accessibleFrom_TypeDecl_visited = new java.util.HashMap(4);        accessibleFrom_TypeDecl_values = null;        size_visited = -1;        isEmpty_visited = -1;        contains_Object_visited = new java.util.HashMap(4);        lineNumber_visited = -1;        throwsException_TypeDecl_visited = new java.util.HashMap(4);        throwsException_TypeDecl_values = null;        name_visited = -1;        signature_visited = -1;        signature_computed = false;        signature_value = null;        sameSignature_MethodDecl_visited = new java.util.HashMap(4);        moreSpecificThan_MethodDecl_visited = new java.util.HashMap(4);        moreSpecificThan_MethodDecl_values = null;        overrides_MethodDecl_visited = new java.util.HashMap(4);        overrides_MethodDecl_values = null;        hides_MethodDecl_visited = new java.util.HashMap(4);        hides_MethodDecl_values = null;        parameterDeclaration_String_visited = new java.util.HashMap(4);        parameterDeclaration_String_values = null;        isSynthetic_visited = -1;        isPublic_visited = -1;        isPrivate_visited = -1;        isProtected_visited = -1;        isAbstract_visited = -1;        isStatic_visited = -1;        isFinal_visited = -1;        isSynchronized_visited = -1;        isNative_visited = -1;        isStrictfp_visited = -1;        dumpString_visited = -1;        type_visited = -1;        type_computed = false;        type_value = null;        isVoid_visited = -1;        mayOverrideReturn_MethodDecl_visited = new java.util.HashMap(4);        handlesException_TypeDecl_visited = new java.util.HashMap(4);        handlesException_TypeDecl_values = null;        unknownMethod_visited = -1;    }     @SuppressWarnings({"unchecked", "cast"})  public MethodDecl clone() throws CloneNotSupportedException {        MethodDecl node = (MethodDecl)super.clone();        node.accessibleFrom_TypeDecl_visited = new java.util.HashMap(4);        node.accessibleFrom_TypeDecl_values = null;        node.size_visited = -1;        node.isEmpty_visited = -1;        node.contains_Object_visited = new java.util.HashMap(4);        node.lineNumber_visited = -1;        node.throwsException_TypeDecl_visited = new java.util.HashMap(4);        node.throwsException_TypeDecl_values = null;        node.name_visited = -1;        node.signature_visited = -1;        node.signature_computed = false;        node.signature_value = null;        node.sameSignature_MethodDecl_visited = new java.util.HashMap(4);        node.moreSpecificThan_MethodDecl_visited = new java.util.HashMap(4);        node.moreSpecificThan_MethodDecl_values = null;        node.overrides_MethodDecl_visited = new java.util.HashMap(4);        node.overrides_MethodDecl_values = null;        node.hides_MethodDecl_visited = new java.util.HashMap(4);        node.hides_MethodDecl_values = null;        node.parameterDeclaration_String_visited = new java.util.HashMap(4);        node.parameterDeclaration_String_values = null;        node.isSynthetic_visited = -1;        node.isPublic_visited = -1;        node.isPrivate_visited = -1;        node.isProtected_visited = -1;        node.isAbstract_visited = -1;        node.isStatic_visited = -1;        node.isFinal_visited = -1;        node.isSynchronized_visited = -1;        node.isNative_visited = -1;        node.isStrictfp_visited = -1;        node.dumpString_visited = -1;        node.type_visited = -1;        node.type_computed = false;        node.type_value = null;        node.isVoid_visited = -1;        node.mayOverrideReturn_MethodDecl_visited = new java.util.HashMap(4);        node.handlesException_TypeDecl_visited = new java.util.HashMap(4);        node.handlesException_TypeDecl_values = null;        node.unknownMethod_visited = -1;        node.in$Circle(false);        node.is$Final(false);    return node;    }     @SuppressWarnings({"unchecked", "cast"})  public MethodDecl copy() {      try {          MethodDecl node = (MethodDecl)clone();          if(children != null) node.children = (ASTNode[])children.clone();          return node;      } catch (CloneNotSupportedException e) {      }      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");      return null;    }     @SuppressWarnings({"unchecked", "cast"})  public MethodDecl fullCopy() {        MethodDecl res = (MethodDecl)copy();        for(int i = 0; i < getNumChildNoTransform(); i++) {          ASTNode node = getChildNoTransform(i);          if(node != null) node = node.fullCopy();          res.setChild(node, i);        }        return res;    }    // Declared in BoundNames.jrag at line 77  public Access createBoundAccess(List args) {    if(isStatic()) {      return hostType().createQualifiedAccess().qualifiesAccess(        new BoundMethodAccess(name(), args, this)      );    }    return new BoundMethodAccess(name(), args, this);  }    // Declared in DataStructures.jrag at line 134  public SimpleSet add(Object o) {    return new SimpleSetImpl().add(this).add(o);  }    // Declared in DataStructures.jrag at line 140  private MethodDecl iterElem;    // Declared in DataStructures.jrag at line 141  public Iterator iterator() { iterElem = this; return this; }    // Declared in DataStructures.jrag at line 142  public boolean hasNext() { return iterElem != null; }    // Declared in DataStructures.jrag at line 143  public Object next() { Object o = iterElem; iterElem = null; return o; }    // Declared in DataStructures.jrag at line 144  public void remove() { throw new UnsupportedOperationException(); }    // Declared in Modifiers.jrag at line 127    // 8.4.3  public void checkModifiers() {    super.checkModifiers();    if(hostType().isClassDecl()) {      // 8.4.3.1      if(isAbstract() && !hostType().isAbstract())        error("class must be abstract to include abstract methods");      // 8.4.3.1      if(isAbstract() && isPrivate())        error("method may not be abstract and private");      // 8.4.3.1      // 8.4.3.2      if(isAbstract() && isStatic())        error("method may not be abstract and static");      if(isAbstract() && isSynchronized())        error("method may not be abstract and synchronized");      // 8.4.3.4      if(isAbstract() && isNative())        error("method may not be abstract and native");      if(isAbstract() && isStrictfp())        error("method may not be abstract and strictfp");      if(isNative() && isStrictfp())        error("method may not be native and strictfp");    }    if(hostType().isInterfaceDecl()) {      // 9.4      if(isStatic())        error("interface method " + signature() + " in " +            hostType().typeName() +  " may not be static");      if(isStrictfp())        error("interface method " + signature() + " in " +            hostType().typeName() +  " may not be strictfp");      if(isNative())        error("interface method " + signature() + " in " +            hostType().typeName() +  " may not be native");      if(isSynchronized())        error("interface method " + signature() + " in " +            hostType().typeName() +  " may not be synchronized");      if(isProtected())        error("interface method " + signature() + " in " +            hostType().typeName() +  " may not be protected");      if(isPrivate())        error("interface method " + signature() + " in " +            hostType().typeName() +  " may not be private");      else if(isFinal())        error("interface method " + signature() + " in " +            hostType().typeName() +  " may not be final");    }  }    // Declared in NameCheck.jrag at line 96  public void nameCheck() {    // 8.4    // 8.4.2    if(!hostType().methodsSignature(signature()).contains(this))      error("method with signature " + signature() + " is multiply declared in type " + hostType().typeName());    // 8.4.3.4    if(isNative() && hasBlock())      error("native methods must have an empty semicolon body");    // 8.4.5    if(isAbstract() && hasBlock())      error("abstract methods must have an empty semicolon body");    // 8.4.5    if(!hasBlock() && !(isNative() || isAbstract()))      error("only abstract and native methods may have an empty semicolon body");  }    // Declared in PrettyPrint.jadd at line 194  public void toString(StringBuffer s) {    s.append(indent());    getModifiers().toString(s);    getTypeAccess().toString(s);    s.append(" " + name() + "(");    if(getNumParameter() > 0) {      getParameter(0).toString(s);      for(int i = 1; i < getNumParameter(); i++) {        s.append(", ");        getParameter(i).toString(s);      }    }    s.append(")");    if(getNumException() > 0) {      s.append(" throws ");      getException(0).toString(s);      for(int i = 1; i < getNumException(); i++) {        s.append(", ");        getException(i).toString(s);      }    }    if(hasBlock()) {      s.append(" ");      getBlock().toString(s);    }    else {      s.append(";\n");    }  }    // Declared in TypeCheck.jrag at line 386  public void typeCheck() {    // Thrown vs super class method see MethodDecl.nameCheck    // 8.4.4    TypeDecl exceptionType = typeThrowable();    for(int i = 0; i < getNumException(); i++) {      TypeDecl typeDecl = getException(i).type();      if(!typeDecl.instanceOf(exceptionType))        error(signature() + " throws non throwable type " + typeDecl.fullName());    }    // check returns    if(!isVoid() && hasBlock() && getBlock().canCompleteNormally())      error("the body of a non void method may not complete normally");  }    // Declared in java.ast at line 3    // Declared in java.ast line 88
    public MethodDecl() {        super();
        setChild(new List(), 2);
        setChild(new List(), 3);
        setChild(new Opt(), 4);

    }    // Declared in java.ast at line 13
    // Declared in java.ast line 88    public MethodDecl(Modifiers p0, Access p1, String p2, List<ParameterDeclaration> p3, List<Access> p4, Opt<Block> p5) {        setChild(p0, 0);        setChild(p1, 1);        setID(p2);        setChild(p3, 2);        setChild(p4, 3);        setChild(p5, 4);    }    // Declared in java.ast at line 23    // Declared in java.ast line 88    public MethodDecl(Modifiers p0, Access p1, beaver.Symbol p2, List<ParameterDeclaration> p3, List<Access> p4, Opt<Block> p5) {        setChild(p0, 0);        setChild(p1, 1);        setID(p2);        setChild(p3, 2);        setChild(p4, 3);        setChild(p5, 4);    }    // Declared in java.ast at line 32

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?