List of usage examples for org.objectweb.asm TypeReference getTypeParameterIndex
public int getTypeParameterIndex()
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 a va2s .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.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; }/*from w ww. j av a2 s.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; }