typedecl.java
来自「JDK1.4编译器前端」· Java 代码 · 共 1,493 行 · 第 1/5 页
JAVA
1,493 行
return inner.next(); } public void remove() { throw new UnsupportedOperationException(); } }; } // Declared in LookupMethod.jrag at line 347 protected boolean allMethodsAbstract(SimpleSet set) { if(set == null) return true; for(Iterator iter = set.iterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); if(!m.isAbstract()) return false; } return true; } // Declared in LookupVariable.jrag at line 208 public TypeDecl subclassWithinBody(TypeDecl typeDecl) { if(instanceOf(typeDecl)) return this; if(isNestedType()) { return enclosingType().subclassWithinBody(typeDecl); } return null; } // Declared in Modifiers.jrag at line 66 public void checkModifiers() { super.checkModifiers(); // 8.1.1 if(isPublic() && !isTopLevelType() && !isMemberType()) error("public pertains only to top level types and member types"); // 8.1.1 if((isProtected() || isPrivate()) && !(isMemberType() && enclosingType().isClassDecl())) error("protected and private may only be used on member types within a directly enclosing class declaration"); // 8.1.1 if(isStatic() && !isMemberType()) error("static pertains only to member types"); // 8.4.3.1 // 8.1.1.1 if(!isAbstract() && hasAbstract()) { StringBuffer s = new StringBuffer(); s.append("" + name() + " is not declared abstract but contains abstract members: \n"); for(Iterator iter = unimplementedMethods().iterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); s.append(" " + m.signature() + " in " + m.hostType().typeName() + "\n"); } error(s.toString()); } } // Declared in NameCheck.jrag at line 246 public void nameCheck() { if(isTopLevelType() && lookupType(packageName(), name()) != this) error("duplicate member " + name() + " in compilation unit"); if(!isTopLevelType() && !isAnonymous() && !isLocalClass() && extractSingleType(enclosingType().memberTypes(name())) != this) error("duplicate member type " + name() + " in type " + enclosingType().typeName()); // 14.3 if(isLocalClass()) { TypeDecl typeDecl = extractSingleType(lookupType(name())); if(typeDecl != null && typeDecl != this && typeDecl.isLocalClass() && enclosingBlock() == typeDecl.enclosingBlock()) error("local class named " + name() + " may not be redeclared as a local class in the same block"); } if(!packageName().equals("") && hasPackage(fullName())) error("duplicate member class and package " + name()); // 8.1 & 9.1 if(hasEnclosingTypeDecl(name())) { error("type may not have the same simple name as an enclosing type declaration"); } } // Declared in QualifiedNames.jrag at line 96 public Access createQualifiedAccess() { if(isLocalClass() || isAnonymous()) { return new TypeAccess(name()); } else if(!isTopLevelType()) { return enclosingType().createQualifiedAccess().qualifiesAccess(new TypeAccess(name())); } else { return new TypeAccess(packageName(), name()); } } // Declared in TypeAnalysis.jrag at line 235 public FieldDeclaration findSingleVariable(String name) { return (FieldDeclaration)memberFields(name).iterator().next(); } // Declared in TypeHierarchyCheck.jrag at line 157 public void typeCheck() { // 8.4.6.4 & 9.4.1 for(Iterator iter1 = localMethodsIterator(); iter1.hasNext(); ) { MethodDecl m = (MethodDecl)iter1.next(); ASTNode target = m.hostType() == this ? (ASTNode)m : (ASTNode)this; //for(Iterator i2 = overrides(m).iterator(); i2.hasNext(); ) { for(Iterator i2 = ancestorMethods(m.signature()).iterator(); i2.hasNext(); ) { MethodDecl decl = (MethodDecl)i2.next(); if(m.overrides(decl)) { // 8.4.6.1 if(!m.isStatic() && decl.isStatic()) target.error("an instance method may not override a static method"); // regardless of overriding // 8.4.6.3 if(!m.mayOverrideReturn(decl)) target.error("the return type of method " + m.signature() + " in " + m.hostType().typeName() + " does not match the return type of method " + decl.signature() + " in " + decl.hostType().typeName() + " and may thus not be overriden"); // regardless of overriding // 8.4.4 for(int i = 0; i < m.getNumException(); i++) { Access e = m.getException(i); boolean found = false; for(int j = 0; !found && j < decl.getNumException(); j++) { if(e.type().instanceOf(decl.getException(j).type())) found = true; } if(!found && e.type().isUncheckedException()) target.error(m.signature() + " in " + m.hostType().typeName() + " may not throw more checked exceptions than overridden method " + decl.signature() + " in " + decl.hostType().typeName()); } // 8.4.6.3 if(decl.isPublic() && !m.isPublic()) target.error("overriding access modifier error"); // 8.4.6.3 if(decl.isProtected() && !(m.isPublic() || m.isProtected())) target.error("overriding access modifier error"); // 8.4.6.3 if((!decl.isPrivate() && !decl.isProtected() && !decl.isPublic()) && m.isPrivate()) target.error("overriding access modifier error"); // regardless of overriding if(decl.isFinal()) target.error("method " + m.signature() + " in " + hostType().typeName() + " can not override final method " + decl.signature() + " in " + decl.hostType().typeName()); } if(m.hides(decl)) { // 8.4.6.2 if(m.isStatic() && !decl.isStatic()) target.error("a static method may not hide an instance method"); // 8.4.6.3 if(!m.mayOverrideReturn(decl)) target.error("can not hide a method with a different return type"); // 8.4.4 for(int i = 0; i < m.getNumException(); i++) { Access e = m.getException(i); boolean found = false; for(int j = 0; !found && j < decl.getNumException(); j++) { if(e.type().instanceOf(decl.getException(j).type())) found = true; } if(!found) target.error("may not throw more checked exceptions than hidden method"); } // 8.4.6.3 if(decl.isPublic() && !m.isPublic()) target.error("hiding access modifier error: public method " + decl.signature() + " in " + decl.hostType().typeName() + " is hidden by non public method " + m.signature() + " in " + m.hostType().typeName()); // 8.4.6.3 if(decl.isProtected() && !(m.isPublic() || m.isProtected())) target.error("hiding access modifier error: protected method " + decl.signature() + " in " + decl.hostType().typeName() + " is hidden by non (public|protected) method " + m.signature() + " in " + m.hostType().typeName()); // 8.4.6.3 if((!decl.isPrivate() && !decl.isProtected() && !decl.isPublic()) && m.isPrivate()) target.error("hiding access modifier error: default method " + decl.signature() + " in " + decl.hostType().typeName() + " is hidden by private method " + m.signature() + " in " + m.hostType().typeName()); if(decl.isFinal()) target.error("method " + m.signature() + " in " + hostType().typeName() + " can not hide final method " + decl.signature() + " in " + decl.hostType().typeName()); } } } } // Declared in java.ast at line 3 // Declared in java.ast line 38
public TypeDecl() { super();
setChild(new List(), 1);
} // Declared in java.ast at line 11
// Declared in java.ast line 38 public TypeDecl(Modifiers p0, String p1, List<BodyDecl> p2) { setChild(p0, 0); setID(p1); setChild(p2, 1); } // Declared in java.ast at line 18 // Declared in java.ast line 38 public TypeDecl(Modifiers p0, beaver.Symbol p1, List<BodyDecl> p2) { setChild(p0, 0); setID(p1); setChild(p2, 1); } // Declared in java.ast at line 24 protected int numChildren() {
return 2;
} // Declared in java.ast at line 27
public boolean mayHaveRewrite() { return false; } // Declared in java.ast at line 2 // Declared in java.ast line 38 public void setModifiers(Modifiers node) { setChild(node, 0); } // Declared in java.ast at line 5 public Modifiers getModifiers() { return (Modifiers)getChild(0); } // Declared in java.ast at line 9 public Modifiers getModifiersNoTransform() { return (Modifiers)getChildNoTransform(0); } // Declared in java.ast at line 2 // Declared in java.ast line 38 private String tokenString_ID; // Declared in java.ast at line 3 public void setID(String value) { tokenString_ID = value; } // Declared in java.ast at line 6 public int IDstart; // Declared in java.ast at line 7 public int IDend; // Declared in java.ast at line 8 public void setID(beaver.Symbol symbol) { if(symbol.value != null && !(symbol.value instanceof String)) throw new UnsupportedOperationException("setID is only valid for String lexemes"); tokenString_ID = (String)symbol.value; IDstart = symbol.getStart(); IDend = symbol.getEnd(); } // Declared in java.ast at line 15 public String getID() { return tokenString_ID != null ? tokenString_ID : ""; } // Declared in java.ast at line 2 // Declared in java.ast line 38 public void setBodyDeclList(List<BodyDecl> list) { setChild(list, 1); } // Declared in java.ast at line 6 private int getNumBodyDecl = 0; // Declared in java.ast at line 7 public int getNumBodyDecl() { return getBodyDeclList().getNumChild();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?