List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:com.poolik.classfinder.info.ClassInfo.java
License:BSD License
/** * Convert an ASM access mask to a reflection Modifier mask. * * @param asmAccessMask the ASM access mask * @return the Modifier mask//from www . jav a2 s . c o m */ private int convertAccessMaskToModifierMask(int asmAccessMask) { int modifier = 0; // Convert the ASM access info into Reflection API modifiers. if ((asmAccessMask & Opcodes.ACC_FINAL) != 0) modifier |= Modifier.FINAL; if ((asmAccessMask & Opcodes.ACC_NATIVE) != 0) modifier |= Modifier.NATIVE; if ((asmAccessMask & Opcodes.ACC_INTERFACE) != 0) modifier |= Modifier.INTERFACE; if ((asmAccessMask & Opcodes.ACC_ABSTRACT) != 0) modifier |= Modifier.ABSTRACT; if ((asmAccessMask & Opcodes.ACC_PRIVATE) != 0) modifier |= Modifier.PRIVATE; if ((asmAccessMask & Opcodes.ACC_PROTECTED) != 0) modifier |= Modifier.PROTECTED; if ((asmAccessMask & Opcodes.ACC_PUBLIC) != 0) modifier |= Modifier.PUBLIC; if ((asmAccessMask & Opcodes.ACC_STATIC) != 0) modifier |= Modifier.STATIC; if ((asmAccessMask & Opcodes.ACC_STRICT) != 0) modifier |= Modifier.STRICT; if ((asmAccessMask & Opcodes.ACC_SYNCHRONIZED) != 0) modifier |= Modifier.SYNCHRONIZED; if ((asmAccessMask & Opcodes.ACC_TRANSIENT) != 0) modifier |= Modifier.TRANSIENT; if ((asmAccessMask & Opcodes.ACC_VOLATILE) != 0) modifier |= Modifier.VOLATILE; return modifier; }
From source file:com.qualogy.qafe.util.inspection.java.PublicModifierFilter.java
License:Apache License
public static boolean isPublic(Modifier modifier) { return ((modifier.getAccess() & Opcodes.ACC_PUBLIC) == 1); }
From source file:com.qualogy.qafe.util.inspection.java.PublicModifierFilter.java
License:Apache License
public static boolean isPublic(int access) { return ((access & Opcodes.ACC_PUBLIC) == 1); }
From source file:com.sixrr.metrics.profile.instanceHolder.MetricInstanceHolder.java
License:Apache License
private void loadMetricsFromProviders() { for (MetricProvider provider : MetricProvider.EXTENSION_POINT_NAME.getExtensions()) { final List<Class<? extends Metric>> classesForProvider = provider.getMetricClasses(); for (Class<? extends Metric> aClass : classesForProvider) { try { myMetricInstances.put(aClass.getName(), aClass.newInstance()); } catch (InstantiationException e) { MetricInstanceHolder.LOGGER.error(e); } catch (IllegalAccessException e) { MetricInstanceHolder.LOGGER.error(e); }/* w ww . j a v a 2 s . c om*/ } } for (Metric metric : Metric.EP_NAME.getExtensions()) { myMetricInstances.put(metric.getClass().getName(), metric); } // add some magic // in Profiles it stored by ClassName. Line Of code is can be handle without new metrics, need only extends LinesOfCodeProjectMetric with // new name for (LineOfCodeFileTypeProviderEP ep : LineOfCodeFileTypeProviderEP.EP_NAME.getExtensions()) { FileType fileTypeByFileName = FileTypeRegistry.getInstance().findFileTypeByName(ep.fileType); if (fileTypeByFileName == null) { LOGGER.error("File type is unknown: " + ep.fileType); fileTypeByFileName = PlainTextFileType.INSTANCE; } String lineOfCodeClass = Type.getInternalName(LinesOfCodeProjectMetric.class); String className = lineOfCodeClass + "$" + ep.fileType; ClassWriter writer = new ClassWriter(Opcodes.F_FULL); writer.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, className, null, lineOfCodeClass, null); String desc = Type.getConstructorDescriptor(LinesOfCodeProjectMetric.class.getConstructors()[0]); MethodVisitor methodVisitor = writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, null, null); methodVisitor.visitMaxs(2, 2); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, lineOfCodeClass, "<init>", desc); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitEnd(); writer.visitEnd(); Class<?> aClass = defineClass(className.replace("/", "."), writer.toByteArray()); try { myMetricInstances.put(aClass.getName(), (Metric) aClass.getConstructors()[0].newInstance(fileTypeByFileName)); } catch (InstantiationException e) { LOGGER.error(e); } catch (IllegalAccessException e) { LOGGER.error(e); } catch (InvocationTargetException e) { LOGGER.error(e); } } }
From source file:com.smartitengineering.util.simple.DefaultClassScannerImplTest.java
License:Open Source License
@Override protected void setUp() throws Exception { super.setUp(); classScanner = IOFactory.getDefaultClassScanner(); classVisitor = new ClassVisitor() { public void visit(int verison, int scope, String name, String signature, String supername, String[] interfaces) { assertEquals((scope & Opcodes.ACC_PUBLIC), Opcodes.ACC_PUBLIC); assert (name.startsWith(TestClass.class.getName().replaceAll("\\.", "/"))); System.out.println(); }//from w w w .j ava 2s . c om public void visitSource(String arg0, String arg1) { } public void visitOuterClass(String arg0, String arg1, String arg2) { } public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return null; } public void visitAttribute(Attribute arg0) { } public void visitInnerClass(String arg0, String arg1, String arg2, int arg3) { } public FieldVisitor visitField(int arg0, String arg1, String arg2, String arg3, Object arg4) { return null; } public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4) { return null; } public void visitEnd() { } }; }
From source file:com.smartitengineering.util.simple.reflection.ClassAnnotationVisitorImpl.java
License:Open Source License
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from ww w. j a va2 s. c o m publicModifier = (Opcodes.ACC_PUBLIC & access) == 1; className = name; superClassName = superName; this.interfaces = interfaces; }
From source file:com.sun.fortress.compiler.codegen.CodeGen.java
License:Open Source License
public void forObjectDeclPrePass(ObjectDecl x) { debug("Begin forObjectDeclPrePass for ", x); TraitTypeHeader header = x.getHeader(); List<TraitTypeWhere> extendsC = header.getExtendsClause(); boolean canCompile = // x.getParams().isNone() && // no parameters // header.getStaticParams().isEmpty() && // no static parameter header.getWhereClause().isNone() && // no where clause header.getThrowsClause().isNone() && // no throws clause header.getContract().isNone() && // no contract // header.getDecls().isEmpty() && // no members Modifiers.ObjectMod.containsAll(header.getMods()) // ( extendsC.size() <= 1 ); // 0 or 1 super trait ;//from www. j a va 2s . c o m if (!canCompile) throw sayWhat(x); // Map<String, String> xlation = new HashMap<String, String>(); List<String> splist = new ArrayList<String>(); final List<StaticParam> original_static_params = header.getStaticParams(); Option<List<Param>> original_params = NodeUtil.getParams(x); Naming.XlationData xldata = xlationData(Naming.OBJECT_GENERIC_TAG); boolean savedInAnObject = inAnObject; inAnObject = true; Id classId = NodeUtil.getName(x); final ClassNameBundle cnb = new_ClassNameBundle(classId, original_static_params, xldata); String erasedSuperI = (EMIT_ERASED_GENERICS && cnb.isGeneric) ? cnb.stemClassName : ""; String[] superInterfaces = NamingCzar.extendsClauseToInterfaces(extendsC, component.getName(), erasedSuperI); if (EMIT_ERASED_GENERICS && cnb.isGeneric) { emitErasedClassFor(cnb, (TraitObjectDecl) x); } String abstractSuperclass; if (superInterfaces.length > 0) { abstractSuperclass = superInterfaces[0] + NamingCzar.springBoard; } else { abstractSuperclass = NamingCzar.internalObject; } traitOrObjectName = cnb.className; debug("forObjectDeclPrePass ", x, " classFile = ", traitOrObjectName); boolean isSingletonObject = NodeUtil.getParams(x).isNone(); List<Param> params; if (!isSingletonObject) { params = NodeUtil.getParams(x).unwrap(); //TUPLE CONSTRUCTOR PROBLEM String init_sig = NamingCzar.jvmSignatureFor(params, "V", thisApi()); // Generate the factory method String sig = NamingCzar.jvmSignatureFor(params, cnb.classDesc, thisApi()); String mname; CodeGen cg = this; String PCN = null; String PCNOuter = null; ArrayList<InitializedStaticField> isf_list = new ArrayList<InitializedStaticField>(); if (cnb.isGeneric) { ArrowType at = FnNameInfo.typeAndParamsToArrow(NodeUtil.getSpan(x), NodeFactory.makeTraitType(classId, STypesUtil.staticParamsToArgs(original_static_params)), original_params.unwrap()); String generic_arrow_type = NamingCzar.jvmTypeDesc(at, thisApi(), false); PCNforClosure pair = nonCollidingClosureName(generic_arrow_type, Naming.NO_SELF, (IdOrOp) x.getHeader().getName(), original_static_params, this.packageAndClassName); PCN = pair.PCN; PCNOuter = pair.PCNOuter; xldata = pair.xldata; cg = new CodeGen(this); cg.cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, cw); // This creates the closure bits // The name is disambiguated by the class in which it appears. mname = InstantiatingClassloader.closureClassPrefix(PCN, cg.cw, PCN, sig, null, isf_list); } else { mname = nonCollidingSingleName(x.getHeader().getName(), sig, ""); } CodeGenClassWriter cw = cg.cw; CodeGenMethodVisitor mv = cw.visitCGMethod(ACC_STATIC + ACC_PUBLIC, mname, sig, null, null); mv.visitTypeInsn(NEW, cnb.className); mv.visitInsn(DUP); // iterate, pushing parameters, beginning at zero. // TODO actually handle N>0 parameters. int numParams = params.size(); //if only a single parameter which is a tuple, signature will give them individually if (numParams == 1 && (params.get(0).getIdType().unwrap() instanceof TupleType)) { Param p0 = params.get(0); TupleType tuple_type = ((TupleType) p0.getIdType().unwrap()); List<Type> tuple_types = tuple_type.getElements(); numParams = tuple_types.size(); } for (int stack_offset = 0; stack_offset < numParams; stack_offset++) { // when we unbox, this will be type-dependent mv.visitVarInsn(ALOAD, stack_offset); } mv.visitMethodInsn(INVOKESPECIAL, cnb.className, "<init>", init_sig); mv.visitInsn(ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); if (cnb.isGeneric) { InstantiatingClassloader.optionalStaticsAndClassInitForTO(isf_list, cg.cw); cg.cw.dumpClass(PCNOuter, xldata); } } else { // singleton params = Collections.<Param>emptyList(); } CodeGenClassWriter prev = cw; /* Yuck, ought to allocate a new codegen here. */ initializedStaticFields_TO = new ArrayList<InitializedStaticField>(); cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, cw); cw.visitSource(NodeUtil.getSpan(x).begin.getFileName(), null); // Until we resolve the directory hierarchy problem. // cw.visit( V1_5, ACC_PUBLIC + ACC_SUPER+ ACC_FINAL, // classFile, null, NamingCzar.internalObject, new String[] { parent }); cw.visit(InstantiatingClassloader.JVM_BYTECODE_VERSION, ACC_PUBLIC + ACC_SUPER + ACC_FINAL, cnb.className, null, abstractSuperclass, superInterfaces); if (isSingletonObject) { initializedStaticFields_TO.add(new InitializedStaticField() { @Override public void forClinit(MethodVisitor imv) { imv.visitTypeInsn(NEW, cnb.className); imv.visitInsn(DUP); imv.visitMethodInsn(INVOKESPECIAL, cnb.className, "<init>", Naming.voidToVoid); imv.visitFieldInsn(PUTSTATIC, cnb.className, NamingCzar.SINGLETON_FIELD_NAME, cnb.classDesc); } @Override public String asmName() { return NamingCzar.SINGLETON_FIELD_NAME; } @Override public String asmSignature() { return cnb.classDesc; } }); /* Used to pass splist to the static-parametered form * but it was always empty. Tests work like that. * Bit of a WTF, keep an eye on this. * Repurpose splist (non-null) for the computation and * caching of RTTI, which also goes in a static. */ addStaticVar(new VarCodeGen.StaticBinding(classId, NodeFactory.makeTraitType(classId), cnb.stemClassName, NamingCzar.SINGLETON_FIELD_NAME, cnb.classDesc)); // // Singleton; generate field in class to hold sole instance. // cw.visitField(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, // NamingCzar.SINGLETON_FIELD_NAME, cnb.classDesc, // null /* for non-generic */, null /* instance has no value */); } currentTraitObjectDecl = x; //create CodeGen for init method // has different set of parameter variables in scope CodeGen initCodeGen = initializeInitMethod(params); initCodeGen.initializedInstanceFields_O = new ArrayList<InitializedInstanceField>(); // List<Binding> fieldsForEnv = new ArrayList<Binding>(); initCodeGen.instanceFields = new InstanceFields(); BATree<String, VarCodeGen> savedLexEnv = lexEnv.copy(); // for each parameter // 1) add field to the class // 2) add field along with initializer to list of instance fields to put in the constructor // 3) add parameter to local scope of init method // 4) add field to scope for use in methods for (int i = 0; i < params.size(); i++) { Param p = params.get(i); String paramName = p.getName().getText(); Type paramType = (Type) p.getIdType().unwrap(); String typeDesc = NamingCzar.jvmBoxedTypeDesc(paramType, thisApi()); Id id = NodeFactory.makeId(NodeUtil.getSpan(p.getName()), paramName); VarCodeGen vcg = new VarCodeGen.FieldVar(id, paramType, cnb.className, paramName, typeDesc); //1) add field to class cw.visitField(ACC_PUBLIC + ACC_FINAL, paramName, typeDesc, null /* for non-generic */, null /* instance has no value */); //2) add field with initializer as a refernce to the parameter initCodeGen.instanceFields.put(vcg, ExprFactory.makeVarRef(id)); //3) add param to scope for init method only initCodeGen.addStaticVar(new VarCodeGen.ParamVar(id, paramType, initCodeGen)); //4) add field to scope for method codegen addStaticVar(vcg); } // find declared fields in the list of decls and // 1) add field to the class // 2) add field along with initializer to list of instance fields to put in the constructor // 3) add field to scope for use in methods for (Decl d : header.getDecls()) { if (d instanceof VarDecl) { // TODO need to spot for "final" fields. Right now we assume mutable, not final. final VarDecl vd = (VarDecl) d; final CodeGen cg = this; int numDecls = vd.getLhs().size(); for (int i = 0; i < numDecls; i++) { LValue l = vd.getLhs().get(i); String fieldName = l.getName().getText(); Type fieldType = (Type) l.getIdType().unwrap(); String typeDesc = NamingCzar.jvmBoxedTypeDesc(fieldType, thisApi()); Id id = NodeFactory.makeId(NodeUtil.getSpan(l.getName()), fieldName); VarCodeGen fieldVcg = new VarCodeGen.MutableFieldVar(id, fieldType, cnb.className, fieldName, typeDesc); //1) add field to class cw.visitField(ACC_PUBLIC, fieldName, typeDesc, null /* for non-generic */, null /* instance has no value */); //2) set up initializer if (vd.getInit().isNone()) sayWhat(vd, "no initializer for declared field(s)"); Expr init = vd.getInit().unwrap(); if (numDecls != 1 && init instanceof TupleExpr) { List<Expr> tupleExprs = ((TupleExpr) init).getExprs(); if (tupleExprs.size() != numDecls) sayWhat(vd, "incorrect initialization for declared fields tuple"); init = tupleExprs.get(i); } initCodeGen.instanceFields.put(fieldVcg, init); //3) add field to scope for method codegen addStaticVar(fieldVcg); } } } debug("Dump overloaded method chaining for ", x); Map<IdOrOpOrAnonymousName, MultiMap<Integer, Functional>> overloads = dumpOverloadedMethodChaining( superInterfaces, false); if (OVERLOADED_METHODS) typeLevelOverloadedNamesAndSigs = generateTopLevelOverloads(thisApi(), overloads, typeAnalyzer, cw, this, new OverloadSet.TraitOrObjectFactory(Opcodes.INVOKEVIRTUAL, cnb, this)); debug("End of dump overloaded method chaining for ", x); debug("Process declarations for ", x); for (Decl d : header.getDecls()) { // This does not work yet. d.accept(this); } debug("End of processing declarations for ", x); initCodeGen.instanceInitForObject(abstractSuperclass); debug("Dump method chaining for ", x); dumpMethodChaining(superInterfaces, false); // dumpErasedMethodChaining(superInterfaces, false); debug("End of dump method chaining for ", x); /* RTTI stuff */ mv = cw.visitCGMethod(Opcodes.ACC_PUBLIC, // acccess Naming.RTTI_GETTER, // name Naming.STATIC_PARAMETER_GETTER_SIG, // sig null, // generics sig? null); // exceptions mv.visitCode(); mv.visitFieldInsn(GETSTATIC, cnb.className, Naming.RTTI_FIELD, Naming.RTTI_CONTAINER_DESC); areturnEpilogue(); emitRttiField(cnb); /* end RTTI stuff */ lexEnv = savedLexEnv; optionalStaticsAndClassInitForTO(classId, cnb, isSingletonObject); if (cnb.isGeneric) { cw.dumpClass(cnb.fileName, xldata.setTraitObjectTag(Naming.OBJECT_GENERIC_TAG)); } else { cw.dumpClass(cnb.className); } cw = prev; initializedInstanceFields_O = null; initializedStaticFields_TO = null; currentTraitObjectDecl = null; traitOrObjectName = null; inAnObject = savedInAnObject; // Needed (above) to embed a reference to the Rtti information for this type. RttiClassAndInterface(x, cnb, xldata); debug("End forObjectDeclPrePass for ", x); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
/** * Given one component, generate a Java bytecode compiled environment * for that component./* w w w .j ava 2 s . c o m*/ */ private static byte[] generateForCompilationUnit(String className, CompilationUnitIndex compUnitIndex) { /* * With new ClassWriter(ClassWriter.COMPUTE_FRAMES) everything is * computed automatically. You don't have to call visitFrame, but you * must still call visitMaxs (arguments will be ignored and recomputed). * Using these options is convenient but this has a cost: the COMPUTE_FRAMES option * makes it two times slower. * * Currently not a performance bottleneck. */ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_FINAL, className, null, Type.getType(BaseEnv.class).getInternalName(), null); // Implementing "static reflection" for the interpreter EnvSymbolNames symbolNames = new EnvSymbolNames(); writeFields(cw, compUnitIndex, symbolNames); writeMethodInit(cw, className); writeMethodGetRaw(cw, className, "getApiNull", EnvironmentClass.ENVIRONMENT, symbolNames); writeMethodPutRaw(cw, className, "putApi", EnvironmentClass.ENVIRONMENT, symbolNames); writeMethodGetRaw(cw, className, "getValueRaw", EnvironmentClass.FVALUE, symbolNames); writeMethodPutRaw(cw, className, "putValueRaw", EnvironmentClass.FVALUE, symbolNames); writeMethodGetRaw(cw, className, "getTypeNull", EnvironmentClass.FTYPE, symbolNames); writeMethodPutRaw(cw, className, "putTypeRaw", EnvironmentClass.FTYPE, symbolNames); writeEmptyMethods(cw, className); writeRemoveMethods(cw, className); writeDumpMethod(cw, className, symbolNames); cw.visitEnd(); return (cw.toByteArray()); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void nameToField(EnvironmentClass nameSpace, ClassWriter cw, EnvSymbolNames symbolNames, String idString) {//w ww. j a v a 2 s . c o m symbolNames.add(nameSpace, idString); idString = idString + nameSpace.namespace(); cw.visitField(Opcodes.ACC_PUBLIC, Naming.mangleIdentifier(idString), nameSpace.descriptor(), null, null) .visitEnd(); return; }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
/** * Generate the default constructor for this class. * This constructors calls the method setToplevel(). * If this environment is not a top-level environment, then a default * constructor does not need to be created. (ASM will generate a * default constructor)./* w w w . ja va 2 s .c o m*/ */ private static void writeMethodInit(ClassWriter cw, String className) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getType(BaseEnv.class).getInternalName(), "<init>", "()V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, "setTopLevel", "()V"); mv.visitInsn(Opcodes.RETURN); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(1, 1); mv.visitEnd(); }