use of com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor in project jqa-java-plugin by buschmais.
the class InvalidClassFileIT method validClass.
@Test
public void validClass() throws IOException {
scanClasses(InvalidClassFileIT.class);
store.beginTransaction();
List<FileDescriptor> fileDescriptors = query("MATCH (c:Class:File) RETURN c").getColumn("c");
assertThat(fileDescriptors.size(), equalTo(1));
FileDescriptor fileDescriptor = fileDescriptors.get(0);
assertThat(fileDescriptor, instanceOf(ClassFileDescriptor.class));
ClassFileDescriptor classFileDescriptor = (ClassFileDescriptor) fileDescriptor;
assertThat(classFileDescriptor.isValid(), equalTo(true));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor in project jqa-java-plugin by buschmais.
the class ClassFileScannerPlugin method scan.
@Override
public ClassFileDescriptor scan(FileResource file, String path, Scope scope, final Scanner scanner) throws IOException {
final FileDescriptor fileDescriptor = scanner.getContext().getCurrentDescriptor();
VisitorHelper visitorHelper = new VisitorHelper(scanner.getContext(), classModelConfiguration);
final ClassVisitor visitor = new ClassVisitor(fileDescriptor, visitorHelper);
ClassFileDescriptor classFileDescriptor;
try (InputStream stream = file.createStream()) {
classFileDescriptor = MD5DigestDelegate.getInstance().digest(stream, new MD5DigestDelegate.DigestOperation<ClassFileDescriptor>() {
@Override
public ClassFileDescriptor execute(InputStream inputStream) throws IOException {
new ClassReader(inputStream).accept(visitor, 0);
return visitor.getTypeDescriptor();
}
});
classFileDescriptor.setValid(true);
} catch (RuntimeException e) {
LOGGER.warn("Cannot scan class '" + path + "'.", e);
classFileDescriptor = visitor.getTypeDescriptor();
if (classFileDescriptor == null) {
classFileDescriptor = scanner.getContext().getStore().addDescriptorType(fileDescriptor, ClassFileDescriptor.class);
}
classFileDescriptor.setValid(false);
}
return classFileDescriptor;
}
use of com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor in project jqa-java-plugin by buschmais.
the class ByteCodeVersionIT method byteCodeVersion.
@Test
public void byteCodeVersion() throws IOException {
scanClasses(Pojo.class);
store.beginTransaction();
List<ClassFileDescriptor> types = query("MATCH (t:Type) WHERE t.name='Pojo' RETURN t").getColumn("t");
assertThat(types.size(), equalTo(1));
ClassFileDescriptor pojo = types.get(0);
// Java 8
assertThat(pojo.getByteCodeVersion(), equalTo(52));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor in project jqa-java-plugin by buschmais.
the class InvalidClassFileIT method classFileWithHeaderOnly.
@Test
public void classFileWithHeaderOnly() throws IOException {
final String path = "/com.buschmais.Test.class";
final FileResource fileResource = new AbstractFileResource() {
@Override
public InputStream createStream() throws IOException {
return new ByteArrayInputStream(ClassFileScannerPlugin.CAFEBABE);
}
};
List<? extends FileDescriptor> fileDescriptors = execute(ARTIFACT_ID, new ScanClassPathOperation() {
@Override
public List<FileDescriptor> scan(JavaArtifactFileDescriptor artifact, Scanner scanner) {
FileDescriptor fileDescriptor = scanner.scan(fileResource, path, JavaScope.CLASSPATH);
return Collections.singletonList(fileDescriptor);
}
});
store.beginTransaction();
assertThat(fileDescriptors.size(), equalTo(1));
FileDescriptor fileDescriptor = fileDescriptors.get(0);
assertThat(fileDescriptor, instanceOf(ClassFileDescriptor.class));
ClassFileDescriptor classFileDescriptor = (ClassFileDescriptor) fileDescriptor;
assertThat(classFileDescriptor.getFileName(), equalTo(path));
assertThat(classFileDescriptor.isValid(), equalTo(false));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor in project jqa-java-plugin by buschmais.
the class PojoIT method attributes.
@Test
public void attributes() throws IOException {
scanClasses(Pojo.class);
store.beginTransaction();
TestResult testResult = query("MATCH (t:Type:Class) WHERE t.fqn =~ '.*Pojo' RETURN t as types");
assertThat(testResult.getRows().size(), equalTo(1));
ClassFileDescriptor typeDescriptor = (ClassFileDescriptor) testResult.getRows().get(0).get("types");
assertThat(typeDescriptor, is(typeDescriptor(Pojo.class)));
assertThat(typeDescriptor.getFileName(), equalTo("/" + Pojo.class.getName().replace('.', '/') + ".class"));
assertThat(typeDescriptor.getSourceFileName(), equalTo(Pojo.class.getSimpleName() + ".java"));
assertThat(query("MATCH (t:Type:Class) WHERE t.fqn =~ '.*Pojo' RETURN t.name as name").getColumn("name"), hasItem(equalTo("Pojo")));
testResult = query("MATCH (t:Type:Class)-[:DECLARES]->(f:Field) RETURN f.signature as signature, f.name as name");
assertThat(testResult.getColumn("signature"), allOf(hasItem(equalTo("java.lang.String stringValue")), hasItem(equalTo("int intValue"))));
assertThat(testResult.getColumn("name"), allOf(hasItem(equalTo("stringValue")), hasItem(equalTo("intValue"))));
testResult = query("MATCH (t:Type:Class)-[:DECLARES]->(m:Method) RETURN m.signature as signature, m.name as name");
assertThat(testResult.getColumn("signature"), allOf(hasItem(equalTo("java.lang.String getStringValue()")), hasItem(equalTo("void setStringValue(java.lang.String)")), hasItem(equalTo("int getIntValue()")), hasItem(equalTo("void setIntValue(int)"))));
assertThat(testResult.getColumn("name"), allOf(hasItem(equalTo("getStringValue")), hasItem(equalTo("setStringValue")), hasItem(equalTo("getIntValue")), hasItem(equalTo("setIntValue"))));
store.commitTransaction();
}
Aggregations