/** * Searches all extended or implemented super classes or interfaces for * special classes that differ with the atomics version and replaces them * with the appropriate class. * * @param n */ private static void replaceParentClassesForAtomics(ClassOrInterfaceDeclaration n) { replaceParentClassesForAtomics(n.getExtendedTypes()); replaceParentClassesForAtomics(n.getImplementedTypes()); }
@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(); for (FieldDeclaration field : n.getFields()) { if (field.getModifiers().contains(Modifier.STATIC)) { for (MethodDeclaration method : n.getMethods()) { String methodName = method.getNameAsString(); if (!methodName.endsWith(methodNameSuffix)) { n.getMembers().add(0, declareLongFieldUpdater(className, variableName));
@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 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)); } } } }
@Test(expected = UnsolvedSymbolException.class) public void aClassInDefaultPackageCanBeAccessedFromOutsideTheDefaultPackageImportingIt() { String code = "package myPackage; import B; class A extends B {}"; MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver(); memoryTypeSolver.addDeclaration("B", new MyClassDeclaration("B")); ClassOrInterfaceType jpType = JavaParser.parse(code).getClassByName("A").get().getExtendedTypes(0); ResolvedType resolvedType = JavaParserFacade.get(memoryTypeSolver).convertToUsage(jpType); assertEquals("B", resolvedType.asReferenceType().getQualifiedName()); }
@Override public Optional<ResolvedType> solveGenericType(String name) { for (com.github.javaparser.ast.type.TypeParameter tp : wrappedNode.getTypeParameters()) { if (tp.getName().getId().equals(name)) { return Optional.of(new ResolvedTypeVariable(new JavaParserTypeParameter(tp, typeSolver))); } } return getParent().solveGenericType(name); }
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())); } } }
@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(); }
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 test_parseGenericClassNode(){ File resultJavaFile = Projects.getTestJavaFile(GenericResult.class); ParseUtils.compilationUnit(resultJavaFile).getChildNodesByType(MethodDeclaration.class).forEach(md->{ md.getType(); }); ParseUtils.compilationUnit(resultJavaFile).getClassByName("GenericResult") .ifPresent(classDeclaration -> { NodeList<TypeParameter> typeParameters = classDeclaration.getTypeParameters(); for(int i = 0, len = typeParameters.size(); i != len; i++){ System.out.println(typeParameters.get(i).getName()); } }); } }
@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; }
private static void writeClassDeclaration(PrintStream s, ClassOrInterfaceDeclaration c) { s.format("\npublic%s class %s", c.isFinal() ? " final" : "", c.getName()); if (c.getImplementedTypes() != null && !c.getImplementedTypes().isEmpty()) { s.format(" implements"); for (ClassOrInterfaceType iface : c.getImplementedTypes()) { s.append(" " + iface); } } s.append(" {\n"); Preconditions.checkArgument(c.getExtendedTypes().size() == 0); }
@Override public void visit(ClassOrInterfaceDeclaration n, Object arg) { super.visit(n, arg); final EnumSet<Modifier> modifiers = n.getModifiers(); if (!modifiers.contains(Modifier.PRIVATE)) { final List<BodyDeclaration<?>> members = n.getMembers(); final SimpleName simpleName = n.getName(); final String clazz = simpleName.getId(); if (body instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration) body; this.getParameterNames(methodDeclaration, n.isInterface()); i++; } else if (body instanceof ConstructorDeclaration) { final ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) body; String name = classOrInterfaceDeclaration.getName().getIdentifier(); String key = this.pkg + '.' + name; name = this.originClassName + '.' + name;
if (n.getJavaDoc() != null) { n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); List<AnnotationExpr> annotations = n.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.size(); i++) { List<TypeParameter> typeParameters = n.getTypeParameters(); if (typeParameters != null) { for (int i = 0; i < typeParameters.size(); i++) { List<ClassOrInterfaceType> extendz = n.getExtends(); if (extendz != null) { for (int i = 0; i < extendz.size(); i++) { List<ClassOrInterfaceType> implementz = n.getImplements(); if (implementz != null) { for (int i = 0; i < implementz.size(); i++) { List<BodyDeclaration> members = n.getMembers(); if (members != null) { for (int i = 0; i < members.size(); i++) {
@Override public boolean isInterface() { return wrappedNode.isInterface(); }
@Override public Set<ResolvedMethodDeclaration> getDeclaredMethods() { Set<ResolvedMethodDeclaration> methods = new HashSet<>(); for (BodyDeclaration<?> member : wrappedNode.getMembers()) { if (member instanceof com.github.javaparser.ast.body.MethodDeclaration) { methods.add(new JavaParserMethodDeclaration((com.github.javaparser.ast.body.MethodDeclaration) member, typeSolver)); } } return methods; }
classInfo.isInterface = cid.isInterface(); List extendsList = cid.getExtends(); classInfo.superclassName = extendsList == null || extendsList.isEmpty() ? null : getClassName(packageName, extendsList.get(0).toString(), imports); List<ClassOrInterfaceType> implementList = cid.getImplements();
if (classDec.getModifiers() == ModifierSet.PUBLIC) { if (classDec.isInterface()) { signature[2] = "Interface"; //interface } else { signature[3] = classDec.getName().substring(0, 1).toLowerCase() + classDec.getName().substring(1);