Example usage for org.objectweb.asm.signature SignatureReader acceptType

List of usage examples for org.objectweb.asm.signature SignatureReader acceptType

Introduction

In this page you can find the example usage for org.objectweb.asm.signature SignatureReader acceptType.

Prototype

public void acceptType(final SignatureVisitor signatureVisitor) 

Source Link

Document

Makes the given visitor visit the signature of this SignatureReader .

Usage

From source file:com.android.build.gradle.shrinker.DependencyFinderVisitor.java

License:Apache License

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    T field = mGraph.getMemberReference(mClassName, name, desc);
    Type fieldType = Type.getType(desc);
    handleDeclarationType(field, fieldType);

    if (signature != null) {
        SignatureReader reader = new SignatureReader(signature);
        SignatureVisitor visitor = new DependencyFinderSignatureVisitor();
        reader.acceptType(visitor);
    }/*from   w  w  w . j a v  a  2  s.com*/

    return super.visitField(access, name, desc, signature, value);
}

From source file:com.android.builder.shrinker.DependencyFinderVisitor.java

License:Apache License

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    T field = mGraph.getMemberReference(mClassName, name, desc);
    Type fieldType = Type.getType(desc);
    handleDeclarationType(field, fieldType);

    if (signature != null) {
        SignatureReader reader = new SignatureReader(signature);
        SignatureVisitor visitor = new DependencyFinderSignatureVisitor(field);
        reader.acceptType(visitor);
    }//from   ww  w . ja  v  a2s  .c  o  m

    return super.visitField(access, name, desc, signature, value);
}

From source file:com.android.mkstubs.sourcer.FieldSourcer.java

License:Apache License

@Override
public void visitEnd() {
    // Need to write type and field name after the annotations and attributes.

    AccessSourcer as = new AccessSourcer(mOutput);
    as.write(mAccess, AccessSourcer.IS_FIELD);

    if (mSignature == null) {
        mOutput.write(" %s", Type.getType(mDesc).getClassName());
    } else {//from w ww .j  a v  a2s.  com
        mOutput.write(" ");
        SignatureReader sigReader = new SignatureReader(mSignature);
        SignatureSourcer sigSourcer = new SignatureSourcer();
        sigReader.acceptType(sigSourcer);
        mOutput.write(sigSourcer.toString());
    }

    mOutput.write(" %s", mName);

    mOutput.write(";\n");
}

From source file:com.android.tools.layoutlib.create.RenameClassAdapter.java

License:Apache License

/**
 * Renames the FieldTypeSignature handled by ClassVisitor.visitField
 * or MethodVisitor.visitLocalVariable.//from www . j av  a2  s  .c  om
 */
String renameFieldSignature(String sig) {
    if (sig == null) {
        return null;
    }
    SignatureReader reader = new SignatureReader(sig);
    SignatureWriter writer = new SignatureWriter();
    reader.acceptType(new RenameSignatureAdapter(writer));
    sig = writer.toString();
    return sig;
}

From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java

License:Open Source License

@Override
public NashornTextifier visitField(final int access, final String name, final String desc,
        final String signature, final Object value) {
    final StringBuilder sb = new StringBuilder();
    //        sb.append('\n');
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        sb.append(tab).append("// DEPRECATED\n");
    }//from  w  ww.j a v  a 2s. c  o  m

    /*        sb.append(tab).
    append("// access flags 0x").
    append(Integer.toHexString(access).toUpperCase()).
    append('\n');
    */

    if (signature != null) {
        sb.append(tab);
        appendDescriptor(sb, FIELD_SIGNATURE, signature);

        final TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
        final SignatureReader r = new SignatureReader(signature);
        r.acceptType(sv);
        sb.append(tab).append("// declaration: ").append(sv.getDeclaration()).append('\n');
    }

    sb.append(tab);
    appendAccess(sb, access);

    final String prunedDesc = desc.endsWith(";") ? desc.substring(0, desc.length() - 1) : desc;
    appendDescriptor(sb, FIELD_DESCRIPTOR, prunedDesc);
    sb.append(' ').append(name);
    if (value != null) {
        sb.append(" = ");
        if (value instanceof String) {
            sb.append('\"').append(value).append('\"');
        } else {
            sb.append(value);
        }
    }

    sb.append(";\n");
    addText(sb);

    final NashornTextifier t = createNashornTextifier();
    addText(t.getText());

    return t;
}

From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java

License:Open Source License

@Override
public void visitLocalVariable(final String name, final String desc, final String signature, final Label start,
        final Label end, final int index) {

    final StringBuilder sb = new StringBuilder();
    if (!localVarsStarted) {
        text.add("\n");
        localVarsStarted = true;/*from  ww w . j av  a 2 s .co m*/
        graph.addNode("vars");
        currentBlock = "vars";
    }

    sb.append(tab2).append("local ").append(name).append(' ');
    final int len = sb.length();
    for (int i = 0; i < 25 - len; i++) {
        sb.append(' ');
    }
    String label;

    label = appendLabel(sb, start);
    for (int i = 0; i < 5 - label.length(); i++) {
        sb.append(' ');
    }
    label = appendLabel(sb, end);
    for (int i = 0; i < 5 - label.length(); i++) {
        sb.append(' ');
    }

    sb.append(index).append(tab2);

    appendDescriptor(sb, FIELD_DESCRIPTOR, desc);
    sb.append('\n');

    if (signature != null) {
        sb.append(tab2);
        appendDescriptor(sb, FIELD_SIGNATURE, signature);

        final TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
        final SignatureReader r = new SignatureReader(signature);
        r.acceptType(sv);
        sb.append(tab2).append("// declaration: ").append(sv.getDeclaration()).append('\n');
    }
    addText(sb.toString());
}

