Skip to content

Commit

Permalink
Automated g4 rollback of changelist 129653292.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Need to update build paths.

*** Original change description ***

Added ParserEnvironment, moved NameTable and Types into it, and defined JDT implementation.

***

	Change on 2016/08/08 by tball <tball@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129671854
  • Loading branch information
tomball committed Sep 7, 2016
1 parent 8fcf44e commit 08b92cd
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 220 deletions.
1 change: 0 additions & 1 deletion translator/.classpath
Expand Up @@ -10,7 +10,6 @@
<classpathentry kind="lib" path="../java_deps/build_result/jsr305.jar"/>
<classpathentry kind="lib" path="../java_deps/build_result/asm.jar"/>
<classpathentry kind="lib" path="../java_deps/build_result/guava-19.0.jar"/>
<classpathentry kind="lib" path="../java_deps/build_result/javac.jar"/>
<classpathentry kind="lib" path="../java_deps/build_result/org.eclipse.core.contenttype_3.4.200.v20140207-1251.jar"/>
<classpathentry kind="lib" path="../java_deps/build_result/org.eclipse.core.jobs_3.6.1.v20141204-0235.jar"/>
<classpathentry kind="lib" path="../java_deps/build_result/org.eclipse.core.resources_3.9.1.v20140825-1431.jar"/>
Expand Down
Expand Up @@ -19,7 +19,7 @@
import com.google.devtools.j2objc.jdt.TreeConverter;
import com.google.devtools.j2objc.types.Types;
import com.google.devtools.j2objc.util.NameTable;
import com.google.devtools.j2objc.util.ParserEnvironment;

import org.eclipse.jdt.core.dom.ASTNode;

