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

📄 typehierarchycheck.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 TypeHierarchyCheck {  inh String Expr.methodHost();  eq TypeDecl.getBodyDecl().methodHost() = typeName();  eq AbstractDot.getRight().methodHost() = getLeft().type().typeName();  eq Program.getChild().methodHost() {    throw new Error("Needs extra equation for methodHost()");  }  eq MethodAccess.getChild().methodHost() = unqualifiedScope().methodHost();  eq ConstructorAccess.getChild().methodHost() = unqualifiedScope().methodHost();    syn boolean Expr.isUnknown() = type().isUnknown();  eq PackageAccess.isUnknown() = !hasPackage(packageName());    public void MethodAccess.nameCheck() {    if(isQualified() && qualifier().isPackageAccess() && !qualifier().isUnknown())      error("The method " + decl().signature() +           " can not be qualified by a package name.");    if(isQualified() && decl().isAbstract() && qualifier().isSuperAccess())      error("may not access abstract methods in superclass");    if(decls().isEmpty() && (!isQualified() || !qualifier().isUnknown())) {      StringBuffer s = new StringBuffer();      s.append("no method named " + name());      s.append("(");      for(int i = 0; i < getNumArg(); i++) {        if(i != 0)          s.append(", ");        s.append(getArg(i).type().typeName());      }      s.append(")" + " in " + methodHost() + " matches.");      if(singleCandidateDecl() != null)        s.append(" However, there is a method " + singleCandidateDecl().signature());      error(s.toString());    }    if(decls().size() > 1) {      boolean allAbstract = true;      for(Iterator iter = decls().iterator(); iter.hasNext() && allAbstract; ) {         MethodDecl m = (MethodDecl)iter.next();        if(!m.isAbstract() && !m.hostType().isObject())          allAbstract = false;      }      if(!allAbstract && validArgs()) {        StringBuffer s = new StringBuffer();        s.append("several most specific methods for " + this + "\n");        for(Iterator iter = decls().iterator(); iter.hasNext(); ) {          MethodDecl m = (MethodDecl)iter.next();          s.append("    " + m.signature() + " in " + m.hostType().typeName() + "\n");        }        error(s.toString());      }           }  }  public void SuperConstructorAccess.nameCheck() {    super.nameCheck();    // 8.8.5.1    TypeDecl c = hostType();    TypeDecl s = c.isClassDecl() && ((ClassDecl)c).hasSuperclass() ? ((ClassDecl)c).superclass() : unknownType();    if(isQualified()) {      if(!s.isInnerType() || s.inStaticContext())        error("the super type " + s.typeName() + " of " + c.typeName() +           " is not an inner class");          else if(!qualifier().type().instanceOf(s.enclosingType()))        error("The type of this primary expression, " +                qualifier().type().typeName() + " is not enclosing the super type, " +                 s.typeName() + ", of " + c.typeName());    }    if(!isQualified() && s.isInnerType()) {      if(!c.isInnerType()) {        error("no enclosing instance for " + s.typeName() + " when accessed in " + this);      }    }    if(s.isInnerType() && hostType().instanceOf(s.enclosingType()))      error("cannot reference this before supertype constructor has been called");  }  public void SuperAccess.nameCheck() {    if(isQualified()) {      if(!hostType().isInnerTypeOf(decl()) && hostType() != decl())        error("qualified super must name an enclosing type");      if(inStaticContext()) {        error("*** Qualified super may not occur in static context");      }    }    // 8.8.5.1    if(inExplicitConstructorInvocation() && hostType().instanceOf(decl().hostType()) )      error("super may not be accessed in an explicit constructor invocation");    // 8.4.3.2    if(inStaticContext())      error("super may not be accessed in a static context");  }  public void ThisAccess.nameCheck() {    // 8.8.5.1    if(inExplicitConstructorInvocation() && hostType() == type())      error("this may not be accessed in an explicit constructor invocation");    else if(isQualified()) {      // 15.8.4      if(inStaticContext())        error("qualified this may not occur in static context");      else if(!hostType().isInnerTypeOf(decl()) && hostType() != decl())        error("qualified this must name an enclosing type: " + getParent());    }    // 8.4.3.2    else if(!isQualified() && inStaticContext())      error("this may not be accessed in static context: " + enclosingStmt());  }      // 8.8.5.1  inh boolean VarAccess.inExplicitConstructorInvocation();  inh boolean MethodAccess.inExplicitConstructorInvocation();  inh boolean SuperAccess.inExplicitConstructorInvocation();  inh boolean ThisAccess.inExplicitConstructorInvocation();  inh boolean ClassInstanceExpr.inExplicitConstructorInvocation();  inh lazy boolean TypeDecl.inExplicitConstructorInvocation();  eq Program.getChild().inExplicitConstructorInvocation() = false;  eq ConstructorAccess.getArg().inExplicitConstructorInvocation() = true;  eq SuperConstructorAccess.getArg().inExplicitConstructorInvocation() = true;  eq ConstructorDecl.getConstructorInvocation().inExplicitConstructorInvocation() = true;  inh boolean Expr.inStaticContext(); // SuperAccess, ThisAccess, ClassInstanceExpr, MethodAccess  inh lazy boolean TypeDecl.inStaticContext();    eq Program.getChild().inStaticContext() = false;  eq TypeDecl.getBodyDecl().inStaticContext() = isStatic() || inStaticContext();  eq StaticInitializer.getBlock().inStaticContext() = true;  eq InstanceInitializer.getBlock().inStaticContext() = false;  eq FieldDeclaration.getInit().inStaticContext() = isStatic() || hostType().isInterfaceDecl();  eq MethodDecl.getBlock().inStaticContext() = isStatic();  eq ConstructorDecl.getBlock().inStaticContext() = false;  eq ConstructorDecl.getConstructorInvocation().inStaticContext() = false;  eq MemberClassDecl.getClassDecl().inStaticContext() = false;    eq ClassInstanceExpr.getTypeDecl().inStaticContext() = isQualified() ?    qualifier().staticContextQualifier() : inStaticContext();  syn boolean Expr.staticContextQualifier() = false;  eq ParExpr.staticContextQualifier() = getExpr().staticContextQualifier();  eq CastExpr.staticContextQualifier() = getExpr().staticContextQualifier();  eq AbstractDot.staticContextQualifier() = lastAccess().staticContextQualifier();  eq TypeAccess.staticContextQualifier() = true;  eq ArrayTypeAccess.staticContextQualifier() = true;  public void TypeDecl.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"); 

⌨️ 快捷键说明

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