Example usage for org.objectweb.asm Opcodes ACC_INTERFACE

List of usage examples for org.objectweb.asm Opcodes ACC_INTERFACE

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_INTERFACE.

Prototype

int ACC_INTERFACE

To view the source code for org.objectweb.asm Opcodes ACC_INTERFACE.

Click Source Link

Usage

From source file:com.google.devtools.build.android.desugar.InterfaceDesugaring.java

License:Open Source License

private ClassVisitor companion() {
    if (companion == null) {
        checkState(BitFlags.isSet(accessFlags, Opcodes.ACC_INTERFACE));
        String companionName = internalName + COMPANION_SUFFIX;

        companion = store.add(companionName);
        companion.visit(bytecodeVersion,
                // Companion class must be public so moved methods can be called from anywhere
                (accessFlags | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PUBLIC) & ~Opcodes.ACC_INTERFACE,
                companionName, (String) null, // signature
                "java/lang/Object", new String[0]);
    }/*  ww w . java 2s.c  o m*/
    return companion;
}

From source file:com.google.devtools.build.android.desugar.io.HeaderClassLoader.java

License:Open Source License

/**
 * If the {@code reader} is an interface, then extract all the declared fields in it. Otherwise,
 * return an empty list./* www.ja va  2  s  .  c  o m*/
 */
private static ImmutableList<FieldInfo> getFieldsIfReaderIsInterface(ClassReader reader) {
    if (BitFlags.isSet(reader.getAccess(), Opcodes.ACC_INTERFACE)) {
        NonPrimitiveFieldCollector collector = new NonPrimitiveFieldCollector();
        reader.accept(collector, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG);
        return collector.declaredNonPrimitiveFields.build();
    }
    return ImmutableList.of();
}

From source file:com.google.devtools.build.android.desugar.Java7Compatibility.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//w  w w.  j  a va  2s .c o  m
    internalName = name;
    isInterface = BitFlags.isSet(access, Opcodes.ACC_INTERFACE);
    super.visit(Math.min(version, Opcodes.V1_7), access, name, signature, superName, interfaces);
}

From source file:com.google.devtools.build.android.desugar.LambdaClassFixer.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {/*from   ww  w.  j  ava2s  .  c o  m*/
    checkArgument(BitFlags.noneSet(access, Opcodes.ACC_INTERFACE), "Not a class: %s", name);
    checkState(this.originalInternalName == null, "not intended for reuse but reused for %s", name);
    originalInternalName = name;
    hasState = false;
    hasFactory = false;
    desc = null;
    this.signature = null;
    this.interfaces = ImmutableList.copyOf(interfaces);
    // Rename to desired name
    super.visit(version, access, getInternalName(), signature, superName, interfaces);
}

From source file:com.google.devtools.build.android.desugar.LambdaDesugaring.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {/*from w w  w .  ja v a 2 s. c  o m*/
    checkState(internalName == null, "not intended for reuse but reused for %s", name);
    internalName = name;
    isInterface = BitFlags.isSet(access, Opcodes.ACC_INTERFACE);
    super.visit(version, access, name, signature, superName, interfaces);
}

From source file:com.google.devtools.build.wireless.testing.java.injector.coverage.CodeCoverageClassAdapter.java

License:Apache License

/**
 * Selects which class to map for coverage. At runtime mapped methods of 
 * mapped classes will have a position in the bitmask used for method 
 * coverage.//  w  ww.  jav  a  2  s .  c om
 * 
 * <p> If the current classname points to an interface it has to be skipped 
 * because interfaces are not marked for coverage. 
 * 
 * <p> If the current class is synthetic it also has to be discarded because
 * synthetic classes do not correspond to any source class and they would 
 * be a useless overhead.  
 * 
 * @return <code>true</code> if the class has to be mapped for coverage.
 */
protected boolean isIncluded() {
    if ((classOpcode & Opcodes.ACC_INTERFACE) > 0 || (classOpcode & Opcodes.ACC_SYNTHETIC) > 0
            || isAutoGeneratedClass) {
        return false;
    }

    return shouldInstrumentClass;
}

From source file:com.google.devtools.build.wireless.testing.java.injector.WhiteBoxClassAdapter.java

