use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class PrivateDeclarationResolver method addPublicType.
private void addPublicType(TypeElement typeElement) {
if (typeElement == null) {
return;
}
AbstractTypeDeclaration typeNode = typeMap.get(typeElement);
if (typeNode == null) {
return;
}
if (publicTypes.add(typeElement)) {
publicNodesToVisit.add(typeNode);
}
// Make sure supertypes of public types remain public, even if declared
// private.
addPublicType(typeElement.getSuperclass());
for (TypeMirror interfaceType : typeElement.getInterfaces()) {
addPublicType(interfaceType);
}
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class OcniExtractor method findBlockComments.
/**
* Finds all block comments and associates them with their containing type.
* This is trickier than you might expect because of inner types.
*/
private static ListMultimap<TreeNode, Comment> findBlockComments(CompilationUnit unit) {
ListMultimap<TreeNode, Comment> blockComments = MultimapBuilder.hashKeys().arrayListValues().build();
for (Comment comment : unit.getCommentList()) {
if (!comment.isBlockComment()) {
continue;
}
int commentPos = comment.getStartPosition();
AbstractTypeDeclaration containingType = null;
int containingTypePos = -1;
for (AbstractTypeDeclaration type : unit.getTypes()) {
int typePos = type.getStartPosition();
if (typePos < 0) {
continue;
}
int typeEnd = typePos + type.getLength();
if (commentPos > typePos && commentPos < typeEnd && typePos > containingTypePos) {
containingType = type;
containingTypePos = typePos;
}
}
blockComments.put(containingType != null ? containingType : unit, comment);
}
return blockComments;
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class CompoundTypeTest method testIsCompound.
// Test TypeUtil.isIntersection(TypeMirror).
public void testIsCompound() throws Exception {
String source = "interface Test<T> extends java.util.Comparator<T> {" + " default Test<T> thenTesting(Test<? super T> other) { " + " return (Test<T> & java.io.Serializable) (c1, c2) -> { " + " int res = compare(c1, c2); " + " return (res != 0) ? res : other.compare(c1, c2); }; }}";
CompilationUnit unit = compileType("Test", source);
AbstractTypeDeclaration decl = unit.getTypes().get(0);
int methodsFound = 0;
for (BodyDeclaration body : decl.getBodyDeclarations()) {
if (body instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) body;
if (ElementUtil.getName(method.getExecutableElement()).equals("thenTesting")) {
// Verify a normal type isn't marked as compound.
TypeMirror returnType = method.getReturnTypeMirror();
assertFalse(TypeUtil.isIntersection(returnType));
// The method's return type isn't compound, but the cast expression in
// its return statement is.
ReturnStatement stmt = (ReturnStatement) method.getBody().getStatements().get(0);
assertTrue(TypeUtil.isIntersection(stmt.getExpression().getTypeMirror()));
methodsFound++;
}
}
}
assertEquals(1, methodsFound);
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class CompoundTypeTest method testCompoundTypeFullName.
// Test NameTable.getObjCType(TypeMirror).
public void testCompoundTypeFullName() throws IOException {
String source = "package foo.bar; interface Test<T> extends java.util.Comparator<T> {" + " default Test<T> thenTesting(Test<? super T> other) { " + " return (Test<T> & java.io.Serializable) (c1, c2) -> { " + " int res = compare(c1, c2); " + " return (res != 0) ? res : other.compare(c1, c2); }; }}";
CompilationUnit unit = compileType("Test", source);
AbstractTypeDeclaration decl = unit.getTypes().get(0);
for (BodyDeclaration body : decl.getBodyDeclarations()) {
if (body instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) body;
if (ElementUtil.getName(method.getExecutableElement()).equals("thenTesting")) {
// The method's return type isn't compound, but the cast expression in
// its return statement is.
ReturnStatement stmt = (ReturnStatement) method.getBody().getStatements().get(0);
TypeMirror mirror = stmt.getExpression().getTypeMirror();
String typeName = unit.getEnv().nameTable().getObjCType(mirror);
assertEquals("id<FooBarTest, JavaIoSerializable>", typeName);
return;
}
}
}
fail("thenTesting method not found");
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class ElementUtilTest method testGetAnnotation.
public void testGetAnnotation() throws IOException {
CompilationUnit unit = translateType("Example", "@com.google.j2objc.annotations.ObjectiveCName(\"E\") class Example {}");
AbstractTypeDeclaration decl = unit.getTypes().get(0);
TypeElement element = decl.getTypeElement();
AnnotationMirror annotation = ElementUtil.getAnnotation(element, ObjectiveCName.class);
assertEquals("com.google.j2objc.annotations.ObjectiveCName", annotation.getAnnotationType().toString());
}
Aggregations