use of javax.lang.model.element.ExecutableElement in project j2objc by google.
the class ElementReferenceMapper method endVisit.
@Override
public void endVisit(ConstructorInvocation invocation) {
ExecutableElement childMethodElement = invocation.getExecutableElement();
handleChildMethod(childMethodElement);
MethodDeclaration parentMethodDeclaration = TreeUtil.getEnclosingMethod(invocation);
if (parentMethodDeclaration == null) {
staticSet.add(stitchMethodIdentifier(childMethodElement));
return;
}
ExecutableElement parentMethodElement = parentMethodDeclaration.getExecutableElement();
handleParentMethod(parentMethodElement, childMethodElement);
}
use of javax.lang.model.element.ExecutableElement in project j2objc by google.
the class ElementReferenceMapper method endVisit.
@Override
public void endVisit(MethodInvocation method) {
ExecutableElement childMethodElement = method.getExecutableElement();
handleChildMethod(childMethodElement);
MethodDeclaration parentMethodDeclaration = TreeUtil.getEnclosingMethod(method);
if (parentMethodDeclaration == null) {
staticSet.add(stitchMethodIdentifier(childMethodElement));
return;
}
ExecutableElement parentMethodElement = parentMethodDeclaration.getExecutableElement();
handleParentMethod(parentMethodElement, childMethodElement);
}
use of javax.lang.model.element.ExecutableElement in project j2objc by google.
the class UnusedCodeTracker method markUsedElements.
/**
* Add to root set, methods from CodeReferenceMap and also all public methods in input classes.
* Then, do tree shaker traversal starting from this root set.
* @param publicRootSet: CodeReferenceMap with public root methods and classes.
*/
//TODO(malvania): Current paradigm: All methods in input CodeReferenceMap are assumed to be
// public roots to traverse from.
//Classes in input CodeReferenceMap here allow user to add Dynamically Loaded Classes and keep
// their public methods in the public root set.
//In the future, when we add support for libraries, we will want to include protected methods
// of those library classes as well, so we should add "|| ElementUtil.isProtected(method)" after
// the isPublic check.
public void markUsedElements(CodeReferenceMap publicRootSet) {
if (publicRootSet == null) {
markUsedElements();
return;
}
//Add all public methods in publicRootClasses to root set
for (String clazz : publicRootSet.getReferencedClasses()) {
ClassReferenceNode classNode = (ClassReferenceNode) elementReferenceMap.get(ElementReferenceMapper.stitchClassIdentifier(clazz));
assert (classNode != null);
Iterable<ExecutableElement> methods = ElementUtil.getMethods(classNode.classElement);
for (ExecutableElement method : methods) {
if (ElementUtil.isPublic(method)) {
rootSet.add(ElementReferenceMapper.stitchMethodIdentifier(method, env.typeUtil(), env.elementUtil()));
}
}
}
//Add input root methods to static set
for (Table.Cell<String, String, ImmutableSet<String>> cell : publicRootSet.getReferencedMethods().cellSet()) {
String clazzName = cell.getRowKey();
String methodName = cell.getColumnKey();
for (String signature : cell.getValue()) {
rootSet.add(ElementReferenceMapper.stitchMethodIdentifier(clazzName, methodName, signature));
}
}
markUsedElements(staticSet);
markUsedElements(rootSet);
}
use of javax.lang.model.element.ExecutableElement in project j2objc by google.
the class NameTableTest method testTypeVariableWithTypeVariableBounds.
public void testTypeVariableWithTypeVariableBounds() {
String source = "class A<T> { <E extends T> void foo(E e) {} }";
CompilationUnit unit = translateType("A", source);
NameTable nameTable = unit.getEnv().nameTable();
final ExecutableElement[] methodElement = new ExecutableElement[1];
unit.accept(new TreeVisitor() {
@Override
public void endVisit(MethodDeclaration node) {
ExecutableElement element = node.getExecutableElement();
if (ElementUtil.getName(element).equals("foo")) {
methodElement[0] = element;
}
}
});
assertNotNull(methodElement[0]);
TypeMirror paramType = methodElement[0].getParameters().get(0).asType();
assertEquals("id", nameTable.getObjCType(paramType));
}
use of javax.lang.model.element.ExecutableElement in project j2objc by google.
the class EnumRewriter method addValueOfMethod.
private void addValueOfMethod(EnumDeclaration node) {
TypeElement type = node.getTypeElement();
ExecutableElement method = ElementUtil.findMethod(type, "valueOf", "java.lang.String");
assert method != null : "Can't find valueOf method on enum type.";
String typeName = nameTable.getFullName(type);
int numConstants = node.getEnumConstants().size();
VariableElement nameParam = GeneratedVariableElement.newParameter("name", method.getParameters().get(0).asType(), method);
MethodDeclaration methodDecl = new MethodDeclaration(method);
methodDecl.addParameter(new SingleVariableDeclaration(nameParam));
Block body = new Block();
methodDecl.setBody(body);
StringBuilder impl = new StringBuilder();
if (numConstants > 0) {
impl.append(UnicodeUtils.format(" for (int i = 0; i < %s; i++) {\n" + " %s *e = %s_values_[i];\n" + " if ([name isEqual:[e name]]) {\n" + " return e;\n" + " }\n" + " }\n", numConstants, typeName, typeName));
}
impl.append(" @throw create_JavaLangIllegalArgumentException_initWithNSString_(name);\n" + " return nil;");
body.addStatement(new NativeStatement(impl.toString()));
node.addBodyDeclaration(methodDecl);
}
Aggregations