From source file:com.google.gwt.dev.javac.asm.CollectReferencesVisitor.java

License:Apache License

private void collectTypesFromFieldSignature(String signature) {
    if (signature == null) {
        return;/*from   w  w  w.  j  ava 2s .  c  om*/
    }
    SignatureReader reader = new SignatureReader(signature);
    reader.acceptType(new CollectGenericTypes());
}

From source file:com.google.gwt.dev.javac.CompilationUnitTypeOracleUpdater.java

License:Apache License

private boolean resolveField(TreeLogger logger, JRealClassType unresolvedType, CollectFieldData field,
        TypeParameterLookup typeParamLookup, int[] nextEnumOrdinal, TypeOracleBuildContext context) {
    Map<Class<? extends Annotation>, Annotation> declaredAnnotations = Maps.newHashMap();
    resolveAnnotations(logger, field.getAnnotations(), declaredAnnotations);
    String name = field.getName();
    JField jfield;//  www .j a v  a 2 s  .co  m
    if ((field.getAccess() & Opcodes.ACC_ENUM) != 0) {
        assert (unresolvedType.isEnum() != null);
        jfield = newEnumConstant(unresolvedType, name, declaredAnnotations, nextEnumOrdinal[0]++);
    } else {
        JField newField = newField(unresolvedType, name, declaredAnnotations);
        jfield = newField;
    }

    // Get modifiers.
    addModifierBits(jfield, mapBits(ASM_TO_SHARED_MODIFIERS, field.getAccess()));

    String signature = field.getSignature();
    JType fieldJType;
    if (signature != null) {
        SignatureReader reader = new SignatureReader(signature);
        JType[] fieldTypeRef = new JType[1];
        reader.acceptType(
                new ResolveTypeSignature(context.resolver, logger, fieldTypeRef, typeParamLookup, null));
        fieldJType = fieldTypeRef[0];
        if (fieldJType == null) {
            logger.log(TreeLogger.ERROR, "Unable to resolve type in field signature " + signature);
            return false;
        }
    } else {
        Type fieldType = Type.getType(field.getDesc());
        fieldJType = resolveType(fieldType);
        if (fieldJType == null) {
            logger.log(TreeLogger.ERROR,
                    "Unable to resolve type " + fieldType.getInternalName() + " of field " + field.getName());
            return false;
        }
    }
    setFieldType(jfield, fieldJType);
    return true;
}

From source file:com.google.gwt.dev.javac.TypeOracleMediator.java

License:Open Source License

private boolean resolveField(TreeLogger logger, JRealClassType type, CollectFieldData field,
        TypeParameterLookup typeParamLookup, int[] nextEnumOrdinal) {
    Map<Class<? extends Annotation>, Annotation> declaredAnnotations = new HashMap<Class<? extends Annotation>, Annotation>();
    resolveAnnotations(logger, field.getAnnotations(), declaredAnnotations);
    String name = field.getName();
    JField jfield;//w  w  w  .ja v a2 s .c  o  m
    if ((field.getAccess() & Opcodes.ACC_ENUM) != 0) {
        assert (type.isEnum() != null);
        jfield = newEnumConstant(type, name, declaredAnnotations, nextEnumOrdinal[0]++);
    } else {
        JField newField = newField(type, name, declaredAnnotations);
        jfield = newField;
    }

    // Get modifiers.
    //
    addModifierBits(jfield, mapBits(ASM_TO_SHARED_MODIFIERS, field.getAccess()));

    String signature = field.getSignature();
    JType fieldType;
    if (signature != null) {
        SignatureReader reader = new SignatureReader(signature);
        JType[] fieldTypeRef = new JType[1];
        reader.acceptType(
                new ResolveTypeSignature(resolver, binaryMapper, logger, fieldTypeRef, typeParamLookup, null));
        fieldType = fieldTypeRef[0];
        // TraceSignatureVisitor trace = new TraceSignatureVisitor(
        // methodData.getAccess());
        // reader.acceptType(trace);
        // System.err.println("Field " + name + ": " + trace.getDeclaration());

    } else {
        fieldType = resolveType(Type.getType(field.getDesc()));
    }
    if (fieldType == null) {
        return false;
    }
    setFieldType(jfield, fieldType);
    return true;
}

From source file:com.pongasoft.kiwidoc.builder.serializer.type.TypeDecoder.java

License:Apache License

/**
 * Decodes the signature for a single type (as was encoded by
 * {@link TypeEncoder#encodeType(Type)}). 
 *//*from  w  w  w .ja  va2  s  .  co  m*/
public Type decodeType(String signature) {
    if (signature == null || signature.equals(""))
        return null;

    SignatureReader sr = new SignatureReader(signature);

    TypeHolder typeHolder = new TypeHolder();

    TypeBuilder visitor = new TypeBuilder(typeHolder);

    try {
        sr.acceptType(visitor);
    } catch (Exception e) {
        throw new IllegalArgumentException("invalid signature " + signature, e);
    }

    return typeHolder.getType();
}