Extracted OutputFileFactory interface.
This commit is contained in:
Generated
+1
@@ -24,6 +24,7 @@
|
||||
<element id="directory" name="jet">
|
||||
<element id="dir-copy" path="$PROJECT_DIR$/idea/builtinsSrc/jet" />
|
||||
</element>
|
||||
<element id="module-output" name="backend-common" />
|
||||
</element>
|
||||
<element id="library" level="project" name="js-libs" />
|
||||
<element id="library" level="project" name="javax.inject" />
|
||||
|
||||
Generated
+1
@@ -6,6 +6,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/android-tests/android-tests.iml" filepath="$PROJECT_DIR$/compiler/android-tests/android-tests.iml" group="compiler" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/annotations-ext/annotations-ext.iml" filepath="$PROJECT_DIR$/compiler/annotations-ext/annotations-ext.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/backend/backend.iml" filepath="$PROJECT_DIR$/compiler/backend/backend.iml" group="compiler/java" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/backend-common/backend-common.iml" filepath="$PROJECT_DIR$/compiler/backend-common/backend-common.iml" group="compiler" />
|
||||
<module fileurl="file://$PROJECT_DIR$/build-tools/build-tools.iml" filepath="$PROJECT_DIR$/build-tools/build-tools.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/cli/cli.iml" filepath="$PROJECT_DIR$/compiler/cli/cli.iml" group="compiler/cli" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/cli/cli-common/cli-common.iml" filepath="$PROJECT_DIR$/compiler/cli/cli-common/cli-common.iml" group="compiler/cli" />
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
<include name="core/descriptor.loader.java/src"/>
|
||||
<include name="compiler/frontend.java/src"/>
|
||||
<include name="core/serialization.java/src"/>
|
||||
<include name="compiler/backend-common/src"/>
|
||||
<include name="compiler/backend/src"/>
|
||||
<include name="compiler/cli/src"/>
|
||||
<include name="compiler/cli/cli-common/src"/>
|
||||
@@ -139,6 +140,7 @@
|
||||
<fileset dir="core/descriptors/src"/>
|
||||
<fileset dir="core/descriptor.loader.java/src"/>
|
||||
<fileset dir="compiler/frontend.java/src"/>
|
||||
<fileset dir="compiler/backend-common/src"/>
|
||||
<fileset dir="compiler/backend/src"/>
|
||||
<fileset dir="compiler/cli/src"/>
|
||||
<fileset dir="j2k/src"/>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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
|
||||
|
||||
import java.io.File
|
||||
|
||||
public trait OutputFileFactory {
|
||||
public val outputFiles: List<String>
|
||||
|
||||
public fun getSourceFiles(file: String): List<File>
|
||||
public fun asBytes(file: String): ByteArray
|
||||
public fun asText(file: String): String
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
<orderEntry type="module" module-name="serialization.java" />
|
||||
<orderEntry type="module" module-name="descriptor.loader.java" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="backend-common" exported="" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.OutputFileFactory;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
@@ -38,7 +39,7 @@ import static org.jetbrains.jet.codegen.AsmUtil.asmTypeByFqNameWithoutInnerClass
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||
import static org.jetbrains.jet.lang.resolve.java.PackageClassUtils.getPackageClassFqName;
|
||||
|
||||
public final class ClassFileFactory extends GenerationStateAware {
|
||||
public final class ClassFileFactory extends GenerationStateAware implements OutputFileFactory {
|
||||
@NotNull private ClassBuilderFactory builderFactory;
|
||||
|
||||
private final Map<FqName, NamespaceCodegen> ns2codegen = new HashMap<FqName, NamespaceCodegen>();
|
||||
@@ -78,21 +79,25 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asText(String file) {
|
||||
done();
|
||||
return builderFactory.asText(generators.get(file).classBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asBytes(String file) {
|
||||
done();
|
||||
return builderFactory.asBytes(generators.get(file).classBuilder);
|
||||
}
|
||||
|
||||
public List<String> files() {
|
||||
@Override
|
||||
public List<String> getOutputFiles() {
|
||||
done();
|
||||
return new ArrayList<String>(generators.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<File> getSourceFiles(String relativeClassFilePath) {
|
||||
ClassBuilderAndSourceFileList pair = generators.get(relativeClassFilePath);
|
||||
if (pair == null) {
|
||||
@@ -116,7 +121,7 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
public String createText() {
|
||||
StringBuilder answer = new StringBuilder();
|
||||
|
||||
List<String> files = files();
|
||||
List<String> files = getOutputFiles();
|
||||
for (String file : files) {
|
||||
// if (!file.startsWith("kotlin/")) {
|
||||
answer.append("@").append(file).append('\n');
|
||||
|
||||
@@ -33,7 +33,7 @@ public class GeneratedClassLoader extends URLClassLoader {
|
||||
@Override
|
||||
protected Class<?> findClass(@NotNull String name) throws ClassNotFoundException {
|
||||
String file = name.replace('.', '/') + ".class";
|
||||
if (state.files().contains(file)) {
|
||||
if (state.getOutputFiles().contains(file)) {
|
||||
byte[] bytes = state.asBytes(file);
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<orderEntry type="module" module-name="cli-common" exported="" />
|
||||
<orderEntry type="module" module-name="descriptor.loader.java" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="backend-common" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import jet.modules.AllModules;
|
||||
import jet.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.OutputFileFactory;
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.common.messages.*;
|
||||
import org.jetbrains.jet.cli.common.modules.ModuleDescription;
|
||||
@@ -178,7 +179,7 @@ public class CompileEnvironmentUtil {
|
||||
mainAttributes.putValue("Main-Class", mainClass.asString());
|
||||
}
|
||||
JarOutputStream stream = new JarOutputStream(fos, manifest);
|
||||
for (String file : factory.files()) {
|
||||
for (String file : factory.getOutputFiles()) {
|
||||
stream.putNextEntry(new JarEntry(file));
|
||||
stream.write(factory.asBytes(file));
|
||||
}
|
||||
@@ -252,11 +253,11 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
|
||||
public static void writeToOutputWithDirector(
|
||||
ClassFileFactory factory,
|
||||
OutputFileFactory factory,
|
||||
@NotNull OutputDirector outputDirector,
|
||||
@NotNull MessageCollector messageCollector
|
||||
) {
|
||||
List<String> files = factory.files();
|
||||
List<String> files = factory.getOutputFiles();
|
||||
for (String file : files) {
|
||||
List<File> sourceFiles = factory.getSourceFiles(file);
|
||||
File target = new File(outputDirector.getOutputDirectory(sourceFiles), file);
|
||||
|
||||
@@ -241,7 +241,7 @@ public class ReplInterpreter {
|
||||
compileScript(psiFile.getScript(), scriptClassType, earlierScripts, generationState,
|
||||
CompilationErrorHandler.THROW_EXCEPTION);
|
||||
|
||||
for (String file : generationState.getFactory().files()) {
|
||||
for (String file : generationState.getFactory().getOutputFiles()) {
|
||||
classLoader.addClass(JvmClassName.byInternalName(file.replaceFirst("\\.class$", "")), generationState.getFactory().asBytes(file));
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -77,7 +77,7 @@ public class KotlinJavaFileStubProvider implements CachedValueProvider<PsiJavaFi
|
||||
public void generate(@NotNull GenerationState state, @NotNull Collection<JetFile> files) {
|
||||
NamespaceCodegen codegen = state.getFactory().forNamespace(packageFqName, files);
|
||||
codegen.generate(CompilationErrorHandler.THROW_EXCEPTION);
|
||||
state.getFactory().files();
|
||||
state.getFactory().getOutputFiles();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class KotlinJavaFileStubProvider implements CachedValueProvider<PsiJavaFi
|
||||
public void generate(@NotNull GenerationState state, @NotNull Collection<JetFile> files) {
|
||||
NamespaceCodegen namespaceCodegen = state.getFactory().forNamespace(getPackageFqName(), files);
|
||||
namespaceCodegen.generateClassOrObject(classOrObject);
|
||||
state.getFactory().files();
|
||||
state.getFactory().getOutputFiles();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
||||
|
||||
String modifiedTestName = ktFile.getName().replace(".kt", ".class");
|
||||
boolean isClassFound = false;
|
||||
for (String filename : factory.files()) {
|
||||
for (String filename : factory.getOutputFiles()) {
|
||||
if (filename.equals(modifiedTestName)) {
|
||||
isClassFound = true;
|
||||
ClassReader cr = new ClassReader(factory.asBytes(filename));
|
||||
|
||||
@@ -40,7 +40,7 @@ public class DxChecker {
|
||||
array[0] = "testArgs";
|
||||
arguments.parse(array);
|
||||
|
||||
for (String file : factory.files()) {
|
||||
for (String file : factory.getOutputFiles()) {
|
||||
try {
|
||||
CfTranslator.translate(file, factory.asBytes(file), arguments.cfOptions, arguments.dexOptions);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class KotlinPackageFragmentAnnotationTest extends CodegenTestCase {
|
||||
String facadeFileName = JvmClassName.byFqNameWithoutInnerClasses(PackageClassUtils.getPackageClassFqName(NAMESPACE_NAME)).getInternalName() + ".class";
|
||||
|
||||
ClassFileFactory factory = generateClassesInFile();
|
||||
for (String fileName : factory.files()) {
|
||||
for (String fileName : factory.getOutputFiles()) {
|
||||
if (!fileName.equals(facadeFileName)) {
|
||||
// The file which is not a facade is a package fragment
|
||||
String fqName = fileName.substring(0, fileName.length() - ".class".length()).replace('/', '.');
|
||||
@@ -60,6 +60,6 @@ public class KotlinPackageFragmentAnnotationTest extends CodegenTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
fail("No package fragment was found: " + factory.files());
|
||||
fail("No package fragment was found: " + factory.getOutputFiles());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class LineNumberTest extends TestCaseWithTmpdir {
|
||||
private static List<Integer> extractActualLineNumbersFromBytecode(@NotNull GenerationState state, boolean testFunInvoke) {
|
||||
ClassFileFactory factory = state.getFactory();
|
||||
List<Integer> actualLineNumbers = Lists.newArrayList();
|
||||
for (String filename : factory.files()) {
|
||||
for (String filename : factory.getOutputFiles()) {
|
||||
if (PackageClassUtils.isPackageClassFqName(new FqName(FileUtil.getNameWithoutExtension(filename)))) {
|
||||
// Don't test line numbers in *Package facade classes
|
||||
continue;
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase
|
||||
public void testTopLevel() {
|
||||
loadFile();
|
||||
String packageClassName = PackageClassUtils.getPackageClassName(FqName.ROOT);
|
||||
for (String fileName : generateClassesInFile().files()) {
|
||||
for (String fileName : generateClassesInFile().getOutputFiles()) {
|
||||
if (fileName.startsWith(packageClassName) && !fileName.equals(packageClassName + ".class")) {
|
||||
// This should be package$src class
|
||||
Class<?> a = generateClass(fileName.substring(0, fileName.length() - ".class".length()));
|
||||
|
||||
@@ -82,7 +82,7 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
||||
List<TestedObject> testedObjects = parseExpectedTestedObject(fileText);
|
||||
for (TestedObject testedObject : testedObjects) {
|
||||
String className = null;
|
||||
for (String filename : factory.files()) {
|
||||
for (String filename : factory.getOutputFiles()) {
|
||||
if (testedObject.isFullContainingClassName && filename.equals(testedObject.containingClass + ".class")) {
|
||||
className = filename;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
|
||||
StringBuilder answer = new StringBuilder();
|
||||
|
||||
ClassFileFactory factory = state.getFactory();
|
||||
for (String filename : factory.files()) {
|
||||
for (String filename : factory.getOutputFiles()) {
|
||||
answer.append("// ================");
|
||||
answer.append(filename);
|
||||
answer.append(" =================\n");
|
||||
|
||||
@@ -128,7 +128,7 @@ public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||
|
||||
private static Map<String, ReferenceType> getReferenceMap(ClassFileFactory classFileFactory) {
|
||||
Map<String, ReferenceType> referencesByName = Maps.newHashMap();
|
||||
for (String classFileName : classFileFactory.files()) {
|
||||
for (String classFileName : classFileFactory.getOutputFiles()) {
|
||||
String name = classFileName.substring(0, classFileName.lastIndexOf('.'));
|
||||
referencesByName.put(name, new MockReferenceType(name));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user