⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 namecheck.jrag

📁 JDK1.4编译器前端
💻 JRAG
📖 第 1 页 / 共 2 页
字号:
/* * The JastAdd Extensible Java Compiler (http://jastadd.org) is covered * by the modified BSD License. You should have received a copy of the * modified BSD license with this compiler. *  * Copyright (c) 2005-2008, Torbjorn Ekman * All rights reserved. */aspect NameCheck {  public void ASTNode.nameCheck() {  }  public TypeDecl ASTNode.extractSingleType(SimpleSet c) {    if(c.size() != 1)      return null;    return (TypeDecl)c.iterator().next();  }  public void SingleTypeImportDecl.nameCheck() {    if(!getAccess().type().typeName().equals(typeName()) && !getAccess().type().isUnknown())      error("Single-type import " + typeName() + " is not the canonical name of type " + getAccess().type().typeName());    else if(allImportedTypes(getAccess().type().name()).size() > 1)      error(getAccess().type().name() + " is imported multiple times");  }  inh SimpleSet SingleTypeImportDecl.allImportedTypes(String name);  eq CompilationUnit.getImportDecl().allImportedTypes(String name) =    importedTypes(name);  public void TypeImportOnDemandDecl.nameCheck() {    if(getAccess().lastAccess().isTypeAccess() && !getAccess().type().typeName().equals(typeName()))      error("On demand type import " + typeName() + ".* is not the canonical name of type " + getAccess().type().typeName());  }  public void CompilationUnit.nameCheck() {    for(int i = 0; i < getNumImportDecl(); i++) {      ImportDecl decl = getImportDecl(i);      if(decl instanceof SingleTypeImportDecl) {        if(localLookupType(decl.getAccess().type().name()).contains(decl.getAccess().type()))          error("" + decl + " is conflicting with visible type");      }    }  }  public void PackageAccess.nameCheck() {    if(!hasPackage(packageName())) {      error(packageName() + " not found");    }  }  public void AmbiguousAccess.nameCheck() {    error("ambiguous name " + name());  }    public void PackageOrTypeAccess.nameCheck() {    error("packageortype name " + name());  }    syn boolean MethodAccess.validArgs() {    for(int i = 0; i < getNumArg(); i++)      if(getArg(i).type().isUnknown())        return false;    return true;  }  public void ConstructorDecl.nameCheck() {    super.nameCheck();    // 8.8    if(!hostType().name().equals(name()))      error("constructor " + name() +" does not have the same name as the simple name of the host class " + hostType().name());        // 8.8.2    if(hostType().lookupConstructor(this) != this)      error("constructor with signature " + signature() + " is multiply declared in type " + hostType().typeName());    if(circularThisInvocation(this))      error("The constructor " + signature() + " may not directly or indirectly invoke itself");  }  // 8.8.5  syn lazy boolean ConstructorDecl.circularThisInvocation(ConstructorDecl decl) {    if(hasConstructorInvocation()) {      Expr e = ((ExprStmt)getConstructorInvocation()).getExpr();      if(e instanceof ConstructorAccess) {        ConstructorDecl constructorDecl = ((ConstructorAccess)e).decl();        if(constructorDecl == decl)          return true;        return constructorDecl.circularThisInvocation(decl);      }    }    return false;  }  public void MethodDecl.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");  }  public void ConstructorAccess.nameCheck() {    super.nameCheck();    if(decls().isEmpty())      error("no constructor named " + this);    if(decls().size() > 1 && validArgs()) {      error("several most specific constructors for " + this);      for(Iterator iter = decls().iterator(); iter.hasNext(); ) {        error("         " + ((ConstructorDecl)iter.next()).signature());      }    }  }  syn boolean ConstructorAccess.validArgs() {    for(int i = 0; i < getNumArg(); i++)      if(getArg(i).type().isUnknown())        return false;    return true;  }  syn boolean ClassInstanceExpr.validArgs() {    for(int i = 0; i < getNumArg(); i++)      if(getArg(i).type().isUnknown())        return false;    return true;  }  public void ClassInstanceExpr.nameCheck() {    super.nameCheck();    if(decls().isEmpty())      error("can not instantiate " + type().typeName() + " no matching constructor found in " + type().typeName());    else if(decls().size() > 1 && validArgs()) {      error("several most specific constructors found");      for(Iterator iter = decls().iterator(); iter.hasNext(); ) {        error("         " + ((ConstructorDecl)iter.next()).signature());      }    }  }        public void ArrayTypeAccess.nameCheck() {    if(decl().elementType().isUnknown())      error("no type named " + decl().elementType().typeName());  }    public void TypeAccess.nameCheck() {    if(isQualified() && !qualifier().isTypeAccess() && !qualifier().isPackageAccess())      error("can not access the type named " + decl().typeName() + " in this context");    if(decls().isEmpty())      error("no visible type named " + typeName());    if(decls().size() > 1) {      StringBuffer s = new StringBuffer();      s.append("several types named " + name() + ":");      for(Iterator iter = decls().iterator(); iter.hasNext(); ) {        TypeDecl t = (TypeDecl)iter.next();        s.append(" " + t.typeName());      }      error(s.toString());    }  }  public void ClassAccess.nameCheck() {    if(isQualified() && !qualifier().isTypeAccess())      error("class literal may only contain type names");  }  public void VarAccess.nameCheck() {    if(decls().isEmpty() && (!isQualified() || !qualifier().type().isUnknown() || qualifier().isPackageAccess()))      error("no field named " + name());    if(decls().size() > 1) {      StringBuffer s = new StringBuffer();      s.append("several fields named " + name());      for(Iterator iter = decls().iterator(); iter.hasNext(); ) {        Variable v = (Variable)iter.next();        s.append("\n    " + v.type().typeName() + "." + v.name() + " declared in " + v.hostType().typeName());      }      error(s.toString());    }          // 8.8.5.1    if(inExplicitConstructorInvocation() && !isQualified() && decl().isInstanceVariable() && hostType() == decl().hostType())      error("instance variable " + name() + " may not be accessed in an explicit constructor invocation");    Variable v = decl();    if(!v.isFinal() && !v.isClassVariable() && !v.isInstanceVariable() && v.hostType() != hostType())      error("A parameter/variable used but not declared in an inner class must be declared final");    // 8.3.2.3    if((decl().isInstanceVariable() || decl().isClassVariable()) && !isQualified()) {      if(hostType() != null && !hostType().declaredBeforeUse(decl(), this)) {        if(inSameInitializer() && !simpleAssignment() && inDeclaringClass()) {          BodyDecl b = closestBodyDecl(hostType());          error("variable " + decl().name() + " is used in " + b + " before it is declared");        }      }    }  }  // find the bodydecl declared in t in which this construct is nested  public BodyDecl VarAccess.closestBodyDecl(TypeDecl t) {    ASTNode node = this;    while(!(node.getParent().getParent() instanceof Program) && node.getParent().getParent() != t) {      node = node.getParent();    }    if(node instanceof BodyDecl)      return (BodyDecl)node;    return null;

⌨️ 快捷键说明

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