Got rid of ModuleDescription intermediate entity.

This commit is contained in:
Evgeny Gerashchenko
2014-07-08 14:51:17 +04:00
parent 40703c125c
commit c4573b8c5a
8 changed files with 91 additions and 221 deletions
+1
View File
@@ -8,6 +8,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
</component>
</module>
@@ -1,112 +0,0 @@
/*
* 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.cli.common.modules;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* This interface duplicates {@link kotlin.modules.Module}, because cli-common should not depend on kotlin-runtime.jar
*/
public interface ModuleDescription {
@NotNull
String getModuleName();
@NotNull
String getOutputDir();
@NotNull
List<String> getSourceFiles();
@NotNull
List<String> getClasspathRoots();
@NotNull
List<String> getAnnotationsRoots();
class Impl implements ModuleDescription {
private String name;
private String outputDir;
private final List<String> sources = new SmartList<String>();
private final List<String> classpath = new SmartList<String>();
private final List<String> annotations = new SmartList<String>();
public void setName(String name) {
this.name = name;
}
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
public void addSourcePath(String path) {
sources.add(path);
}
public void addClassPath(String path) {
classpath.add(path);
}
public void addAnnotationPath(String path) {
annotations.add(path);
}
@NotNull
@Override
public String getModuleName() {
return name;
}
@NotNull
@Override
public String getOutputDir() {
return outputDir;
}
@NotNull
@Override
public List<String> getSourceFiles() {
return sources;
}
@NotNull
@Override
public List<String> getClasspathRoots() {
return classpath;
}
@NotNull
@Override
public List<String> getAnnotationsRoots() {
return annotations;
}
@Override
public String toString() {
return name +
"\n\toutputDir=" + outputDir +
"\n\tsources=" + sources +
"\n\tclasspath=" + classpath +
"\n\tannotations=" + annotations;
}
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2010-2014 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.cli.common.modules;
import kotlin.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
public class ModuleScriptData {
public static final ModuleScriptData EMPTY = new ModuleScriptData(Collections.<Module>emptyList(), null);
@Nullable
private final String incrementalCacheDir;
@NotNull
private final List<Module> modules;
@NotNull
public List<Module> getModules() {
return modules;
}
@Nullable
public String getIncrementalCacheDir() {
return incrementalCacheDir;
}
public ModuleScriptData(@NotNull List<Module> modules, @Nullable String incrementalCacheDir) {
this.incrementalCacheDir = incrementalCacheDir;
this.modules = modules;
}
}
@@ -16,11 +16,14 @@
package org.jetbrains.jet.cli.common.modules;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.StreamUtil;
import com.intellij.util.SmartList;
import kotlin.modules.Module;
import kotlin.modules.ModuleBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil;
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -29,11 +32,10 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.*;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.*;
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.*;
import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.ERROR;
public class ModuleXmlParser {
@@ -48,7 +50,7 @@ public class ModuleXmlParser {
public static final String EXTERNAL_ANNOTATIONS = "externalAnnotations";
@NotNull
public static Pair<List<ModuleDescription>, String> parseModuleDescriptionsAndIncrementalCacheDir(
public static ModuleScriptData parseModuleScript(
@NotNull String xmlFile,
@NotNull MessageCollector messageCollector
) {
@@ -60,7 +62,7 @@ public class ModuleXmlParser {
}
catch (FileNotFoundException e) {
MessageCollectorUtil.reportException(messageCollector, e);
return Pair.create(Collections.<ModuleDescription>emptyList(), null);
return ModuleScriptData.EMPTY;
}
finally {
StreamUtil.closeStream(stream);
@@ -69,7 +71,7 @@ public class ModuleXmlParser {
private final MessageCollector messageCollector;
private String incrementalCacheDir;
private final List<ModuleDescription> descriptions = new SmartList<ModuleDescription>();
private final List<Module> modules = new SmartList<Module>();
private DefaultHandler currentState;
private ModuleXmlParser(@NotNull MessageCollector messageCollector) {
@@ -80,7 +82,7 @@ public class ModuleXmlParser {
this.currentState = currentState;
}
private Pair<List<ModuleDescription>, String> parse(@NotNull InputStream xml) {
private ModuleScriptData parse(@NotNull InputStream xml) {
try {
setCurrentState(initial);
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
@@ -91,7 +93,7 @@ public class ModuleXmlParser {
return currentState;
}
});
return Pair.create(descriptions, incrementalCacheDir);
return new ModuleScriptData(modules, incrementalCacheDir);
}
catch (ParserConfigurationException e) {
MessageCollectorUtil.reportException(messageCollector, e);
@@ -102,7 +104,7 @@ public class ModuleXmlParser {
catch (IOException e) {
MessageCollectorUtil.reportException(messageCollector, e);
}
return Pair.create(Collections.<ModuleDescription>emptyList(), null);
return ModuleScriptData.EMPTY;
}
private final DefaultHandler initial = new DefaultHandler() {
@@ -140,27 +142,25 @@ public class ModuleXmlParser {
private class InsideModule extends DefaultHandler {
private final ModuleDescription.Impl moduleDescription;
private final ModuleBuilder moduleBuilder;
private InsideModule(String name, String outputDir) {
this.moduleDescription = new ModuleDescription.Impl();
this.moduleDescription.setName(name);
this.moduleDescription.setOutputDir(outputDir);
descriptions.add(moduleDescription);
this.moduleBuilder = new ModuleBuilder(name, outputDir);
modules.add(moduleBuilder);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (SOURCES.equalsIgnoreCase(qName)) {
String path = getAttribute(attributes, PATH, qName);
moduleDescription.addSourcePath(path);
moduleBuilder.addSourceFiles(path);
}
else if (CLASSPATH.equalsIgnoreCase(qName)) {
String path = getAttribute(attributes, PATH, qName);
moduleDescription.addClassPath(path);
moduleBuilder.addClasspathEntry(path);
}
else if (EXTERNAL_ANNOTATIONS.equalsIgnoreCase(qName)) {
String path = getAttribute(attributes, PATH, qName);
moduleDescription.addAnnotationPath(path);
moduleBuilder.addAnnotationsPathEntry(path);
}
else {
throw createError(qName);