Skip to content

Commit

Permalink
Enable kotlin in the MOE codebase expressions package, using data cla…
Browse files Browse the repository at this point in the history
…sses in place of @autovalue.

In the process, merge AbstractExpression with Expression, as AE is a needless layer.  Also, remove BinaryExpression which was needed for the validation logic, but after some consideration, that validation logic is overzealous, and all the Expression creation is basically local to the expressions package (except for RepositoryExpression which is the base case anyway). The whole validation bit was just overengineered.

Note: This definitely breaks the opensource, despite my attempts to make it work.  I've definitely updated the maven stuff, and it ought to work, but it's got its issues. I'm finding it slow going, fixing it by rebuilding MOE stuff, so I'm going to take this as a two-pronged approach, namely get this in and working internally, and then fixing the external build in a separate commit (possibly by fixing hte maven bits, or possibly my migrating to bazel).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=208061385
  • Loading branch information
cgruber committed Sep 4, 2018
1 parent 7b4d217 commit 4de8f47
Show file tree
Hide file tree
Showing 46 changed files with 532 additions and 636 deletions.
66 changes: 66 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</description>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
Expand Down Expand Up @@ -90,6 +94,68 @@
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals> <goal>kapt</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class CodebaseMerger {
public MergeResult merge(Codebase original, Codebase modified, Codebase destination) {
MergeResult.Builder resultBuilder = MergeResult.builder();
File mergedDir = filesystem.getTemporaryDirectory("merged_codebase_");
RepositoryExpression mergedExpression = RepositoryExpression.create("merged");
RepositoryExpression mergedExpression = new RepositoryExpression("merged");
resultBuilder.setMergedCodebase(Codebase.create(mergedDir, "merged", mergedExpression));
Set<String> filesToMerge = Sets.union(findFiles(destination), findFiles(modified));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class EditedCodebaseProcessor implements CodebaseProcessor<EditExpression
@Override
public Codebase createCodebase(EditExpression expression, ProjectContext context)
throws CodebaseCreationError {
Codebase codebaseToEdit = expressionEngine.createCodebase(expression.operand(), context);
String editorName = expression.operation().term().identifier();
Codebase codebaseToEdit = expressionEngine.createCodebase(expression.getOperand(), context);
String editorName = expression.getOperation().getTerm().getIdentifier();
Editor editor = context.editors().get(editorName);
if (editor == null) {
throw new CodebaseCreationError("no editor %s", editorName);
Expand All @@ -34,7 +34,8 @@ public Codebase createCodebase(EditExpression expression, ProjectContext context
try (Task task =
ui.newTask(
"edit", "Editing %s with editor %s", codebaseToEdit.path(), editor.getDescription())) {
return task.keep(editor.edit(codebaseToEdit, expression.operation().term().options()))
return task.keep(
editor.edit(codebaseToEdit, expression.getOperation().getTerm().getOptions()))
.copyWithExpression(expression);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RepositoryCodebaseProcessor implements CodebaseProcessor<Repository
@Override
public Codebase createCodebase(RepositoryExpression expression, ProjectContext context)
throws CodebaseCreationError {
String repositoryName = expression.term().identifier();
String repositoryName = expression.getTerm().getIdentifier();
CodebaseCreator codebaseCreator =
(repositoryName.equals("file"))
? fileCodebaseCreator.get() // for testing
Expand All @@ -37,7 +37,7 @@ public Codebase createCodebase(RepositoryExpression expression, ProjectContext c
try (Task createTask =
ui.newTask("create_codebase", "Creating codebase for '%s'", expression)) {
try {
return createTask.keep(codebaseCreator.create(expression.term().options()));
return createTask.keep(codebaseCreator.create(expression.getTerm().getOptions()));
} catch (CodebaseCreationError e) {
ui.message("%s", e);
createTask.result().append("Unable to create codebase " + this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public TranslatedCodebaseProcessor(Ui ui, ExpressionEngine expressionEngine) {
@Override
public Codebase createCodebase(TranslateExpression expression, ProjectContext context)
throws CodebaseCreationError {
Codebase codebaseToTranslate = expressionEngine.createCodebase(expression.operand(), context);
String toProjectSpace = expression.operation().term().identifier();
Codebase codebaseToTranslate =
expressionEngine.createCodebase(expression.getOperand(), context);
String toProjectSpace = expression.getOperation().getTerm().getIdentifier();
TranslationPath path =
TranslationPath.create(codebaseToTranslate.projectSpace(), toProjectSpace);
TranslationPipeline translator = context.translators().get(path);
Expand All @@ -50,7 +51,7 @@ public Codebase createCodebase(TranslateExpression expression, ProjectContext co

Codebase translatedCodebase =
translator.translate(
codebaseToTranslate, expression.operation().term().options(), context);
codebaseToTranslate, expression.getOperation().getTerm().getOptions(), context);

// Don't mark the translated codebase for persistence if it wasn't allocated by the
// Translator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public WriterFactory(Ui ui) {
*/
public Writer createWriter(RepositoryExpression expression, ProjectContext context)
throws WritingError {
RepositoryType repositoryType = context.getRepository(expression.term().identifier());
RepositoryType repositoryType = context.getRepository(expression.getTerm().getIdentifier());
WriterCreator wc = repositoryType.writerCreator();

try (Task task = ui.newTask("create_writer", "Creating Writer \"%s\"", expression.term())) {
return task.keep(wc.create(expression.term().options()));
try (Task task = ui.newTask("create_writer", "Creating Writer \"%s\"", expression.getTerm())) {
return task.keep(wc.create(expression.getTerm().getOptions()));
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2011 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.devtools.moe.client.codebase.expressions

/**
* An expression encapsulating the transformation of the given Expression's Codebase via the
* application of an [com.google.devtools.moe.client.translation.editors.Editor]. For example,
*
* <pre>`new RepositoryExpression("myRepo").editWith("myEditor", { "option1": "foo" })
`</pre> *
*
* returns an EditExpression for
*
* <pre>`"myRepo|myEditor(option1=foo)"`</pre>
*
* .
*/
data class EditExpression
internal constructor(val operand: Expression, val operation: Operation) : Expression() {
override fun toString(): String = "$operand$operation"
}
Loading

0 comments on commit 4de8f47

Please sign in to comment.