use of com.google.devtools.j2objc.types.HeaderImportCollector 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);
}
}
}
use of com.google.devtools.j2objc.types.HeaderImportCollector 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);
}
Aggregations