List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:org.gradle.api.internal.tasks.compile.incremental.analyzer.ClassDependenciesVisitor.java
License:Apache License
private static boolean isConstant(int access) { return (access & Opcodes.ACC_FINAL) != 0 && (access & Opcodes.ACC_STATIC) != 0; }
From source file:org.gradle.api.internal.tasks.testing.junit.JUnitTestClassDetecter.java
License:Apache License
@Override public void visitInnerClass(String name, String outerName, String innerName, int access) { if (name.equals(className) && (access & Opcodes.ACC_STATIC) == 0) { isAbstract = true;/*from w w w .j a v a 2 s . c om*/ } }
From source file:org.gradle.external.junit.JUnitTestClassDetecter.java
License:Apache License
/** * Visits information about an inner class. This inner class is not * necessarily a member of the class being visited. * * @param name the internal name of an inner class (see * {@link Type#getInternalName() getInternalName}). * @param outerName the internal name of the class to which the inner class * belongs (see {@link Type#getInternalName() getInternalName}). May * be <tt>null</tt> for not member classes. * @param innerName the (simple) name of the inner class inside its * enclosing class. May be <tt>null</tt> for anonymous inner * classes.//from w w w. j av a 2s. c om * @param access the access flags of the inner class as originally declared * in the enclosing class. */ public void visitInnerClass(String name, String outerName, String innerName, int access) { boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; boolean isPublic = (access & Opcodes.ACC_PUBLIC) != 0; if (outerName != null && innerName != null && isStatic && isPublic) { final File innerTestClassFile = new File(detector.getTestClassesDirectory(), className + "$" + innerName + ".class"); if (innerTestClassFile.exists()) { if (detector.processPossibleTestClass(innerTestClassFile)) LOG.debug("test-class-scan : [inner test class] : " + className + " : [name: " + name + ", outerName: " + outerName + ", innerName: " + innerName + "]"); } } }
From source file:org.gradle.groovy.scripts.internal.GradleResolveVisitor.java
License:Apache License
private boolean resolveAliasFromModule(ClassNode type) { // In case of getting a ConstructedClassWithPackage here we do not do checks for partial // matches with imported classes. The ConstructedClassWithPackage is already a constructed // node and any subclass resolving will then take place elsewhere if (type instanceof ConstructedClassWithPackage) { return false; }//www .j a v a 2 s . co m ModuleNode module = currentClass.getModule(); if (module == null) { return false; } String name = type.getName(); // check module node imports aliases // the while loop enables a check for inner classes which are not fully imported, // but visible as the surrounding class is imported and the inner class is public/protected static String pname = name; int index = name.length(); /* * we have a name foo.bar and an import foo.foo. This means foo.bar is possibly * foo.foo.bar rather than foo.bar. This means to cut at the dot in foo.bar and * foo for import */ while (true) { pname = name.substring(0, index); ClassNode aliasedNode = null; ImportNode importNode = module.getImport(pname); if (importNode != null && importNode != currImportNode) { aliasedNode = importNode.getType(); } if (aliasedNode == null) { importNode = module.getStaticImports().get(pname); if (importNode != null && importNode != currImportNode) { // static alias only for inner classes and must be at end of chain ClassNode tmp = new ConstructedNestedClass(importNode.getType(), importNode.getFieldName()); if (resolve(tmp, false, false, true)) { if ((tmp.getModifiers() & Opcodes.ACC_STATIC) != 0) { type.setRedirect(tmp.redirect()); return true; } } } } if (aliasedNode != null) { if (pname.length() == name.length()) { // full match // We can compare here by length, because pname is always // a substring of name, so same length means they are equal. type.setRedirect(aliasedNode); return true; } else { //partial match // At this point we know that we have a match for pname. This may // mean, that name[pname.length()..<-1] is a static inner class. // For this the rest of the name does not need any dots in its name. // It is either completely a inner static class or it is not. // Since we do not want to have useless lookups we create the name // completely and use a ConstructedClassWithPackage to prevent lookups against the package. String className = aliasedNode.getNameWithoutPackage() + '$' + name.substring(pname.length() + 1).replace('.', '$'); ConstructedClassWithPackage tmp = new ConstructedClassWithPackage( aliasedNode.getPackageName() + ".", className); if (resolve(tmp, true, true, false)) { type.setRedirect(tmp.redirect()); return true; } } } index = pname.lastIndexOf('.'); if (index == -1) { break; } } return false; }
From source file:org.gradle.groovy.scripts.internal.GradleResolveVisitor.java
License:Apache License
private boolean resolveFromModule(ClassNode type, boolean testModuleImports) { if (type instanceof ConstructedNestedClass) { return false; }//from www .ja v a 2s . c o m // we decided if we have a vanilla name starting with a lower case // letter that we will not try to resolve this name against .* // imports. Instead a full import is needed for these. // resolveAliasFromModule will do this check for us. This method // does also check the module contains a class in the same package // of this name. This check is not done for vanilla names starting // with a lower case letter anymore if (type instanceof LowerCaseClass) { return resolveAliasFromModule(type); } String name = type.getName(); ModuleNode module = currentClass.getModule(); if (module == null) { return false; } boolean newNameUsed = false; // we add a package if there is none yet and the module has one. But we // do not add that if the type is a ConstructedClassWithPackage. The code in ConstructedClassWithPackage // hasPackageName() will return true if ConstructedClassWithPackage#className has no dots. // but since the prefix may have them and the code there does ignore that // fact. We check here for ConstructedClassWithPackage. if (!type.hasPackageName() && module.hasPackageName() && !(type instanceof ConstructedClassWithPackage)) { type.setName(module.getPackageName() + name); newNameUsed = true; } // look into the module node if there is a class with that name List<ClassNode> moduleClasses = module.getClasses(); for (ClassNode mClass : moduleClasses) { if (mClass.getName().equals(type.getName())) { if (mClass != type) { type.setRedirect(mClass); } return true; } } if (newNameUsed) { type.setName(name); } if (testModuleImports) { if (resolveAliasFromModule(type)) { return true; } if (module.hasPackageName()) { // check package this class is defined in. The usage of ConstructedClassWithPackage here // means, that the module package will not be involved when the // compiler tries to find an inner class. ConstructedClassWithPackage tmp = new ConstructedClassWithPackage(module.getPackageName(), name); if (resolve(tmp, false, false, false)) { ambiguousClass(type, tmp, name); type.setRedirect(tmp.redirect()); return true; } } if (!name.contains(".")) { // check module static imports (for static inner classes) for (ImportNode importNode : module.getStaticImports().values()) { if (importNode.getFieldName().equals(name)) { ClassNode tmp = new ConstructedNestedClass(importNode.getType(), name); if (resolve(tmp, false, false, true)) { if ((tmp.getModifiers() & Opcodes.ACC_STATIC) != 0) { type.setRedirect(tmp.redirect()); return true; } } } } // check module node import packages for (ImportNode importNode : module.getStarImports()) { String packagePrefix = importNode.getPackageName(); // We limit the inner class lookups here by using ConstructedClassWithPackage. // This way only the name will change, the packagePrefix will // not be included in the lookup. The case where the // packagePrefix is really a class is handled elsewhere. ConstructedClassWithPackage tmp = new ConstructedClassWithPackage(packagePrefix, name); if (resolve(tmp, false, false, true)) { ambiguousClass(type, tmp, name); type.setRedirect(tmp.redirect()); return true; } } // check for star imports (import static pkg.Outer.*) matching static inner classes for (ImportNode importNode : module.getStaticStarImports().values()) { ClassNode tmp = new ConstructedNestedClass(importNode.getType(), name); if (resolve(tmp, false, false, true)) { if ((tmp.getModifiers() & Opcodes.ACC_STATIC) != 0) { ambiguousClass(type, tmp, name); type.setRedirect(tmp.redirect()); return true; } } } } } return false; }
From source file:org.gradle.groovy.scripts.internal.GradleResolveVisitor.java
License:Apache License
private void checkThisAndSuperAsPropertyAccess(PropertyExpression expression) { if (expression.isImplicitThis()) { return;//from www. j a v a2 s . co m } String prop = expression.getPropertyAsString(); if (prop == null) { return; } if (!prop.equals("this") && !prop.equals("super")) { return; } ClassNode type = expression.getObjectExpression().getType(); if (expression.getObjectExpression() instanceof ClassExpression) { if (!(currentClass instanceof InnerClassNode) && !Traits.isTrait(type)) { addError("The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.", expression); return; } if (currentScope != null && !currentScope.isInStaticContext() && Traits.isTrait(type) && "super".equals(prop) && directlyImplementsTrait(type)) { return; } ClassNode iterType = currentClass; while (iterType != null) { if (iterType.equals(type)) { break; } iterType = iterType.getOuterClass(); } if (iterType == null) { addError("The class '" + type.getName() + "' needs to be an outer class of '" + currentClass.getName() + "' when using '.this' or '.super'.", expression); } if ((currentClass.getModifiers() & Opcodes.ACC_STATIC) == 0) { return; } if (currentScope != null && !currentScope.isInStaticContext()) { return; } addError("The usage of 'Class.this' and 'Class.super' within static nested class '" + currentClass.getName() + "' is not allowed in a static context.", expression); } }
From source file:org.gradle.language.base.internal.tasks.apigen.ApiStubGenerator.java
License:Apache License
private boolean isPackagePrivate(int access) { return access == 0 || access == Opcodes.ACC_STATIC || access == Opcodes.ACC_SUPER || access == (Opcodes.ACC_SUPER | Opcodes.ACC_STATIC); }
From source file:org.greencheek.gc.memusage.agent.MonitoringAspectGenerator.java
License:Apache License
/** * Visits a field of the class./* w w w .j ava2 s . co m*/ * The method is overriden to perform the functions of: * <ol> * <li>Adding a static AtomicLong to the class</li> * <li>statically initialising the AtomicLong if a static initialiser isn't already present</li> * </ol> * * @param access the field's access flags (see {@link Opcodes}). This * parameter also indicates if the field is synthetic and/or * deprecated. * @param name the field's name. * @param desc the field's descriptor (see {@link Type Type}). * @param signature the field's signature. May be <tt>null</tt> if the * field's type does not use generic types. * @param value the field's initial value. This parameter, which may be * <tt>null</tt> if the field does not have an initial value, must * be an {@link Integer}, a {@link Float}, a {@link Long}, a * {@link Double} or a {@link String} (for <tt>int</tt>, * <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields * respectively). <i>This parameter is only used for static fields</i>. * Its value is ignored for non static fields, which must be * initialized through bytecode instructions in constructors or * methods. * @return a visitor to visit field annotations and attributes, or * <tt>null</tt> if this class visitor is not interested in * visiting these annotations and attributes. */ public void visitEnd() { for (MethodInfo method : overrideMethodNames.values()) { System.out.println("Adding: public final static AtomicLong " + method.getFieldName()); FieldVisitor fv = cv.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, method.getFieldName(), "Ljava/util/concurrent/atomic/AtomicLong;", null, null); fv.visitEnd(); } if (!hasCinit) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); AddStaticAtomicLongInitializer initialiser = new AddStaticAtomicLongInitializer(Opcodes.ASM4, mv, overrideMethodNames.values()); initialiser.visitCode(); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } super.visitEnd(); }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
@Override public void visit(FunctionDefinition node) throws ASTVisitorException { fd = node;//from w w w . j a va2 s. c om //fix the signature System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~ " + node.getIdentifier() + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); if (node.getStorageSpecifier() == null) { //if the function is static LocalIndexPool safeLocalIndexPool = ASTUtils.getSafeLocalIndexPool(node); int localIndex = safeLocalIndexPool.getLocalIndex(); } LocalIndexPool safeLocalIndexPool = ASTUtils.getSafeLocalIndexPool(node); String methodType = Type.getMethodDescriptor(node.getType().getTypeSpecifier(), node.getParameters().getParameterTypes()); int accessor = Opcodes.ACC_PUBLIC; if (ASTUtils.getIsStatic(node)) { accessor = accessor + Opcodes.ACC_STATIC; } MethodNode methodNode; if (node.getIdentifier().equals("main")) { methodNode = new MethodNode(accessor, node.getIdentifier(), "([Ljava/lang/String;)V", null, null); } else { methodNode = new MethodNode(accessor, node.getIdentifier(), methodType, null, null); } mn = methodNode; node.getParameters().accept(this); node.getCompoundStatement().accept(this); mn.instructions.add(new InsnNode(Opcodes.RETURN)); // mn.maxLocals = 30; // mn.maxStack = 30; cn.methods.add(mn); fd = null; mn = null; }
From source file:org.icesquirrel.compiler.SquirrelCompiler.java
License:Open Source License
public void compile(InputStream in, String scriptName) throws Exception { SquirrelLexer l = new SquirrelLexer(new ANTLRInputStream(in)); SquirrelParser p = new SquirrelParser(new CommonTokenStream(l)); p.addErrorListener(new BaseErrorListener() { @Override/*from w w w.j av a2 s .co m*/ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new IllegalStateException("failed to parse at line " + line + " due to " + msg, e); } }); ScriptContext script = p.script(); // Determine class name String className = convertClassName((namespace == null ? "" : namespace + ".") + scriptName); LOG.info(String.format("Generating class %s", className)); // Write the class definition and main() method ClassWriter cw = new ClassWriter(0); cw.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", new String[] { convertClassName(SquirrelMain.class.getName()) }); final MethodVisitor visitMethod = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "(L[java/lang/String;)V", null, null); compileMain(cw, visitMethod, script); visitMethod.visitEnd(); // Finish writing the main class cw.visitEnd(); // Output the class file File dir = namespace == null ? output : new File(output, namespace.replace('.', File.separatorChar)); if (!dir.exists() && !dir.mkdirs()) { throw new IOException(String.format("Could not create output directory %s", dir)); } File classFile = new File(dir, scriptName + ".class"); LOG.info(String.format("Writing class to %s", classFile.getPath())); FileOutputStream fos = new FileOutputStream(classFile); try { fos.write(cw.toByteArray()); } finally { fos.close(); } }