List of usage examples for org.objectweb.asm TypeReference getSort
public int getSort()
From source file:org.decojer.cavaj.readers.asm.ReadClassVisitor.java
License:Open Source License
@Override public AnnotationVisitor visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) { final A a = this.readAnnotationMemberVisitor.init(desc, visible ? RetentionPolicy.RUNTIME : RetentionPolicy.CLASS); if (a == null) { log.warn(getT() + ": Cannot read annotation for descriptor '" + desc + "'!"); return null; }//from w w w . j ava 2 s.c o m final TypeReference typeReference = new TypeReference(typeRef); switch (typeReference.getSort()) { case TypeReference.CLASS_EXTENDS: { final int superTypeIndex = typeReference.getSuperTypeIndex(); if (superTypeIndex == -1) { // -1: annotation targets extends type final T superT = getT().getSuperT(); if (superT == null) { log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing super type!"); break; } getT().setSuperT(annotateT(superT, a, typePath)); break; } // 0-based interface index final T[] interfaceTs = getT().getInterfaceTs(); if (superTypeIndex <= interfaceTs.length) { log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing interface type at index '" + superTypeIndex + "'!"); break; } final T interfaceT = interfaceTs[superTypeIndex]; assert interfaceT != null; interfaceTs[superTypeIndex] = annotateT(interfaceT, a, typePath); break; } case TypeReference.CLASS_TYPE_PARAMETER: { final int typeParameterIndex = typeReference.getTypeParameterIndex(); final T[] typeParams = getT().getTypeParams(); if (typeParams.length <= typeParameterIndex) { log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing type parameter at index '" + typeParameterIndex + "'!"); break; } final T typeParam = typeParams[typeParameterIndex]; assert typeParam != null; typeParams[typeParameterIndex] = annotateT(typeParam, a, typePath); break; } case TypeReference.CLASS_TYPE_PARAMETER_BOUND: { final int typeParameterIndex = typeReference.getTypeParameterIndex(); final int typeParameterBoundIndex = typeReference.getTypeParameterBoundIndex(); final T t = getT().getTypeParams()[typeParameterIndex]; if (typeParameterBoundIndex == 0) { // 0: annotation targets extends type final T superT = t.getSuperT(); if (superT == null) { log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing type parameter bound super type!"); break; } t.setSuperT(annotateT(superT, a, typePath)); break; } // 1-based interface index final T[] interfaceTs = t.getInterfaceTs(); if (interfaceTs.length <= typeParameterBoundIndex - 1) { log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing interface type at index '" + (typeParameterBoundIndex - 1) + "'!"); break; } final T interfaceT = interfaceTs[typeParameterBoundIndex - 1]; assert interfaceT != null; interfaceTs[typeParameterBoundIndex - 1] = annotateT(interfaceT, a, typePath); break; } default: log.warn( this.t + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort()) + "' : " + typeRef + " : " + typePath + " : " + desc + " : " + visible); } return this.readAnnotationMemberVisitor; }
From source file:org.decojer.cavaj.readers.asm.ReadFieldVisitor.java
License:Open Source License
@Override public AnnotationVisitor visitTypeAnnotation(final int typeRef, @Nullable final TypePath typePath, final String desc, final boolean visible) { final A a = this.readAnnotationMemberVisitor.init(desc, visible ? RetentionPolicy.RUNTIME : RetentionPolicy.CLASS); if (a == null) { log.warn(getF() + ": Cannot read annotation for descriptor '" + desc + "'!"); return null; }//from w w w.ja v a2s . c o m final TypeReference typeReference = new TypeReference(typeRef); switch (typeReference.getSort()) { case TypeReference.FIELD: getF().setValueT(annotateT(getF().getValueT(), a, typePath)); break; default: log.warn( getF() + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort()) + "' : " + typeRef + " : " + typePath + " : " + desc + " : " + visible); } return this.readAnnotationMemberVisitor; }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
private boolean applyOperationAnnotation(@Nonnull final A a, final int typeRef, @Nullable final TypePath typePath, final boolean logError) { final Op op = this.ops.get(this.ops.size() - 1); final TypeReference typeReference = new TypeReference(typeRef); switch (typeReference.getSort()) { case TypeReference.CAST: { if (op instanceof CAST) { ((CAST) op).setToT(annotateT(((CAST) op).getToT(), a, typePath)); return true; }/*from www.ja v a 2 s . c om*/ if (logError) { log.warn(getM() + ": Wrong operation '" + op + "' for type annotation ref sort 'CAST' : " + typeRef + " : " + typePath + " : " + a); } return false; } case TypeReference.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: case TypeReference.METHOD_INVOCATION_TYPE_ARGUMENT: { if (op instanceof INVOKE) { log.warn(getM() + ": Missing bytecode info, cannot really apply type annotation ref sort 'CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT' or 'METHOD_INVOCATION_TYPE_ARGUMENT' : " + typeRef + " : " + typePath + " : " + a); return true; } if (logError) { log.warn(getM() + ": Wrong operation '" + op + "' for type annotation ref sort 'CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT' or 'METHOD_INVOCATION_TYPE_ARGUMENT' : " + typeRef + " : " + typePath + " : " + a); } return false; } case TypeReference.CONSTRUCTOR_REFERENCE: case TypeReference.METHOD_REFERENCE: { if (op instanceof INVOKE) { final Object[] bsArgs = ((INVOKE) op).getBsArgs(); if (bsArgs != null && bsArgs.length > 1) { final Object bsArg = bsArgs[1]; if (bsArg instanceof M) { bsArgs[1] = annotateM((M) bsArg, a, typePath); return true; } } } if (logError) { log.warn(getM() + ": Wrong operation '" + op + "' for type annotation ref sort 'CONSTRUCTOR_REFERENCE' or 'METHOD_REFERENCE' : " + typeRef + " : " + typePath + " : " + a); } return false; } case TypeReference.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: case TypeReference.METHOD_REFERENCE_TYPE_ARGUMENT: { if (op instanceof INVOKE) { final Object[] bsArgs = ((INVOKE) op).getBsArgs(); if (bsArgs != null && bsArgs.length > 1 && bsArgs[1] instanceof M) { log.warn(getM() + ": Missing bytecode info, cannot really apply type annotation ref sort 'CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT' or 'METHOD_REFERENCE_TYPE_ARGUMENT' : " + typeRef + " : " + typePath + " : " + a); return true; } } if (logError) { log.warn(getM() + ": Wrong operation '" + op + "' for type annotation ref sort 'CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT' or 'METHOD_REFERENCE_TYPE_ARGUMENT' : " + typeRef + " : " + typePath + " : " + a); } return false; } case TypeReference.NEW: { if (op instanceof NEW || op instanceof NEWARRAY) { ((TypedOp) op).setT(annotateT(((TypedOp) op).getT(), a, typePath)); return true; } if (logError) { log.warn(getM() + ": Wrong operation '" + op + "' for type annotation ref sort 'NEW' : " + typeRef + " : " + typePath + " : " + a); } return false; } default: log.warn( getM() + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort()) + "' : " + typeRef + " : " + typePath + " : " + a); } return false; }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public AnnotationVisitor visitLocalVariableAnnotation(final int typeRef, final TypePath typePath, final Label[] start, final Label[] end, final int[] index, final String desc, final boolean visible) { /*/* w w w .j a v a2 s . c o m*/ * 3.3.7: The table length field specifies the number of entries in the table array; * multiple entries are necessary because a compiler is permitted to break a single variable * into multiple live ranges with different local variable indices. The start pc and length * fields specify the variables live range in the bytecodes of the local variables * containing method (from offset start pc, inclusive, to offset start pc + length, * exclusive). The index field stores the local variables index in that method. These * fields are similar to those of the optional LocalVariableTable attribute [LBBY12, * 4.8.12]. Storing local variable type annotations in the class file raises certain * challenges. For example, live ranges are not isomorphic to local variables. Note that a * local variable with no live range might not appear in the class file; that is OK, because * it is irrelevant to the program. A Runtime[In]visibleTypeAnnotations attribute containing * a localvar target appears in the attributes table of a Code attribute. */ final A a = this.annotationVisitor.init(desc, visible ? RetentionPolicy.RUNTIME : RetentionPolicy.CLASS); if (a == null) { log.warn(getM() + ": Cannot read annotation for descriptor '" + desc + "'!"); return null; } final TypeReference typeReference = new TypeReference(typeRef); switch (typeReference.getSort()) { case TypeReference.LOCAL_VARIABLE: for (int i = index.length; i-- > 0;) { final List<V> vs = this.reg2vs.get(index[i]); if (vs != null) { // TODO hmmm, we may have to remember this info (like receiver), // we cannot apply it without variable analysis in none-debug bytecode, // missing local variable tables! this whole new bytecode sucks for (final V v : vs) { if (v.validIn(getPc(start[i]), getPc(end[i]))) { v.setT(annotateT(v.getT(), a, typePath)); } } } } break; default: log.warn( getM() + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort()) + "' : " + typeRef + " : " + typePath + " : " + desc + " : " + visible); } return this.annotationVisitor; }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public AnnotationVisitor visitTryCatchAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) { final A a = this.annotationVisitor.init(desc, visible ? RetentionPolicy.RUNTIME : RetentionPolicy.CLASS); if (a == null) { log.warn(getM() + ": Cannot read annotation for descriptor '" + desc + "'!"); return null; }//from w w w .j av a2 s . c o m final TypeReference typeReference = new TypeReference(typeRef); switch (typeReference.getSort()) { case TypeReference.EXCEPTION_PARAMETER: { final int tryCatchBlockIndex = typeReference.getTryCatchBlockIndex(); final Exc exc = this.excs.get(tryCatchBlockIndex); if (exc == null) { log.warn(getM() + ": Cannot apply type annotation '" + a + "' to missing exception!"); break; } final T excT = exc.getT(); if (excT == null) { log.warn(getM() + ": Cannot apply type annotation '" + a + "' to catch all exception!"); break; } exc.setT(annotateT(excT, a, typePath)); break; } default: log.warn( getM() + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort()) + "' : " + typeRef + " : " + typePath + " : " + desc + " : " + visible); } return this.annotationVisitor; }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public AnnotationVisitor visitTypeAnnotation(final int typeRef, @Nullable final TypePath typePath, final String desc, final boolean visible) { final A a = this.annotationVisitor.init(desc, visible ? RetentionPolicy.RUNTIME : RetentionPolicy.CLASS); if (a == null) { log.warn(getM() + ": Cannot read annotation for descriptor '" + desc + "'!"); return null; }/* w ww . j a v a2s . com*/ final TypeReference typeReference = new TypeReference(typeRef); switch (typeReference.getSort()) { case TypeReference.METHOD_FORMAL_PARAMETER: { final int formalParameterIndex = typeReference.getFormalParameterIndex(); final T[] paramTs = getM().getParamTs(); if (paramTs.length <= formalParameterIndex) { log.warn(getM() + ": Cannot apply type annotation '" + a + "' to missing method parameter at index '" + formalParameterIndex + "'!"); break; } final T paramT = paramTs[formalParameterIndex]; assert paramT != null; paramTs[formalParameterIndex] = annotateT(paramT, a, typePath); break; } case TypeReference.METHOD_RECEIVER: { // for type annotations like: void test(@Annots This this, ...) for none-static methods // TODO receiver needs full signature, test-method DU#getQualifiedT(T) does't work, // because we would have to read outer classes first T receiverT = getM().getReceiverT(); if (receiverT == null) { receiverT = getM().getT(); } if (receiverT == null) { assert getM().isDynamic(); log.warn(getM() + ": Cannot apply type annotation '" + a + "' to missing method receiver!"); break; } getM().setReceiverT(annotateT(receiverT, a, typePath)); break; } case TypeReference.METHOD_RETURN: getM().setReturnT(annotateT(getM().getReturnT(), a, typePath)); break; case TypeReference.METHOD_TYPE_PARAMETER: { final int typeParameterIndex = typeReference.getTypeParameterIndex(); final T[] typeParams = getM().getTypeParams(); if (typeParams.length <= typeParameterIndex) { log.warn(getM() + ": Cannot apply type annotation '" + a + "' to missing method type parameter at index '" + typeParameterIndex + "'!"); break; } final T typeParam = typeParams[typeParameterIndex]; assert typeParam != null; typeParams[typeParameterIndex] = annotateT(typeParam, a, typePath); break; } case TypeReference.METHOD_TYPE_PARAMETER_BOUND: { final int typeParameterIndex = typeReference.getTypeParameterIndex(); final int typeParameterBoundIndex = typeReference.getTypeParameterBoundIndex(); final T t = getM().getTypeParams()[typeParameterIndex]; if (typeParameterBoundIndex == 0) { // 0: annotation targets extends type final T superT = t.getSuperT(); if (superT == null) { log.warn(getM() + ": Cannot apply type annotation '" + a + "' to missing super type!"); break; } t.setSuperT(annotateT(superT, a, typePath)); break; } // 1-based interface index final T[] interfaceTs = t.getInterfaceTs(); if (interfaceTs.length < typeParameterBoundIndex) { log.warn(getM() + ": Cannot apply type annotation '" + a + "' to missing interface type!"); break; } final T interfaceT = interfaceTs[typeParameterBoundIndex - 1]; assert interfaceT != null; interfaceTs[typeParameterBoundIndex - 1] = annotateT(interfaceT, a, typePath); break; } case TypeReference.THROWS: { final int exceptionIndex = typeReference.getExceptionIndex(); final T[] throwsTs = getM().getThrowsTs(); if (throwsTs.length < exceptionIndex) { log.warn(getM() + ": Cannot apply type annotation '" + a + "' to missing throws type!"); break; } final T throwsT = throwsTs[exceptionIndex]; assert throwsT != null; throwsTs[exceptionIndex] = annotateT(throwsT, a, typePath); break; } default: log.warn( getM() + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort()) + "' : " + typeRef + " : " + typePath + " : " + desc + " : " + visible); } return this.annotationVisitor; }