Search in sources :

Example 1 with CodeUnit

use of com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit in project ArchUnit by TNG.

the class ClassGraphCreator method createEnclosingCodeUnit.

@Override
public Optional<JavaCodeUnit> createEnclosingCodeUnit(JavaClass owner) {
    Optional<CodeUnit> enclosingCodeUnit = importRecord.getEnclosingCodeUnitFor(owner.getName());
    if (!enclosingCodeUnit.isPresent()) {
        return Optional.empty();
    }
    CodeUnit codeUnit = enclosingCodeUnit.get();
    JavaClass enclosingClass = classes.getOrResolve(codeUnit.getDeclaringClassName());
    return enclosingClass.tryGetCodeUnitWithParameterTypeNames(codeUnit.getName(), codeUnit.getRawParameterTypeNames());
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) JavaCodeUnit(com.tngtech.archunit.core.domain.JavaCodeUnit) CodeUnit(com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit)

Example 2 with CodeUnit

use of com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit in project ArchUnit by TNG.

the class JavaClassProcessor method visitMethod.

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (importAborted()) {
        return super.visitMethod(access, name, desc, signature, exceptions);
    }
    LOG.trace("Analyzing method {}.{}:{}", className, name, desc);
    CodeUnit codeUnit = new CodeUnit(name, desc, className);
    accessHandler.setContext(codeUnit);
    JavaClassDescriptor rawReturnType = JavaClassDescriptorImporter.importAsmMethodReturnType(desc);
    DomainBuilders.JavaCodeUnitBuilder<?, ?> codeUnitBuilder = addCodeUnitBuilder(name, codeUnit.getRawParameterTypeNames(), rawReturnType.getFullyQualifiedClassName());
    JavaCodeUnitSignature codeUnitSignature = JavaCodeUnitSignatureImporter.parseAsmMethodSignature(signature, declarationHandler);
    List<JavaClassDescriptor> throwsDeclarations = typesFrom(exceptions);
    codeUnitBuilder.withName(name).withModifiers(JavaModifier.getModifiersForMethod(access)).withTypeParameters(codeUnitSignature.getTypeParameterBuilders()).withParameterTypes(codeUnitSignature.getParameterTypes(), codeUnit.getRawParameterTypes()).withReturnType(codeUnitSignature.getReturnType(), rawReturnType).withDescriptor(desc).withThrowsClause(throwsDeclarations);
    declarationHandler.onDeclaredThrowsClause(fullyQualifiedClassNamesOf(throwsDeclarations));
    return new MethodProcessor(className, accessHandler, codeUnitBuilder, declarationHandler);
}
Also used : JavaCodeUnitSignature(com.tngtech.archunit.core.importer.JavaCodeUnitSignatureImporter.JavaCodeUnitSignature) JavaClassDescriptor(com.tngtech.archunit.core.domain.JavaClassDescriptor) CodeUnit(com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit)

Example 3 with CodeUnit

use of com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit in project ArchUnit by TNG.

the class JavaClassProcessor method visitOuterClass.

@Override
public void visitOuterClass(String owner, String name, String desc) {
    if (importAborted()) {
        return;
    }
    declarationHandler.registerEnclosingClass(className, createTypeName(owner));
    if (name != null && desc != null) {
        JavaClassDescriptor ownerType = JavaClassDescriptorImporter.createFromAsmObjectTypeName(owner);
        CodeUnit codeUnit = new CodeUnit(name, desc, ownerType.getFullyQualifiedClassName());
        declarationHandler.registerEnclosingCodeUnit(className, codeUnit);
    }
}
Also used : JavaClassDescriptor(com.tngtech.archunit.core.domain.JavaClassDescriptor) CodeUnit(com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit)

Aggregations

CodeUnit (com.tngtech.archunit.core.importer.RawAccessRecord.CodeUnit)3 JavaClassDescriptor (com.tngtech.archunit.core.domain.JavaClassDescriptor)2 JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 JavaCodeUnit (com.tngtech.archunit.core.domain.JavaCodeUnit)1 JavaCodeUnitSignature (com.tngtech.archunit.core.importer.JavaCodeUnitSignatureImporter.JavaCodeUnitSignature)1