use of com.google.devtools.j2objc.ast.Comment 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.Comment in project j2objc by google.
the class OcniExtractor method visitType.
private void visitType(AbstractTypeDeclaration node) {
TypeElement type = node.getTypeElement();
Set<String> methodsPrinted = Sets.newHashSet();
List<BodyDeclaration> bodyDeclarations = node.getBodyDeclarations();
int minPos = 0;
int declIdx = 0;
for (Comment comment : blockComments.get(node)) {
int commentPos = comment.getStartPosition();
while (declIdx < bodyDeclarations.size()) {
BodyDeclaration decl = bodyDeclarations.get(declIdx);
if (decl.getStartPosition() > commentPos) {
break;
}
minPos = Math.max(minPos, decl.getStartPosition() + decl.getLength());
declIdx++;
}
if (commentPos > minPos) {
NativeDeclaration nativeDecl = extractNativeDeclaration(comment);
if (nativeDecl != null) {
findMethodSignatures(nativeDecl.getImplementationCode(), methodsPrinted);
bodyDeclarations.add(declIdx++, nativeDecl);
}
}
}
// methods are always live.
if (typeUtil.findSupertype(type.asType(), "java.lang.Iterable") != null && !methodsPrinted.contains("countByEnumeratingWithState:objects:count:") && (deadCodeMap == null || !deadCodeMap.containsClass(type, elementUtil))) {
bodyDeclarations.add(NativeDeclaration.newInnerDeclaration(null, "- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state " + "objects:(__unsafe_unretained id *)stackbuf count:(NSUInteger)len {\n" + " return JreDefaultFastEnumeration(self, state, stackbuf);\n}\n"));
}
}
Aggregations