License:Apache License

/**
 * Visits a class and stores a flag saying if it is an interface.
 *///from   w w  w  .j a va 2 s .c o  m
@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {
    cv.visit(version, access, name, signature, superName, interfaces);
    currentClass = name;
    isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
}

From source file:com.google.devtools.kythe.analyzers.jvm.KytheClassVisitor.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from   ww  w. ja  va  2 s .c  om
    classType = JvmGraph.Type.referenceType(name);
    classVName = flagSet(access, Opcodes.ACC_ENUM) ? jvmGraph.emitEnumNode(classType)
            : flagSet(access, Opcodes.ACC_INTERFACE) ? jvmGraph.emitInterfaceNode(classType)
                    : jvmGraph.emitClassNode(classType);
    if (enclosingJarFile != null) {
        entrySets.emitEdge(entrySets.newImplicitAnchorAndEmit(enclosingJarFile).getVName(), EdgeKind.DEFINES,
                classVName);
    }
    if (superName != null) {
        entrySets.emitEdge(classVName, EdgeKind.EXTENDS,
                jvmGraph.getReferenceVName(JvmGraph.Type.referenceType(superName)));
    }
    for (String iface : interfaces) {
        entrySets.emitEdge(classVName, EdgeKind.EXTENDS,
                jvmGraph.emitInterfaceNode(JvmGraph.Type.referenceType(iface)));
    }
    super.visit(version, access, name, signature, superName, interfaces);
}

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

License:Apache License

/**
 * Doesn't retain a reference to the TypeData.
 */// www.j a va 2 s.c o  m
private JRealClassType createType(TypeData typeData, CollectClassData collectClassData,
        CollectClassData enclosingClassData) {
    int access = collectClassData.getAccess();
    String simpleName = Shared.getShortName(typeData.sourceName);
    JRealClassType type = null;
    String packageName = typeData.packageName;
    JPackage pkg = typeOracle.getOrCreatePackage(packageName);
    boolean isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    assert !collectClassData.hasNoExternalName();
    String enclosingSimpleName = null;
    if (enclosingClassData != null) {
        enclosingSimpleName = enclosingClassData.getNestedSourceName();
    }
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        type = newAnnotationType(pkg, enclosingSimpleName, simpleName);
    } else if ((access & Opcodes.ACC_ENUM) != 0) {
        type = newEnumType(pkg, enclosingSimpleName, simpleName);
    } else {
        JTypeParameter[] typeParams = getTypeParametersForClass(collectClassData);
        if ((typeParams != null && typeParams.length > 0)
                || nonStaticInsideGeneric(collectClassData, enclosingClassData)) {
            type = new JGenericType(typeOracle, pkg, enclosingSimpleName, simpleName, isInterface, typeParams);
        } else {
            type = newRealClassType(pkg, enclosingSimpleName, simpleName, isInterface);
        }
    }

    type.addModifierBits(mapBits(ASM_TO_SHARED_MODIFIERS, access));
    if (isInterface) {
        // Always add implicit modifiers on interfaces.
        type.addModifierBits(Shared.MOD_STATIC | Shared.MOD_ABSTRACT);
    }
    type.addLastModifiedTime(typeData.lastModifiedTime);

    return type;
}

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

License:Apache License

