use of com.google.devtools.j2objc.Options 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);
TypeDeclarationGenerator.generate(builder, typeNode);
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);
}
Aggregations