com.github.javaparser.ast.type.TypeParameter Java Examples

The following examples show how to use com.github.javaparser.ast.type.TypeParameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParseUtilsTest.java    From JApiDocs with Apache License 2.0 7 votes vote down vote up
@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());
                }
            });
}
 
Example #2
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void visit(final TypeParameter n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    for (AnnotationExpr ann : n.getAnnotations()) {
        ann.accept(this, arg);
        printer.print(" ");
    }
    n.getName().accept(this, arg);
    if (!isNullOrEmpty(n.getTypeBound())) {
        printer.print(" extends ");
        for (final Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext(); ) {
            final ClassOrInterfaceType c = i.next();
            c.accept(this, arg);
            if (i.hasNext()) {
                printer.print(" & ");
            }
        }
    }
}
 
Example #3
Source File: RuleUnitGenerator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void classDeclaration(ClassOrInterfaceDeclaration cls) {
    cls.setName(targetTypeName)
            .setModifiers(Modifier.Keyword.PUBLIC)
            .getExtendedTypes().get(0).setTypeArguments(nodeList(new ClassOrInterfaceType(null, typeName)));

    if (annotator != null) {
        annotator.withSingletonComponent(cls);
        cls.findFirst(ConstructorDeclaration.class, c -> !c.getParameters().isEmpty()) // non-empty constructor
                .ifPresent(annotator::withInjection);
    }

    String ruleUnitInstanceFQCN = RuleUnitInstanceGenerator.qualifiedName(packageName, typeName);
    cls.findAll(ConstructorDeclaration.class).forEach(this::setClassName);
    cls.findAll(ObjectCreationExpr.class, o -> o.getType().getNameAsString().equals("$InstanceName$"))
            .forEach(o -> o.setType(ruleUnitInstanceFQCN));
    cls.findAll(ObjectCreationExpr.class, o -> o.getType().getNameAsString().equals("$Application$"))
            .forEach(o -> o.setType(applicationPackageName + ".Application"));
    cls.findAll(ObjectCreationExpr.class, o -> o.getType().getNameAsString().equals("$RuleModelName$"))
            .forEach(o -> o.setType(packageName + "." + generatedSourceFile + "_" + typeName));
    cls.findAll(MethodDeclaration.class, m -> m.getType().asString().equals("$InstanceName$"))
            .stream()
            .map(m -> m.setType(ruleUnitInstanceFQCN))
            .flatMap(m -> m.getParameters().stream())
            .filter(p -> p.getType().asString().equals("$ModelName$"))
            .forEach(o -> o.setType(typeName));
    cls.findAll( MethodCallExpr.class).stream()
            .flatMap( mCall -> mCall.getArguments().stream() )
            .filter( e -> e.isNameExpr() && e.toNameExpr().get().getNameAsString().equals( "$ModelClass$" ) )
            .forEach( e -> e.toNameExpr().get().setName( typeName + ".class" ) );
    cls.findAll(TypeParameter.class)
            .forEach(tp -> tp.setName(typeName));
}
 
Example #4
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
private void printTypeParameters(final NodeList<TypeParameter> args, final Void arg) {
    if (!isNullOrEmpty(args)) {
        printer.print("<");
        for (final Iterator<TypeParameter> i = args.iterator(); i.hasNext(); ) {
            final TypeParameter t = i.next();
            t.accept(this, arg);
            if (i.hasNext()) {
                printer.print(", ");
            }
        }
        printer.print(">");
    }
}
 
Example #5
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncTypeParameters(List<TypeParameter> typeParameters, Map<String, ImportDeclaration> imports) {
    for (TypeParameter typeParameter : typeParameters) {
        String value = typeParameter.toString();
        javaClass.addRuntimeTypeParameter(value);
        syncImportSnippet(value, imports);
    }
}
 
Example #6
Source File: GroovydocJavaVisitor.java    From groovy with Apache License 2.0 4 votes vote down vote up
private String genericTypesAsString(NodeList<TypeParameter> typeParameters) {
    if (typeParameters == null || typeParameters.size() == 0)
        return "";
    return "<" + DefaultGroovyMethods.join(typeParameters, ", ") + ">";
}
 
Example #7
Source File: TraceVisitor.java    From JCTools with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(TypeParameter n, Void arg) {
    out.println("TypeParameter: " + (extended ? n : ""));
    super.visit(n, arg);
}