Search in sources :

Example 1 with ImplementationImportCollector

use of com.google.devtools.j2objc.types.ImplementationImportCollector in project j2objc by google.

the class GeneratedType method fromTypeDeclaration.

public static GeneratedType fromTypeDeclaration(AbstractTypeDeclaration typeNode) {
    TypeElement typeElement = typeNode.getTypeElement();
    CompilationUnit unit = TreeUtil.getCompilationUnit(typeNode);
    NameTable nameTable = unit.getEnv().nameTable();
    boolean emitLineDirectives = unit.getEnv().options().emitLineDirectives();
    ImmutableList.Builder<String> superTypes = ImmutableList.builder();
    TypeElement superclass = ElementUtil.getSuperclass(typeElement);
    if (superclass != null) {
        superTypes.add(nameTable.getFullName(superclass));
    }
    for (TypeElement superInterface : ElementUtil.getInterfaces(typeElement)) {
        superTypes.add(nameTable.getFullName(superInterface));
    }
    HeaderImportCollector headerCollector = new HeaderImportCollector(unit, HeaderImportCollector.Filter.PUBLIC_ONLY);
    typeNode.accept(headerCollector);
    HeaderImportCollector privateDeclarationCollector = new HeaderImportCollector(unit, HeaderImportCollector.Filter.PRIVATE_ONLY);
    typeNode.accept(privateDeclarationCollector);
    ImplementationImportCollector importCollector = new ImplementationImportCollector(unit);
    typeNode.accept(importCollector);
    SourceBuilder builder = new SourceBuilder(emitLineDirectives);
    GeneratedSourceMappings generatedSourceMappings = new GeneratedSourceMappings();
    TypeDeclarationGenerator.generate(builder, typeNode, generatedSourceMappings);
    String publicDeclarationCode = builder.toString();
    builder = new SourceBuilder(emitLineDirectives);
    TypePrivateDeclarationGenerator.generate(builder, typeNode);
    String privateDeclarationCode;
    String implementationCode;
    Options options = unit.getEnv().options();
    if (unit.getEnv().translationUtil().generateImplementation(typeElement)) {
        builder = new SourceBuilder(options.emitLineDirectives());
        TypePrivateDeclarationGenerator.generate(builder, typeNode);
        privateDeclarationCode = builder.toString();
        builder = new SourceBuilder(options.emitLineDirectives());
        TypeImplementationGenerator.generate(builder, typeNode);
        implementationCode = builder.toString();
    } else {
        privateDeclarationCode = "";
        implementationCode = String.format("// Implementation not generated because %s is on the bootclasspath.\n", ElementUtil.getQualifiedName(typeElement));
    }
    ImmutableSet.Builder<Import> implementationIncludes = ImmutableSet.builder();
    implementationIncludes.addAll(privateDeclarationCollector.getSuperTypes());
    implementationIncludes.addAll(importCollector.getImports());
    return new GeneratedType(nameTable.getFullName(typeElement), typeNode.hasPrivateDeclaration(), superTypes.build(), ImmutableSet.copyOf(headerCollector.getForwardDeclarations()), ImmutableSet.copyOf(headerCollector.getSuperTypes()), ImmutableSet.copyOf(privateDeclarationCollector.getForwardDeclarations()), implementationIncludes.build(), publicDeclarationCode, privateDeclarationCode, implementationCode, generatedSourceMappings);
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) Options(com.google.devtools.j2objc.Options) Import(com.google.devtools.j2objc.types.Import) TypeElement(javax.lang.model.element.TypeElement) ImmutableList(com.google.common.collect.ImmutableList) HeaderImportCollector(com.google.devtools.j2objc.types.HeaderImportCollector) ImplementationImportCollector(com.google.devtools.j2objc.types.ImplementationImportCollector) ImmutableSet(com.google.common.collect.ImmutableSet) NameTable(com.google.devtools.j2objc.util.NameTable)

Example 2 with ImplementationImportCollector

use of com.google.devtools.j2objc.types.ImplementationImportCollector in project j2objc by google.

the class TranslationProcessor method checkDependencies.

private void checkDependencies(CompilationUnit unit) {
    HeaderImportCollector hdrCollector = new HeaderImportCollector(unit, HeaderImportCollector.Filter.INCLUDE_ALL);
    hdrCollector.run();
    ImplementationImportCollector implCollector = new ImplementationImportCollector(unit);
    implCollector.run();
    Set<Import> imports = hdrCollector.getForwardDeclarations();
    imports.addAll(hdrCollector.getSuperTypes());
    imports.addAll(implCollector.getImports());
    for (Import imp : imports) {
        String qualifiedName = imp.getJavaQualifiedName();
        if (qualifiedName != null) {
            closureQueue.addName(qualifiedName);
        }
    }
}
Also used : Import(com.google.devtools.j2objc.types.Import) HeaderImportCollector(com.google.devtools.j2objc.types.HeaderImportCollector) ImplementationImportCollector(com.google.devtools.j2objc.types.ImplementationImportCollector)

Aggregations

HeaderImportCollector (com.google.devtools.j2objc.types.HeaderImportCollector)2 ImplementationImportCollector (com.google.devtools.j2objc.types.ImplementationImportCollector)2 Import (com.google.devtools.j2objc.types.Import)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Options (com.google.devtools.j2objc.Options)1 CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)1 NameTable (com.google.devtools.j2objc.util.NameTable)1 TypeElement (javax.lang.model.element.TypeElement)1