use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class SignatureGeneratorTest method testGenericInterface.
public void testGenericInterface() throws IOException {
CompilationUnit unit = translateType("A", "interface A<E> extends java.util.Collection<E> {}");
SignatureGenerator signatureGenerator = unit.getEnv().signatureGenerator();
List<AbstractTypeDeclaration> decls = unit.getTypes();
assertEquals(1, decls.size());
assertEquals("<E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Collection<TE;>;", signatureGenerator.createClassSignature(decls.get(0).getTypeElement()));
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class InnerClassExtractorTest method translateClassBody.
protected List<AbstractTypeDeclaration> translateClassBody(String testSource) {
String source = "public class Test { " + testSource + " }";
CompilationUnit unit = translateType("Test", source);
return unit.getTypes();
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class TreeConverter method convertCompilationUnit.
public static CompilationUnit convertCompilationUnit(TranslationEnvironment env, org.eclipse.jdt.core.dom.CompilationUnit jdtUnit, String sourceFilePath, String mainTypeName, String source) {
CompilationUnit unit = new CompilationUnit(env, sourceFilePath, mainTypeName, source);
if (jdtUnit.getPackage() == null) {
unit.setPackage(new PackageDeclaration());
} else {
unit.setPackage((PackageDeclaration) TreeConverter.convert(jdtUnit.getPackage()));
}
for (Object comment : jdtUnit.getCommentList()) {
// Comments are not normally parented in the JDT AST. Javadoc nodes are
// normally parented by the BodyDeclaration they apply to, so here we only
// keep the unparented comments to avoid duplicate comment nodes.
ASTNode commentParent = ((ASTNode) comment).getParent();
if (commentParent == null || commentParent.equals(jdtUnit)) {
Comment newComment = (Comment) TreeConverter.convert(comment);
// Since the comment is unparented, it's constructor is unable to get
// the root CompilationUnit to determine the line number.
newComment.setLineNumber(jdtUnit.getLineNumber(newComment.getStartPosition()));
unit.addComment(newComment);
}
}
for (Object type : jdtUnit.types()) {
unit.addType((AbstractTypeDeclaration) TreeConverter.convert(type));
}
return unit;
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class FileProcessor method processInput.
private void processInput(ProcessingContext input) {
try {
InputFile file = input.getFile();
if (isBatchable(file)) {
batchInputs.add(input);
if (batchInputs.size() == batchSize) {
processBatch();
}
return;
}
logger.finest("parsing " + file);
CompilationUnit compilationUnit = parser.parse(file);
if (compilationUnit == null) {
handleError(input);
return;
}
processCompiledSource(input, compilationUnit);
} catch (RuntimeException | Error e) {
ErrorUtil.fatalError(e, input.getOriginalSourcePath());
}
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class InputFilePreprocessor method processPackageInfoSource.
private void processPackageInfoSource(ProcessingContext input) throws IOException {
InputFile file = input.getFile();
String source = options.fileUtil().readFile(file);
CompilationUnit compilationUnit = parser.parse(FileUtil.getMainTypeName(file), file.getUnitName(), source);
if (compilationUnit != null) {
extractPackagePrefix(file, compilationUnit);
}
}
Aggregations