J2K: reverted temporary fix after update to IDEA 132.325 EAP -- removed JavaToKotlinTranslator#NEVER_CHANGE.
This commit is contained in:
@@ -20,7 +20,6 @@ import com.intellij.core.JavaCoreProjectEnvironment;
|
|||||||
import com.intellij.lang.java.JavaLanguage;
|
import com.intellij.lang.java.JavaLanguage;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.ProjectRootModificationTracker;
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.PsiFileFactory;
|
import com.intellij.psi.PsiFileFactory;
|
||||||
@@ -44,13 +43,6 @@ public class JavaToKotlinTranslator {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*package*/ static final ProjectRootModificationTracker NEVER_CHANGED = new ProjectRootModificationTracker() {
|
|
||||||
@Override
|
|
||||||
public long getModificationCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private JavaToKotlinTranslator() {
|
private JavaToKotlinTranslator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +66,6 @@ public class JavaToKotlinTranslator {
|
|||||||
JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(DISPOSABLE);
|
JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(DISPOSABLE);
|
||||||
JavaCoreProjectEnvironment javaCoreEnvironment = new JavaCoreProjectEnvironment(DISPOSABLE, applicationEnvironment);
|
JavaCoreProjectEnvironment javaCoreEnvironment = new JavaCoreProjectEnvironment(DISPOSABLE, applicationEnvironment);
|
||||||
|
|
||||||
javaCoreEnvironment.getProject().registerService(ProjectRootModificationTracker.class, NEVER_CHANGED);
|
|
||||||
|
|
||||||
javaCoreEnvironment.addJarToClassPath(PathUtil.findRtJar());
|
javaCoreEnvironment.addJarToClassPath(PathUtil.findRtJar());
|
||||||
File annotations = findAnnotations();
|
File annotations = findAnnotations();
|
||||||
if (annotations != null && annotations.exists()) {
|
if (annotations != null && annotations.exists()) {
|
||||||
@@ -167,6 +157,8 @@ public class JavaToKotlinTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used in the Kotlin Web Demo.
|
||||||
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public static String translateToKotlin(String code) {
|
public static String translateToKotlin(String code) {
|
||||||
return generateKotlinCode(code);
|
return generateKotlinCode(code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.j2k;
|
package org.jetbrains.jet.j2k;
|
||||||
|
|
||||||
import com.intellij.mock.MockProject;
|
|
||||||
import com.intellij.openapi.roots.ProjectRootModificationTracker;
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.PsiJavaFile;
|
import com.intellij.psi.PsiJavaFile;
|
||||||
@@ -35,10 +33,12 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations;
|
import static org.jetbrains.jet.JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations;
|
||||||
|
|
||||||
|
@SuppressWarnings("JUnitTestCaseWithNoTests")
|
||||||
public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase {
|
public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase {
|
||||||
private final String myDataPath;
|
private final String myDataPath;
|
||||||
private final String myName;
|
private final String myName;
|
||||||
|
|
||||||
|
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||||
public StandaloneJavaToKotlinConverterTest(String dataPath, String name) {
|
public StandaloneJavaToKotlinConverterTest(String dataPath, String name) {
|
||||||
myDataPath = dataPath;
|
myDataPath = dataPath;
|
||||||
myName = name;
|
myName = name;
|
||||||
@@ -48,10 +48,7 @@ public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase {
|
|||||||
protected void runTest() throws Throwable {
|
protected void runTest() throws Throwable {
|
||||||
JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
|
JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
|
||||||
|
|
||||||
MockProject project = (MockProject) jetCoreEnvironment.getProject();
|
Converter converter = new Converter(jetCoreEnvironment.getProject());
|
||||||
project.registerService(ProjectRootModificationTracker.class, JavaToKotlinTranslator.NEVER_CHANGED);
|
|
||||||
|
|
||||||
Converter converter = new Converter(project);
|
|
||||||
|
|
||||||
String javaPath = "j2k/tests/testData/" + getTestFilePath();
|
String javaPath = "j2k/tests/testData/" + getTestFilePath();
|
||||||
String kotlinPath = javaPath.replace(".jav", ".kt");
|
String kotlinPath = javaPath.replace(".jav", ".kt");
|
||||||
@@ -127,7 +124,7 @@ public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String fileToKotlin(Converter converter, @NotNull String text) {
|
private static String fileToKotlin(Converter converter, @NotNull String text) {
|
||||||
return generateKotlinCode(converter, JavaToKotlinTranslator.createFile(converter.getProject(), text));
|
return generateKotlinCode(converter, JavaToKotlinTranslator.createFile(converter.getProject(), text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +138,7 @@ public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String methodToKotlin(Converter converter, String text) throws IOException {
|
private static String methodToKotlin(Converter converter, String text) throws IOException {
|
||||||
String result = fileToKotlin(converter, "final class C {" + text + "}")
|
String result = fileToKotlin(converter, "final class C {" + text + "}")
|
||||||
.replaceAll("class C\\(\\) \\{", "");
|
.replaceAll("class C\\(\\) \\{", "");
|
||||||
result = result.substring(0, result.lastIndexOf("}"));
|
result = result.substring(0, result.lastIndexOf("}"));
|
||||||
@@ -149,7 +146,7 @@ public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String statementToKotlin(Converter converter, String text) throws Exception {
|
private static String statementToKotlin(Converter converter, String text) throws Exception {
|
||||||
String result = methodToKotlin(converter, "void main() {" + text + "}");
|
String result = methodToKotlin(converter, "void main() {" + text + "}");
|
||||||
int pos = result.lastIndexOf("}");
|
int pos = result.lastIndexOf("}");
|
||||||
result = result.substring(0, pos).replaceFirst("fun main\\(\\) : Unit \\{", "");
|
result = result.substring(0, pos).replaceFirst("fun main\\(\\) : Unit \\{", "");
|
||||||
@@ -157,7 +154,7 @@ public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String expressionToKotlin(Converter converter, String code) throws Exception {
|
private static String expressionToKotlin(Converter converter, String code) throws Exception {
|
||||||
String result = statementToKotlin(converter, "Object o =" + code + "}");
|
String result = statementToKotlin(converter, "Object o =" + code + "}");
|
||||||
result = result.replaceFirst("var o : Any\\? =", "");
|
result = result.replaceFirst("var o : Any\\? =", "");
|
||||||
return prettify(result);
|
return prettify(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user