@Override public void visit(ClassOrInterfaceDeclaration node, Void arg) { super.visit(node, arg); replaceParentClassesForAtomics(node); node.setName(translateQueueName(node.getNameAsString())); if (MPSC_LINKED_ATOMIC_QUEUE_NAME.equals(node.getNameAsString())) { /* * Special case for MPSC */ node.removeModifier(Modifier.ABSTRACT); node.addModifier(Modifier.FINAL); } if (isCommentPresent(node, GEN_DIRECTIVE_CLASS_CONTAINS_ORDERED_FIELD_ACCESSORS)) { node.setComment(null); removeStaticFieldsAndInitialisers(node); patchAtomicFieldUpdaterAccessorMethods(node); } for (MethodDeclaration method : node.getMethods()) { if (isCommentPresent(method, GEN_DIRECTIVE_METHOD_IGNORE)) { method.remove(); } } node.setJavadocComment(formatMultilineJavadoc(0, "NOTE: This class was automatically generated by " + JavaParsingAtomicLinkedQueueGenerator.class.getName(), "which can found in the jctools-build module. The original source file is " + sourceFileName + ".") + node.getJavadocComment().orElse(new JavadocComment("")).getContent()); }
@Override public void visit(ClassOrInterfaceDeclaration node, Void arg) { super.visit(node, arg); replaceParentClassesForAtomics(node); node.setName(translateQueueName(node.getNameAsString())); if (isCommentPresent(node, GEN_DIRECTIVE_CLASS_CONTAINS_ORDERED_FIELD_ACCESSORS)) { node.setComment(null); removeStaticFieldsAndInitialisers(node); patchAtomicFieldUpdaterAccessorMethods(node); } for (MethodDeclaration method : node.getMethods()) { if (isCommentPresent(method, GEN_DIRECTIVE_METHOD_IGNORE)) { method.remove(); } } if (!node.getMethodsByName("failFastOffer").isEmpty()) { MethodDeclaration deprecatedMethodRedirect = node.addMethod("weakOffer", Modifier.PUBLIC); patchMethodAsDepreciatedRedirector(deprecatedMethodRedirect, "failFastOffer", PrimitiveType.intType(), new Parameter(classType("E"), "e")); } node.setJavadocComment(formatMultilineJavadoc(0, "NOTE: This class was automatically generated by " + JavaParsingAtomicArrayQueueGenerator.class.getName(), "which can found in the jctools-build module. The original source file is " + sourceFileName + ".") + node.getJavadocComment().orElse(new JavadocComment("")).getContent()); }
public static void main(String[] args) throws FileNotFoundException { // The directory where we store the examples String pathToExamplesDir = "." + separator + "src" + separator + "main" + separator + "resources"; // Parse the code of an entire source file, a.k.a. a Compilation Unit CompilationUnit compilationUnitNode = JavaParser.parse(new File(pathToExamplesDir + separator + "ASimpleClass.java")); printCompilationUnit("My original class", compilationUnitNode); // Modifying the name of the class compilationUnitNode.getClassByName("ASimpleClass").get() .setName("MyRenamedClass"); printCompilationUnit("Renamed class", compilationUnitNode); // Adding a method: we add a setter MethodDeclaration setter = compilationUnitNode .getClassByName("MyRenamedClass").get() .addMethod("setAField", Modifier.PUBLIC); setter.addParameter("boolean", "aField"); setter.getBody().get().getStatements().add(new ExpressionStmt( new AssignExpr( new FieldAccessExpr(new ThisExpr(),"aField"), new NameExpr("aField"), AssignExpr.Operator.ASSIGN ))); printCompilationUnit("With a setter", compilationUnitNode); } }
@Override public TypeDeclaration<?> getTypeDeclaration(final TypeData.Type type, final String suffix) { final ClassOrInterfaceDeclaration decl = new ClassOrInterfaceDeclaration(); decl.setInterface(false); decl.setPublic(true); String _name = type.getName(); String _plus = (_name + suffix); decl.setName(_plus); boolean _isEnum = this.isEnum(type); if (_isEnum) { this.requireTypes(EnumOverlay.class); StringConcatenation _builder = new StringConcatenation(); _builder.append("EnumOverlay<"); String _name_1 = type.getName(); _builder.append(_name_1); _builder.append(">"); decl.addExtendedType(_builder.toString()); } else { decl.addExtendedType(this.getSuperType(type)); decl.addImplementedType(type.getName()); } return decl; }
public static ClassOrInterfaceDeclaration mergeType(ClassOrInterfaceDeclaration one, ClassOrInterfaceDeclaration two) { if (isAllNull(one, two)) return null; ClassOrInterfaceDeclaration coid = null; if (isAllNotNull(one, two)) { coid = new ClassOrInterfaceDeclaration(); coid.setName(one.getName()); coid.setJavaDoc(mergeSelective(one.getJavaDoc(), two.getJavaDoc())); coid.setComment(mergeSelective(one.getComment(), two.getComment())); coid.setAnnotations(mergeListNoDuplicate(one.getAnnotations(), two.getAnnotations())); coid.setModifiers(mergeModifiers(one.getModifiers(), two.getModifiers())); coid.setExtends(mergeListNoDuplicate(one.getExtends(), two.getExtends())); coid.setImplements(mergeListNoDuplicate(one.getImplements(), two.getImplements())); coid.setTypeParameters(mergeSelective(one.getTypeParameters(), two.getTypeParameters())); coid.setInterface(one.isInterface()); coid.setMembers(mergeBodies(one.getMembers(), two.getMembers())); LOG.info("merge ClassOrInterfaceDeclaration --> {}", coid.getName()); } else { coid = findFirstNotNull(one, two); LOG.info("add ClassOrInterfaceDeclaration --> {}", coid.getName()); } return coid; }
@Override public ClassOrInterfaceDeclaration doMerge(ClassOrInterfaceDeclaration first, ClassOrInterfaceDeclaration second) { ClassOrInterfaceDeclaration declaration = new ClassOrInterfaceDeclaration(); declaration.setInterface(first.isInterface()); declaration.setName(first.getName()); declaration.setModifiers(mergeModifiers(first.getModifiers(), second.getModifiers())); declaration.setJavaDoc(mergeSingle(first.getJavaDoc(), second.getJavaDoc())); declaration.setTypeParameters(mergeCollections(first.getTypeParameters(), second.getTypeParameters())); declaration.setImplements(mergeCollections(first.getImplements(), second.getImplements())); declaration.setExtends(mergeCollections(first.getExtends(), second.getExtends())); declaration.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations())); declaration.setMembers(mergeCollections(first.getMembers(), second.getMembers())); return declaration; }