J2K Translator migrated onto Leda

This commit is contained in:
Andrey Breslav
2012-07-24 22:29:07 +04:00
parent cee77c3b7e
commit d8632f81aa
2 changed files with 52 additions and 47 deletions
@@ -1,21 +1,22 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* 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.
*/
* Copyright 2010-2012 JetBrains s.r.o.
*
* 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 org.jetbrains.jet.j2k;
import com.intellij.core.JavaCoreEnvironment;
import com.intellij.core.JavaCoreApplicationEnvironment;
import com.intellij.core.JavaCoreProjectEnvironment;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.text.StringUtil;
@@ -35,41 +36,45 @@ import java.net.URL;
import java.net.URLClassLoader;
/**
* @author ignatov
*/
* @author ignatov
*/
public class JavaToKotlinTranslator {
private JavaToKotlinTranslator() {
}
private static final Disposable DISPOSABLE = new Disposable() {
@Override
public void dispose() {
}
};
private static final Converter CONVERTER = new Converter();
private JavaToKotlinTranslator() {
}
@Nullable
private static PsiFile createFile(@NotNull String text) {
JavaCoreEnvironment javaCoreEnvironment = setUpJavaCoreEnvironment();
JavaCoreProjectEnvironment javaCoreEnvironment = setUpJavaCoreEnvironment();
return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText(
"test.java", JavaLanguage.INSTANCE, text
);
}
@Nullable
static PsiFile createFile(@NotNull JavaCoreEnvironment javaCoreEnvironment, @NotNull String text) {
static PsiFile createFile(@NotNull JavaCoreProjectEnvironment javaCoreEnvironment, @NotNull String text) {
return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText(
"test.java", JavaLanguage.INSTANCE, text
);
}
@NotNull
static JavaCoreEnvironment setUpJavaCoreEnvironment() {
JavaCoreEnvironment javaCoreEnvironment = new JavaCoreEnvironment(new Disposable() {
@Override
public void dispose() {
}
});
static JavaCoreProjectEnvironment setUpJavaCoreEnvironment() {
JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(DISPOSABLE);
JavaCoreProjectEnvironment javaCoreEnvironment = new JavaCoreProjectEnvironment(DISPOSABLE, applicationEnvironment);
javaCoreEnvironment.addToClasspath(findRtJar());
javaCoreEnvironment.addJarToClassPath(findRtJar());
File annotations = findAnnotations();
if (annotations != null && annotations.exists()) {
javaCoreEnvironment.addToClasspath(annotations);
javaCoreEnvironment.addJarToClassPath(annotations);
}
return javaCoreEnvironment;
}
@@ -1,22 +1,22 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* 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.
*/
* Copyright 2010-2012 JetBrains s.r.o.
*
* 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 org.jetbrains.jet.j2k;
import com.intellij.core.JavaCoreEnvironment;
import com.intellij.core.JavaCoreProjectEnvironment;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaFile;
@@ -31,13 +31,13 @@ import java.io.File;
import java.io.IOException;
/**
* @author ignatov
*/
* @author ignatov
*/
public class StandaloneJavaToKotlinConverterTest extends TestCase {
private final String myDataPath;
private final String myName;
@NotNull
private final static JavaCoreEnvironment myJavaCoreEnvironment = JavaToKotlinTranslator.setUpJavaCoreEnvironment();
private final static JavaCoreProjectEnvironment myJavaCoreEnvironment = JavaToKotlinTranslator.setUpJavaCoreEnvironment();
public StandaloneJavaToKotlinConverterTest(String dataPath, String name) {
myDataPath = dataPath;