@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()); }
for (MethodDeclaration method : n.getMethods()) { String methodName = method.getNameAsString(); if (!methodName.endsWith(methodNameSuffix)) {
@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()); }
for (MethodDeclaration method : n.getMethods()) { String methodName = method.getNameAsString(); if (!methodName.endsWith(methodNameSuffix)) {
private static void writeStaticMethods(PrintStream s, String indent, ClassOrInterfaceDeclaration c) { if (!c.getMethods().isEmpty()) { c // .getMethods() // .stream() // .filter(x -> x.isStatic()) // .forEach(x -> { s.format("\n\n%s%s", indent, x.toString().replaceAll("\n", "\n" + indent)); }); } }
private static void writeStaticMethods(PrintStream s, String indent, ClassOrInterfaceDeclaration c) { if (!c.getMethods().isEmpty()) { c // .getMethods() // .stream() // .filter(x -> x.isStatic()) // .forEach(x -> { s.format("\n\n%s%s", indent, x.toString().replaceAll("\n", "\n" + indent)); }); } }
public MethodImp parse(final String signature) { final StringBuilder sb = new StringBuilder(); sb.append("class A {\n"); if (!signature.contains("(")) { sb.append(signature.contains("()") ? signature : signature.concat("()")); } else { sb.append(signature); } if (!signature.contains("{}")) { sb.append(" {}"); } sb.append("\n}"); final MethodImp method = new MethodImp("NOT_DEFINED"); final CompilationUnit compilationUnit = JavaParser.parse(sb.toString()); compilationUnit.getClassByName("A").ifPresent(clazz -> { clazz.getMethods().forEach(md -> { method.name(md.getNameAsString()); method.visibility(this.getVisibility(md)); method.modifiers(this.getModifiers(md)); method.returnType(this.getReturnType(md)); method.exceptions(this.getExceptions(md)); md.getAnnotations().forEach(an -> this.getAnnotationMethod(an) .ifPresent(x -> method.annotation(x))); md.getParameters().forEach(p -> this.getField(p) .ifPresent(x -> method.parameters().add(x))); }); }); return method; }
List<MethodDeclaration> methods = currentClass.getMethods();
@Test public void resolveArrayType() throws ParseException { TypeSolver typeSolver = new ReflectionTypeSolver(); CompilationUnit cu = parseSample("SymbolResolverExample"); new JavaSymbolSolver(typeSolver).inject(cu); MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMethods().get(0); ResolvedType resolvedType = methodDeclaration.getType().resolve(); assertEquals("A[]", resolvedType.describe()); } }
@Test public void resolveMethodDeclaration() throws ParseException { TypeSolver typeSolver = new ReflectionTypeSolver(); CompilationUnit cu = parseSample("SymbolResolverExample"); new JavaSymbolSolver(typeSolver).inject(cu); MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMethods().get(0); ResolvedMethodDeclaration resolvedMethodDeclaration = methodDeclaration.resolve(); assertEquals("foo", resolvedMethodDeclaration.getName()); assertEquals("A[]", resolvedMethodDeclaration.getReturnType().describe()); assertEquals("java.lang.String[]", resolvedMethodDeclaration.getParam(0).getType().describe()); assertEquals("int[]", resolvedMethodDeclaration.getParam(1).getType().describe()); }
List<MethodDeclaration> methods = currentClass.getMethods();
List<MethodDeclaration> methods = currentClass.getMethods();