Search in sources :

Example 1 with JavaClassDescriptor

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);
}
Also used : JavaClassDescriptor(com.tngtech.archunit.core.domain.JavaClassDescriptor)

Example 2 with JavaClassDescriptor

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);
}
Also used : JavaTypeCreationProcess(com.tngtech.archunit.core.importer.DomainBuilders.JavaTypeCreationProcess) JavaClassDescriptor(com.tngtech.archunit.core.domain.JavaClassDescriptor)

Example 3 with JavaClassDescriptor

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());
}
Also used : JavaClassDescriptor(com.tngtech.archunit.core.domain.JavaClassDescriptor)

Example 4 with JavaClassDescriptor

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);
}
Also used : Type(org.objectweb.asm.Type) JavaClassDescriptor(com.tngtech.archunit.core.domain.JavaClassDescriptor) Test(org.junit.Test)

Example 5 with JavaClassDescriptor

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());
    }
}
Also used : JavaClassDescriptor(com.tngtech.archunit.core.domain.JavaClassDescriptor)

Aggregations

JavaClassDescriptor (com.tngtech.archunit.core.domain.JavaClassDescriptor)11 CodeUnit (com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit)2 Test (org.junit.Test)2 JavaClassBuilder (com.tngtech.archunit.core.importer.DomainBuilders.JavaClassBuilder)1 JavaTypeCreationProcess (com.tngtech.archunit.core.importer.DomainBuilders.JavaTypeCreationProcess)1 JavaCodeUnitSignature (com.tngtech.archunit.core.importer.JavaCodeUnitSignatureImporter.JavaCodeUnitSignature)1 Type (org.objectweb.asm.Type)1