import java.util.List;
Expand All @@ -29,7 +29,8 @@
*/
public class CompilationUnit extends TreeNode {

private final ParserEnvironment env;
private final Types typeEnv;
private final NameTable nameTable;
private final String sourceFilePath;
private final String mainTypeName;
private final String source;
Expand All @@ -45,10 +46,11 @@ public class CompilationUnit extends TreeNode {
ChildList.create(AbstractTypeDeclaration.class, this);

public CompilationUnit(
ParserEnvironment env, org.eclipse.jdt.core.dom.CompilationUnit jdtNode,
String sourceFilePath, String mainTypeName, String source) {
org.eclipse.jdt.core.dom.CompilationUnit jdtNode, String sourceFilePath,
String mainTypeName, String source, NameTable.Factory nameTableFactory) {
super(jdtNode);
this.env = env;
typeEnv = new Types(jdtNode.getAST());
nameTable = nameTableFactory == null ? null : nameTableFactory.newNameTable(typeEnv);
this.sourceFilePath = Preconditions.checkNotNull(sourceFilePath);
this.mainTypeName = Preconditions.checkNotNull(mainTypeName);
this.source = Preconditions.checkNotNull(source);
Expand Down Expand Up @@ -78,7 +80,8 @@ public CompilationUnit(

public CompilationUnit(CompilationUnit other) {
super(other);
this.env = other.env;
typeEnv = other.getTypeEnv();
nameTable = other.getNameTable();
sourceFilePath = other.getSourceFilePath();
mainTypeName = other.getMainTypeName();
source = other.getSource();
Expand All @@ -96,11 +99,11 @@ public Kind getKind() {
}

public Types getTypeEnv() {
return env.types();
return typeEnv;
}

public NameTable getNameTable() {
return env.nameTable();
return nameTable;
}

public String getSourceFilePath() {
Expand Down

This file was deleted.

Expand Up @@ -107,7 +107,7 @@
import com.google.devtools.j2objc.ast.VariableDeclarationFragment;
import com.google.devtools.j2objc.ast.VariableDeclarationStatement;
import com.google.devtools.j2objc.ast.WhileStatement;
import com.google.devtools.j2objc.util.ParserEnvironment;
import com.google.devtools.j2objc.util.NameTable;
import java.util.ArrayList;
import java.util.List;
import javax.lang.model.element.ExecutableElement;
Expand All @@ -120,9 +120,9 @@
public class TreeConverter {

public static CompilationUnit convertCompilationUnit(
ParserEnvironment env, org.eclipse.jdt.core.dom.CompilationUnit jdtUnit,
String sourceFilePath, String mainTypeName, String source) {
return new CompilationUnit(env, jdtUnit, sourceFilePath, mainTypeName, source);
org.eclipse.jdt.core.dom.CompilationUnit jdtUnit, String sourceFilePath, String mainTypeName,
String source, NameTable.Factory nameTableFactory) {
return new CompilationUnit(jdtUnit, sourceFilePath, mainTypeName, source, nameTableFactory);
}

public static Statement convertStatement(org.eclipse.jdt.core.dom.Statement jdtStatement) {
Expand Down
Expand Up @@ -21,13 +21,15 @@
import com.google.devtools.j2objc.jdt.JdtTypeBinding;
import com.google.devtools.j2objc.util.BindingUtil;
import com.google.devtools.j2objc.util.NameTable;
import com.google.devtools.j2objc.util.ParserEnvironment;

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.Modifier;

import java.util.HashMap;
import java.util.Map;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.Modifier;

/**
* Types is a singleton service class for type-related operations.
Expand All @@ -36,7 +38,7 @@
*/
public class Types {

private final ParserEnvironment environment;
private final AST ast;
private final Map<ITypeBinding, ITypeBinding> typeMap = Maps.newHashMap();
private final Map<ITypeBinding, ITypeBinding> primitiveToWrapperTypes =
new HashMap<ITypeBinding, ITypeBinding>();
Expand Down Expand Up @@ -84,8 +86,8 @@ public class Types {
private final IOSMethodBinding allocMethod;
private final IOSMethodBinding deallocMethod;

public Types(ParserEnvironment env) {
this.environment = env;
public Types(AST ast) {
this.ast = ast;

// Find core java types.
javaObjectType = resolveWellKnownType("java.lang.Object");
Expand Down Expand Up @@ -188,7 +190,7 @@ private void populatePrimitiveAndWrapperTypeMaps() {
}

private JdtTypeBinding resolveWellKnownType(String name) {
return (JdtTypeBinding) BindingConverter.unwrapElement(environment.resolve(name));
return BindingConverter.wrapBinding(ast.resolveWellKnownType(name));
}

private void loadPrimitiveAndWrapperTypes(String primitiveName, String wrapperName) {
Expand Down
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.j2objc.Options.LintOption;
import com.google.devtools.j2objc.file.InputFile;
import com.google.devtools.j2objc.file.RegularInputFile;
import com.google.devtools.j2objc.jdt.BindingConverter;
import com.google.devtools.j2objc.jdt.TreeConverter;
import java.io.File;
import java.io.IOException;
Expand All @@ -31,7 +30,6 @@
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.lang.model.element.Element;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
Expand Down Expand Up @@ -169,9 +167,8 @@ public com.google.devtools.j2objc.ast.CompilationUnit parse(String mainTypeName,
RegularInputFile file = new RegularInputFile(path);
mainTypeName = FileUtil.getQualifiedMainTypeName(file, unit);
}
ParserEnvironment env =
new JdtParserEnvironment(unit.getAST(), nameTableFactory);
return TreeConverter.convertCompilationUnit(env, unit, path, mainTypeName, source);
return TreeConverter.convertCompilationUnit(
unit, path, mainTypeName, source, NameTable.newFactory());
}

private CompilationUnit parse(String unitName, String source, boolean resolveBindings) {
Expand All @@ -198,11 +195,9 @@ public void acceptAST(String sourceFilePath, CompilationUnit ast) {
RegularInputFile file = new RegularInputFile(sourceFilePath);
try {
String source = FileUtil.readFile(file);
ParserEnvironment env =
new JdtParserEnvironment(ast.getAST(), nameTableFactory);
com.google.devtools.j2objc.ast.CompilationUnit unit =
TreeConverter.convertCompilationUnit(
env, ast, sourceFilePath, FileUtil.getMainTypeName(file), source);
ast, sourceFilePath, FileUtil.getMainTypeName(file), source, nameTableFactory);
handler.handleParsedUnit(sourceFilePath, unit);
} catch (IOException e) {
ErrorUtil.error("Error reading file " + file.getPath() + ": " + e.getMessage());
Expand Down Expand Up @@ -269,28 +264,4 @@ private boolean checkCompilationErrors(String filename, CompilationUnit unit) {
}
return !hasErrors;
}

private static class JdtParserEnvironment extends ParserEnvironment {
private final AST ast;

JdtParserEnvironment(AST ast, NameTable.Factory nameTableFactory) {
super(nameTableFactory);
this.ast = ast;
}

@Override
public Element resolve(String name) {
return BindingConverter.getElement(ast.resolveWellKnownType(name));
}

@Override
public javax.lang.model.util.Elements elementUtilities() {
throw new AssertionError("not implemented");
}

@Override
public javax.lang.model.util.Types typeUtilities() {
throw new AssertionError("not implemented");
}
}
}
Expand Up @@ -29,6 +29,13 @@
import com.google.devtools.j2objc.types.PointerTypeBinding;
import com.google.devtools.j2objc.types.Types;
import com.google.j2objc.annotations.ObjectiveCName;

import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -45,11 +52,6 @@
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;

/**
* Singleton service for type/method/variable name support.
Expand Down Expand Up @@ -330,8 +332,8 @@ private Factory() {
}
}

public NameTable newNameTable(ParserEnvironment env) {
return new NameTable(env, prefixMap, methodMappings);
public NameTable newNameTable(Types typeEnv) {
return new NameTable(typeEnv, prefixMap, methodMappings);
}
}

Expand All @@ -340,8 +342,8 @@ public static Factory newFactory() {
}

private NameTable(
ParserEnvironment env, PackagePrefixes prefixMap, Map<String, String> methodMappings) {
this.typeEnv = env.types();
Types typeEnv, PackagePrefixes prefixMap, Map<String, String> methodMappings) {
this.typeEnv = typeEnv;
this.prefixMap = prefixMap;
this.methodMappings = methodMappings;
}
Expand Down Expand Up @@ -923,8 +925,7 @@ public String getFullName(TypeMirror t) {
* name is "JavaUtilArrayList_ListItr".
*/
public String getFullName(ITypeBinding binding) {
// Make sure type variables aren't included.
binding = typeEnv.mapType(binding.getErasure());
binding = typeEnv.mapType(binding.getErasure()); // Make sure type variables aren't included.

// Avoid package prefix renaming for package-info types, and use a valid ObjC name that doesn't
// have a dash character.
Expand Down

0 comments on commit 08b92cd

Please sign in to comment.