use of com.google.devtools.j2objc.ast.BodyDeclaration in project j2objc by google.
the class Rewriter method endVisit.
@Override
public void endVisit(FieldDeclaration node) {
if (options.isJDT()) {
ListMultimap<Integer, VariableDeclarationFragment> newDeclarations = rewriteExtraDimensions(node.getFragments());
if (newDeclarations != null) {
List<BodyDeclaration> bodyDecls = TreeUtil.asDeclarationSublist(node);
for (Integer dimensions : newDeclarations.keySet()) {
List<VariableDeclarationFragment> fragments = newDeclarations.get(dimensions);
FieldDeclaration newDecl = new FieldDeclaration(fragments.get(0));
newDecl.getFragments().addAll(fragments.subList(1, fragments.size()));
bodyDecls.add(newDecl);
}
}
}
}
use of com.google.devtools.j2objc.ast.BodyDeclaration 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, len);\n}\n"));
}
}
use of com.google.devtools.j2objc.ast.BodyDeclaration in project j2objc by google.
the class DeadCodeEliminator method removeDeadMethods.
/**
* Remove dead methods from a type's body declarations.
*/
private void removeDeadMethods(String clazz, List<BodyDeclaration> declarations) {
Iterator<BodyDeclaration> declarationsIter = declarations.iterator();
while (declarationsIter.hasNext()) {
BodyDeclaration declaration = declarationsIter.next();
if (declaration instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) declaration;
// TODO(kstanger): Remove the method and its OCNI comment.
if (Modifier.isNative(method.getModifiers())) {
continue;
}
ExecutableElement elem = method.getExecutableElement();
String name = typeUtil.getReferenceName(elem);
String signature = typeUtil.getReferenceSignature(elem);
if (deadCodeMap.containsMethod(clazz, name, signature)) {
if (method.isConstructor()) {
deadCodeMap.addConstructorRemovedClass(clazz);
}
declarationsIter.remove();
}
}
}
}
Aggregations