List of usage examples for org.objectweb.asm Opcodes H_GETSTATIC
int H_GETSTATIC
To view the source code for org.objectweb.asm Opcodes H_GETSTATIC.
Click Source Link
From source file:com.devexperts.usages.ClassUsagesAnalyzer.java
License:Open Source License
private void markHandleUse(Handle handle, Member usedFrom, UseKind useKind) { markTypeUse(Type.getType(handle.getDesc()), usedFrom, useKind); String className = Type.getType(handle.getOwner()).getClassName(); switch (handle.getTag()) { case Opcodes.H_GETFIELD: case Opcodes.H_GETSTATIC: case Opcodes.H_PUTFIELD: case Opcodes.H_PUTSTATIC: markMemberUse(className, handle.getName(), usedFrom, useKind); break;//w w w .jav a 2 s . co m case Opcodes.H_INVOKEVIRTUAL: case Opcodes.H_INVOKESTATIC: case Opcodes.H_INVOKESPECIAL: case Opcodes.H_NEWINVOKESPECIAL: case Opcodes.H_INVOKEINTERFACE: markMemberUse(className, Member.methodMemberName(handle.getName(), Type.getType(handle.getDesc())), usedFrom, useKind); } }
From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java
License:Open Source License
private static void appendHandle(final StringBuilder sb, final Handle h) { switch (h.getTag()) { case Opcodes.H_GETFIELD: sb.append("getfield"); break;//from w ww. j a v a2 s .com case Opcodes.H_GETSTATIC: sb.append("getstatic"); break; case Opcodes.H_PUTFIELD: sb.append("putfield"); break; case Opcodes.H_PUTSTATIC: sb.append("putstatic"); break; case Opcodes.H_INVOKEINTERFACE: sb.append("interface"); break; case Opcodes.H_INVOKESPECIAL: sb.append("special"); break; case Opcodes.H_INVOKESTATIC: sb.append("static"); break; case Opcodes.H_INVOKEVIRTUAL: sb.append("virtual"); break; case Opcodes.H_NEWINVOKESPECIAL: sb.append("new_special"); break; default: assert false; break; } sb.append(" '"); sb.append(h.getName()); sb.append("'"); }
From source file:com.google.devtools.build.android.desugar.scan.PrefixReferenceScanner.java
License:Open Source License
void handleReference(Handle handle) { switch (handle.getTag()) { case Opcodes.H_GETFIELD: case Opcodes.H_GETSTATIC: case Opcodes.H_PUTFIELD: case Opcodes.H_PUTSTATIC: fieldReference(handle.getOwner(), handle.getName(), handle.getDesc()); break;/*from w w w. j av a 2s . c o m*/ default: methodReference(handle.getOwner(), handle.getName(), handle.getDesc()); break; } }
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 w w w. ja va 2 s . co m*/ 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; } }; }
From source file:org.teavm.parsing.ProgramParser.java
License:Apache License
private static MethodHandle parseHandle(Handle handle) { switch (handle.getTag()) { case Opcodes.H_GETFIELD: return MethodHandle.fieldGetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_GETSTATIC: return MethodHandle.staticFieldGetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_PUTFIELD: return MethodHandle.fieldSetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_PUTSTATIC: return MethodHandle.staticFieldSetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_INVOKEVIRTUAL: return MethodHandle.virtualCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_INVOKESTATIC: return MethodHandle.staticCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_INVOKESPECIAL: return MethodHandle.specialCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_NEWINVOKESPECIAL: return MethodHandle.constructorCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_INVOKEINTERFACE: return MethodHandle.interfaceCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); default://from www .j a va2 s . c o m throw new IllegalArgumentException("Unknown handle tag: " + handle.getTag()); } }