com.github.javaparser.ast.nodeTypes.NodeWithName Java Examples

The following examples show how to use com.github.javaparser.ast.nodeTypes.NodeWithName. 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: ProcessToExecModelGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public MethodDeclaration generateMethod(WorkflowProcess process) {

        CompilationUnit clazz = parse(this.getClass().getResourceAsStream("/class-templates/ProcessTemplate.java"));
        clazz.setPackageDeclaration(process.getPackageName());

        String extractedProcessId = extractProcessId(process.getId());

        String packageName = clazz.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null);
        ProcessMetaData metadata = new ProcessMetaData(process.getId(),
                extractedProcessId,
                process.getName(),
                process.getVersion(),
                packageName,
                "process");

        MethodDeclaration processMethod = new MethodDeclaration();
        processVisitor.visitProcess(process, processMethod, metadata);

        return processMethod;
    }
 
Example #2
Source File: PackageInfoReader.java    From jig with Apache License 2.0 6 votes vote down vote up
Optional<PackageAlias> read(PackageInfoSource packageInfoSource) {
    CompilationUnit cu = StaticJavaParser.parse(packageInfoSource.toInputStream());

    Optional<PackageIdentifier> optPackageIdentifier = cu.getPackageDeclaration()
            .map(NodeWithName::getNameAsString)
            .map(PackageIdentifier::new);

    Optional<Alias> optAlias = getJavadoc(cu)
            .map(Javadoc::getDescription)
            .map(JavadocDescription::toText)
            .map(JavadocAliasSource::new)
            .map(JavadocAliasSource::toAlias);

    return optPackageIdentifier.flatMap(packageIdentifier -> optAlias.map(alias ->
            new PackageAlias(packageIdentifier, alias)));
}
 
Example #3
Source File: ProcessToExecModelGenerator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public ProcessMetaData generate(WorkflowProcess process) {
    CompilationUnit parsedClazzFile = parse(this.getClass().getResourceAsStream(PROCESS_TEMPLATE_FILE));
    parsedClazzFile.setPackageDeclaration(process.getPackageName());
    Optional<ClassOrInterfaceDeclaration> processClazzOptional = parsedClazzFile.findFirst(ClassOrInterfaceDeclaration.class, sl -> true);

    String extractedProcessId = extractProcessId(process.getId());

    if (!processClazzOptional.isPresent()) {
        throw new NoSuchElementException("Cannot find class declaration in the template");
    }
    ClassOrInterfaceDeclaration processClazz = processClazzOptional.get();
    processClazz.setName(StringUtils.capitalize(extractedProcessId + PROCESS_CLASS_SUFFIX));
    String packageName = parsedClazzFile.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null);
    ProcessMetaData metadata = new ProcessMetaData(process.getId(),
            extractedProcessId,
            process.getName(),
            process.getVersion(),
            packageName,
            processClazz.getNameAsString());

    Optional<MethodDeclaration> processMethod = parsedClazzFile.findFirst(MethodDeclaration.class, sl -> sl.getName().asString().equals("process"));

    processVisitor.visitProcess(process, processMethod.get(), metadata);

    metadata.setGeneratedClassModel(parsedClazzFile);
    return metadata;
}
 
Example #4
Source File: SourceCode.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * @return Class package in standard format <i>(Not internal, using ".")</i>
 */
public String getPackage() {
	if (packageName != null)
		return packageName;
	// fetch package
	return packageName = unit.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(DEFAULT_PACKAGE);
}
 
Example #5
Source File: CompilationUnitIndexer.java    From jql with MIT License 5 votes vote down vote up
public void index(com.github.javaparser.ast.CompilationUnit compilationUnit, String fileName) {
    String packageName = compilationUnit.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse("");
    io.github.benas.jql.model.CompilationUnit cu = new io.github.benas.jql.model.CompilationUnit(fileName, packageName);
    int cuId =  compilationUnitDao.save(cu);
    List<TypeDeclaration<?>> types = compilationUnit.getTypes();
    for (TypeDeclaration<?> type : types) {
        typeIndexer.index(type, cuId);
    }
}