List of usage examples for org.objectweb.asm Opcodes ACC_INTERFACE
int ACC_INTERFACE
To view the source code for org.objectweb.asm Opcodes ACC_INTERFACE.
Click Source Link
From source file:com.google.gwt.dev.javac.CompilationUnitTypeOracleUpdater.java
License:Apache License
private boolean resolveEnclosingClass(TreeLogger logger, JRealClassType unresolvedType, TypeOracleBuildContext context) { assert unresolvedType != null; if (unresolvedType.getEnclosingType() != null) { return true; }//from w w w . ja v a2 s . c om // Find our enclosing class and set it CollectClassData classData = context.classDataByType.get(unresolvedType); assert classData != null; String enclosingClassInternalName = classData.getEnclosingInternalName(); JRealClassType enclosingType = null; if (enclosingClassInternalName != null) { enclosingType = findByInternalName(enclosingClassInternalName); // Ensure enclosing classes are resolved if (enclosingType != null) { if (!resolveEnclosingClass(logger, enclosingType, context)) { return false; } if (enclosingType.isGenericType() != null && (classData.getAccess() & (Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE)) != 0) { // If the inner class doesn't have access to it's enclosing type's // type variables, the enclosing type must be the raw type instead // of the generic type. JGenericType genericType = enclosingType.isGenericType(); setEnclosingType(unresolvedType, genericType.getRawType()); } else { setEnclosingType(unresolvedType, enclosingType); } } } return true; }
From source file:com.google.gwt.dev.javac.TypeOracleMediator.java
License:Open Source License
private JRealClassType createType(CompiledClass compiledClass, CollectClassData classData, CollectClassData enclosingClassData) { int access = classData.getAccess(); String qname = compiledClass.getSourceName(); String className = Shared.getShortName(qname); JRealClassType resultType = null;/*www . j av a 2 s.co m*/ String jpkgName = compiledClass.getPackageName(); JPackage pkg = typeOracle.getOrCreatePackage(jpkgName); boolean isIntf = (access & Opcodes.ACC_INTERFACE) != 0; assert !classData.hasNoExternalName(); String enclosingTypeName = null; if (enclosingClassData != null) { enclosingTypeName = InternalName.toSourceName(InternalName.getClassName(enclosingClassData.getName())); } if ((access & Opcodes.ACC_ANNOTATION) != 0) { resultType = newAnnotationType(pkg, enclosingTypeName, className); } else if ((access & Opcodes.ACC_ENUM) != 0) { resultType = newEnumType(pkg, enclosingTypeName, className); } else { JTypeParameter[] typeParams = getTypeParametersForClass(classData); if ((typeParams != null && typeParams.length > 0) || nonStaticInsideGeneric(classData, enclosingClassData)) { resultType = new JGenericType(typeOracle, pkg, enclosingTypeName, className, isIntf, typeParams); } else { resultType = newRealClassType(pkg, enclosingTypeName, className, isIntf); } } /* * Declare type parameters for all methods; we must do this during the first * pass. */ // if (typeDecl.methods != null) { // for (AbstractMethodDeclaration method : typeDecl.methods) { // declareTypeParameters(method.typeParameters()); // } // } /* * Add modifiers since these are needed for * TypeOracle.getParameterizedType's error checking code. */ resultType.addModifierBits(mapBits(ASM_TO_SHARED_MODIFIERS, access)); if (isIntf) { // Always add implicit modifiers on interfaces. resultType.addModifierBits(Shared.MOD_STATIC | Shared.MOD_ABSTRACT); } return resultType; }
From source file:com.google.gwt.dev.javac.TypeOracleMediator.java
License:Open Source License
private boolean resolveClass(TreeLogger logger, JRealClassType type) { assert type != null; // Avoid cycles and useless computation. if (resolved.contains(type)) { return true; }/* w w w .ja va2 s .com*/ resolved.add(type); // Make sure our enclosing type is resolved first. if (type.getEnclosingType() != null && !resolveClass(logger, type.getEnclosingType())) { 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(type); CollectClassData classData = classMapType.get(type); assert classData != null; int access = classData.getAccess(); assert (!classData.getClassType().hasNoExternalName()); logger = logger.branch(TreeLogger.SPAM, "Found type '" + type.getQualifiedSourceName() + "'", null); // Handle package-info classes. if (isPackageInfoTypeName(type.getSimpleSourceName())) { return resolvePackage(logger, type, classData.getAnnotations()); } // Resolve annotations Map<Class<? extends Annotation>, Annotation> declaredAnnotations = new HashMap<Class<? extends Annotation>, Annotation>(); resolveAnnotations(logger, classData.getAnnotations(), declaredAnnotations); addAnnotations(type, declaredAnnotations); String signature = classData.getSignature(); if (signature != null) { // If we have a signature, use it for superclass and interfaces SignatureReader reader = new SignatureReader(signature); ResolveClassSignature classResolver = new ResolveClassSignature(resolver, binaryMapper, logger, type, typeParamLookup); reader.accept(classResolver); classResolver.finish(); } else { // Set the super type for non-interfaces if ((access & Opcodes.ACC_INTERFACE) == 0) { String superName = classData.getSuperName(); if (superName != null) { JClassType superType = binaryMapper.get(superName); if (superType == null || !resolveClass(logger, superType)) { logger.log(TreeLogger.WARN, "Unable to resolve supertype " + superName); return false; } setSuperClass(type, (JClassType) possiblySubstituteRawType(superType)); } } // Set interfaces for (String intfName : classData.getInterfaces()) { JClassType intf = binaryMapper.get(intfName); if (intf == null || !resolveClass(logger, intf)) { logger.log(TreeLogger.WARN, "Unable to resolve interface " + intfName); return false; } addImplementedInterface(type, (JClassType) possiblySubstituteRawType(intf)); } } if (((access & Opcodes.ACC_INTERFACE) == 0) && type.getSuperclass() == null) { // Only Object or interfaces should not have a superclass assert "java/lang/Object".equals(classData.getName()); } // Process methods for (CollectMethodData method : classData.getMethods()) { if (!resolveMethod(logger, type, method, typeParamLookup)) { logger.log(TreeLogger.WARN, "Unable to resolve method " + method); return false; } } // Process fields // Track the next enum ordinal across resolveField calls. int[] nextEnumOrdinal = new int[] { 0 }; for (CollectFieldData field : classData.getFields()) { if (!resolveField(logger, type, field, typeParamLookup, nextEnumOrdinal)) { logger.log(TreeLogger.WARN, "Unable to resolve field " + field); return false; } } return true; }
From source file:com.google.gwt.dev.javac.TypeOracleMediator.java
License:Open Source License
private boolean resolveEnclosingClass(TreeLogger logger, JRealClassType type) { assert type != null; if (type.getEnclosingType() != null) { return true; }//from w ww . j av a 2 s.c o m // Find our enclosing class and set it CollectClassData classData = classMapType.get(type); assert classData != null; String outerClass = classData.getOuterClass(); JRealClassType enclosingType = null; if (outerClass != null) { enclosingType = binaryMapper.get(outerClass); // Ensure enclosing classes are resolved if (enclosingType != null) { if (!resolveEnclosingClass(logger, enclosingType)) { return false; } if (enclosingType.isGenericType() != null && (classData.getAccess() & (Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE)) != 0) { // If the inner class doesn't have access to it's enclosing type's // type variables, the enclosign type must be the raw type instead // of the generic type. JGenericType genericType = enclosingType.isGenericType(); setEnclosingType(type, genericType.getRawType()); } else { setEnclosingType(type, enclosingType); } } } return true; }
From source file:com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.java
License:Apache License
public byte[] writeJsoIntf(final String className, byte classBytes[]) { String desc = toDescriptor(className); assert (jsoIntfDescs.contains(desc)); assert (jsoSuperDescs.containsKey(desc)); List<String> superDescs = jsoSuperDescs.get(desc); assert (superDescs != null); assert (superDescs.size() > 0); // The ASM model is to chain a bunch of visitors together. ClassWriter writer = new ClassWriter(0); final ClassVisitor v = writer; // v = new CheckClassAdapter(v); // v = new TraceClassVisitor(v, new PrintWriter(System.out)); String[] interfaces;// w w w. ja va 2 s . com // TODO(bov): something better than linear? if (superDescs.contains("java/lang/Object")) { interfaces = null; } else { interfaces = superDescs.toArray(new String[superDescs.size()]); } v.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE, desc, null, "java/lang/Object", interfaces); if (classBytes != null) { // Java7 enforces innerclass/outerclass consistency. In order to fix this, copy from original ClassVisitor cv = new EmptyVisitor() { @Override public void visitInnerClass(String name, String outerName, String innerName, int access) { // copy inner class table from original JSO to synthetic interface v.visitInnerClass(name, outerName, innerName, access); } @Override public void visitOuterClass(String owner, String name, String desc) { // copy outer class table from original JSO to synthetic interface v.visitOuterClass(owner, name, desc); } }; new ClassReader(classBytes).accept(cv, 0); } v.visitEnd(); return writer.toByteArray(); }
From source file:com.google.gwt.dev.shell.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {/*from www . jav a2 s .c o m*/ assert currentTypeName == null; super.visit(version, access, name, signature, superName, interfaces); /* * This visitor would mangle JSO$ since it acts as a roll-up of all * SingleJso types and the result would be repeated method definitions due * to the trampoline methods this visitor would create. */ if (name.equals(HostedModeClassRewriter.JAVASCRIPTOBJECT_IMPL_DESC)) { return; } currentTypeName = name; inSingleJsoImplInterfaceType = jsoData.getSingleJsoIntfTypes().contains(name); /* * Implements objective #2: non-JSO types that implement a SingleJsoImpl * interface don't have their original instance methods altered. Instead, we * add trampoline methods with mangled names that simply call over to the * original methods. */ if (interfaces != null && (access & Opcodes.ACC_INTERFACE) == 0) { Set<String> toStub = computeAllInterfaces(interfaces); toStub.retainAll(jsoData.getSingleJsoIntfTypes()); for (String stubIntr : toStub) { writeTrampoline(stubIntr); } } }
From source file:com.google.test.metric.asm.ClassInfoBuilderVisitor.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from w w w . j a v a 2 s.c om ClassInfo superClass = null; superClass = superName == null ? null : repository.getClass(namer.nameClass(superName)); List<ClassInfo> interfaceList = new ArrayList<ClassInfo>(); for (String interfaze : interfaces) { interfaceList.add(repository.getClass(namer.nameClass(interfaze))); } boolean isInterface = (access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE; classInfo = new ClassInfo(namer.nameClass(name), isInterface, superClass, interfaceList, guessSourceFileName(name)); repository.addClass(classInfo); }
From source file:com.googlecode.ddom.weaver.ext.ModelExtensionFactoryDelegateInterface.java
License:Apache License
public void accept(ClassVisitor classVisitor) { String factoryName = Util.classNameToInternalName(info.getFactoryDelegateInterfaceName()); // TODO: the reactor currently has an issue with interfaces classVisitor.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE, factoryName, null, "java/lang/Object", new String[0]); for (ConstructorInfo constructor : info.getConstructors()) { MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "create", constructor.getFactoryDelegateMethodDescriptor(), constructor.getSignature(), constructor.getExceptions()); if (mv != null) { mv.visitEnd();//from w w w . j a v a2 s . c om } } classVisitor.visitEnd(); }
From source file:com.googlecode.ddom.weaver.reactor.WeavableClassInfoBuilder.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from www . ja va 2 s .c o m this.name = Util.internalNameToClassName(name); isInterface = (access & Opcodes.ACC_INTERFACE) != 0; this.superName = superName; interfaceNames = interfaces; }
From source file:com.googlecode.dex2jar.ir.ToStringUtil.java
License:Apache License
public static String getAccDes(int acc) { StringBuilder sb = new StringBuilder(); if ((acc & Opcodes.ACC_PUBLIC) != 0) { sb.append("public "); }// w w w . j a v a 2 s .c o m if ((acc & Opcodes.ACC_PROTECTED) != 0) { sb.append("protected "); } if ((acc & Opcodes.ACC_PRIVATE) != 0) { sb.append("private "); } if ((acc & Opcodes.ACC_STATIC) != 0) { sb.append("static "); } if ((acc & Opcodes.ACC_ABSTRACT) != 0 && (acc & Opcodes.ACC_INTERFACE) == 0) { sb.append("abstract "); } if ((acc & Opcodes.ACC_ANNOTATION) != 0) { sb.append("annotation "); } if ((acc & Opcodes.ACC_BRIDGE) != 0) { sb.append("bridge "); } if ((acc & Opcodes.ACC_DEPRECATED) != 0) { sb.append("deprecated "); } if ((acc & Opcodes.ACC_ENUM) != 0) { sb.append("enum "); } if ((acc & Opcodes.ACC_FINAL) != 0) { sb.append("final "); } if ((acc & Opcodes.ACC_INTERFACE) != 0) { sb.append("interace "); } if ((acc & Opcodes.ACC_NATIVE) != 0) { sb.append("native "); } if ((acc & Opcodes.ACC_STRICT) != 0) { sb.append("strict "); } if ((acc & Opcodes.ACC_SYNCHRONIZED) != 0) { sb.append("synchronized "); } if ((acc & Opcodes.ACC_TRANSIENT) != 0) { sb.append("transient "); } if ((acc & Opcodes.ACC_VARARGS) != 0) { sb.append("varargs "); } if ((acc & Opcodes.ACC_VOLATILE) != 0) { sb.append("volatile "); } return sb.toString(); }