List of usage examples for org.objectweb.asm Opcodes ACC_DEPRECATED
int ACC_DEPRECATED
To view the source code for org.objectweb.asm Opcodes ACC_DEPRECATED.
Click Source Link
From source file:com.geeksaga.light.profiler.asm.ClassNodeWrapper.java
License:Apache License
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { if ((access & Opcodes.ACC_SYNTHETIC) != 0) { constantPool.newUTF8("Synthetic", isExtend); }//from www. j a v a 2 s .c o m if ((access & Opcodes.ACC_DEPRECATED) != 0) { constantPool.newUTF8("Deprecated", isExtend); } constantPool.newUTF8(name, isExtend); constantPool.newUTF8(desc, isExtend); if (signature != null) { constantPool.newUTF8("Signature", isExtend); constantPool.newUTF8(signature, isExtend); } if (exceptions != null) { constantPool.newUTF8("Exceptions", isExtend); for (String exception : exceptions) { constantPool.newClass(exception, isExtend); } } MethodWrapper methodWrapper = new MethodWrapper( super.visitMethod(access, name, desc, signature, exceptions), constantPool); methodVisitWrappers.add(methodWrapper); return methodWrapper; }
From source file:com.github.veithen.phos.enforcer.ClassProcessor.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from w w w . j a va 2 s .c o m deprecated = (access & Opcodes.ACC_DEPRECATED) != 0; if (!deprecated) { referenceProcessor = new ReferenceProcessor(referenceCollector, new Clazz(Type.getObjectType(name).getClassName()), isPublic(access)); referenceProcessor.processType(Type.getObjectType(superName), true); for (String iface : interfaces) { referenceProcessor.processType(Type.getObjectType(iface), true); } } }
From source file:com.github.veithen.phos.enforcer.ClassProcessor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (!deprecated && (access & Opcodes.ACC_DEPRECATED) == 0) { boolean isPublic = isPublic(access); referenceProcessor.processType(Type.getMethodType(desc), isPublic); if (exceptions != null) { for (String exception : exceptions) { referenceProcessor.processType(Type.getObjectType(exception), isPublic); }// w ww .ja v a 2 s.c o m } return new MethodProcessor(referenceProcessor); } else { return null; } }
From source file:com.googlecode.dex2jar.ir.ToStringUtil.java
License:Apache License
public static String getAccDes(int acc) { StringBuilder sb = new StringBuilder(); if ((acc & Opcodes.ACC_PUBLIC) != 0) { sb.append("public "); }/*from ww w .ja va 2 s . c o m*/ if ((acc & Opcodes.ACC_PROTECTED) != 0) { sb.append("protected "); } if ((acc & Opcodes.ACC_PRIVATE) != 0) { sb.append("private "); } if ((acc & Opcodes.ACC_STATIC) != 0) { sb.append("static "); } if ((acc & Opcodes.ACC_ABSTRACT) != 0 && (acc & Opcodes.ACC_INTERFACE) == 0) { sb.append("abstract "); } if ((acc & Opcodes.ACC_ANNOTATION) != 0) { sb.append("annotation "); } if ((acc & Opcodes.ACC_BRIDGE) != 0) { sb.append("bridge "); } if ((acc & Opcodes.ACC_DEPRECATED) != 0) { sb.append("deprecated "); } if ((acc & Opcodes.ACC_ENUM) != 0) { sb.append("enum "); } if ((acc & Opcodes.ACC_FINAL) != 0) { sb.append("final "); } if ((acc & Opcodes.ACC_INTERFACE) != 0) { sb.append("interace "); } if ((acc & Opcodes.ACC_NATIVE) != 0) { sb.append("native "); } if ((acc & Opcodes.ACC_STRICT) != 0) { sb.append("strict "); } if ((acc & Opcodes.ACC_SYNCHRONIZED) != 0) { sb.append("synchronized "); } if ((acc & Opcodes.ACC_TRANSIENT) != 0) { sb.append("transient "); } if ((acc & Opcodes.ACC_VARARGS) != 0) { sb.append("varargs "); } if ((acc & Opcodes.ACC_VOLATILE) != 0) { sb.append("volatile "); } return sb.toString(); }
From source file:com.googlecode.dex2jar.tools.JarAccessCmd.java
License:Apache License
static int str2acc(String s) { if (s == null) { return 0; }//from w w w .ja v a 2 s .c o m int result = 0; s = s.toLowerCase(); if (s.contains("public")) { result |= Opcodes.ACC_PUBLIC; } if (s.contains("private")) { result |= Opcodes.ACC_PRIVATE; } if (s.contains("protected")) { result |= Opcodes.ACC_PROTECTED; } if (s.contains("final")) { result |= Opcodes.ACC_FINAL; } if (s.contains("static")) { result |= Opcodes.ACC_STATIC; } if (s.contains("super")) { result |= Opcodes.ACC_SUPER; } if (s.contains("synchronized")) { result |= Opcodes.ACC_SYNCHRONIZED; } if (s.contains("volatile")) { result |= Opcodes.ACC_VOLATILE; } if (s.contains("bridge")) { result |= Opcodes.ACC_BRIDGE; } if (s.contains("transient")) { result |= Opcodes.ACC_TRANSIENT; } if (s.contains("varargs")) { result |= Opcodes.ACC_VARARGS; } if (s.contains("native")) { result |= Opcodes.ACC_NATIVE; } if (s.contains("strict")) { result |= Opcodes.ACC_STRICT; } if (s.contains("interface")) { result |= Opcodes.ACC_INTERFACE; } if (s.contains("abstract")) { result |= Opcodes.ACC_ABSTRACT; } if (s.contains("synthetic")) { result |= Opcodes.ACC_SYNTHETIC; } if (s.contains("annotation")) { result |= Opcodes.ACC_ANNOTATION; } if (s.contains("enum")) { result |= Opcodes.ACC_ENUM; } if (s.contains("deprecated")) { result |= Opcodes.ACC_DEPRECATED; } return result; }
From source file:de.sanandrew.core.manpack.transformer.AnnotationChecker.java
License:Creative Commons License
@Override public byte[] transform(String name, String transformedName, byte[] bytes) { ClassNode cn = ASMHelper.createClassNode(bytes); for (MethodNode method : cn.methods) { if (method.visibleAnnotations != null) { for (AnnotationNode annotation : method.visibleAnnotations) { if (annotation.desc.equals("Lde/sanandrew/core/manpack/util/annotation/ASMOverride;")) { String asmMethodName = annotation.values.get(1).toString(); MethodNode asmMethod = getSignature(asmMethodName); if (!method.name.equals(asmMethod.name)) { String err = "Attempting to override Method %s in Class %s with incompatible name %s!"; ManPackLoadingPlugin.MOD_LOG.log(Level.FATAL, String.format(err, asmMethod.name, cn.name, method.name)); throw new OverrideException(String.format("Method name %s is not equal to %s!", method.name, asmMethod.name)); } else if (!method.desc.equals(asmMethod.desc)) { String err = "Attempting to override Method %s, description %s, in Class %s with incompatible description %s!"; ManPackLoadingPlugin.MOD_LOG.log(Level.FATAL, String.format(err, asmMethod.name, asmMethod.desc, cn.name, method.desc)); throw new OverrideException(String.format("Method desc %s is not equal to %s!", method.desc, asmMethod.desc)); } else if (getAccessLevelInt(method.access) < getAccessLevelInt(asmMethod.access)) { String err = "Attempting to assign weaker access privileges ('%s') on %s in %s; should be '%s'"; ManPackLoadingPlugin.MOD_LOG.log(Level.FATAL, String.format(err, getAccessLevelName(method.access), asmMethod.name, cn.name, getAccessLevelName(asmMethod.access))); throw new OverrideException(String.format("Access level %s is weaker than %s!", getAccessLevelName(method.access), getAccessLevelName(asmMethod.access))); } else if (getAccessLevelInt(asmMethod.access) == 1) { String classPkg = cn.name.substring(0, cn.name.lastIndexOf('/')); String ownerPkg = ASMHelper.getMethodInsnNode(asmMethod.access, asmMethodName, false).owner.substring(0, cn.name.lastIndexOf('/')); if (!classPkg.equals(ownerPkg)) { String err = "Attempting to override packageLocal method %s outside of package %s in class %s, which is in package %s!"; ManPackLoadingPlugin.MOD_LOG.log(Level.FATAL, String.format(err, method.name, ownerPkg, cn.name, classPkg)); throw new OverrideException(String.format( "Class %s lies outside package %s for method %s to be overridden", cn.name, ownerPkg, classPkg)); }/* ww w .ja v a 2 s . c om*/ } else if (checkBitwiseEqual(asmMethod.access, Opcodes.ACC_DEPRECATED)) { ManPackLoadingPlugin.MOD_LOG.log(Level.WARN, String.format( "The Method %s is marked as deprecated! It is most likely that the method is " + "not injected in any superclass anymore! Thus this may not be called!", asmMethod.name)); } } } } } return bytes; }
From source file:de.sanandrew.core.manpack.transformer.AnnotationChecker.java
License:Creative Commons License
private static int getAccessLevelOpcode(String accessName) { String[] accessSplit = accessName.split(";"); int ret = 0;//w ww . j av a 2 s . c om for (String acc : accessSplit) { switch (acc) { case "private": ret |= Opcodes.ACC_PRIVATE; break; case "protected": ret |= Opcodes.ACC_PROTECTED; break; case "public": ret |= Opcodes.ACC_PUBLIC; break; case "deprecated": ret |= Opcodes.ACC_DEPRECATED; break; } } return ret; }
From source file:de.thetaphi.forbiddenapis.ClassScanner.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from ww w .java 2 s . c o m this.internalMainClassName = name; this.isDeprecated = (access & Opcodes.ACC_DEPRECATED) != 0; reportClassViolation(checkClassDefinition(superName, interfaces), "class declaration"); if (this.isDeprecated) { classSuppressed |= suppressAnnotations.matcher(DEPRECATED_TYPE.getClassName()).matches(); reportClassViolation(checkType(DEPRECATED_TYPE), "deprecation on class declaration"); } }
From source file:de.thetaphi.forbiddenapis.ClassScanner.java
License:Apache License
@Override public FieldVisitor visitField(final int access, final String name, final String desc, String signature, Object value) {/* w w w .j a va2 s.c o m*/ currentGroupId++; if (classSuppressed) { return null; } return new FieldVisitor(Opcodes.ASM5) { final boolean isDeprecated = (access & Opcodes.ACC_DEPRECATED) != 0; { // only check signature, if field is not synthetic if ((access & Opcodes.ACC_SYNTHETIC) == 0) { reportFieldViolation(checkDescriptor(desc), "field declaration"); } if (this.isDeprecated) { maybeSuppressCurrentGroup(DEPRECATED_TYPE); reportFieldViolation(checkType(DEPRECATED_TYPE), "deprecation on field declaration"); } } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (this.isDeprecated && DEPRECATED_DESCRIPTOR.equals(desc)) { // don't report 2 times! return null; } final Type type = Type.getType(desc); maybeSuppressCurrentGroup(type); reportFieldViolation(checkAnnotationDescriptor(type, visible), "annotation on field declaration"); return null; } @Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { reportFieldViolation(checkAnnotationDescriptor(Type.getType(desc), visible), "type annotation on field declaration"); return null; } private void reportFieldViolation(String violation, String where) { if (violation != null) { violations.add(new ForbiddenViolation(currentGroupId, violation, String.format(Locale.ENGLISH, "%s of '%s'", where, name), -1)); } } }; }
From source file:de.thetaphi.forbiddenapis.ClassScanner.java
License:Apache License
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, String signature, String[] exceptions) {/*from ww w. j ava 2 s. c om*/ currentGroupId++; if (classSuppressed) { return null; } return new MethodVisitor(Opcodes.ASM5) { private final Method myself = new Method(name, desc); private final boolean isDeprecated = (access & Opcodes.ACC_DEPRECATED) != 0; private int lineNo = -1; { // only check signature, if method is not synthetic if ((access & Opcodes.ACC_SYNTHETIC) == 0) { reportMethodViolation(checkDescriptor(desc), "method declaration"); } if (this.isDeprecated) { maybeSuppressCurrentGroup(DEPRECATED_TYPE); reportMethodViolation(checkType(DEPRECATED_TYPE), "deprecation on method declaration"); } } private String checkMethodAccess(String owner, Method method) { String violation = checkClassUse(owner, "class/interface"); if (violation != null) { return violation; } final String printout = forbiddenMethods.get(owner + '\000' + method); if (printout != null) { return "Forbidden method invocation: " + printout; } final ClassSignature c = lookup.lookupRelatedClass(owner); if (c != null && !c.methods.contains(method)) { if (c.superName != null && (violation = checkMethodAccess(c.superName, method)) != null) { return violation; } // JVM spec says: interfaces after superclasses if (c.interfaces != null) { for (String intf : c.interfaces) { if (intf != null && (violation = checkMethodAccess(intf, method)) != null) { return violation; } } } } return null; } private String checkFieldAccess(String owner, String field) { String violation = checkClassUse(owner, "class/interface"); if (violation != null) { return violation; } final String printout = forbiddenFields.get(owner + '\000' + field); if (printout != null) { return "Forbidden field access: " + printout; } final ClassSignature c = lookup.lookupRelatedClass(owner); if (c != null && !c.fields.contains(field)) { if (c.interfaces != null) { for (String intf : c.interfaces) { if (intf != null && (violation = checkFieldAccess(intf, field)) != null) { return violation; } } } // JVM spec says: superclasses after interfaces if (c.superName != null && (violation = checkFieldAccess(c.superName, field)) != null) { return violation; } } return null; } private String checkHandle(Handle handle, boolean checkLambdaHandle) { switch (handle.getTag()) { case Opcodes.H_GETFIELD: case Opcodes.H_PUTFIELD: case Opcodes.H_GETSTATIC: case Opcodes.H_PUTSTATIC: return checkFieldAccess(handle.getOwner(), handle.getName()); case Opcodes.H_INVOKEVIRTUAL: case Opcodes.H_INVOKESTATIC: case Opcodes.H_INVOKESPECIAL: case Opcodes.H_NEWINVOKESPECIAL: case Opcodes.H_INVOKEINTERFACE: final Method m = new Method(handle.getName(), handle.getDesc()); if (checkLambdaHandle && handle.getOwner().equals(internalMainClassName) && handle.getName().startsWith(LAMBDA_METHOD_NAME_PREFIX)) { // as described in <http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html>, // we will record this metafactory call as "lambda" invokedynamic, // so we can assign the called lambda with the same groupId like *this* method: lambdas.put(m, currentGroupId); } return checkMethodAccess(handle.getOwner(), m); } return null; } private String checkConstant(Object cst, boolean checkLambdaHandle) { if (cst instanceof Type) { return checkType((Type) cst); } else if (cst instanceof Handle) { return checkHandle((Handle) cst, checkLambdaHandle); } return null; } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (this.isDeprecated && DEPRECATED_DESCRIPTOR.equals(desc)) { // don't report 2 times! return null; } final Type type = Type.getType(desc); maybeSuppressCurrentGroup(type); reportMethodViolation(checkAnnotationDescriptor(type, visible), "annotation on method declaration"); return null; } @Override public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { reportMethodViolation(checkAnnotationDescriptor(Type.getType(desc), visible), "parameter annotation on method declaration"); return null; } @Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { reportMethodViolation(checkAnnotationDescriptor(Type.getType(desc), visible), "type annotation on method declaration"); return null; } @Override public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { reportMethodViolation(checkAnnotationDescriptor(Type.getType(desc), visible), "annotation in method body"); return null; } @Override public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { reportMethodViolation(checkAnnotationDescriptor(Type.getType(desc), visible), "annotation in method body"); return null; } @Override public AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { reportMethodViolation(checkAnnotationDescriptor(Type.getType(desc), visible), "annotation in method body"); return null; } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { reportMethodViolation(checkMethodAccess(owner, new Method(name, desc)), "method body"); } @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { reportMethodViolation(checkFieldAccess(owner, name), "method body"); } @Override public void visitTypeInsn(int opcode, String type) { if (opcode == Opcodes.ANEWARRAY) { reportMethodViolation(checkType(Type.getObjectType(type)), "method body"); } } @Override public void visitMultiANewArrayInsn(String desc, int dims) { reportMethodViolation(checkDescriptor(desc), "method body"); } @Override public void visitLdcInsn(Object cst) { reportMethodViolation(checkConstant(cst, false), "method body"); } @Override public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { final boolean isLambdaMetaFactory = LAMBDA_META_FACTORY_INTERNALNAME.equals(bsm.getOwner()); reportMethodViolation(checkHandle(bsm, false), "method body"); for (final Object cst : bsmArgs) { reportMethodViolation(checkConstant(cst, isLambdaMetaFactory), "method body"); } } private String getHumanReadableMethodSignature() { final Type[] args = Type.getType(myself.getDescriptor()).getArgumentTypes(); final StringBuilder sb = new StringBuilder(myself.getName()).append('('); boolean comma = false; for (final Type t : args) { if (comma) sb.append(','); sb.append(t.getClassName()); comma = true; } sb.append(')'); return sb.toString(); } private void reportMethodViolation(String violation, String where) { if (violation != null) { violations.add(new ForbiddenViolation(currentGroupId, myself, violation, String.format(Locale.ENGLISH, "%s of '%s'", where, getHumanReadableMethodSignature()), lineNo)); } } @Override public void visitLineNumber(int lineNo, Label start) { this.lineNo = lineNo; } }; }