private boolean resolveClass(TreeLogger logger, JRealClassType unresolvedType, TypeOracleBuildContext context) {
    assert unresolvedType != null;
    // Avoid cycles and useless computation.
    if (resolvedTypeSourceNames.contains(unresolvedType.getQualifiedSourceName())) {
        return true;
    }//  w  w  w.j a  v  a  2s .c om
    resolvedTypeSourceNames.add(unresolvedType.getQualifiedSourceName());

    // Make sure our enclosing type is resolved first.
    if (unresolvedType.getEnclosingType() != null
            && !resolveClass(logger, unresolvedType.getEnclosingType(), context)) {
        return false;
    }

    // Build a search list for type parameters to find their definition,
    // resolving enclosing classes as we go up.
    TypeParameterLookup typeParamLookup = new TypeParameterLookup();
    typeParamLookup.pushEnclosingScopes(unresolvedType);

    CollectClassData classData = context.classDataByType.get(unresolvedType);
    assert classData != null;
    int access = classData.getAccess();

    assert (!classData.getClassType().hasNoExternalName());

    logger = logger.branch(TreeLogger.SPAM, "Found type '" + unresolvedType.getQualifiedSourceName() + "'",
            null);

    // Handle package-info classes.
    if (isPackageInfoTypeName(unresolvedType.getSimpleSourceName())) {
        return resolvePackage(logger, unresolvedType, classData.getAnnotations());
    }

    // Resolve annotations
    Map<Class<? extends Annotation>, Annotation> declaredAnnotations = Maps.newHashMap();
    resolveAnnotations(logger, classData.getAnnotations(), declaredAnnotations);
    addAnnotations(unresolvedType, declaredAnnotations);

    String signature = classData.getSignature();

    /*
     * Note: Byte code from the OpenJDK compiler doesn't contain a type signature for non-static
     * inner classes of parameterized types that do not contain new parameters (but JDT compiled
     * byte code does). That can cause some differences in the way generic types are represented in
     * the type oracle.
     *
     * These differences also show up when using java.lang.reflect to look at types.
     */
    boolean isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    if (signature != null) {
        // If we have a signature, use it for superclass and interfaces
        SignatureReader reader = new SignatureReader(signature);
        ResolveClassSignature classResolver = new ResolveClassSignature(context.resolver, logger,
                unresolvedType, typeParamLookup);
        reader.accept(classResolver);
        classResolver.finish();

        if (unresolvedType.getSuperclass() != null
                && !resolveClass(logger, unresolvedType.getSuperclass(), context)) {
            logger.log(TreeLogger.WARN,
                    "Unable to resolve supertype " + unresolvedType.getSuperclass().getName());
            return false;
        }
    } else {
        // Set the super type for non-interfaces
        if (!isInterface) {
            String superInternalName = classData.getSuperInternalName();
            assert Name.isInternalName(superInternalName);
            if (superInternalName != null) {
                JClassType superType = findByInternalName(superInternalName);
                if (superType == null || !resolveClass(logger, superType, context)) {
                    logger.log(TreeLogger.WARN, "Unable to resolve supertype " + superInternalName);
                    return false;
                }
                setSuperClass(unresolvedType, (JClassType) possiblySubstituteRawType(superType));
            }
        }

        // Set interfaces
        for (String interfaceInternalName : classData.getInterfaceInternalNames()) {
            JClassType interfaceType = findByInternalName(interfaceInternalName);
            if (interfaceType == null || !resolveClass(logger, interfaceType, context)) {
                logger.log(TreeLogger.WARN, "Unable to resolve interface " + interfaceInternalName);
                return false;
            }
            addImplementedInterface(unresolvedType, (JClassType) possiblySubstituteRawType(interfaceType));
        }
    }
    if (!isInterface && unresolvedType.getSuperclass() == null) {
        // Only Object or interfaces should not have a superclass
        assert "java/lang/Object".equals(classData.getInternalName());
    }

    // Process methods
    for (CollectMethodData method : classData.getMethods()) {
        TreeLogger branch = logger.branch(TreeLogger.SPAM, "Resolving method " + method.getName());
        // TODO(rluble): Allow the users to ask for Java 8 features. For now these are filtered out.
        if (isInterface && isJava8InterfaceMethod(method)) {
            logger.log(TreeLogger.Type.SPAM, "Ignoring Java 8 interface method " + method.getName());
            continue;
        }
        if (!resolveMethod(branch, unresolvedType, method, typeParamLookup, context)) {
            // Already logged.
            return false;
        }
    }

    // Process fields
    // Track the next enum ordinal across resolveField calls.
    int[] nextEnumOrdinal = new int[] { 0 };
    for (CollectFieldData field : classData.getFields()) {
        TreeLogger branch = logger.branch(TreeLogger.SPAM, "Resolving field " + field.getName());
        if (!resolveField(branch, unresolvedType, field, typeParamLookup, nextEnumOrdinal, context)) {
            // Already logged.
            return false;
        }
    }
    return true;
}