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();
}
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;
}
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();
}
Aggregations