@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()); }
@Test public void issue257() throws FileNotFoundException { String pathToSourceFile = adaptPath("src/test/resources/issue257/A.java.txt"); CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile)); Statement statement = cu.getClassByName("A").get().getMethodsByName("run").get(0).getBody().get().getStatement(0); ExpressionStmt expressionStmt = (ExpressionStmt)statement; Expression expression = expressionStmt.getExpression(); JavaParserFacade.get(typeSolver).getType(expression); }
@Test public void parameterDeclarationResolve() throws IOException { File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java")); ParserConfiguration parserConfiguration = new ParserConfiguration(); parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver)); CompilationUnit cu = new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get(); ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0); assertEquals("CompilationUnit", classDeclaration.getNameAsString()); MethodDeclaration methodDeclaration = classDeclaration.getMethodsByName("setComments").get(0); Parameter declaration = methodDeclaration.getParameter(0); ResolvedParameterDeclaration resolvedDeclaration = declaration.resolve(); }
@Test(expected = UnsolvedSymbolException.class) public void issue144() throws ParseException { CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld"); ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld"); ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0); MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression(); Expression firstParameter = methodCallExpr.getArgument(0); JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver); javaParserFacade.solve(firstParameter).isSolved(); }
@Test public void loopOnStaticallyImportedType() throws ParseException { CompilationUnit cu = parseSampleWithStandardExtension("issue128/foo/Issue128"); ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest"); ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("test").get(0).getBody().get().getStatement(0); MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression(); JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver); assertEquals(false, javaParserFacade.solve(methodCallExpr).isSolved()); } }
@Test public void methodDeclarationResolve() throws IOException { File f = adaptPath(new File("src/test/resources/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java")); CompilationUnit cu = parseWithSymbolResolution(f); ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0); assertEquals("CompilationUnit", classDeclaration.getNameAsString()); MethodDeclaration declaration = classDeclaration.getMethodsByName("getComments").get(0); ResolvedMethodDeclaration resolvedDeclaration = declaration.resolve(); assertEquals("getComments", resolvedDeclaration.getName()); assertEquals(0, resolvedDeclaration.getNumberOfParams()); }
@Test public void issue144WithReflectionTypeSolver() throws ParseException { CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld"); ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld"); ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0); MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression(); Expression firstParameter = methodCallExpr.getArgument(0); JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver(true)); assertEquals(true, javaParserFacade.solve(firstParameter).isSolved()); }
@Test public void issue144WithCombinedTypeSolver() throws ParseException { CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld"); ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld"); ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0); MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression(); Expression firstParameter = methodCallExpr.getArgument(0); JavaParserFacade javaParserFacade = JavaParserFacade.get(new CombinedTypeSolver(typeSolver, new ReflectionTypeSolver(true))); assertEquals(true, javaParserFacade.solve(firstParameter).isSolved()); } }