Search in sources :

Example 1 with TypeDescriptor

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();
}
Also used : A(com.buschmais.jqassistant.plugin.java.test.set.scanner.resolver.A) Scanner(com.buschmais.jqassistant.core.scanner.api.Scanner) TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) File(java.io.File) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) ArtifactFileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.ArtifactFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor) Test(org.junit.Test)

Example 2 with TypeDescriptor

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(")");
}
Also used : TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor)

Example 3 with TypeDescriptor

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();
}
Also used : TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor) AnonymousInnerClass(com.buschmais.jqassistant.plugin.java.test.set.scanner.innerclass.AnonymousInnerClass) MethodDescriptor(com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor)

Example 4 with TypeDescriptor

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();
}
Also used : TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor) OuterClass(com.buschmais.jqassistant.plugin.java.test.set.scanner.serviceloader.OuterClass) Service(com.buschmais.jqassistant.plugin.java.test.set.scanner.serviceloader.Service) ServiceLoaderDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor)

Example 5 with TypeDescriptor

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;
}
Also used : TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ServiceLoaderDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)

Aggregations

TypeDescriptor (com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor)8 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)3 JavaArtifactFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)2 ServiceLoaderDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor)2 Scanner (com.buschmais.jqassistant.core.scanner.api.Scanner)1 ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)1 ArtifactFileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.ArtifactFileDescriptor)1 ClassFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor)1 MethodDescriptor (com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor)1 ParameterDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ParameterDescriptor)1 AnonymousInnerClass (com.buschmais.jqassistant.plugin.java.test.set.scanner.innerclass.AnonymousInnerClass)1 A (com.buschmais.jqassistant.plugin.java.test.set.scanner.resolver.A)1 OuterClass (com.buschmais.jqassistant.plugin.java.test.set.scanner.serviceloader.OuterClass)1 Service (com.buschmais.jqassistant.plugin.java.test.set.scanner.serviceloader.Service)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1