use of com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor in project jqa-java-plugin by buschmais.
the class TypeResolverIT method duplicateTypeInSameArtifact.
/**
* @throws IOException
* If the test fails.
*/
@Test
public void duplicateTypeInSameArtifact() throws IOException {
File directory = getClassesDirectory(A.class);
final String resource = "/" + A.class.getName().replace(".", "/") + ".class";
final File file = new File(directory, resource);
scanClasses(B.class);
List<? extends FileDescriptor> descriptors = execute("a1", new ScanClassPathOperation() {
@Override
public List<FileDescriptor> scan(JavaArtifactFileDescriptor artifact, Scanner scanner) {
List<FileDescriptor> result = new ArrayList<>();
FileDescriptor fileDescriptor1 = scanner.scan(file, "/1.0" + resource, JavaScope.CLASSPATH);
FileDescriptor fileDescriptor2 = scanner.scan(file, resource, JavaScope.CLASSPATH);
result.add(fileDescriptor1);
result.add(fileDescriptor2);
return result;
}
});
store.beginTransaction();
assertThat(descriptors.size(), equalTo(2));
FileDescriptor fileDescriptor1 = descriptors.get(0);
assertThat(fileDescriptor1.getFileName(), equalTo("/1.0" + resource));
assertThat(fileDescriptor1, instanceOf(TypeDescriptor.class));
assertThat(((TypeDescriptor) fileDescriptor1).getFullQualifiedName(), equalTo(A.class.getName()));
FileDescriptor fileDescriptor2 = descriptors.get(1);
assertThat(fileDescriptor2.getFileName(), equalTo(resource));
assertThat(fileDescriptor2, instanceOf(TypeDescriptor.class));
assertThat(((TypeDescriptor) fileDescriptor2).getFullQualifiedName(), equalTo(A.class.getName()));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor in project jqa-java-plugin by buschmais.
the class AbstractMemberDescriptorMatcher method describeMismatchSafely.
@Override
protected void describeMismatchSafely(T item, Description mismatchDescription) {
mismatchDescription.appendText(item.getClass().getSimpleName());
TypeDescriptor declaringType = item.getDeclaringType();
if (declaringType != null) {
mismatchDescription.appendText("(").appendText(declaringType.getFullQualifiedName());
}
mismatchDescription.appendText("#").appendText(item.getSignature()).appendText(")");
}
use of com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor in project jqa-java-plugin by buschmais.
the class AnonymousInnerClassIT method assertOuterClassContainsInnerClass.
/**
* Asserts that the outer class can be fetched and contains a relation to
* the inner class.
*/
private void assertOuterClassContainsInnerClass() throws NoSuchMethodException {
store.beginTransaction();
TestResult testResult = query("MATCH (outerClass:Type)-[:DECLARES]->(innerClass:Type)<-[:DECLARES]-(method:Method)<-[:DECLARES]-(outerClass) RETURN outerClass, innerClass, method");
assertThat(testResult.getRows().size(), equalTo(1));
Map<String, Object> row = testResult.getRows().get(0);
TypeDescriptor outerClass = (TypeDescriptor) row.get("outerClass");
assertThat(outerClass, typeDescriptor(AnonymousInnerClass.class));
TypeDescriptor innerClass = (TypeDescriptor) row.get("innerClass");
assertThat(innerClass, typeDescriptor(INNERCLASS_NAME));
MethodDescriptor method = (MethodDescriptor) row.get("method");
assertThat(method, methodDescriptor(AnonymousInnerClass.class, "iterator"));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor in project jqa-java-plugin by buschmais.
the class ServiceLoaderIT method verifyServiceLoaderDescriptor.
/**
* Verifies the expected service loader descriptor and its content.
*/
private void verifyServiceLoaderDescriptor() {
store.beginTransaction();
List<ServiceLoaderDescriptor> serviceLoaderDescriptors = query("MATCH (sd:ServiceLoader:File) RETURN sd").getColumn("sd");
assertThat(serviceLoaderDescriptors.size(), equalTo(1));
ServiceLoaderDescriptor serviceLoaderDescriptor = serviceLoaderDescriptors.get(0);
assertThat(serviceLoaderDescriptor.getFileName(), endsWith("/META-INF/services/" + Service.class.getName()));
assertThat(serviceLoaderDescriptor.getType(), typeDescriptor(Service.class));
List<TypeDescriptor> serviceTypes = serviceLoaderDescriptor.getContains();
assertThat(serviceTypes.size(), equalTo(2));
assertThat(serviceTypes, hasItem(typeDescriptor(ServiceImpl.class)));
assertThat(serviceTypes, hasItem(typeDescriptor(OuterClass.InnerClassServiceImpl.class)));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor in project jqa-java-plugin by buschmais.
the class ServiceLoaderFileScannerPlugin method scan.
@Override
public ServiceLoaderDescriptor scan(FileResource item, String path, Scope scope, Scanner scanner) throws IOException {
Matcher matcher = PATTERN.matcher(path);
if (!matcher.matches()) {
throw new IOException("Cannot match path name: " + path);
}
String serviceInterface = matcher.group(2);
ScannerContext context = scanner.getContext();
FileDescriptor fileDescriptor = context.getCurrentDescriptor();
ServiceLoaderDescriptor serviceLoaderDescriptor = context.getStore().addDescriptorType(fileDescriptor, ServiceLoaderDescriptor.class);
TypeDescriptor interfaceTypeDescriptor = getTypeDescriptor(serviceInterface, context);
serviceLoaderDescriptor.setType(interfaceTypeDescriptor);
try (InputStream stream = item.createStream()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String serviceImplementation;
while ((serviceImplementation = reader.readLine()) != null) {
if (!isEmptyOrComment(serviceImplementation)) {
TypeDescriptor implementationTypeDescriptor = getTypeDescriptor(serviceImplementation, context);
serviceLoaderDescriptor.getContains().add(implementationTypeDescriptor);
}
}
}
return serviceLoaderDescriptor;
}
Aggregations