use of com.strobel.decompiler.languages.java.ast.ParameterDeclaration 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