List of usage examples for org.objectweb.asm Opcodes ACC_ABSTRACT
int ACC_ABSTRACT
To view the source code for org.objectweb.asm Opcodes ACC_ABSTRACT.
Click Source Link
From source file:org.codehaus.groovy.tools.javac.JavaStubGenerator.java
License:Apache License
private static void printModifiers(PrintWriter out, int modifiers) { if ((modifiers & Opcodes.ACC_PUBLIC) != 0) out.print("public "); if ((modifiers & Opcodes.ACC_PROTECTED) != 0) out.print("protected "); if ((modifiers & Opcodes.ACC_PRIVATE) != 0) out.print("private "); if ((modifiers & Opcodes.ACC_STATIC) != 0) out.print("static "); if ((modifiers & Opcodes.ACC_SYNCHRONIZED) != 0) out.print("synchronized "); if ((modifiers & Opcodes.ACC_FINAL) != 0) out.print("final "); if ((modifiers & Opcodes.ACC_ABSTRACT) != 0) out.print("abstract "); }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java
License:Open Source License
/** * Build JDT TypeDeclarations for the groovy type declarations that were parsed from the source file. *//*from w ww . j ava2 s. com*/ private void createTypeDeclarations(ModuleNode moduleNode) { List<ClassNode> moduleClassNodes = moduleNode.getClasses(); List<TypeDeclaration> typeDeclarations = new ArrayList<TypeDeclaration>(); Map<ClassNode, TypeDeclaration> fromClassNodeToDecl = new HashMap<ClassNode, TypeDeclaration>(); char[] mainName = toMainName(compilationResult.getFileName()); boolean isInner = false; List<ClassNode> classNodes = null; classNodes = moduleClassNodes; Map<ClassNode, List<TypeDeclaration>> innersToRecord = new HashMap<ClassNode, List<TypeDeclaration>>(); for (ClassNode classNode : classNodes) { if (!classNode.isPrimaryClassNode()) { continue; } GroovyTypeDeclaration typeDeclaration = new GroovyTypeDeclaration(compilationResult, classNode); typeDeclaration.annotations = transformAnnotations(classNode.getAnnotations()); // FIXASC duplicates code further down, tidy this up if (classNode instanceof InnerClassNode) { InnerClassNode innerClassNode = (InnerClassNode) classNode; ClassNode outerClass = innerClassNode.getOuterClass(); String outername = outerClass.getNameWithoutPackage(); String newInner = innerClassNode.getNameWithoutPackage().substring(outername.length() + 1); typeDeclaration.name = newInner.toCharArray(); isInner = true; } else { typeDeclaration.name = classNode.getNameWithoutPackage().toCharArray(); isInner = false; } // classNode.getInnerClasses(); // classNode. boolean isInterface = classNode.isInterface(); int mods = classNode.getModifiers(); if ((mods & Opcodes.ACC_ENUM) != 0) { // remove final mods = mods & ~Opcodes.ACC_FINAL; } // FIXASC should this modifier be set? // mods |= Opcodes.ACC_PUBLIC; // FIXASC should not do this for inner classes, just for top level types // FIXASC does this make things visible that shouldn't be? mods = mods & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED); if (!isInner) { if ((mods & Opcodes.ACC_STATIC) != 0) { mods = mods & ~(Opcodes.ACC_STATIC); } } typeDeclaration.modifiers = mods & ~(isInterface ? Opcodes.ACC_ABSTRACT : 0); if (!(classNode instanceof InnerClassNode)) { if (!CharOperation.equals(typeDeclaration.name, mainName)) { typeDeclaration.bits |= ASTNode.IsSecondaryType; } } fixupSourceLocationsForTypeDeclaration(typeDeclaration, classNode); if (classNode.getGenericsTypes() != null) { GenericsType[] genericInfo = classNode.getGenericsTypes(); // Example case here: Foo<T extends Number & I> // the type parameter is T, the 'type' is Number and the bounds for the type parameter are just the extra bound // I. typeDeclaration.typeParameters = new TypeParameter[genericInfo.length]; for (int tp = 0; tp < genericInfo.length; tp++) { TypeParameter typeParameter = new TypeParameter(); typeParameter.name = genericInfo[tp].getName().toCharArray(); ClassNode[] upperBounds = genericInfo[tp].getUpperBounds(); if (upperBounds != null) { // FIXASC (M3) Positional info for these references? typeParameter.type = createTypeReferenceForClassNode(upperBounds[0]); typeParameter.bounds = (upperBounds.length > 1 ? new TypeReference[upperBounds.length - 1] : null); for (int b = 1, max = upperBounds.length; b < max; b++) { typeParameter.bounds[b - 1] = createTypeReferenceForClassNode(upperBounds[b]); typeParameter.bounds[b - 1].bits |= ASTNode.IsSuperType; } } typeDeclaration.typeParameters[tp] = typeParameter; } } boolean isEnum = (classNode.getModifiers() & Opcodes.ACC_ENUM) != 0; configureSuperClass(typeDeclaration, classNode.getSuperClass(), isEnum); configureSuperInterfaces(typeDeclaration, classNode); typeDeclaration.methods = createMethodAndConstructorDeclarations(classNode, isEnum, compilationResult); typeDeclaration.fields = createFieldDeclarations(classNode); typeDeclaration.properties = classNode.getProperties(); if (classNode instanceof InnerClassNode) { InnerClassNode innerClassNode = (InnerClassNode) classNode; ClassNode outerClass = innerClassNode.getOuterClass(); String outername = outerClass.getNameWithoutPackage(); String newInner = innerClassNode.getNameWithoutPackage().substring(outername.length() + 1); typeDeclaration.name = newInner.toCharArray(); // Record that we need to set the parent of this inner type later List<TypeDeclaration> inners = innersToRecord.get(outerClass); if (inners == null) { inners = new ArrayList<TypeDeclaration>(); innersToRecord.put(outerClass, inners); } inners.add(typeDeclaration); } else { typeDeclarations.add(typeDeclaration); } fromClassNodeToDecl.put(classNode, typeDeclaration); } // For inner types, now attach them to their parents. This was not done earlier as sometimes the types are processed in // such an order that inners are dealt with before outers for (Map.Entry<ClassNode, List<TypeDeclaration>> innersToRecordEntry : innersToRecord.entrySet()) { TypeDeclaration outerTypeDeclaration = fromClassNodeToDecl.get(innersToRecordEntry.getKey()); // Check if there is a problem locating the parent for the inner if (outerTypeDeclaration == null) { throw new GroovyEclipseBug( "Failed to find the type declaration for " + innersToRecordEntry.getKey().getName()); } List<TypeDeclaration> newInnersList = innersToRecordEntry.getValue(); outerTypeDeclaration.memberTypes = newInnersList.toArray(new TypeDeclaration[newInnersList.size()]); } types = typeDeclarations.toArray(new TypeDeclaration[typeDeclarations.size()]); }
From source file:org.compass.core.config.binding.metadata.AsmClassMetaData.java
License:Apache License
public void visit(int version, int access, String name, String signature, String supername, String[] interfaces) {/*from ww w . j a va 2 s. c o m*/ this.className = ClassUtils.convertResourcePathToClassName(name); this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0); this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0); if (supername != null) { this.superClassName = ClassUtils.convertResourcePathToClassName(supername); } this.interfaces = new String[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]); } }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddEmptyMethodAdapter.java
License:Open Source License
@Override public void visitEnd() { MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); if ((this.access & Opcodes.ACC_ABSTRACT) != 0) { mv.visitEnd();//w w w . j av a 2s .c om return; } mv.visitCode(); boolean needConstValue = true; if (superToCall != null) { needConstValue = false; boolean isStatic = (this.access & Opcodes.ACC_STATIC) != 0; int firstArgIndex = isStatic ? 0 : 1; if (!isStatic) mv.visitVarInsn(Opcodes.ALOAD, 0); // "this" Type[] args = Type.getArgumentTypes(desc); for (int i = 0, slot = firstArgIndex; i < args.length; slot += args[i++].getSize()) mv.visitVarInsn(args[i].getOpcode(Opcodes.ILOAD), slot); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superToCall, name, desc, false); } Type returnType = Type.getReturnType(this.desc); switch (returnType.getSort()) { case Type.VOID: mv.visitInsn(Opcodes.RETURN); break; case Type.INT: case Type.BOOLEAN: case Type.CHAR: case Type.BYTE: case Type.SHORT: if (needConstValue) mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IRETURN); break; case Type.FLOAT: if (needConstValue) mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FRETURN); break; case Type.LONG: if (needConstValue) mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LRETURN); break; case Type.DOUBLE: case Type.OBJECT: case Type.ARRAY: if (needConstValue) mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); break; } mv.visitMaxs(1, maxLocals); mv.visitEnd(); }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddImplicitActivationAdapter.java
License:Open Source License
private static boolean canImplicitlyActivate(int methFlags, String methName, String methDesc) { boolean isCandidate = ((methFlags & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC)) == 0) && (!methName.startsWith("_OT$")) && (!methName.equals("<init>")) && (!(methName.equals("activate") && methDesc.equals("()V"))) && (!(methName.equals("deactivate") && methDesc.equals("()V"))) && (!ConstantMembers.isReflectiveOTMethod(methName, methDesc)); return isCandidate; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AsmWritableBoundClass.java
License:Open Source License
/** * Do all transformations needed at load time *///from w w w. jav a2 s . c o m @Override protected void prepareAsPossibleBaseClass() { if (!isFirstTransformation) return; addInterface(ClassNames.I_BOUND_BASE_SLASH); int methodModifiers = Types.ACCESS_PUBLIC; if (isInterface()) methodModifiers |= Opcodes.ACC_ABSTRACT; if (!isInterface()) addField(ConstantMembers.roleSet, Types.ACCESS_PUBLIC); addEmptyMethod(ConstantMembers.callOrig, methodModifiers, null, null, null); addEmptyMethod(ConstantMembers.callAllBindingsClient, methodModifiers, null, null, null); // the methods callOrigStatic and accessStatic have to already exist to call it in a concrete team if (!isInterface()) { addEmptyMethod(getCallOrigStatic(), Types.ACCESS_PUBLIC + Types.ACCESS_STATIC, null, null, null); addEmptyMethod(ConstantMembers.accessStatic, Types.ACCESS_PUBLIC + Types.ACCESS_STATIC, null, null, null); } String superClassName = getSuperClassName().replace('.', '/'); if (!ObjectTeamsTransformer.isWeavable(superClassName)) superClassName = null; addEmptyMethod(ConstantMembers.access, methodModifiers, null, null, superClassName); addEmptyMethod(ConstantMembers.addOrRemoveRole, methodModifiers, null, null, null); if (!isInterface()) multiAdapter.addVisitor(new AddAfterClassLoadingHook(this.writer, this)); if (AddThreadNotificationAdapter.shouldNotify(this)) multiAdapter.addVisitor(new AddThreadNotificationAdapter(this.writer, this)); }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateCallAllBindingsCallInOrgMethod.java
License:Open Source License
@Override public boolean transform() { MethodNode method = getMethod(orgMethod); if ((method.access & Opcodes.ACC_ABSTRACT) != 0) return false; // if (method.name.equals("<init>")) { // int size = method.instructions.size(); // for (int i = 0; i < size; i++) { // AbstractInsnNode insn = method.instructions.get(i); // System.out.println(insn+" "+insn.getOpcode()); // }//from ww w .j ava2 s .co m // } // System.out.println("================"); AbstractInsnNode insertBefore = null; if (orgMethod.getName().equals("<init>")) { // keep instructions, find insertion point: int last = method.instructions.size(); LabelNode callAll = new LabelNode(); while (--last >= 0) { if (method.instructions.get(last).getOpcode() == Opcodes.RETURN) { AbstractInsnNode ret = method.instructions.get(last); method.instructions.set(ret, callAll); insertBefore = callAll; break; } } if (insertBefore == null) throw new IllegalStateException("Insertion point for weaving into ctor not found!!!"); // FIXME: triggers NPE in MethodVisitor.visitMaxs // // replace RETURN with GOTO // for (int i=0; i<last; i++) { // AbstractInsnNode current = method.instructions.get(i); // if (current.getOpcode() == Opcodes.RETURN) // method.instructions.set(current, new JumpInsnNode(Opcodes.GOTO, callAll)); // } } else { method.instructions.clear(); } // start of try-block: InsnList newInstructions = new InsnList(); LabelNode start = new LabelNode(); newInstructions.add(start); // put this on the stack newInstructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); // put boundMethodId on the stack newInstructions.add(createLoadIntConstant(boundMethodId)); Type[] args = Type.getArgumentTypes(method.desc); // box the arguments newInstructions.add(getBoxingInstructions(args, false)); // this.callAllBindings(boundMethodId, args); newInstructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, this.name, ConstantMembers.callAllBindingsClient.getName(), ConstantMembers.callAllBindingsClient.getSignature())); Type returnType = Type.getReturnType(method.desc); newInstructions.add(getUnboxingInstructionsForReturnValue(returnType)); if (insertBefore != null) { method.instructions.insertBefore(insertBefore, newInstructions); method.instructions.remove(insertBefore); // remove extra RETURN } else { method.instructions.add(newInstructions); } // if (method.name.equals("<init>")) { // int size = method.instructions.size(); // for (int i = 0; i < size; i++) { // AbstractInsnNode insn = method.instructions.get(i); // System.out.println(insn+" "+insn.getOpcode()); // } // } // catch and unwrap SneakyException: addCatchSneakyException(method, start); int localSlots = 0; int maxArgSize = 1; for (Type type : args) { int size = type.getSize(); localSlots += size; if (size == 2) maxArgSize = 2; } method.maxStack = args.length > 0 ? 5 + maxArgSize : 3; method.maxLocals = localSlots + 1; return true; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateDispatchCodeInOrgMethodAdapter.java
License:Open Source License
@Override public boolean transform() { MethodNode orgMethod = getMethod(method); if ((orgMethod.access & Opcodes.ACC_ABSTRACT) != 0) return false; orgMethod.instructions.clear();/*from w w w .j a v a 2 s.c o m*/ orgMethod.instructions.add(getDispatchCode(orgMethod, joinPointId, boundMethodId)); orgMethod.maxStack = getMaxStack(); orgMethod.maxLocals = getMaxLocals(); return true; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.MoveCodeToCallOrigAdapter.java
License:Open Source License
public boolean transform() { MethodNode orgMethod = getMethod(method); if ((orgMethod.access & Opcodes.ACC_ABSTRACT) != 0) return false; MethodNode callOrig = getMethod(this.callOrig); Type returnType = Type.getReturnType(orgMethod.desc); InsnList newInstructions = new InsnList(); //Unboxing arguments Type[] args = Type.getArgumentTypes(orgMethod.desc); int boundMethodIdSlot = firstArgIndex; if (args.length > 0) { // move boundMethodId to a higher slot, to make lower slots available for original locals newInstructions.add(new IntInsnNode(Opcodes.ILOAD, boundMethodIdSlot)); boundMethodIdSlot = callOrig.maxLocals + 1; newInstructions.add(new IntInsnNode(Opcodes.ISTORE, boundMethodIdSlot)); newInstructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + argOffset + 1)); int slot = firstArgIndex + argOffset; for (int i = argOffset; i < args.length; i++) { if (i < args.length - 1) { newInstructions.add(new InsnNode(Opcodes.DUP)); }//w w w. j a v a 2s .c o m newInstructions.add(createLoadIntConstant(i)); newInstructions.add(new InsnNode(Opcodes.AALOAD)); Type arg = args[i]; if (arg.getSort() != Type.ARRAY && arg.getSort() != Type.OBJECT) { String objectType = AsmTypeHelper.getObjectType(arg); newInstructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType)); newInstructions.add(AsmTypeHelper.getUnboxingInstructionForType(arg, objectType)); } else { newInstructions.add(new TypeInsnNode(Opcodes.CHECKCAST, arg.getInternalName())); } newInstructions.add(new IntInsnNode(args[i].getOpcode(Opcodes.ISTORE), slot)); slot += arg.getSize(); } } if (superIsWeavable) adjustSuperCalls(orgMethod.instructions, orgMethod.name, args, returnType, boundMethodIdSlot); // replace return of the original method with areturn and box the result value if needed replaceReturn(orgMethod.instructions, returnType); newInstructions.add(orgMethod.instructions); addNewLabelToSwitch(callOrig.instructions, newInstructions, boundMethodId); // a minimum stacksize of 3 is needed to box the arguments callOrig.maxStack = Math.max(Math.max(callOrig.maxStack, orgMethod.maxStack), 3); // we have to increment the max. stack size, because we have to put NULL on the stack if (returnType.getSort() == Type.VOID) { callOrig.maxStack += 1; } callOrig.maxLocals = Math.max(callOrig.maxLocals, orgMethod.maxLocals); return true; }
From source file:org.eclipse.pde.api.tools.internal.builder.ReferenceExtractor.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (fIsVisitMembers) { IApiMember member = this.getMember(); IApiType owner = null;/* ww w .jav a 2 s .c om*/ if (member instanceof IApiType) { owner = (IApiType) member; } else { try { owner = member.getEnclosingType(); } catch (CoreException e) { // should not happen for field or method ApiPlugin.log(e.getStatus()); } } if (owner == null) { return null; } IApiMethod method = owner.getMethod(name, desc); if (method == null) { ApiPlugin.log(new Status(IStatus.WARNING, ApiPlugin.PLUGIN_ID, NLS.bind(BuilderMessages.ReferenceExtractor_failed_to_lookup_method, new String[] { name, desc, Signatures.getQualifiedTypeSignature(owner) }))); // if we can't find the method there is no point trying to // process it return null; } this.enterMember(method); // record potential method override reference if ((access & (Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) > 0) { try { IApiType def = null; if (fVersion >= Opcodes.V1_8) { // See if we are overriding a default interface method def = getDefaultDefined(owner, name, desc, true); } if (def != null) { addReference(Reference.methodReference(method, def.getName(), method.getName(), method.getSignature(), IReference.REF_OVERRIDE, IReference.F_DEFAULT_METHOD)); } else if (!this.fSuperStack.isEmpty()) { String superTypeName = this.fSuperStack.peek(); addReference(Reference.methodReference(method, superTypeName, method.getName(), method.getSignature(), IReference.REF_OVERRIDE)); } } catch (CoreException e) { // Do nothing, skip this reference } } int argumentcount = 0; if ((access & Opcodes.ACC_SYNTHETIC) == 0) { if (signature != null) { this.processSignature(name, signature, IReference.REF_PARAMETERIZED_METHODDECL, METHOD); argumentcount = this.signaturevisitor.argumentcount; } else { Type[] arguments = Type.getArgumentTypes(desc); for (int i = 0; i < arguments.length; i++) { Type type = arguments[i]; this.addTypeReference(type, IReference.REF_PARAMETER); argumentcount += type.getSize(); } this.addTypeReference(Type.getReturnType(desc), IReference.REF_RETURNTYPE); if (exceptions != null) { for (int i = 0; i < exceptions.length; i++) { this.addTypeReference(Type.getObjectType(exceptions[i]), IReference.REF_THROWS); } } } } MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (mv != null && ((access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0)) { return new ClassFileMethodVisitor(mv, name, argumentcount); } } return null; }