use of com.strobel.decompiler.languages.java.ast.MemberReferenceExpression in project j2objc by google.
the class MethodTranslator method visitInvocationExpression.
@Override
public TreeNode visitInvocationExpression(InvocationExpression node, Void data) {
MethodReference methodDef = (MethodReference) node.getUserData(Keys.MEMBER_REFERENCE);
com.strobel.decompiler.languages.java.ast.Expression target = node.getTarget();
if (target instanceof SuperReferenceExpression) {
return target.acceptVisitor(this, null);
}
if (target instanceof ThisReferenceExpression) {
ThisExpression cons = (ThisExpression) target.acceptVisitor(this, null);
TypeElement type = (TypeElement) ((DeclaredType) cons.getTypeMirror()).asElement();
List<Expression> args = node.getArguments().stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
ExecutableElement sym = findConstructor(type, methodDef);
ConstructorInvocation newNode = new ConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setArguments(args);
return newNode;
}
if (target instanceof MemberReferenceExpression) {
TypeMirror type = resolve(methodDef.getDeclaringType());
List<Expression> args = node.getArguments().stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
ExecutableElement sym = findMethod(methodDef.getName(), type, methodDef);
Expression expr = (Expression) target.getFirstChild().acceptVisitor(this, null);
MethodInvocation newNode = new MethodInvocation().setExecutablePair(new ExecutablePair(sym)).setTypeMirror(sym.getReturnType()).setArguments(args).setExpression(expr);
return newNode;
}
throw new AssertionError("not implemented");
}
use of com.strobel.decompiler.languages.java.ast.MemberReferenceExpression in project j2objc by google.
the class MethodTranslator method visitMemberReferenceExpression.
@Override
public TreeNode visitMemberReferenceExpression(MemberReferenceExpression node, Void data) {
Expression qualifier = (Expression) node.getFirstChild().acceptVisitor(this, null);
TypeElement owner = (TypeElement) ((DeclaredType) qualifier.getTypeMirror()).asElement();
VariableElement field = ElementUtil.findField(owner, node.getMemberName());
if (field != null) {
return new FieldAccess(field, qualifier);
}
throw new AssertionError("not implemented");
}
use of com.strobel.decompiler.languages.java.ast.MemberReferenceExpression in project j2objc by google.
the class PackageInfoLookup method parseDataFromClassFile.
private PackageData parseDataFromClassFile(InputFile file) throws IOException {
PackageDataBuilder builder = new PackageDataBuilder();
ClassFile classFile = ClassFile.create(file);
TypeDeclaration typeDecl = classFile.getType();
for (Annotation annotation : typeDecl.getAnnotations()) {
String signature = annotation.getType().toTypeReference().getErasedSignature();
if (signature.equals("Lcom/google/j2objc/annotations/ObjectiveCName;")) {
for (Expression expr : annotation.getArguments()) {
if (expr instanceof MemberReferenceExpression) {
String value = ((MemberReferenceExpression) expr).getMemberName();
builder.setObjectiveCName(value);
} else if (expr instanceof PrimitiveExpression) {
Object value = ((PrimitiveExpression) expr).getValue();
builder.setObjectiveCName((String) value);
}
}
} else if (signature.equals("Ljavax/annotation/ParametersAreNonnullByDefault;")) {
builder.setParametersAreNonnullByDefault();
} else if (signature.equals("Lcom/google/j2objc/annotations/ReflectionSupport;")) {
for (Expression expr : annotation.getArguments()) {
if (expr instanceof MemberReferenceExpression) {
String value = ((MemberReferenceExpression) expr).getMemberName();
builder.setReflectionSupportLevel(ReflectionSupport.Level.valueOf(value));
}
}
}
}
return builder.build();
}
Aggregations