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.parboiled.compiler.notNullVerification.MyMethodAdapter.java
License:Apache License
@Override public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; boolean isParameter = isStatic ? index < args.length : index <= args.length; mv.visitLocalVariable(name, desc, signature, (isParameter && myStartGeneratedCodeLabel != null) ? myStartGeneratedCodeLabel : start, end, index); }
From source file:org.parboiled.compiler.notNullVerification.NotNullVerifyingInstrumenter.java
License:Apache License
public void visitInnerClass(String name, String outerName, String innerName, int access) { super.visitInnerClass(name, outerName, innerName, access); if (myClassName.equals(name)) { myIsNotStaticInner = (access & Opcodes.ACC_STATIC) == 0; }//w w w .j a va2 s. c o m }
From source file:org.rascalmpl.library.lang.java.m3.internal.JarConverter.java
License:Open Source License
private IConstructor mapFieldAccesCode(int code, int where) { // Check the original M3 implementation for possible IConstructor types. switch (code) { case Opcodes.ACC_PUBLIC: return constructModifierNode("public"); case Opcodes.ACC_PRIVATE: return constructModifierNode("private"); case Opcodes.ACC_PROTECTED: return constructModifierNode("protected"); case Opcodes.ACC_STATIC: return constructModifierNode("static"); case Opcodes.ACC_FINAL: return constructModifierNode("final"); case Opcodes.ACC_SYNCHRONIZED: if (where == CLASSE) return null; return constructModifierNode("synchronized"); case Opcodes.ACC_ABSTRACT: return constructModifierNode("abstract"); case Opcodes.ACC_VOLATILE: return constructModifierNode("volatile"); case Opcodes.ACC_TRANSIENT: return constructModifierNode("transient"); case Opcodes.ACC_NATIVE: return constructModifierNode("native"); // TODO: GIT PULL/MERGE ORIGINAL RASCAL VERSION < 2013-11-30 (Shahin commit) // case Opcodes.ACC_DEPRECATED: // return constructModifierNode("deprecated"); default:// w w w. j a v a2 s .co m return null; } }
From source file:org.revapi.java.compilation.ClassTreeInitializer.java
License:Apache License
private void processClassBytes(final Archive currentArchive, InputStream data, final InitTreeContext context) throws IOException { ClassReader classReader = new ClassReader(data); classReader.accept(new ClassVisitor(Opcodes.ASM5) { private String visitedClassInternalName; private String visitedClassBinaryName; private String[] visitedClassOwners; private boolean isInnerClass; private int visitedInnerClassAccess; private TypeTreeConstructor.ClassProcessor classProcessor; @Override/*from www . ja va 2 s . c om*/ public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { visitedClassInternalName = name; visitedClassBinaryName = Type.getObjectType(name).getClassName(); boolean visible = isAccessible(access); boolean isPublicAPI = !context.processingSupplementaryArchives && visible; classProcessor = context.typeTreeConstructor.createApiClassProcessor(currentArchive, visitedClassBinaryName, isPublicAPI); //add the superclass and interface use sites reportUse(Type.getObjectType(superName), UseSite.Type.IS_INHERITED, RawUseSite.SiteType.CLASS, null, null, -1); for (String iface : interfaces) { reportUse(Type.getObjectType(iface), UseSite.Type.IS_IMPLEMENTED, RawUseSite.SiteType.CLASS, null, null, -1); } if (name.indexOf('$') >= 0) { visitedClassOwners = name.split("\\$"); } if (LOG.isTraceEnabled()) { LOG.trace("visit(): name={}, signature={}, access=0x{}", name, signature, Integer.toHexString(access)); } } @Override public FieldVisitor visitField(int access, final String name, final String desc, String signature, Object value) { //only consider public or protected fields - only those contribute to the API if (isAccessible(access)) { reportUse(Type.getType(desc), UseSite.Type.HAS_TYPE, RawUseSite.SiteType.FIELD, name, desc, -1); return new FieldVisitor(Opcodes.ASM5) { @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { reportUse(Type.getType(desc), UseSite.Type.ANNOTATES, RawUseSite.SiteType.FIELD, name, desc, -1); return null; } }; } return null; } @Override public void visitInnerClass(String name, String outerName, String innerName, int access) { LOG.trace("Visiting inner class spec {} {}", innerName, outerName); boolean isThisClass = visitedClassInternalName.equals(name); if (isThisClass) { visitedInnerClassAccess = access; } isInnerClass = isInnerClass || isThisClass; if (isThisClass || isTransitiveOwnerOfVisitedClass(name)) { //visiting some outer class of the currently processed class classProcessor.getInnerClassHierarchyConstructor().addName(outerName, innerName); } } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { reportUse(Type.getType(desc), UseSite.Type.ANNOTATES, RawUseSite.SiteType.CLASS, null, null, -1); return null; } @Override public MethodVisitor visitMethod(int access, final String name, final String desc, String signature, String[] exceptions) { LOG.trace("Visiting method {} {}", name, desc); //only consider public or protected methods - only those contribute to the API if (isAccessible(access)) { Type[] argumentTypes = Type.getArgumentTypes(desc); reportUse(Type.getReturnType(desc), UseSite.Type.RETURN_TYPE, RawUseSite.SiteType.METHOD, name, desc, -1); //instance inner classes synthesize their constructors to always have the enclosing type as the //first parameter. Ignore that parameter for usage reporting. int ai = isInnerClass && "<init>".equals(name) && (visitedInnerClassAccess & Opcodes.ACC_STATIC) == 0 ? 1 : 0; while (ai < argumentTypes.length) { Type t = argumentTypes[ai]; reportUse(t, UseSite.Type.PARAMETER_TYPE, RawUseSite.SiteType.METHOD_PARAMETER, name, desc, ai++); } if (exceptions != null && exceptions.length > 0) { for (String ex : exceptions) { reportUse(Type.getObjectType(ex), UseSite.Type.IS_THROWN, RawUseSite.SiteType.METHOD, name, desc, -1); } } return new MethodVisitor(Opcodes.ASM5) { @Override public AnnotationVisitor visitAnnotation(String annotationDesc, boolean visible) { reportUse(Type.getType(annotationDesc), UseSite.Type.ANNOTATES, RawUseSite.SiteType.METHOD, name, desc, -1); return null; } @Override public AnnotationVisitor visitParameterAnnotation(int parameter, String parameterDesc, boolean visible) { reportUse(Type.getType(parameterDesc), UseSite.Type.ANNOTATES, RawUseSite.SiteType.METHOD_PARAMETER, name, desc, parameter); return null; } }; } return null; } @Override public void visitEnd() { if (LOG.isTraceEnabled()) { LOG.trace("Visited {}, isInner={}, onlyAdditional={}", visitedClassInternalName, isInnerClass, context.processingSupplementaryArchives); } classProcessor.commitClass(); } private void reportUse(Type t, UseSite.Type useType, RawUseSite.SiteType siteType, String siteName, String siteDescriptor, int sitePosition) { if (skipUseTracking) { return; } if (t.getSort() < Type.ARRAY) { //primitive type return; } if (ignoreMissingAnnotations && useType == UseSite.Type.ANNOTATES) { return; } String binaryName = t.getClassName(); RawUseSite useSite = new RawUseSite(useType, siteType, visitedClassBinaryName, siteName, siteDescriptor, sitePosition); switch (t.getSort()) { case Type.OBJECT: classProcessor.addUse(binaryName, useSite); break; case Type.ARRAY: String desc = t.getDescriptor(); desc = desc.substring(desc.lastIndexOf('[') + 1); reportUse(Type.getType(desc), useType, siteType, siteName, siteDescriptor, sitePosition); break; case Type.METHOD: throw new AssertionError("A method type should not enter here."); //all other cases are primitive types that we don't need to consider } } private boolean isTransitiveOwnerOfVisitedClass(String owningClass) { if (visitedClassOwners == null) { return false; } if (owningClass.length() > visitedClassInternalName.length()) { return false; } int startIdx = 0; int dollarIdx = owningClass.indexOf('$'); int ownerIdx = 0; while (dollarIdx >= 0 && ownerIdx < visitedClassOwners.length) { String owner = owningClass.substring(startIdx, dollarIdx); if (!visitedClassOwners[ownerIdx++].equals(owner)) { return false; } startIdx = dollarIdx + 1; dollarIdx = owningClass.indexOf('$', startIdx); } if (ownerIdx < visitedClassOwners.length) { return visitedClassOwners[ownerIdx].equals(owningClass.substring(startIdx)); } else { return dollarIdx == -1; } } }, ClassReader.SKIP_CODE); }
From source file:org.sonar.java.bytecode.asm.AsmAccessFlags.java
License:Open Source License
public static boolean isStatic(int accessFlags) { return (accessFlags & Opcodes.ACC_STATIC) != 0; }
From source file:org.sonar.java.resolve.FlagsTest.java
License:Open Source License
/** * Flags can be easily loaded from class-files into symbols. *//*from w w w . j a va 2 s .c o m*/ @Test public void flags_match_asm_opcodes() { assertThat(Flags.PUBLIC).isEqualTo(Opcodes.ACC_PUBLIC); assertThat(Flags.PRIVATE).isEqualTo(Opcodes.ACC_PRIVATE); assertThat(Flags.PROTECTED).isEqualTo(Opcodes.ACC_PROTECTED); assertThat(Flags.STATIC).isEqualTo(Opcodes.ACC_STATIC); assertThat(Flags.FINAL).isEqualTo(Opcodes.ACC_FINAL); assertThat(Flags.SYNCHRONIZED).isEqualTo(Opcodes.ACC_SYNCHRONIZED); assertThat(Flags.VOLATILE).isEqualTo(Opcodes.ACC_VOLATILE); assertThat(Flags.TRANSIENT).isEqualTo(Opcodes.ACC_TRANSIENT); assertThat(Flags.NATIVE).isEqualTo(Opcodes.ACC_NATIVE); assertThat(Flags.INTERFACE).isEqualTo(Opcodes.ACC_INTERFACE); assertThat(Flags.ABSTRACT).isEqualTo(Opcodes.ACC_ABSTRACT); assertThat(Flags.STRICTFP).isEqualTo(Opcodes.ACC_STRICT); assertThat(Flags.SYNTHETIC).isEqualTo(Opcodes.ACC_SYNTHETIC); assertThat(Flags.ANNOTATION).isEqualTo(Opcodes.ACC_ANNOTATION); assertThat(Flags.ENUM).isEqualTo(Opcodes.ACC_ENUM); }
From source file:org.spongepowered.asm.mixin.transformer.ClassInfo.java
License:MIT License
private void addMethod(MethodNode method, boolean injected) { if (!method.name.startsWith("<") && (method.access & Opcodes.ACC_PRIVATE) == 0 && (method.access & Opcodes.ACC_STATIC) == 0) { this.methods.add(new Method(method, injected)); }// w w w . j ava 2s . co m }
From source file:org.spongepowered.asm.mixin.transformer.MixinInfo.java
License:MIT License
/** * Performs pre-flight checks on the mixin * //from ww w . ja v a 2 s .c o m * @param classNode */ private void validateMixin(ClassNode classNode) { // isInner (shouldn't) return true for static inner classes if (this.classInfo.isInner()) { throw new InvalidMixinException(this, "Inner class mixin must be declared static"); } // Can't have remappable fields or methods on a multi-target mixin, because after obfuscation the fields will remap to conflicting names if (this.targetClasses.size() > 1) { for (FieldNode field : classNode.fields) { this.checkRemappable(Shadow.class, field.name, ASMHelper.getVisibleAnnotation(field, Shadow.class)); } for (MethodNode method : classNode.methods) { this.checkRemappable(Shadow.class, method.name, ASMHelper.getVisibleAnnotation(method, Shadow.class)); AnnotationNode overwrite = ASMHelper.getVisibleAnnotation(method, Overwrite.class); if (overwrite != null && ((method.access & Opcodes.ACC_STATIC) == 0 || (method.access & Opcodes.ACC_PUBLIC) == 0)) { throw new InvalidMixinException(this, "Found @Overwrite annotation on " + method.name + " in " + this); } } } }
From source file:org.spongepowered.asm.mixin.transformer.MixinPreProcessor.java
License:MIT License
private boolean validateField(MixinTargetContext context, FieldNode field, AnnotationNode shadow) { // Public static fields will fall foul of early static binding in java, including them in a mixin is an error condition if (MixinTransformer.hasFlag(field, Opcodes.ACC_STATIC) && !MixinTransformer.hasFlag(field, Opcodes.ACC_PRIVATE)) { throw new InvalidMixinException(context, String .format("Mixin classes cannot contain visible static methods or fields, found %s", field.name)); }/*from ww w. j av a 2 s.c om*/ // Shadow fields can't have prefixes, it's meaningless for them anyway String prefix = ASMHelper.<String>getAnnotationValue(shadow, "prefix", Shadow.class); if (field.name.startsWith(prefix)) { throw new InvalidMixinException(context, String.format( "Shadow field %s in %s has a shadow prefix. This is not allowed.", field.name, context)); } // Imaginary super fields get stripped from the class, but first we validate them if (Constants.IMAGINARY_SUPER.equals(field.name)) { if (field.access != Opcodes.ACC_PRIVATE) { throw new InvalidMixinException(this.mixin, "Imaginary super field " + field.name + " must be private and non-final"); } if (!field.desc.equals("L" + this.mixin.getClassRef() + ";")) { throw new InvalidMixinException(this.mixin, "Imaginary super field " + field.name + " must have the same type as the parent mixin"); } return false; } return true; }
From source file:org.spongepowered.asm.mixin.transformer.MixinTargetContext.java
License:MIT License
/** * Handle "imaginary super" invokations, these are invokations in * non-derived mixins for accessing methods known to exist in a supermixin * which is not directly inherited by this mixix. The method can only call * its <b>own</b> super-implmentation and the methd must also be tagged with * {@link SoftOverride} to indicate that the method must exist in a super * class.// www . j a v a 2 s . c om * * @param method Method being processed * @param fieldInsn the GETFIELD insn which access the pseudo-field which is * used as a handle to the superclass */ private void processImaginarySuper(MethodNode method, FieldInsnNode fieldInsn) { if (fieldInsn.getOpcode() != Opcodes.GETFIELD) { if (MixinTargetContext.INIT.equals(method.name)) { throw new InvalidMixinException(this, "Illegal imaginary super declaration: field " + fieldInsn.name + " must not specify an initialiser"); } throw new InvalidMixinException(this, "Illegal imaginary super access: found " + ASMHelper.getOpcodeName(fieldInsn.getOpcode()) + " opcode in " + method.name + method.desc); } if ((method.access & Opcodes.ACC_PRIVATE) != 0 || (method.access & Opcodes.ACC_STATIC) != 0) { throw new InvalidMixinException(this, "Illegal imaginary super access: method " + method.name + method.desc + " is private or static"); } if (ASMHelper.getInvisibleAnnotation(method, SoftOverride.class) == null) { throw new InvalidMixinException(this, "Illegal imaginary super access: method " + method.name + method.desc + " is not decorated with @SoftOverride"); } for (Iterator<AbstractInsnNode> methodIter = method.instructions .iterator(method.instructions.indexOf(fieldInsn)); methodIter.hasNext();) { AbstractInsnNode insn = methodIter.next(); if (insn instanceof MethodInsnNode) { MethodInsnNode methodNode = (MethodInsnNode) insn; if (methodNode.owner.equals(this.getClassRef()) && methodNode.name.equals(method.name) && methodNode.desc.equals(method.desc)) { methodNode.setOpcode(Opcodes.INVOKESPECIAL); this.updateStaticBinding(method, methodNode); return; } } } throw new InvalidMixinException(this, "Illegal imaginary super access: could not find INVOKE for " + method.name + method.desc); }