List of usage examples for org.objectweb.asm Opcodes ACC_SYNTHETIC
int ACC_SYNTHETIC
To view the source code for org.objectweb.asm Opcodes ACC_SYNTHETIC.
Click Source Link
From source file:org.codehaus.groovy.ast.MixinASTTransformation.java
License:Apache License
public void visit(ASTNode nodes[], SourceUnit source) { if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException( "Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes)); }/*from ww w .ja v a2s . c om*/ AnnotationNode node = (AnnotationNode) nodes[0]; AnnotatedNode parent = (AnnotatedNode) nodes[1]; if (!MY_TYPE.equals(node.getClassNode())) return; final Expression expr = node.getMember("value"); if (expr == null) { return; } Expression useClasses = null; if (expr instanceof ClassExpression) { useClasses = expr; } else if (expr instanceof ListExpression) { ListExpression listExpression = (ListExpression) expr; for (Expression ex : listExpression.getExpressions()) { if (!(ex instanceof ClassExpression)) return; } useClasses = expr; } if (useClasses == null) return; if (parent instanceof ClassNode) { ClassNode annotatedClass = (ClassNode) parent; final Parameter[] noparams = new Parameter[0]; MethodNode clinit = annotatedClass.getDeclaredMethod("<clinit>", noparams); if (clinit == null) { clinit = annotatedClass.addMethod("<clinit>", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, ClassHelper.VOID_TYPE, noparams, null, new BlockStatement()); clinit.setSynthetic(true); } final BlockStatement code = (BlockStatement) clinit.getCode(); code.addStatement(new ExpressionStatement(new MethodCallExpression( new PropertyExpression(new ClassExpression(annotatedClass), "metaClass"), "mixin", useClasses))); } }
From source file:org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.java
License:Apache License
private MethodNode addSyntheticMethodForDGSM(MethodNode mn) { Parameter[] parameters = removeFirstParameter(mn.getParameters()); ArgumentListExpression args = args(parameters); args.getExpressions().add(0, ConstantExpression.NULL); MethodNode syntheticMethodNode = controller.getClassNode().addSyntheticMethod( "dgsm$$" + mn.getParameters()[0].getType().getName().replace(".", "$") + "$$" + mn.getName(), Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, mn.getReturnType(), parameters, ClassNode.EMPTY_ARRAY, block(returnS(callX(new ClassExpression(mn.getDeclaringClass()), mn.getName(), args)))); syntheticMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(Generated.class))); syntheticMethodNode// w w w. j a v a2 s. c o m .addAnnotation(new AnnotationNode(ClassHelper.make(groovy.transform.CompileStatic.class))); return syntheticMethodNode; }
From source file:org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.java
License:Apache License
private MethodNode addSyntheticMethodForConstructorReference(String syntheticMethodName, ClassNode returnType, Parameter[] parametersWithExactType) { ArgumentListExpression ctorArgs = args(parametersWithExactType); MethodNode syntheticMethodNode = controller.getClassNode() .addSyntheticMethod(syntheticMethodName, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, returnType, parametersWithExactType, ClassNode.EMPTY_ARRAY, block(returnS(//from w w w .ja v a 2 s . c om returnType.isArray() ? new ArrayExpression( ClassHelper.make( ArrayTypeUtils.elementType(returnType.getTypeClass())), null, ctorArgs.getExpressions()) : ctorX(returnType, ctorArgs)))); syntheticMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(Generated.class))); syntheticMethodNode .addAnnotation(new AnnotationNode(ClassHelper.make(groovy.transform.CompileStatic.class))); return syntheticMethodNode; }
From source file:org.codehaus.groovy.classgen.InnerClassCompletionVisitor.java
License:Apache License
private boolean hasSyntheticModifier(MethodNode existingMethodNode) { return (existingMethodNode.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0; }
From source file:org.codehaus.groovy.control.OptimizerVisitor.java
License:Apache License
private void setConstField(ConstantExpression constantExpression) { final Object n = constantExpression.getValue(); if (!(n instanceof Number)) return;//from w ww.java 2 s. c o m if (n instanceof Integer || n instanceof Double) return; if (n instanceof Long && (0L == (Long) n || 1L == (Long) n)) return; // LCONST_0, LCONST_1 boolean isPrimitive = isPrimitiveType(constantExpression.getType()); FieldNode field = isPrimitive ? const2Prims.get(n) : const2Objects.get(n); if (field != null) { constantExpression.setConstantName(field.getName()); return; } String name; do { name = "$const$" + index++; } while (currentClass.getDeclaredField(name) != null); // TODO consider moving initcode to <clinit> and remaking field final field = new FieldNode(name, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, constantExpression.getType(), currentClass, constantExpression); field.setSynthetic(true); missingFields.add(field); constantExpression.setConstantName(field.getName()); if (isPrimitive) { const2Prims.put(n, field); } else { const2Objects.put(n, field); } }
From source file:org.codehaus.groovy.eclipse.core.compiler.GroovySnippetCompiler.java
License:Open Source License
/** * Compiles source code into a ModuleNode. Source code * must be a complete file including package declaration * and import statements./*from w w w. j a v a 2 s . c o m*/ * * @param source the groovy source code to compile * @param sourcePath the path including file name to compile. Can be null */ public ModuleNode compile(String source, String sourcePath) { GroovyCompilationUnitDeclaration decl = internalCompile(source, sourcePath); ModuleNode node = decl.getModuleNode(); // Remove any remaining synthetic methods for (ClassNode classNode : (Iterable<ClassNode>) node.getClasses()) { for (Iterator<MethodNode> methodIter = classNode.getMethods().iterator(); methodIter.hasNext();) { MethodNode method = methodIter.next(); if ((method.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0) { methodIter.remove(); } } } return node; }
From source file:org.codehaus.groovy.eclipse.core.compiler.GroovySnippetParser.java
License:Open Source License
/** * Compiles source code into a ModuleNode. Source code * must be a complete file including package declaration * and import statements./*from w ww .j ava 2 s . co m*/ * * @param source the groovy source code to compile */ @SuppressWarnings("unchecked") public ModuleNode parse(String source) { Hashtable table = JavaCore.getOptions(); table.put(CompilerOptions.OPTIONG_BuildGroovyFiles, CompilerOptions.ENABLED); CompilerOptions options = new CompilerOptions(table); ProblemReporter reporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), options, new DefaultProblemFactory()); GroovyParser parser = new GroovyParser(options, reporter, false, true); ICompilationUnit unit = new MockCompilationUnit(source.toCharArray(), "Hello.groovy".toCharArray()); CompilationResult compilationResult = new CompilationResult(unit, 0, 0, options.maxProblemsPerUnit); GroovyCompilationUnitDeclaration decl = (GroovyCompilationUnitDeclaration) parser.dietParse(unit, compilationResult); ModuleNode node = decl.getModuleNode(); if (node == null) { return null; } // Remove any remaining synthetic methods for (ClassNode classNode : (Iterable<ClassNode>) node.getClasses()) { for (Iterator<MethodNode> methodIter = classNode.getMethods().iterator(); methodIter.hasNext();) { MethodNode method = methodIter.next(); if ((method.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0) { methodIter.remove(); } } } problems = compilationResult.getErrors(); return node; }
From source file:org.codehaus.groovy.parser.antlr4.ASTBuilder.java
License:Apache License
public ClassNode parseClassDeclaration(final GroovyLangParser.ClassDeclarationContext ctx) { boolean isEnum = asBoolean(ctx.KW_ENUM()); final ClassNode outerClass = asBoolean(classNodeStack) ? classNodeStack.peek() : null; ClassNode[] interfaces = asBoolean(ctx.implementsClause()) ? collect(ctx.implementsClause().genericClassNameExpression(), new Closure<ClassNode>(this, this) { public ClassNode doCall(GroovyLangParser.GenericClassNameExpressionContext it) { return parseExpression(it); }//from w w w . j av a2s . co m }).toArray(new ClassNode[0]) : new ClassNode[0]; ClassNode classNode; String packageName = moduleNode.getPackageName(); packageName = packageName != null && asBoolean(packageName) ? packageName : ""; if (isEnum) { classNode = EnumHelper.makeEnumNode( asBoolean(outerClass) ? ctx.IDENTIFIER().getText() : packageName + ctx.IDENTIFIER().getText(), Modifier.PUBLIC, interfaces, outerClass); } else { if (outerClass != null) { String name = outerClass.getName() + "$" + String.valueOf(ctx.IDENTIFIER()); classNode = new InnerClassNode(outerClass, name, Modifier.PUBLIC, ClassHelper.OBJECT_TYPE); } else { classNode = new ClassNode(packageName + String.valueOf(ctx.IDENTIFIER()), Modifier.PUBLIC, ClassHelper.OBJECT_TYPE); } } setupNodeLocation(classNode, ctx); if (asBoolean(ctx.KW_TRAIT())) { attachTraitTransformAnnotation(classNode); } attachAnnotations(classNode, ctx.annotationClause()); // moduleNode.addClass(classNode); classes.add(classNode); if (asBoolean(ctx.extendsClause())) { if (asBoolean(ctx.KW_INTERFACE()) && !asBoolean(ctx.AT())) { // interface(NOT annotation) List<ClassNode> interfaceList = new LinkedList<ClassNode>(); for (GroovyLangParser.GenericClassNameExpressionContext genericClassNameExpressionContext : ctx .extendsClause().genericClassNameExpression()) { interfaceList.add(parseExpression(genericClassNameExpressionContext)); } (classNode).setInterfaces(interfaceList.toArray(new ClassNode[0])); (classNode).setSuperClass(ClassHelper.OBJECT_TYPE); } else { (classNode).setSuperClass(parseExpression(ctx.extendsClause().genericClassNameExpression(0))); } } if (asBoolean(ctx.implementsClause())) { (classNode).setInterfaces(interfaces); } if (!isEnum) { (classNode).setGenericsTypes(parseGenericDeclaration(ctx.genericDeclarationList())); (classNode).setUsingGenerics( (classNode.getGenericsTypes() != null && classNode.getGenericsTypes().length != 0) || (classNode).getSuperClass().isUsingGenerics() || DefaultGroovyMethods .any(classNode.getInterfaces(), new Closure<Boolean>(this, this) { public Boolean doCall(ClassNode it) { return it.isUsingGenerics(); } })); } classNode.setModifiers( parseClassModifiers(ctx.classModifier()) | (isEnum ? (Opcodes.ACC_ENUM | Opcodes.ACC_FINAL) : ((asBoolean(ctx.KW_INTERFACE()) ? Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT : 0)))); classNode.setSyntheticPublic((classNode.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0); classNode.setModifiers(classNode.getModifiers() & ~Opcodes.ACC_SYNTHETIC);// FIXME Magic with synthetic modifier. if (asBoolean(ctx.AT())) { classNode.addInterface(ClassHelper.Annotation_TYPE); classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ANNOTATION); } classNodeStack.add(classNode); parseClassBody(classNode, ctx.classBody()); classNodeStack.pop(); if (classNode.isInterface()) { // FIXME why interface has null mixin try { // FIXME Hack with visibility. Field field = ClassNode.class.getDeclaredField("mixins"); field.setAccessible(true); field.set(classNode, null); } catch (IllegalAccessException e) { log.warning(createExceptionMessage(e)); } catch (NoSuchFieldException e) { log.warning(createExceptionMessage(e)); } } this.attachDocCommentAsMetaData(classNode, ctx); return classNode; }
From source file:org.codehaus.groovy.parser.antlr4.ASTBuilder.java
License:Apache License
public int parseClassModifiers(List<? extends GroovyLangParser.ClassModifierContext> ctxs) { List<TerminalNode> visibilityModifiers = new LinkedList<TerminalNode>(); int modifiers = 0; for (int i = 0; i < ctxs.size(); i++) { for (Object ctx : ctxs.get(i).children) { ParseTree child = null;/*from ww w . ja v a 2s. c o m*/ if (ctx instanceof List) { List list = (List) ctx; assert list.size() == 1; child = (ParseTree) list.get(0); } else child = (ParseTree) ctx; assert child instanceof TerminalNode; switch (((TerminalNode) child).getSymbol().getType()) { case GroovyLangLexer.VISIBILITY_MODIFIER: visibilityModifiers.add((TerminalNode) child); break; case GroovyLangLexer.KW_STATIC: modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_STATIC, (TerminalNode) child); break; case GroovyLangLexer.KW_ABSTRACT: modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_ABSTRACT, (TerminalNode) child); break; case GroovyLangLexer.KW_FINAL: modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_FINAL, (TerminalNode) child); break; case GroovyLangLexer.KW_STRICTFP: modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_STRICT, (TerminalNode) child); break; } } } if (asBoolean(visibilityModifiers)) modifiers |= parseVisibilityModifiers(visibilityModifiers, 0); else modifiers |= Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC; return modifiers; }
From source file:org.codehaus.groovy.runtime.callsite.CallSiteGenerator.java
License:Apache License
private static void classHeader(ClassWriter cw, String internalName, String superName) { if (VMPluginFactory.getPlugin().getVersion() >= 8) { cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, internalName, null, superName, null); } else {// w ww. ja v a 2 s . c o m cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, internalName, null, superName, null); } }