Skip to content

Commit

Permalink
Remove childLink name from MethodDeclaration node
Browse files Browse the repository at this point in the history
	Change on 2017/02/24 by zgao <zgao@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148498053
  • Loading branch information
zhouyanggao authored and tomball committed Mar 13, 2017
1 parent 7d94b1a commit baa0ce7
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 28 deletions.
Expand Up @@ -15,11 +15,13 @@
package com.google.devtools.j2objc.ast;

import com.google.devtools.j2objc.gen.SourceBuilder;
import com.google.devtools.j2objc.util.ElementUtil;
import com.google.devtools.j2objc.util.ErrorUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;

/**
Expand Down Expand Up @@ -141,7 +143,7 @@ public boolean visit(MemberValuePair node) {

@Override
public boolean visit(MethodDeclaration node) {
printName(node.getName());
printName(node.getExecutableElement());
return true;
}

Expand Down Expand Up @@ -262,6 +264,11 @@ public boolean visit(VariableDeclarationFragment node) {
return true;
}

private void printName(Element element) {
sb.print(": ");
sb.print(ElementUtil.getName(element));
}

private void printName(Name name) {
if (name != null) {
sb.print(": ");
Expand Down
Expand Up @@ -642,7 +642,7 @@ public boolean visit(MethodDeclaration node) {
}
sb.print(' ');
}
node.getName().accept(this);
sb.print(ElementUtil.getName(meth));
sb.print("(");
for (Iterator<SingleVariableDeclaration> it = node.getParameters().iterator(); it.hasNext(); ) {
it.next().accept(this);
Expand Down
Expand Up @@ -28,7 +28,6 @@ public class MethodDeclaration extends BodyDeclaration {
private boolean hasDeclaration = true;
private boolean isUnavailable = false;
private ChildLink<Type> returnType = ChildLink.create(Type.class, this);
private ChildLink<SimpleName> name = ChildLink.create(SimpleName.class, this);
private ChildList<SingleVariableDeclaration> parameters =
ChildList.create(SingleVariableDeclaration.class, this);
private ChildLink<Block> body = ChildLink.create(Block.class, this);
Expand All @@ -42,7 +41,6 @@ public MethodDeclaration(MethodDeclaration other) {
hasDeclaration = other.hasDeclaration();
isUnavailable = other.isUnavailable();
returnType.copyFrom(other.getReturnType());
name.copyFrom(other.getName());
parameters.copyFrom(other.getParameters());
body.copyFrom(other.getBody());
}
Expand All @@ -52,7 +50,6 @@ public MethodDeclaration(ExecutableElement method) {
executableElement = method;
isConstructor = ElementUtil.isConstructor(method);
returnType.set(Type.newType(method.getReturnType()));
name.set(new SimpleName(method));
}

@Override
Expand Down Expand Up @@ -105,15 +102,6 @@ public MethodDeclaration setReturnType(Type newType) {
return this;
}

public SimpleName getName() {
return name.get();
}

public MethodDeclaration setName(SimpleName newName) {
name.set(newName);
return this;
}

public SingleVariableDeclaration getParameter(int index) {
return parameters.get(index);
}
Expand All @@ -137,7 +125,6 @@ protected void acceptInner(TreeVisitor visitor) {
javadoc.accept(visitor);
annotations.accept(visitor);
returnType.accept(visitor);
name.accept(visitor);
parameters.accept(visitor);
body.accept(visitor);
}
Expand Down
Expand Up @@ -727,8 +727,8 @@ public int compare(MethodDeclaration m1, MethodDeclaration m2) {
if (!m1.isConstructor() && m2.isConstructor()) {
return 1;
}
String m1Name = m1.getName().getIdentifier();
String m2Name = m2.getName().getIdentifier();
String m1Name = ElementUtil.getName(m1.getExecutableElement());
String m2Name = ElementUtil.getName(m2.getExecutableElement());
if (!m1Name.equals(m2Name)) {
return m1Name.compareToIgnoreCase(m2Name);
}
Expand Down
Expand Up @@ -35,7 +35,6 @@
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
Expand All @@ -47,7 +46,7 @@
*/
public class TypeImplementationGenerator extends TypeGenerator {

private static final Set<String> NSNUMBER_DESIGNATED_INITIALIZERS = ImmutableSet.of(
private static final ImmutableSet<String> NSNUMBER_DESIGNATED_INITIALIZERS = ImmutableSet.of(
"initWithBool:",
"initWithChar:",
"initWithDouble:",
Expand Down Expand Up @@ -242,7 +241,7 @@ protected void printMethodDeclaration(MethodDeclaration m) {
if (isDesignatedInitializer) {
println("J2OBJC_IGNORE_DESIGNATED_BEGIN");
}
syncLineNumbers(m.getName()); // avoid doc-comment
syncLineNumbers(m); // avoid doc-comment
String methodBody = generateStatement(m.getBody());
print(getMethodSignature(m) + " " + reindent(methodBody) + "\n");
if (isDesignatedInitializer) {
Expand Down
Expand Up @@ -900,7 +900,6 @@ private TreeNode convertMethodDeclaration(JCTree.JCMethodDecl node) {
newNode.addParameter((SingleVariableDeclaration) convert(param));
}
return newNode
.setName(convertSimpleName(node.sym, node.type, getNamePosition(node)))
.setIsConstructor(ElementUtil.isConstructor(node.sym))
.setExecutableElement(node.sym)
.setBody((Block) convert(node.getBody()))
Expand Down
Expand Up @@ -942,7 +942,6 @@ private static TreeNode convertMethodDeclaration(
newNode.addParameter((SingleVariableDeclaration) TreeConverter.convert(param));
}
newNode
.setName((SimpleName) TreeConverter.convert(node.getName()))
.setIsConstructor(node.isConstructor())
.setReturnType((Type) TreeConverter.convert(node.getReturnType2()))
.setExecutableElement(BindingConverter.getExecutableElement(node.resolveBinding()))
Expand Down
Expand Up @@ -378,7 +378,7 @@ private FunctionDeclaration makeFunction(MethodDeclaration method) {
FunctionDeclaration function =
new FunctionDeclaration(nameTable.getFullFunctionName(elem), elem.getReturnType());
function.setJniSignature(signatureGenerator.createJniFunctionSignature(elem));
function.setLineNumber(method.getName().getLineNumber());
function.setLineNumber(method.getLineNumber());

if (!ElementUtil.isStatic(elem)) {
VariableElement var = GeneratedVariableElement.newParameter(
Expand Down Expand Up @@ -427,7 +427,7 @@ private FunctionDeclaration makeAllocatingConstructor(
String name = releasing ? nameTable.getReleasingConstructorName(element)
: nameTable.getAllocatingConstructorName(element);
FunctionDeclaration function = new FunctionDeclaration(name, declaringClass.asType());
function.setLineNumber(method.getName().getLineNumber());
function.setLineNumber(method.getLineNumber());
function.setModifiers(ElementUtil.isPrivate(element) ? Modifier.PRIVATE : Modifier.PUBLIC);
function.setReturnsRetained(!releasing);
TreeUtil.copyList(method.getParameters(), function.getParameters());
Expand Down
Expand Up @@ -33,6 +33,7 @@
import com.google.devtools.j2objc.pipeline.ProcessingContext;
import com.google.devtools.j2objc.pipeline.TranslationProcessor;
import com.google.devtools.j2objc.util.CodeReferenceMap;
import com.google.devtools.j2objc.util.ElementUtil;
import com.google.devtools.j2objc.util.ErrorUtil;
import com.google.devtools.j2objc.util.FileUtil;
import com.google.devtools.j2objc.util.NameTable;
Expand Down Expand Up @@ -141,7 +142,7 @@ protected List<Statement> translateStatements(String stmts) {
unit.accept(new TreeVisitor() {
@Override
public boolean visit(MethodDeclaration node) {
if (node.getName().getIdentifier().equals("test")) {
if (ElementUtil.getName(node.getExecutableElement()).equals("test")) {
statements.addAll(node.getBody().getStatements());
}
return false;
Expand Down Expand Up @@ -322,7 +323,7 @@ protected MethodDeclaration translateMethod(String method) {
unit.accept(new TreeVisitor() {
@Override
public boolean visit(MethodDeclaration node) {
String name = node.getName().getIdentifier();
String name = ElementUtil.getName(node.getExecutableElement());
if (name.equals(NameTable.INIT_NAME)
|| name.equals(NameTable.FINALIZE_METHOD)
|| name.equals(NameTable.DEALLOC_METHOD)) {
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.google.devtools.j2objc.ast.CompilationUnit;
import com.google.devtools.j2objc.ast.MethodDeclaration;
import com.google.devtools.j2objc.ast.ReturnStatement;
import com.google.devtools.j2objc.util.ElementUtil;
import com.google.devtools.j2objc.util.TypeUtil;
import java.io.IOException;
import javax.lang.model.type.TypeMirror;
Expand All @@ -44,7 +45,7 @@ public void testIsCompound() throws Exception {
for (BodyDeclaration body : decl.getBodyDeclarations()) {
if (body instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) body;
if (method.getName().getIdentifier().equals("thenTesting")) {
if (ElementUtil.getName(method.getExecutableElement()).equals("thenTesting")) {
// Verify a normal type isn't marked as compound.
TypeMirror returnType = method.getReturnType().getTypeMirror();
assertFalse(TypeUtil.isIntersection(returnType));
Expand All @@ -71,7 +72,7 @@ public void testCompoundTypeFullName() throws IOException {
for (BodyDeclaration body : decl.getBodyDeclarations()) {
if (body instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) body;
if (method.getName().getIdentifier().equals("thenTesting")) {
if (ElementUtil.getName(method.getExecutableElement()).equals("thenTesting")) {
// The method's return type isn't compound, but the cast expression in
// its return statement is.
ReturnStatement stmt = (ReturnStatement) method.getBody().getStatements().get(0);
Expand Down

0 comments on commit baa0ce7

Please sign in to comment.