use of com.strobel.decompiler.languages.java.ast.EntityDeclaration in project j2objc by google.
the class ClassFileConverter method convertClassInitializer.
/**
* The clinit method isn't converted into a member element by javac,
* so extract it separately from the classfile.
*/
private void convertClassInitializer(AbstractTypeDeclaration typeDecl) {
EntityDeclaration decl = classFile.getMethod("<clinit>", "()V");
if (decl == null) {
// Class doesn't have a static initializer.
return;
}
MethodTranslator translator = new MethodTranslator(parserEnv, translationEnv, null, typeDecl, null);
Block block = (Block) decl.acceptVisitor(translator, null);
for (Statement stmt : block.getStatements()) {
typeDecl.addClassInitStatement(stmt.copy());
}
}
use of com.strobel.decompiler.languages.java.ast.EntityDeclaration in project j2objc by google.
the class ClassFileConverter method convertMethodDeclaration.
private TreeNode convertMethodDeclaration(ExecutableElement element, AbstractTypeDeclaration node) {
MethodDeclaration methodDecl = new MethodDeclaration(element);
convertBodyDeclaration(methodDecl, element);
HashMap<String, VariableElement> localVariableTable = new HashMap<>();
List<SingleVariableDeclaration> parameters = methodDecl.getParameters();
String name = element.getSimpleName().toString();
String descriptor = getMethodDescriptor(element);
if (element.getParameters().size() > 0) {
Iterator<ParameterDeclaration> paramsIterator = methodDecl.isConstructor() ? classFile.getConstructor(descriptor).getParameters().iterator() : classFile.getMethod(name, descriptor).getParameters().iterator();
// to work around potential javac8 bug iterating over parameter names.
for (VariableElement param : element.getParameters()) {
SingleVariableDeclaration varDecl = (SingleVariableDeclaration) convert(param, methodDecl);
String nameDef = paramsIterator.next().getName();
// If element's name doesn't match the ParameterNode's name, use the latter.
if (!nameDef.equals(param.getSimpleName().toString())) {
param = GeneratedVariableElement.newParameter(nameDef, param.asType(), param.getEnclosingElement());
varDecl.setVariableElement(param);
}
parameters.add(varDecl);
localVariableTable.put(param.getSimpleName().toString(), param);
}
}
if (element.isVarArgs()) {
SingleVariableDeclaration lastParam = parameters.get(parameters.size() - 1);
TypeMirror paramType = lastParam.getType().getTypeMirror();
assert paramType.getKind() == TypeKind.ARRAY;
TypeMirror varArgType = ((ArrayType) paramType).getComponentType();
lastParam.setType(Type.newType(varArgType));
lastParam.setIsVarargs(true);
}
if (!ElementUtil.isAbstract(element)) {
EntityDeclaration decl = methodDecl.isConstructor() ? classFile.getConstructor(descriptor) : classFile.getMethod(name, descriptor);
MethodTranslator translator = new MethodTranslator(parserEnv, translationEnv, element, node, localVariableTable);
methodDecl.setBody((Block) decl.acceptVisitor(translator, null));
}
return methodDecl;
}
Aggregations