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.apache.groovy.parser.antlr4.AstBuilder.java
License:Apache License
@Override public ClassNode visitClassDeclaration(ClassDeclarationContext ctx) { String packageName = moduleNode.getPackageName(); packageName = null != packageName ? packageName : ""; List<ModifierNode> modifierNodeList = ctx.getNodeMetaData(TYPE_DECLARATION_MODIFIERS); Objects.requireNonNull(modifierNodeList, "modifierNodeList should not be null"); ModifierManager modifierManager = new ModifierManager(this, modifierNodeList); int modifiers = modifierManager.getClassModifiersOpValue(); boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0); modifiers &= ~Opcodes.ACC_SYNTHETIC; final ClassNode outerClass = classNodeStack.peek(); ClassNode classNode;/* w ww . ja v a2 s. c o m*/ String className = this.visitIdentifier(ctx.identifier()); if (VAR_STR.equals(className)) { throw createParsingFailedException("var cannot be used for type declarations", ctx.identifier()); } if (asBoolean(ctx.ENUM())) { classNode = EnumHelper.makeEnumNode(asBoolean(outerClass) ? className : packageName + className, modifiers, null, outerClass); } else { if (asBoolean(outerClass)) { classNode = new InnerClassNode(outerClass, outerClass.getName() + "$" + className, modifiers | (outerClass.isInterface() ? Opcodes.ACC_STATIC : 0), ClassHelper.OBJECT_TYPE); } else { classNode = new ClassNode(packageName + className, modifiers, ClassHelper.OBJECT_TYPE); } } configureAST(classNode, ctx); classNode.putNodeMetaData(CLASS_NAME, className); classNode.setSyntheticPublic(syntheticPublic); if (asBoolean(ctx.TRAIT())) { attachTraitAnnotation(classNode); } classNode.addAnnotations(modifierManager.getAnnotations()); classNode.setGenericsTypes(this.visitTypeParameters(ctx.typeParameters())); boolean isInterface = asBoolean(ctx.INTERFACE()) && !asBoolean(ctx.AT()); boolean isInterfaceWithDefaultMethods = false; // declaring interface with default method if (isInterface && this.containsDefaultMethods(ctx)) { isInterfaceWithDefaultMethods = true; attachTraitAnnotation(classNode); classNode.putNodeMetaData(IS_INTERFACE_WITH_DEFAULT_METHODS, true); } if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()) || isInterfaceWithDefaultMethods) { // class OR trait OR interface with default methods classNode.setSuperClass(this.visitType(ctx.sc)); classNode.setInterfaces(this.visitTypeList(ctx.is)); this.initUsingGenerics(classNode); } else if (isInterface) { // interface(NOT annotation) classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT); classNode.setSuperClass(ClassHelper.OBJECT_TYPE); classNode.setInterfaces(this.visitTypeList(ctx.scs)); this.initUsingGenerics(classNode); this.hackMixins(classNode); } else if (asBoolean(ctx.ENUM())) { // enum classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL); classNode.setInterfaces(this.visitTypeList(ctx.is)); this.initUsingGenerics(classNode); } else if (asBoolean(ctx.AT())) { // annotation classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_ANNOTATION); classNode.addInterface(ClassHelper.Annotation_TYPE); this.hackMixins(classNode); } else { throw createParsingFailedException("Unsupported class declaration: " + ctx.getText(), ctx); } // we put the class already in output to avoid the most inner classes // will be used as first class later in the loader. The first class // there determines what GCL#parseClass for example will return, so we // have here to ensure it won't be the inner class if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT())) { classNodeList.add(classNode); } classNodeStack.push(classNode); ctx.classBody().putNodeMetaData(CLASS_DECLARATION_CLASS_NODE, classNode); this.visitClassBody(ctx.classBody()); classNodeStack.pop(); if (!(asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()))) { classNodeList.add(classNode); } groovydocManager.handle(classNode, ctx); return classNode; }
From source file:org.apache.groovy.parser.antlr4.AstBuilder.java
License:Apache License
private MethodNode createMethodNodeForClass(MethodDeclarationContext ctx, ModifierManager modifierManager, String methodName, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code, ClassNode classNode, int modifiers) { MethodNode methodNode;/*from www .j ava2 s. c om*/ if (asBoolean(ctx.elementValue())) { // the code of annotation method code = configureAST(new ExpressionStatement(this.visitElementValue(ctx.elementValue())), ctx.elementValue()); } modifiers |= !modifierManager.containsAny(STATIC) && (classNode.isInterface() || (isTrue(classNode, IS_INTERFACE_WITH_DEFAULT_METHODS) && !modifierManager.containsAny(DEFAULT))) ? Opcodes.ACC_ABSTRACT : 0; checkWhetherMethodNodeWithSameSignatureExists(classNode, methodName, parameters, ctx); methodNode = classNode.addMethod(methodName, modifiers, returnType, parameters, exceptions, code); methodNode.setAnnotationDefault(asBoolean(ctx.elementValue())); return methodNode; }
From source file:org.apache.tika.parser.asm.XHTMLClassVisitor.java
License:Apache License
private void writeAccess(int access) throws SAXException { writeAccess(access, Opcodes.ACC_PRIVATE, "private"); writeAccess(access, Opcodes.ACC_PROTECTED, "protected"); writeAccess(access, Opcodes.ACC_PUBLIC, "public"); writeAccess(access, Opcodes.ACC_STATIC, "static"); writeAccess(access, Opcodes.ACC_FINAL, "final"); writeAccess(access, Opcodes.ACC_ABSTRACT, "abstract"); writeAccess(access, Opcodes.ACC_SYNCHRONIZED, "synchronized"); writeAccess(access, Opcodes.ACC_TRANSIENT, "transient"); writeAccess(access, Opcodes.ACC_VOLATILE, "volatile"); writeAccess(access, Opcodes.ACC_NATIVE, "native"); }
From source file:org.apache.tuscany.sdo.codegen.BytecodeInterfaceGenerator.java
License:Apache License
public void visitType(Type type) { String name = type.getName(); int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { name = name.replace('.', '/'); } else {/*from w w w . j ava2 s .c om*/ name = Character.toUpperCase(name.charAt(0)) + name.substring(1); } List baseTypes = type.getBaseTypes(); String[] interfaces = new String[baseTypes.size()]; for (int i = 0; i < baseTypes.size(); i++) { Type baseType = (Type) baseTypes.get(i); interfaces[i] = baseType.getInstanceClass().getName().replace('.', '/'); } cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE, name, null, "java/lang/Object", interfaces); }
From source file:org.apache.tuscany.sdo.codegen.BytecodeInterfaceGenerator.java
License:Apache License
public void visitProperty(Property property) { String name = property.getName(); String propertyName = Character.toUpperCase(name.charAt(0)) + name.substring(1); Class javaType = property.getType().getInstanceClass(); String desc = org.objectweb.asm.Type.getDescriptor(javaType); if (property.isMany()) { cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "get" + propertyName, "()Ljava/util/List;", null, null).visitEnd();//from ww w . ja v a 2 s . c o m } else { if (boolean.class.equals(javaType)) { cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "is" + propertyName, "()Z", null, null) .visitEnd(); } else { cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "get" + propertyName, "()" + desc, null, null).visitEnd(); } if (!property.isReadOnly()) { cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "set" + propertyName, '(' + desc + ")V", null, null).visitEnd(); } } }
From source file:org.brutusin.instrumentation.utils.Helper.java
License:Apache License
public static boolean isAbstract(MethodNode m) { return (m.access & Opcodes.ACC_ABSTRACT) != 0; }
From source file:org.bundlemaker.core.parser.bytecode.asm.ArtefactAnalyserClassVisitor.java
License:Open Source License
/** * @inheritDoc//from w w w . j av a2 s .c o m */ @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { // get the type _type = Type.getObjectType(name); // get the abstract flag boolean abstractType = ((access & Opcodes.ACC_ABSTRACT) != 0); // get the type type TypeEnum typeEnum = null; if ((access & Opcodes.ACC_ENUM) != 0) { typeEnum = TypeEnum.ENUM; } else if ((access & Opcodes.ACC_ANNOTATION) != 0) { typeEnum = TypeEnum.ANNOTATION; } else if ((access & Opcodes.ACC_INTERFACE) != 0) { typeEnum = TypeEnum.INTERFACE; abstractType = true; } else { typeEnum = TypeEnum.CLASS; } // get the fully qualified name String fullyQualifiedName = VisitorUtils.getFullyQualifiedTypeName(_type); // record the contained type _recorder.recordContainedType(fullyQualifiedName, typeEnum, abstractType); if (_analyzeReferences) { // super type // TODO: USES Type superType = Type.getObjectType(superName); VisitorUtils.recordReferencedTypes(_recorder, true, false, false, superType); // for (String interfaceName : interfaces) { // implemented interfaces // TODO: USES Type implementsType = Type.getObjectType(interfaceName); VisitorUtils.recordReferencedTypes(_recorder, false, true, false, implementsType); } } }
From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java
License:Apache License
protected void annotationDef(AST classDef) { List<AnnotationNode> annotations = new ArrayList<>(); AST node = classDef.getFirstChild(); int modifiers = Opcodes.ACC_PUBLIC; if (isType(MODIFIERS, node)) { modifiers = modifiers(node, annotations, modifiers); checkNoInvalidModifier(classDef, "Annotation Definition", modifiers, Opcodes.ACC_SYNCHRONIZED, "synchronized"); node = node.getNextSibling();/* ww w . j a va 2s.c om*/ } modifiers |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_ANNOTATION; String name = identifier(node); node = node.getNextSibling(); ClassNode superClass = ClassHelper.OBJECT_TYPE; GenericsType[] genericsType = null; if (isType(TYPE_PARAMETERS, node)) { genericsType = makeGenericsType(node); node = node.getNextSibling(); } ClassNode[] interfaces = ClassNode.EMPTY_ARRAY; if (isType(EXTENDS_CLAUSE, node)) { interfaces = interfaces(node); node = node.getNextSibling(); } boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0); modifiers &= ~Opcodes.ACC_SYNTHETIC; classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, null); classNode.setSyntheticPublic(syntheticPublic); classNode.addAnnotations(annotations); classNode.setGenericsTypes(genericsType); classNode.addInterface(ClassHelper.Annotation_TYPE); configureAST(classNode, classDef); assertNodeType(OBJBLOCK, node); objectBlock(node); output.addClass(classNode); classNode = null; }
From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java
License:Apache License
protected void innerInterfaceDef(AST classDef) { List<AnnotationNode> annotations = new ArrayList<>(); AST node = classDef.getFirstChild(); int modifiers = Opcodes.ACC_PUBLIC; if (isType(MODIFIERS, node)) { modifiers = modifiers(node, annotations, modifiers); checkNoInvalidModifier(classDef, "Interface", modifiers, Opcodes.ACC_SYNCHRONIZED, "synchronized"); node = node.getNextSibling();/*from w ww . j a v a 2 s . c om*/ } modifiers |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE; String name = identifier(node); node = node.getNextSibling(); ClassNode superClass = ClassHelper.OBJECT_TYPE; GenericsType[] genericsType = null; if (isType(TYPE_PARAMETERS, node)) { genericsType = makeGenericsType(node); node = node.getNextSibling(); } ClassNode[] interfaces = ClassNode.EMPTY_ARRAY; if (isType(EXTENDS_CLAUSE, node)) { interfaces = interfaces(node); node = node.getNextSibling(); } ClassNode outerClass = classNode; boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0); modifiers &= ~Opcodes.ACC_SYNTHETIC; if (classNode != null) { name = classNode.getNameWithoutPackage() + "$" + name; String fullName = dot(classNode.getPackageName(), name); classNode = new InnerClassNode(classNode, fullName, modifiers, superClass, interfaces, null); } else { classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, null); } classNode.setSyntheticPublic(syntheticPublic); classNode.addAnnotations(annotations); classNode.setGenericsTypes(genericsType); configureAST(classNode, classDef); assertNodeType(OBJBLOCK, node); objectBlock(node); output.addClass(classNode); classNode = outerClass; }
From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java
License:Apache License
protected void methodDef(AST methodDef) { MethodNode oldNode = methodNode;/*w ww.ja va 2 s . co m*/ List<AnnotationNode> annotations = new ArrayList<>(); AST node = methodDef.getFirstChild(); GenericsType[] generics = null; if (isType(TYPE_PARAMETERS, node)) { generics = makeGenericsType(node); node = node.getNextSibling(); } int modifiers = Opcodes.ACC_PUBLIC; if (isType(MODIFIERS, node)) { modifiers = modifiers(node, annotations, modifiers); checkNoInvalidModifier(methodDef, "Method", modifiers, Opcodes.ACC_VOLATILE, "volatile"); node = node.getNextSibling(); } if (isAnInterface()) { modifiers |= Opcodes.ACC_ABSTRACT; } ClassNode returnType = null; if (isType(TYPE, node)) { returnType = makeTypeWithArguments(node); node = node.getNextSibling(); } String name = identifier(node); if (classNode != null && !classNode.isAnnotationDefinition()) { if (classNode.getNameWithoutPackage().equals(name)) { if (isAnInterface()) { throw new ASTRuntimeException(methodDef, "Constructor not permitted within an interface."); } throw new ASTRuntimeException(methodDef, "Invalid constructor format. Remove '" + returnType.getName() + "' as the return type if you want a constructor, or use a different name if you want a method."); } } node = node.getNextSibling(); Parameter[] parameters = Parameter.EMPTY_ARRAY; ClassNode[] exceptions = ClassNode.EMPTY_ARRAY; if (classNode == null || !classNode.isAnnotationDefinition()) { assertNodeType(PARAMETERS, node); parameters = parameters(node); if (parameters == null) parameters = Parameter.EMPTY_ARRAY; node = node.getNextSibling(); if (isType(LITERAL_throws, node)) { AST throwsNode = node.getFirstChild(); List<ClassNode> exceptionList = new ArrayList<>(); throwsList(throwsNode, exceptionList); exceptions = exceptionList.toArray(exceptions); node = node.getNextSibling(); } } boolean hasAnnotationDefault = false; Statement code = null; boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0); modifiers &= ~Opcodes.ACC_SYNTHETIC; methodNode = new MethodNode(name, modifiers, returnType, parameters, exceptions, code); if ((modifiers & Opcodes.ACC_ABSTRACT) == 0) { if (node == null) { throw new ASTRuntimeException(methodDef, "You defined a method without a body. Try adding a body, or declare it abstract."); } else { assertNodeType(SLIST, node); code = statementList(node); } } else if (node != null) { if (classNode != null && classNode.isAnnotationDefinition()) { code = statement(node); hasAnnotationDefault = true; } else { throw new ASTRuntimeException(methodDef, "Abstract methods do not define a body."); } } methodNode.setCode(code); methodNode.addAnnotations(annotations); methodNode.setGenericsTypes(generics); methodNode.setAnnotationDefault(hasAnnotationDefault); methodNode.setSyntheticPublic(syntheticPublic); configureAST(methodNode, methodDef); if (classNode != null) { classNode.addMethod(methodNode); } else { output.addMethod(methodNode); } methodNode = oldNode; }