Java Code Examples for com.github.javaparser.ast.body.ClassOrInterfaceDeclaration#getNameAsString()

The following examples show how to use com.github.javaparser.ast.body.ClassOrInterfaceDeclaration#getNameAsString() . 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: FinalRClassBuilder.java    From Briefness with Apache License 2.0 6 votes vote down vote up
private static void addResourceType(List<String> supportedTypes, TypeSpec.Builder result,
                                    ClassOrInterfaceDeclaration node, boolean useLegacyTypes) {
  if (!supportedTypes.contains(node.getNameAsString())) {
    return;
  }

  String type = node.getNameAsString();
  TypeSpec.Builder resourceType = TypeSpec.classBuilder(type)
      .addModifiers(PUBLIC, STATIC, FINAL);

  for (BodyDeclaration field : node.getMembers()) {
    if (field instanceof FieldDeclaration) {
      FieldDeclaration declaration = (FieldDeclaration) field;
      // Check that the field is an Int because styleable also contains Int arrays which can't be
      // used in annotations.
      if (isInt(declaration)) {
        addResourceField(resourceType, declaration.getVariables().get(0),
                getSupportAnnotationClass(type, useLegacyTypes));
      }
    }
  }

  result.addType(resourceType.build());
}
 
Example 2
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 3
Source File: RemoveMethodParameter.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * Check if post refactoring signature already exists in given class or
 * interface
 * 
 * @param currentClassOrInterface
 * @param postRefactoringSignature
 * @throws BotRefactoringException
 */
private void validatePostRefactoringSignatureNotAlreadyExists(ClassOrInterfaceDeclaration currentClassOrInterface,
		String postRefactoringSignature) throws BotRefactoringException {
	if (RefactoringHelper.isLocalMethodSignatureInClassOrInterface(currentClassOrInterface,
			postRefactoringSignature)) {
		throw new BotRefactoringException(
				"Removal of parameter would result in a method signature that is already present inside the class or interface '"
						+ currentClassOrInterface.getNameAsString() + "'.");
	}
}
 
Example 4
Source File: RenameMethod.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * Check if post refactoring signature already exists in given class or
 * interface
 * 
 * @param currentClassOrInterface
 * @param postRefactoringSignature
 * @throws BotRefactoringException
 */
private void validatePostRefactoringSignatureNotAlreadyExists(ClassOrInterfaceDeclaration classOrInterface,
		String postRefactoringSignature) throws BotRefactoringException {
	if (RefactoringHelper.isLocalMethodSignatureInClassOrInterface(classOrInterface, postRefactoringSignature)) {
		throw new BotRefactoringException(
				"Renaming of method would result in a method signature that is already present inside the class or interface '"
						+ classOrInterface.getNameAsString() + "'.");
	}
}
 
Example 5
Source File: DefaultTest.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
    if (n.getNameAsString().equals("ExampleUnitTest") || n.getNameAsString().equals("ExampleInstrumentedTest")) {
        testClass = new TestClass(n.getNameAsString());
        testClass.setHasSmell(true);
        smellyElementList.add(testClass);
    }
    super.visit(n, arg);
}
 
Example 6
Source File: LazyTest.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
    if (Objects.equals(fileType, PRODUCTION_FILE)) {
        productionClassName = n.getNameAsString();
    }
    super.visit(n, arg);
}
 
Example 7
Source File: EagerTest.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
    if (Objects.equals(fileType, PRODUCTION_FILE)) {
        productionClassName = n.getNameAsString();
    }
    super.visit(n, arg);
}
 
Example 8
Source File: IgnoredTest.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method will check if the class has the @Ignore annotation
 */
@Override
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
    if (n.getAnnotationByName("Ignore").isPresent()) {
        testClass = new TestClass(n.getNameAsString());
        testClass.setHasSmell(true);
        smellyElementList.add(testClass);
    }
    super.visit(n, arg);
}
 
Example 9
Source File: OpenApiObjectGenerator.java    From flow with Apache License 2.0 5 votes vote down vote up
private void addTagsInformation() {
    for (Map.Entry<ClassOrInterfaceDeclaration, String> endpointJavadoc : endpointsJavadoc
            .entrySet()) {
        Tag tag = new Tag();
        ClassOrInterfaceDeclaration endpointDeclaration = endpointJavadoc
                .getKey();
        String simpleClassName = endpointDeclaration.getNameAsString();
        tag.name(simpleClassName);
        tag.description(endpointJavadoc.getValue());
        tag.addExtension(EXTENSION_VAADIN_FILE_PATH,
                qualifiedNameToPath.get(endpointDeclaration
                        .getFullyQualifiedName().orElse(simpleClassName)));
        openApiModel.addTagsItem(tag);
    }
}
 
Example 10
Source File: ConfigurableEagerTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
    if (Objects.equals(fileType, PRODUCTION_FILE)) {
        productionClassName = n.getNameAsString();
    }
    super.visit(n, arg);
}
 
Example 11
Source File: JavaDocParserVisitor.java    From jaxrs-analyzer with Apache License 2.0 4 votes vote down vote up
private String calculateClassName(ClassOrInterfaceDeclaration classOrInterface) {
    if (StringUtils.isBlank(packageName))
        return classOrInterface.getNameAsString();
    return packageName.replace('.', '/') + "/" + classOrInterface.getNameAsString();
}