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

📄 typehierarchycheck.jrag

📁 JDK1.4编译器前端
💻 JRAG
📖 第 1 页 / 共 2 页
字号:
          // 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());        }      }    }  }  syn boolean MethodDecl.mayOverrideReturn(MethodDecl m) = type() == m.type();  public void ClassDecl.nameCheck() {    super.nameCheck();    if(hasSuperClassAccess() && !getSuperClassAccess().type().isClassDecl())      error("class may only inherit a class and not " + getSuperClassAccess().type().typeName());    if(isObject() && hasSuperClassAccess())      error("class Object may not have superclass");    if(isObject() && getNumImplements() != 0)      error("class Object may not implement interfaces");        // 8.1.3    if(isCircular())      error("circular inheritance dependency in " + typeName());           // 8.1.4    HashSet set = new HashSet();    for(int i = 0; i < getNumImplements(); i++) {      TypeDecl decl = getImplements(i).type();      if(!decl.isInterfaceDecl() && !decl.isUnknown())        error("type " + fullName() + " tries to implement non interface type " + decl.fullName());      if(set.contains(decl))        error("type " + decl.fullName() + " mentionened multiple times in implements clause");      set.add(decl);    }    for(Iterator iter = interfacesMethodsIterator(); iter.hasNext(); ) {      MethodDecl m = (MethodDecl)iter.next();      if(localMethodsSignature(m.signature()).isEmpty()) {        SimpleSet s = superclass().methodsSignature(m.signature());        for(Iterator i2 = s.iterator(); i2.hasNext(); ) {          MethodDecl n = (MethodDecl)i2.next();          if(n.accessibleFrom(this)) {            interfaceMethodCompatibleWithInherited(m, n);          }        }        if(s.isEmpty()) {          for(Iterator i2 = interfacesMethodsSignature(m.signature()).iterator(); i2.hasNext(); ) {            MethodDecl n = (MethodDecl)i2.next();            if(!n.mayOverrideReturn(m) && !m.mayOverrideReturn(n))              error("Xthe return type of method " + m.signature() + " in " + m.hostType().typeName() +                   " does not match the return type of method " + n.signature() + " in " +                   n.hostType().typeName() + " and may thus not be overriden");          }        }      }    }  }  private void ClassDecl.interfaceMethodCompatibleWithInherited(MethodDecl m, MethodDecl n) {    if(n.isStatic())      error("Xa static method may not hide an instance method");    if(!n.isAbstract() && !n.isPublic())      error("Xoverriding access modifier error for " + m.signature() + " in " + m.hostType().typeName() + " and " + n.hostType().typeName());    if(!n.mayOverrideReturn(m) && !m.mayOverrideReturn(m))      error("Xthe return type of method " + m.signature() + " in " + m.hostType().typeName() +             " does not match the return type of method " + n.signature() + " in " +             n.hostType().typeName() + " and may thus not be overriden");    if(!n.isAbstract()) {      // n implements and overrides method m in the interface      // may not throw more checked exceptions      for(int i = 0; i < n.getNumException(); i++) {        Access e = n.getException(i);        boolean found = false;        for(int j = 0; !found && j < m.getNumException(); j++) {          if(e.type().instanceOf(m.getException(j).type()))            found = true;        }        if(!found && e.type().isUncheckedException())          error("X" + n.signature() + " in " + n.hostType().typeName() + " may not throw more checked exceptions than overridden method " +           m.signature() + " in " + m.hostType().typeName());      }    }  }  public void InterfaceDecl.nameCheck() {    super.nameCheck();    if(isCircular())      error("circular inheritance dependency in " + typeName());     else {      for(int i = 0; i < getNumSuperInterfaceId(); i++) {        TypeDecl typeDecl = getSuperInterfaceId(i).type();        if(typeDecl.isCircular())          error("circular inheritance dependency in " + typeName());       }    }    for(Iterator iter = methodsSignatureMap().values().iterator(); iter.hasNext(); ) {      SimpleSet set = (SimpleSet)iter.next();      if(set.size() > 1) {        Iterator i2 = set.iterator();        MethodDecl m = (MethodDecl)i2.next();        while(i2.hasNext()) {          MethodDecl n = (MethodDecl)i2.next();          if(!n.mayOverrideReturn(m) && !m.mayOverrideReturn(n))            error("multiply inherited methods with the same signature must have the same return type");        }      }    }  }}

⌨️ 快捷键说明

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