📄 modifiers.jrag
字号:
/* * 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 Modifiers { void ASTNode.checkModifiers() { } syn lazy boolean TypeDecl.hasAbstract() = false; syn lazy Collection TypeDecl.unimplementedMethods() = Collections.EMPTY_LIST; eq ClassDecl.unimplementedMethods() { Collection c = new ArrayList(); for(Iterator iter = interfacesMethodsIterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); boolean implemented = false; SimpleSet set = (SimpleSet)localMethodsSignature(m.signature()); if(set.size() == 1) { MethodDecl n = (MethodDecl)set.iterator().next(); if(!n.isAbstract()) implemented = true; } if(!implemented) { set = (SimpleSet)ancestorMethods(m.signature()); for(Iterator i2 = set.iterator(); i2.hasNext(); ) { MethodDecl n = (MethodDecl)i2.next(); if(!n.isAbstract()) implemented = true; } } if(!implemented) { c.add(m); } } if(hasSuperclass()) { for(Iterator iter = superclass().unimplementedMethods().iterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); SimpleSet set = (SimpleSet)localMethodsSignature(m.signature()); if(set.size() == 1) { MethodDecl n = (MethodDecl)set.iterator().next(); if(n.isAbstract() || !n.overrides(m)) c.add(m); } else c.add(m); } } for(Iterator iter = localMethodsIterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); if(m.isAbstract()) { c.add(m); } } return c; } eq ClassDecl.hasAbstract() = !unimplementedMethods().isEmpty(); public void TypeDecl.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()); } } public void ClassDecl.checkModifiers() { super.checkModifiers(); // 8.1.1.2 final Classes TypeDecl typeDecl = hasSuperclass() ? superclass() : null; if(typeDecl != null && typeDecl.isFinal()) { error("class " + fullName() + " may not extend final class " + typeDecl.fullName()); } } public void InterfaceDecl.checkModifiers() { super.checkModifiers(); } public void ConstructorDecl.checkModifiers() { super.checkModifiers(); } public void FieldDeclaration.checkModifiers() { super.checkModifiers(); if(hostType().isInterfaceDecl()) { if(isProtected()) error("an interface field may not be protected"); if(isPrivate()) error("an interface field may not be private"); if(isTransient()) error("an interface field may not be transient"); if(isVolatile()) error("an interface field may not be volatile"); } } // 8.4.3 public void MethodDecl.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"); } } // 8.1.2 public void StaticInitializer.checkModifiers() { super.checkModifiers(); if(hostType().isInnerClass()) error("*** Inner classes may not declare static initializers"); } // 8.1.2 public void MemberInterfaceDecl.checkModifiers() { super.checkModifiers(); if(hostType().isInnerClass()) error("*** Inner classes may not declare member interfaces"); } public void MemberDecl.checkModifiers() { if(!isSynthetic()) { super.checkModifiers(); if(isStatic() && hostType().isInnerClass() && !isConstant()) error("*** Inner classes may not declare static members, unless they are compile-time constant fields"); } } syn lazy boolean TypeDecl.isPublic() = getModifiers().isPublic() || isMemberType() && enclosingType().isInterfaceDecl(); //eq InterfaceDecl.isPublic() = !isProtected() && !isPrivate(); syn boolean TypeDecl.isPrivate() = getModifiers().isPrivate();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -