Skip to content

Commit

Permalink
Automated g4 rollback of changelist 179497585:
Browse files Browse the repository at this point in the history
Support classfile translation from command-line, rather than just from tests.

*** Reason for rollback ***

Restored original CL, as build breakage was due to different change.

*** Original change description ***

Automated g4 rollback of changelist 179465118.

*** Reason for rollback ***

iOS tests timeout with this change.

*** Original change description ***

Support classfile translation from command-line, rather than just from tests.

***

***

	Change on 2017/12/19 by tball <tball@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179597752
  • Loading branch information
tomball committed Dec 28, 2017
1 parent 26ae328 commit f9da788
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Expand Up @@ -156,7 +156,8 @@ private TreeNode convert(Element element, TreeNode parent) {
break;
case CONSTRUCTOR:
case METHOD:
node = convertMethodDeclaration((ExecutableElement) element, (TypeDeclaration) parent);
node = convertMethodDeclaration(
(ExecutableElement) element, (AbstractTypeDeclaration) parent);
break;
case ENUM:
node = convertEnumDeclaration((TypeElement) element);
Expand Down Expand Up @@ -280,7 +281,10 @@ private TreeNode convertTypeDeclaration(TypeElement element) {
TypeDeclaration typeDecl = new TypeDeclaration(element);
convertBodyDeclaration(typeDecl, element);
for (Element elem : element.getEnclosedElements()) {
typeDecl.addBodyDeclaration((BodyDeclaration) convert(elem, typeDecl));
// Ignore inner types, as they are defined by other classfiles.
if (!elem.getKind().isClass() && !elem.getKind().isInterface()) {
typeDecl.addBodyDeclaration((BodyDeclaration) convert(elem, typeDecl));
}
}
if (typeDecl.isInterface()) {
removeInterfaceModifiers(typeDecl);
Expand All @@ -292,7 +296,8 @@ private String getMethodDescriptor(ExecutableElement exec) {
return translationEnv.typeUtil().getMethodDescriptor((ExecutableType) exec.asType());
}

private TreeNode convertMethodDeclaration(ExecutableElement element, TypeDeclaration node) {
private TreeNode convertMethodDeclaration(ExecutableElement element,
AbstractTypeDeclaration node) {
MethodDeclaration methodDecl = new MethodDeclaration(element);
convertBodyDeclaration(methodDecl, element);
HashMap<String, VariableElement> localVariableTable = new HashMap<>();
Expand Down
Expand Up @@ -14,6 +14,7 @@

package com.google.devtools.j2objc.javac;

import com.google.devtools.j2objc.ast.AbstractTypeDeclaration;
import com.google.devtools.j2objc.ast.ArrayAccess;
import com.google.devtools.j2objc.ast.ArrayCreation;
import com.google.devtools.j2objc.ast.ArrayInitializer;
Expand Down Expand Up @@ -47,7 +48,6 @@
import com.google.devtools.j2objc.ast.TreeNode.Kind;
import com.google.devtools.j2objc.ast.TreeUtil;
import com.google.devtools.j2objc.ast.Type;
import com.google.devtools.j2objc.ast.TypeDeclaration;
import com.google.devtools.j2objc.ast.VariableDeclarationExpression;
import com.google.devtools.j2objc.ast.VariableDeclarationFragment;
import com.google.devtools.j2objc.ast.VariableDeclarationStatement;
Expand All @@ -68,7 +68,6 @@
import com.strobel.decompiler.languages.java.ast.IAstVisitor;
import com.strobel.decompiler.languages.java.ast.Keys;
import com.strobel.decompiler.patterns.Pattern;
import com.sun.tools.javac.code.Symbol;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -87,17 +86,18 @@
* Procyon AST visitor that converts method/constructor bodies.
*
* @author Manvith Narahari
* @author Tom Ball
*/
class MethodTranslator implements IAstVisitor<Void, TreeNode> {
private final JavacEnvironment parserEnv;
private final TypeUtil typeUtil;
private final ExecutableElement executableElement;
private final TypeDeclaration typeDecl;
private final AbstractTypeDeclaration typeDecl;
private final Map<String, VariableElement> localVariableTable;
private final boolean sourceDebugging;

public MethodTranslator(JavacEnvironment parserEnv, TranslationEnvironment translationEnv,
ExecutableElement executableElement, TypeDeclaration typeDecl,
ExecutableElement executableElement, AbstractTypeDeclaration typeDecl,
Map<String, VariableElement> localVariableTable) {
this.parserEnv = parserEnv;
this.typeUtil = translationEnv.typeUtil();
Expand Down Expand Up @@ -150,11 +150,7 @@ private TypeMirror resolve(TypeReference typeRef) {
}
String typeName = typeRef.getFullName();
Element element = parserEnv.resolve(typeName);
if (element instanceof TypeElement && ((Symbol.ClassSymbol) element).classfile == null) {
// Should never happen, since all types for the classfile this method
// is from should have been previously loaded by javac.
throw new AssertionError("failed resolving type: " + typeName);
}
// TODO(tball): element is raw, any support for type parameters needed?
return element.asType();
}

Expand Down Expand Up @@ -192,7 +188,7 @@ public TreeNode visitInvocationExpression(
}
throw new AssertionError("not implemented");
}

private ExecutableElement findConstructor(TypeElement type, MethodDefinition methodDef) {
String signature = methodDef.getSignature();
String erasedSignature = methodDef.getErasedSignature();
Expand Down
Expand Up @@ -144,7 +144,8 @@ private void processJarFile(String filename) {
while (enumerator.hasMoreElements()) {
ZipEntry entry = enumerator.nextElement();
String internalPath = entry.getName();
if (internalPath.endsWith(".java")) {
if (internalPath.endsWith(".java")
|| (options.translateClassfiles() && internalPath.endsWith(".class"))) {
// Extract JAR file to a temporary directory
File outputFile = options.fileUtil().extractZipEntry(tempDir, zfile, entry);
InputFile newFile = new RegularInputFile(outputFile.getAbsolutePath(), internalPath);
Expand Down
Expand Up @@ -32,7 +32,7 @@
import java.util.logging.Logger;

/**
* Preprocesses each input file in the batch.
* Preprocesses each Java file in the batch.
*/
public class InputFilePreprocessor {

Expand All @@ -49,7 +49,9 @@ public InputFilePreprocessor(Parser parser) {

public void processInputs(Iterable<ProcessingContext> inputs) {
for (ProcessingContext input : inputs) {
processInput(input);
if (input.getFile().getUnitName().endsWith(".java")) {
processInput(input);
}
}
}

Expand Down

0 comments on commit f9da788

Please sign in to comment.