use of com.tngtech.archunit.core.domain.JavaClassDescriptor in project ArchUnit by TNG.
the class JavaClassProcessor method visit.
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
LOG.debug("Processing class '{}'", name);
JavaClassDescriptor descriptor = JavaClassDescriptorImporter.createFromAsmObjectTypeName(name);
if (alreadyImported(descriptor)) {
return;
}
List<String> interfaceNames = createInterfaceNames(interfaces);
LOG.trace("Found interfaces {} on class '{}'", interfaceNames, name);
boolean opCodeForInterfaceIsPresent = (access & Opcodes.ACC_INTERFACE) != 0;
boolean opCodeForEnumIsPresent = (access & Opcodes.ACC_ENUM) != 0;
boolean opCodeForAnnotationIsPresent = (access & Opcodes.ACC_ANNOTATION) != 0;
Optional<String> superclassName = getSuperclassName(superName, opCodeForInterfaceIsPresent);
LOG.trace("Found superclass {} on class '{}'", superclassName.orElse(null), name);
javaClassBuilder = new DomainBuilders.JavaClassBuilder().withSourceDescriptor(sourceDescriptor).withDescriptor(descriptor).withInterface(opCodeForInterfaceIsPresent).withEnum(opCodeForEnumIsPresent).withAnnotation(opCodeForAnnotationIsPresent).withModifiers(JavaModifier.getModifiersForClass(access));
className = descriptor.getFullyQualifiedClassName();
declarationHandler.onNewClass(className, superclassName, interfaceNames);
JavaClassSignatureImporter.parseAsmTypeSignature(signature, declarationHandler);
}
use of com.tngtech.archunit.core.domain.JavaClassDescriptor in project ArchUnit by TNG.
the class JavaClassProcessor method visitField.
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
if (importAborted()) {
return super.visitField(access, name, desc, signature, value);
}
JavaClassDescriptor rawType = JavaClassDescriptorImporter.importAsmTypeFromDescriptor(desc);
Optional<JavaTypeCreationProcess<JavaField>> genericType = JavaFieldTypeSignatureImporter.parseAsmFieldTypeSignature(signature, declarationHandler);
DomainBuilders.JavaFieldBuilder fieldBuilder = new DomainBuilders.JavaFieldBuilder().withName(name).withType(genericType, rawType).withModifiers(JavaModifier.getModifiersForField(access)).withDescriptor(desc);
declarationHandler.onDeclaredField(fieldBuilder, rawType.getFullyQualifiedClassName());
return new FieldProcessor(fieldBuilder, declarationHandler);
}
use of com.tngtech.archunit.core.domain.JavaClassDescriptor in project ArchUnit by TNG.
the class SignatureTypeArgumentProcessor method visitClassType.
@Override
public void visitClassType(String internalObjectName) {
JavaClassDescriptor type = JavaClassDescriptorImporter.createFromAsmObjectTypeName(internalObjectName);
log.trace("Encountered {} for {}: Class type {}", typeArgumentType.description, parameterizedType.getTypeName(), type.getFullyQualifiedClassName());
currentTypeArgument = new JavaParameterizedTypeBuilder<>(type);
typeArgumentType.addTypeArgumentToBuilder(parameterizedType, new NewJavaTypeCreationProcess<>(this.currentTypeArgument, typeFinisher));
declarationHandler.onDeclaredGenericSignatureType(type.getFullyQualifiedClassName());
}
use of com.tngtech.archunit.core.domain.JavaClassDescriptor in project ArchUnit by TNG.
the class JavaClassDescriptorImporterTest method asm_Type.
@Test
public void asm_Type() throws NoSuchMethodException {
Type toStringType = Type.getReturnType(Object.class.getDeclaredMethod("toString"));
JavaClassDescriptor toStringDescriptor = JavaClassDescriptorImporter.importAsmType(toStringType);
assertThat(toStringDescriptor.getFullyQualifiedClassName()).isEqualTo(String.class.getName());
assertThat(toStringDescriptor.resolveClass()).isEqualTo(String.class);
}
use of com.tngtech.archunit.core.domain.JavaClassDescriptor in project ArchUnit by TNG.
the class ImportedClasses method ensureAllComponentTypesPresent.
private void ensureAllComponentTypesPresent(JavaClass javaClass) {
JavaClassDescriptor current = JavaClassDescriptor.From.javaClass(javaClass);
while (current.tryGetComponentType().isPresent()) {
current = current.tryGetComponentType().get();
ensurePresent(current.getFullyQualifiedClassName());
}
}
Aggregations