@Override public void visit(ClassOrInterfaceDeclaration n, Void arg) { out.println("ClassOrInterfaceDeclaration: " + (extended ? n : n.getNameAsString())); super.visit(n, arg); }
@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()); }
String className = n.getNameAsString();
String className = n.getNameAsString();
@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()); }
private String calculateClassName(ClassOrInterfaceDeclaration classOrInterface) { if (StringUtils.isBlank(packageName)) return classOrInterface.getNameAsString(); return packageName.replace('.', '/') + "/" + classOrInterface.getNameAsString(); }
private String calculateClassName(ClassOrInterfaceDeclaration classOrInterface) { if (StringUtils.isBlank(packageName)) return classOrInterface.getNameAsString(); return packageName.replace('.', '/') + "/" + classOrInterface.getNameAsString(); }
public void visit(ClassOrInterfaceDeclaration n, String objectType) { try { Comment comment = n.getComment().get(); javadoc.append(String.format("{panel}%s{panel}\n", formatJavadoc(comment.getContent()))); } catch (NoSuchElementException e) { javadoc.append(String.format("{panel}%s de la classe %s{panel}\n", objectType, n.getNameAsString())); } } }
protected void prepareClassComment(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, TypeDocMeta typeDocMeta) { if (DfStringUtil.is_Null_or_Empty(typeDocMeta.getComment()) && classOrInterfaceDeclaration.getNameAsString().equals(typeDocMeta.getSimpleTypeName())) { String comment = adjustComment(classOrInterfaceDeclaration); if (DfStringUtil.is_NotNull_and_NotEmpty(comment)) { typeDocMeta.setComment(comment); Matcher matcher = CLASS_METHOD_COMMENT_END_PATTERN.matcher(comment); if (matcher.find()) { typeDocMeta.setDescription(matcher.group(1)); } } } }
/** {@inheritDoc} */ @Override public void visit(ClassOrInterfaceDeclaration n, ClassBuilder builder) { classNames.addLast(n.getNameAsString()); if (n.getParentNode().isPresent() && n.getParentNode().get() instanceof CompilationUnit) { super.visit(n, builder); setAttributes(builder, n); } else { String fullPackageName = packageName + "." + classNames.stream().limit(classNames.size() - 1).collect(joining(".")); imports.put(n.getNameAsString(), fullPackageName); ClassBuilder child = ClassBuilder.classBuilder(); child.withPackageName(fullPackageName); setAttributes(child, n); super.visit(n, child); builder.withInnerClass(child.build()); } classNames.removeLast(); }
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) { List<ClassOrInterfaceType> implementedInterfaces = classOrInterfaceDeclaration.getImplementedTypes(); for (ClassOrInterfaceType implementedInterface : implementedInterfaces) { String implementedInterfaceName = implementedInterface.getNameAsString(); String implementedInterfacePackageName = implementedInterface .findCompilationUnit() .flatMap(CompilationUnit::getPackageDeclaration) .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???"); if (typeDao.exist(implementedInterfaceName, implementedInterfacePackageName)) { // JDK interfaces are not indexed int interfaceId = typeDao.getId(implementedInterfaceName, implementedInterfacePackageName); String cuPackageName = compilationUnit.getPackageDeclaration().get().getNameAsString(); int nbClasses = typeDao.count(classOrInterfaceDeclaration.getNameAsString(), cuPackageName); if (nbClasses > 1) { System.err.println("More than one class having the same name '" + classOrInterfaceDeclaration.getName() + "' and package '" + cuPackageName + "'"); } else { int classId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), cuPackageName); implementsDao.save(new Implements(classId, interfaceId)); } } } } }
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) { List<ClassOrInterfaceType> extendedTypes = classOrInterfaceDeclaration.getExtendedTypes(); for (ClassOrInterfaceType extendedType : extendedTypes) { String extendedTypeName = extendedType.getNameAsString(); String extendedTypePackageName = extendedType .findCompilationUnit() .flatMap(CompilationUnit::getPackageDeclaration) .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???"); if (typeDao.exist(extendedTypeName, extendedTypePackageName)) { // JDK interfaces are not indexed int extendedInterfaceId = typeDao.getId(extendedTypeName, extendedTypePackageName); int interfaceId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), compilationUnit.getPackageDeclaration().get().getNameAsString()); extendsDao.save(new Extends(interfaceId, extendedInterfaceId)); } } } }
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) { List<AnnotationExpr> annotations = classOrInterfaceDeclaration.getAnnotations(); for (AnnotationExpr annotation : annotations) { String annotationName = annotation.getNameAsString(); String annotationPackageName = annotation .findCompilationUnit() .flatMap(CompilationUnit::getPackageDeclaration) .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???"); if (typeDao.exist(annotationName, annotationPackageName)) { // JDK annotations are not indexed int annotationId = typeDao.getId(annotationName, annotationPackageName); int typeId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), compilationUnit.getPackageDeclaration().get().getNameAsString()); annotatedWithDao.save(new AnnotatedWith(typeId, annotationId)); } } } }
private void setAttributes(ClassBuilder builder, ClassOrInterfaceDeclaration n) { builder.withName(n.getNameAsString()); if (isClass(n)) { CanonicalNameFactory factory = new CanonicalNameFactory(packageName, imports); n.getExtendedTypes().stream().findFirst() .ifPresent(parent -> builder.withParent(new Parent(factory.build(parent.getNameAsString())))); } }
@Test public void fieldDeclarationResolve() 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()); FieldDeclaration declaration = classDeclaration.getFields().get(0); ResolvedFieldDeclaration resolvedDeclaration = declaration.resolve(); }
public SymbolReference<ResolvedConstructorDeclaration> solve(ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt, boolean solveLambdas) { List<ResolvedType> argumentTypes = new LinkedList<>(); List<LambdaArgumentTypePlaceholder> placeholders = new LinkedList<>(); solveArguments(explicitConstructorInvocationStmt, explicitConstructorInvocationStmt.getArguments(), solveLambdas, argumentTypes, placeholders); Optional<ClassOrInterfaceDeclaration> optAncestor = explicitConstructorInvocationStmt.getAncestorOfType(ClassOrInterfaceDeclaration.class); if (!optAncestor.isPresent()) { return SymbolReference.unsolved(ResolvedConstructorDeclaration.class); } ClassOrInterfaceDeclaration classNode = optAncestor.get(); ResolvedTypeDeclaration typeDecl = null; if (!explicitConstructorInvocationStmt.isThis()) { ResolvedType classDecl = JavaParserFacade.get(typeSolver).convert(classNode.getExtendedTypes(0), classNode); if (classDecl.isReferenceType()) { typeDecl = classDecl.asReferenceType().getTypeDeclaration(); } } else { SymbolReference<ResolvedTypeDeclaration> sr = JavaParserFactory.getContext(classNode, typeSolver).solveType(classNode.getNameAsString(), typeSolver); if (sr.isSolved()) { typeDecl = sr.getCorrespondingDeclaration(); } } if (typeDecl == null) { return SymbolReference.unsolved(ResolvedConstructorDeclaration.class); } SymbolReference<ResolvedConstructorDeclaration> res = ConstructorResolutionLogic.findMostApplicable(((ResolvedClassDeclaration) typeDecl).getConstructors(), argumentTypes, typeSolver); for (LambdaArgumentTypePlaceholder placeholder : placeholders) { placeholder.setMethod(res); } return res; }
@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(); }
public SymbolReference<ResolvedConstructorDeclaration> solve(ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt, boolean solveLambdas) { List<ResolvedType> argumentTypes = new LinkedList<>(); List<LambdaArgumentTypePlaceholder> placeholders = new LinkedList<>(); solveArguments(explicitConstructorInvocationStmt, explicitConstructorInvocationStmt.getArguments(), solveLambdas, argumentTypes, placeholders); Optional<ClassOrInterfaceDeclaration> optAncestor = explicitConstructorInvocationStmt.findAncestor(ClassOrInterfaceDeclaration.class); if (!optAncestor.isPresent()) { return SymbolReference.unsolved(ResolvedConstructorDeclaration.class); } ClassOrInterfaceDeclaration classNode = optAncestor.get(); ResolvedTypeDeclaration typeDecl = null; if (!explicitConstructorInvocationStmt.isThis()) { ResolvedType classDecl = JavaParserFacade.get(typeSolver).convert(classNode.getExtendedTypes(0), classNode); if (classDecl.isReferenceType()) { typeDecl = classDecl.asReferenceType().getTypeDeclaration(); } } else { SymbolReference<ResolvedTypeDeclaration> sr = JavaParserFactory.getContext(classNode, typeSolver).solveType(classNode.getNameAsString()); if (sr.isSolved()) { typeDecl = sr.getCorrespondingDeclaration(); } } if (typeDecl == null) { return SymbolReference.unsolved(ResolvedConstructorDeclaration.class); } SymbolReference<ResolvedConstructorDeclaration> res = ConstructorResolutionLogic.findMostApplicable(((ResolvedClassDeclaration) typeDecl).getConstructors(), argumentTypes, typeSolver); for (LambdaArgumentTypePlaceholder placeholder : placeholders) { placeholder.setMethod(res); } return res; }
@Test public void interfaceDeclarationResolve() throws IOException { File f = adaptPath(new File("src/test/resources/MethodTypeParams.java.txt")); CompilationUnit cu = parseWithSymbolResolution(f); ClassOrInterfaceDeclaration declaration = (ClassOrInterfaceDeclaration)cu.getType(1); assertEquals("VoidVisitor", declaration.getNameAsString()); assertEquals(true, declaration.isInterface()); declaration.resolve(); }
@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()); }