Search in sources :

Example 1 with PackageDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor in project jqa-java-plugin by buschmais.

the class TypeSourceHelper method getSourceLocation.

static Optional<FileLocation> getSourceLocation(TypeDescriptor typeDescriptor, Optional<Integer> startLine, Optional<Integer> endLine) {
    if (typeDescriptor instanceof ClassFileDescriptor) {
        ClassFileDescriptor classFileDescriptor = (ClassFileDescriptor) typeDescriptor;
        for (FileDescriptor parent : classFileDescriptor.getParents()) {
            if (parent instanceof PackageDescriptor) {
                // File location can only safely built if a parent package exists.
                PackageDescriptor packageDescriptor = (PackageDescriptor) parent;
                FileLocation.FileLocationBuilder fileLocationBuilder = FileLocation.builder();
                fileLocationBuilder.parent(FileSourceHelper.getParentLocation(classFileDescriptor));
                fileLocationBuilder.fileName(packageDescriptor.getFileName() + "/" + classFileDescriptor.getSourceFileName());
                fileLocationBuilder.startLine(startLine);
                fileLocationBuilder.endLine(endLine);
                return of(fileLocationBuilder.build());
            }
        }
    }
    return empty();
}
Also used : FileLocation(com.buschmais.jqassistant.core.report.api.model.source.FileLocation) PackageDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)

Example 2 with PackageDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor in project jqa-java-plugin by buschmais.

the class PackageDirectoryScannerPlugin method scan.

@Override
public PackageDescriptor scan(DirectoryResource item, String path, Scope scope, Scanner scanner) throws IOException {
    ScannerContext context = scanner.getContext();
    DirectoryDescriptor directoryDescriptor = context.getCurrentDescriptor();
    PackageDescriptor descriptor = context.getStore().addDescriptorType(directoryDescriptor, PackageDescriptor.class);
    String packageName = path.substring(1).replaceAll("/", ".");
    String name;
    int separatorIndex = packageName.lastIndexOf('.');
    if (separatorIndex != -1) {
        name = packageName.substring(separatorIndex + 1);
    } else {
        name = packageName;
    }
    descriptor.setName(name);
    descriptor.setFullQualifiedName(packageName);
    return descriptor;
}
Also used : DirectoryDescriptor(com.buschmais.jqassistant.plugin.common.api.model.DirectoryDescriptor) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) PackageDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)

Example 3 with PackageDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor in project jqa-java-plugin by buschmais.

the class DependencyIT method packageCycles.

/**
 * Verifies the constraint "dependency:PackageCycles".
 *
 * @throws IOException
 *             If the test fails.
 */
@Test
void packageCycles() throws Exception {
    scanClassPathDirectory(getClassesDirectory(A.class));
    assertThat(validateConstraint("dependency:PackageCycles").getStatus(), equalTo(FAILURE));
    store.beginTransaction();
    Map<String, Result<Constraint>> constraintViolations = reportPlugin.getConstraintResults();
    Matcher<Iterable<? super Result<Constraint>>> matcher = hasItem(result(constraint("dependency:PackageCycles")));
    assertThat(constraintViolations.values(), matcher);
    Result<Constraint> result = constraintViolations.get("dependency:PackageCycles");
    List<Map<String, Object>> rows = result.getRows();
    assertThat(rows.size(), equalTo(2));
    for (Map<String, Object> row : rows) {
        PackageDescriptor p = (PackageDescriptor) row.get("Package");
        assertThat(p.getFullQualifiedName(), anyOf(equalTo(A.class.getPackage().getName()), equalTo(B.class.getPackage().getName())));
    }
    store.commitTransaction();
}
Also used : A(com.buschmais.jqassistant.plugin.java.test.set.rules.dependency.packages.a.A) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) PackageDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor) Result(com.buschmais.jqassistant.core.report.api.model.Result) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

PackageDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)3 Result (com.buschmais.jqassistant.core.report.api.model.Result)1 FileLocation (com.buschmais.jqassistant.core.report.api.model.source.FileLocation)1 Constraint (com.buschmais.jqassistant.core.rule.api.model.Constraint)1 ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)1 DirectoryDescriptor (com.buschmais.jqassistant.plugin.common.api.model.DirectoryDescriptor)1 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)1 ClassFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor)1 A (com.buschmais.jqassistant.plugin.java.test.set.rules.dependency.packages.a.A)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1