diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/AbstractOutputItemCollector.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/AbstractOutputItemCollector.java new file mode 100644 index 00000000000..a1a0b675f5b --- /dev/null +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/AbstractOutputItemCollector.java @@ -0,0 +1,69 @@ +/* + * 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.compiler.runner; + +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public abstract class AbstractOutputItemCollector implements OutputItemsCollector { + private static final String FOR_SOURCE_PREFIX = "For source: "; + private static final String EMITTING_PREFIX = "Emitting: "; + private S currentSource; + private final List answer = ContainerUtil.newArrayList(); + private final List sources = ContainerUtil.newArrayList(); + + private final String outputPath; + + public AbstractOutputItemCollector(@NotNull String outputPath) { + this.outputPath = outputPath; + } + + @Override + public final void learn(String message) { + message = message.trim(); + if (message.startsWith(FOR_SOURCE_PREFIX)) { + String sourcePath = message.substring(FOR_SOURCE_PREFIX.length()); + currentSource = convertSource(sourcePath); + if (currentSource != null) { + sources.add(currentSource); + } + } + else if (message.startsWith(EMITTING_PREFIX)) { + if (currentSource != null) { + String resultPath = message.substring(EMITTING_PREFIX.length()); + R item = convertResult(outputPath + "/" + resultPath, currentSource); + if (item != null) { + answer.add(item); + } + } + } + } + + protected abstract R convertResult(String resultPath, S correspondingSource); + + protected abstract S convertSource(String sourcePath); + + public List getOutputs() { + return answer; + } + + public List getSources() { + return sources; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java b/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java index e3b2f5bb3c0..bb93dc1a123 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java @@ -24,12 +24,10 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.compiler.runner.AbstractOutputItemCollector; import org.jetbrains.jet.compiler.runner.CompilerEnvironment; -import org.jetbrains.jet.compiler.runner.OutputItemsCollector; import java.io.File; -import java.util.ArrayList; -import java.util.List; /** * @author Pavel Talanov @@ -51,42 +49,21 @@ public final class CompilerUtils { return new File(file.getPath()); } - public static class OutputItemsCollectorImpl implements OutputItemsCollector { - private static final String FOR_SOURCE_PREFIX = "For source: "; - private static final String EMITTING_PREFIX = "Emitting: "; - private final String outputPath; - private VirtualFile currentSource; - private List answer = new ArrayList(); - private List sources = new ArrayList(); + public static class OutputItemsCollectorImpl extends AbstractOutputItemCollector { - public OutputItemsCollectorImpl(String outputPath) { - this.outputPath = outputPath; + public OutputItemsCollectorImpl(@NotNull String outputPath) { + super(outputPath); } @Override - public void learn(String message) { - message = message.trim(); - if (message.startsWith(FOR_SOURCE_PREFIX)) { - currentSource = LocalFileSystem.getInstance().findFileByPath(message.substring(FOR_SOURCE_PREFIX.length())); - if (currentSource != null) { - sources.add(currentSource); - } - } - else if (message.startsWith(EMITTING_PREFIX)) { - if (currentSource != null) { - OutputItemImpl item = new OutputItemImpl(outputPath + "/" + message.substring(EMITTING_PREFIX.length()), currentSource); - LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(item.getOutputPath())); - answer.add(item); - } - } + protected TranslatingCompiler.OutputItem convertResult(String resultPath, VirtualFile correspondingSource) { + LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(resultPath)); + return new OutputItemImpl(resultPath, correspondingSource); } - public List getOutputs() { - return answer; - } - - public List getSources() { - return sources; + @Override + protected VirtualFile convertSource(String sourcePath) { + return LocalFileSystem.getInstance().findFileByPath(sourcePath); } } }