Merge branch 'master' of github.com:JetBrains/kotlin
This commit is contained in:
Generated
+1
@@ -17,6 +17,7 @@
|
|||||||
<entry name="?*.jet" />
|
<entry name="?*.jet" />
|
||||||
<entry name="?*.ft" />
|
<entry name="?*.ft" />
|
||||||
<entry name="?*.kt" />
|
<entry name="?*.kt" />
|
||||||
|
<entry name="?*.template" />
|
||||||
</wildcardResourcePatterns>
|
</wildcardResourcePatterns>
|
||||||
<annotationProcessing enabled="false" useClasspath="true" />
|
<annotationProcessing enabled="false" useClasspath="true" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
Generated
+1
@@ -6,6 +6,7 @@
|
|||||||
<module fileurl="file://$PROJECT_DIR$/compiler/backend/backend.iml" filepath="$PROJECT_DIR$/compiler/backend/backend.iml" />
|
<module fileurl="file://$PROJECT_DIR$/compiler/backend/backend.iml" filepath="$PROJECT_DIR$/compiler/backend/backend.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/build-tools/build-tools.iml" filepath="$PROJECT_DIR$/build-tools/build-tools.iml" />
|
<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" />
|
<module fileurl="file://$PROJECT_DIR$/compiler/cli/cli.iml" filepath="$PROJECT_DIR$/compiler/cli/cli.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/compiler/integration-tests/compiler-integration-tests.iml" filepath="$PROJECT_DIR$/compiler/integration-tests/compiler-integration-tests.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/compiler/tests/compiler-tests.iml" filepath="$PROJECT_DIR$/compiler/tests/compiler-tests.iml" />
|
<module fileurl="file://$PROJECT_DIR$/compiler/tests/compiler-tests.iml" filepath="$PROJECT_DIR$/compiler/tests/compiler-tests.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/compiler/frontend/frontend.iml" filepath="$PROJECT_DIR$/compiler/frontend/frontend.iml" />
|
<module fileurl="file://$PROJECT_DIR$/compiler/frontend/frontend.iml" filepath="$PROJECT_DIR$/compiler/frontend/frontend.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" />
|
<module fileurl="file://$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" />
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@
|
|||||||
<property name="plugin.xml.bk" value="${plugin.xml}.bk"/>
|
<property name="plugin.xml.bk" value="${plugin.xml}.bk"/>
|
||||||
<property name="plugin.xml.versioned" value="${plugin.xml}.versioned" />
|
<property name="plugin.xml.versioned" value="${plugin.xml}.versioned" />
|
||||||
|
|
||||||
<property name="compiler.version.java" value="compiler/cli/src/org/jetbrains/jet/cli/CompilerVersion.java"/>
|
<property name="compiler.version.java" value="compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerVersion.java"/>
|
||||||
<property name="compiler.version.java.bk" value="${compiler.version.java}.bk"/>
|
<property name="compiler.version.java.bk" value="${compiler.version.java}.bk"/>
|
||||||
<property name="compiler.version.java.versioned" value="${compiler.version.java}.versioned" />
|
<property name="compiler.version.java.versioned" value="${compiler.version.java}.versioned" />
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ classpath="$classpath:$root/lib/*:$ideaRoot/lib/*:$ideaRoot/lib/rt/*"
|
|||||||
|
|
||||||
exec java $JAVA_OPTS \
|
exec java $JAVA_OPTS \
|
||||||
-classpath "$classpath" \
|
-classpath "$classpath" \
|
||||||
org.jetbrains.jet.cli.KotlinCompiler \
|
org.jetbrains.jet.cli.jvm.K2JVMCompiler \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# vim: set ts=4 sw=4 et:
|
# vim: set ts=4 sw=4 et:
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.apache.tools.ant.Task;
|
|||||||
import org.apache.tools.ant.types.Path;
|
import org.apache.tools.ant.types.Path;
|
||||||
import org.apache.tools.ant.types.Reference;
|
import org.apache.tools.ant.types.Reference;
|
||||||
import org.jetbrains.jet.buildtools.core.BytecodeCompiler;
|
import org.jetbrains.jet.buildtools.core.BytecodeCompiler;
|
||||||
import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<orderEntry type="module" module-name="cli" />
|
<orderEntry type="module" module-name="cli" />
|
||||||
<orderEntry type="library" name="intellij-core" level="project" />
|
<orderEntry type="library" name="intellij-core" level="project" />
|
||||||
<orderEntry type="module" module-name="frontend.java" />
|
<orderEntry type="module" module-name="frontend.java" />
|
||||||
|
<orderEntry type="module" module-name="runtime" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.buildtools.core;
|
package org.jetbrains.jet.buildtools.core;
|
||||||
|
|
||||||
|
import jet.modules.Module;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.compiler.*;
|
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||||
import org.jetbrains.jet.compiler.messages.MessageCollector;
|
import org.jetbrains.jet.cli.jvm.compiler.*;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ public class BytecodeCompiler {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of {@link org.jetbrains.jet.compiler.CompileEnvironmentConfiguration} instance using the arguments specified.
|
* Creates new instance of {@link org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration} instance using the arguments specified.
|
||||||
*
|
*
|
||||||
* @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty
|
* @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty
|
||||||
* @param classpath compilation classpath, only used if not null and not empty
|
* @param classpath compilation classpath, only used if not null and not empty
|
||||||
@@ -128,7 +130,7 @@ public class BytecodeCompiler {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code CompileEnvironment#compileModuleScript} wrapper.
|
* {@code CompileEnvironment#compileModules} wrapper.
|
||||||
*
|
*
|
||||||
* @param module compilation module file
|
* @param module compilation module file
|
||||||
* @param jar compilation destination jar
|
* @param jar compilation destination jar
|
||||||
@@ -139,7 +141,9 @@ public class BytecodeCompiler {
|
|||||||
public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
|
public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||||
try {
|
try {
|
||||||
CompileEnvironmentConfiguration env = env(stdlib, classpath);
|
CompileEnvironmentConfiguration env = env(stdlib, classpath);
|
||||||
boolean success = KotlinToJVMBytecodeCompiler.compileModuleScript(env, module, jar, null, includeRuntime);
|
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(module, env.getMessageCollector());
|
||||||
|
File directory = new File(module).getParentFile();
|
||||||
|
boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, jar, null, includeRuntime);
|
||||||
if ( ! success ) {
|
if ( ! success ) {
|
||||||
throw new CompileEnvironmentException( errorMessage( module, false ));
|
throw new CompileEnvironmentException( errorMessage( module, false ));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
<target name="compileStdlib" depends="jar,jarLang,compileRT">
|
<target name="compileStdlib" depends="jar,jarLang,compileRT">
|
||||||
<mkdir dir="${output}/classes/stdlib"/>
|
<mkdir dir="${output}/classes/stdlib"/>
|
||||||
<java classname="org.jetbrains.jet.cli.KotlinCompiler" failonerror="true" fork="true">
|
<java classname="org.jetbrains.jet.cli.jvm.K2JVMCompiler" failonerror="true" fork="true">
|
||||||
<classpath>
|
<classpath>
|
||||||
<path refid="classpath"/>
|
<path refid="classpath"/>
|
||||||
<pathelement location="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
<pathelement location="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
<target name="compileJDKHeaders" depends="jar,jarLang">
|
<target name="compileJDKHeaders" depends="jar,jarLang">
|
||||||
<mkdir dir="${output}/classes/stdlib"/>
|
<mkdir dir="${output}/classes/stdlib"/>
|
||||||
<java classname="org.jetbrains.jet.cli.KotlinCompiler" failonerror="true">
|
<java classname="org.jetbrains.jet.cli.jvm.K2JVMCompiler" failonerror="true">
|
||||||
<classpath>
|
<classpath>
|
||||||
<path refid="classpath"/>
|
<path refid="classpath"/>
|
||||||
<pathelement location="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
<pathelement location="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
<target name="compileLang" depends="jar">
|
<target name="compileLang" depends="jar">
|
||||||
<mkdir dir="${output}/classes/lang"/>
|
<mkdir dir="${output}/classes/lang"/>
|
||||||
<java classname="org.jetbrains.jet.cli.KotlinCompiler" failonerror="true">
|
<java classname="org.jetbrains.jet.cli.jvm.K2JVMCompiler" failonerror="true">
|
||||||
<classpath>
|
<classpath>
|
||||||
<path refid="classpath"/>
|
<path refid="classpath"/>
|
||||||
<pathelement location="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
<pathelement location="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
||||||
@@ -210,7 +210,7 @@
|
|||||||
<attribute name="Implementation-Title" value="Kotlin Compiler"/>
|
<attribute name="Implementation-Title" value="Kotlin Compiler"/>
|
||||||
<attribute name="Implementation-Version" value="${build.number}"/>
|
<attribute name="Implementation-Version" value="${build.number}"/>
|
||||||
|
|
||||||
<attribute name="Main-Class" value="org.jetbrains.jet.cli.KotlinCompiler"/>
|
<attribute name="Main-Class" value="org.jetbrains.jet.cli.jvm.K2JVMCompiler"/>
|
||||||
</manifest>
|
</manifest>
|
||||||
</jar>
|
</jar>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
@@ -90,9 +90,10 @@ public abstract class ClassBodyCodegen {
|
|||||||
try {
|
try {
|
||||||
genNamedFunction((JetNamedFunction) declaration, functionCodegen);
|
genNamedFunction((JetNamedFunction) declaration, functionCodegen);
|
||||||
}
|
}
|
||||||
catch(CompilationException e) {
|
catch (CompilationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (RuntimeException e) {
|
}
|
||||||
|
catch (RuntimeException e) {
|
||||||
throw new RuntimeException("Error generating method " + myClass.getName() + "." + declaration.getName() + " in " + context, e);
|
throw new RuntimeException("Error generating method " + myClass.getName() + "." + declaration.getName() + " in " + context, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ public interface CompilationErrorHandler {
|
|||||||
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
|
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void reportException(Throwable exception, String fileUrl) {
|
public void reportException(Throwable exception, String fileUrl) {
|
||||||
|
if (exception instanceof RuntimeException) {
|
||||||
|
throw (RuntimeException)exception;
|
||||||
|
}
|
||||||
throw new IllegalStateException(exception);
|
throw new IllegalStateException(exception);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,49 +16,28 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Document;
|
|
||||||
import com.intellij.openapi.util.TextRange;
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class CompilationException extends RuntimeException {
|
public class CompilationException extends RuntimeException {
|
||||||
private PsiElement element;
|
private final PsiElement element;
|
||||||
|
|
||||||
CompilationException(String message, Throwable cause, PsiElement element) {
|
CompilationException(@NotNull String message, @Nullable Throwable cause, @NotNull PsiElement element) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
this.element = element;
|
this.element = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public PsiElement getElement() {
|
public PsiElement getElement() {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
PsiFile psiFile = element.getContainingFile();
|
|
||||||
TextRange textRange = element.getTextRange();
|
|
||||||
Document document = psiFile.getViewProvider().getDocument();
|
|
||||||
int line;
|
|
||||||
int col;
|
|
||||||
if (document != null) {
|
|
||||||
line = document.getLineNumber(textRange.getStartOffset());
|
|
||||||
col = textRange.getStartOffset() - document.getLineStartOffset(line) + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
line = -1;
|
|
||||||
col = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String s2 = "";
|
|
||||||
Throwable cause = getCause();
|
|
||||||
if (cause != null) {
|
|
||||||
s2 = cause.getMessage() != null ? cause.getMessage() : cause.toString();
|
|
||||||
}
|
|
||||||
return "Internal error: (" + (line+1) + "," + col + ") " + s2 + "\n@" + where();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String where() {
|
private String where() {
|
||||||
Throwable cause = getCause();
|
Throwable cause = getCause();
|
||||||
@@ -67,13 +46,20 @@ public class CompilationException extends RuntimeException {
|
|||||||
if (stackTrace != null && stackTrace.length > 0) {
|
if (stackTrace != null && stackTrace.length > 0) {
|
||||||
return stackTrace[0].getFileName() + ":" + stackTrace[0].getLineNumber();
|
return stackTrace[0].getFileName() + ":" + stackTrace[0].getLineNumber();
|
||||||
}
|
}
|
||||||
else {
|
return "unknown";
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return this.toString();
|
StringBuilder message = new StringBuilder("Back-end (JVM) Internal error: ").append(super.getMessage()).append("\n");
|
||||||
|
Throwable cause = getCause();
|
||||||
|
if (cause != null) {
|
||||||
|
String causeMessage = cause.getMessage();
|
||||||
|
message.append("Cause: ").append(causeMessage == null ? cause.toString() : causeMessage).append("\n");
|
||||||
|
}
|
||||||
|
message.append("File being compiled and position: ").append(DiagnosticUtils.atLocation(element)).append("\n");
|
||||||
|
message.append("The root cause was thrown at: ").append(where());
|
||||||
|
|
||||||
|
return message.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,4 +170,8 @@ public class GenerationState {
|
|||||||
|
|
||||||
return answer.toString();
|
return answer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
injector.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ public class NamespaceCodegen {
|
|||||||
else if (declaration instanceof JetNamedFunction) {
|
else if (declaration instanceof JetNamedFunction) {
|
||||||
try {
|
try {
|
||||||
functionCodegen.gen((JetNamedFunction) declaration);
|
functionCodegen.gen((JetNamedFunction) declaration);
|
||||||
} catch (CompilationException e) {
|
}
|
||||||
|
catch (CompilationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
|||||||
@@ -30,21 +30,31 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||||
public class InjectorForJetTypeMapper {
|
public class InjectorForJetTypeMapper {
|
||||||
|
|
||||||
|
private final JetStandardLibrary jetStandardLibrary;
|
||||||
|
private final BindingContext bindingContext;
|
||||||
|
private final List<JetFile> listOfJetFile;
|
||||||
private JetTypeMapper jetTypeMapper;
|
private JetTypeMapper jetTypeMapper;
|
||||||
|
private CompilerSpecialMode compilerSpecialMode;
|
||||||
|
private ClassBuilderMode classBuilderMode;
|
||||||
|
private ClosureAnnotator closureAnnotator;
|
||||||
|
|
||||||
public InjectorForJetTypeMapper(
|
public InjectorForJetTypeMapper(
|
||||||
@NotNull JetStandardLibrary jetStandardLibrary,
|
@NotNull JetStandardLibrary jetStandardLibrary,
|
||||||
@NotNull BindingContext bindingContext,
|
@NotNull BindingContext bindingContext,
|
||||||
@NotNull List<JetFile> listOfJetFile
|
@NotNull List<JetFile> listOfJetFile
|
||||||
) {
|
) {
|
||||||
|
this.jetStandardLibrary = jetStandardLibrary;
|
||||||
|
this.bindingContext = bindingContext;
|
||||||
|
this.listOfJetFile = listOfJetFile;
|
||||||
this.jetTypeMapper = new JetTypeMapper();
|
this.jetTypeMapper = new JetTypeMapper();
|
||||||
CompilerSpecialMode compilerSpecialMode = CompilerSpecialMode.REGULAR;
|
this.compilerSpecialMode = CompilerSpecialMode.REGULAR;
|
||||||
ClassBuilderMode classBuilderMode = ClassBuilderMode.FULL;
|
this.classBuilderMode = ClassBuilderMode.FULL;
|
||||||
ClosureAnnotator closureAnnotator = new ClosureAnnotator();
|
this.closureAnnotator = new ClosureAnnotator();
|
||||||
|
|
||||||
this.jetTypeMapper.setBindingContext(bindingContext);
|
this.jetTypeMapper.setBindingContext(bindingContext);
|
||||||
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
|
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
|
||||||
@@ -61,6 +71,10 @@ public class InjectorForJetTypeMapper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
public JetTypeMapper getJetTypeMapper() {
|
public JetTypeMapper getJetTypeMapper() {
|
||||||
return this.jetTypeMapper;
|
return this.jetTypeMapper;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,15 +40,23 @@ import org.jetbrains.jet.codegen.ClassBuilderMode;
|
|||||||
import org.jetbrains.jet.codegen.GenerationState;
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||||
public class InjectorForJvmCodegen {
|
public class InjectorForJvmCodegen {
|
||||||
|
|
||||||
private final JetStandardLibrary jetStandardLibrary;
|
private final JetStandardLibrary jetStandardLibrary;
|
||||||
|
private final BindingContext bindingContext;
|
||||||
|
private final List<JetFile> listOfJetFile;
|
||||||
|
private final Project project;
|
||||||
|
private final CompilerSpecialMode compilerSpecialMode;
|
||||||
|
private final ClassBuilderMode classBuilderMode;
|
||||||
private final GenerationState generationState;
|
private final GenerationState generationState;
|
||||||
|
private final ClassBuilderFactory classBuilderFactory;
|
||||||
private JetTypeMapper jetTypeMapper;
|
private JetTypeMapper jetTypeMapper;
|
||||||
private IntrinsicMethods intrinsics;
|
private IntrinsicMethods intrinsics;
|
||||||
private ClassFileFactory classFileFactory;
|
private ClassFileFactory classFileFactory;
|
||||||
|
private ClosureAnnotator closureAnnotator;
|
||||||
|
|
||||||
public InjectorForJvmCodegen(
|
public InjectorForJvmCodegen(
|
||||||
@NotNull JetStandardLibrary jetStandardLibrary,
|
@NotNull JetStandardLibrary jetStandardLibrary,
|
||||||
@@ -61,11 +69,17 @@ public class InjectorForJvmCodegen {
|
|||||||
@NotNull ClassBuilderFactory classBuilderFactory
|
@NotNull ClassBuilderFactory classBuilderFactory
|
||||||
) {
|
) {
|
||||||
this.jetStandardLibrary = jetStandardLibrary;
|
this.jetStandardLibrary = jetStandardLibrary;
|
||||||
|
this.bindingContext = bindingContext;
|
||||||
|
this.listOfJetFile = listOfJetFile;
|
||||||
|
this.project = project;
|
||||||
|
this.compilerSpecialMode = compilerSpecialMode;
|
||||||
|
this.classBuilderMode = classBuilderMode;
|
||||||
this.generationState = generationState;
|
this.generationState = generationState;
|
||||||
|
this.classBuilderFactory = classBuilderFactory;
|
||||||
this.jetTypeMapper = new JetTypeMapper();
|
this.jetTypeMapper = new JetTypeMapper();
|
||||||
this.intrinsics = new IntrinsicMethods();
|
this.intrinsics = new IntrinsicMethods();
|
||||||
this.classFileFactory = new ClassFileFactory();
|
this.classFileFactory = new ClassFileFactory();
|
||||||
ClosureAnnotator closureAnnotator = new ClosureAnnotator();
|
this.closureAnnotator = new ClosureAnnotator();
|
||||||
|
|
||||||
this.jetTypeMapper.setBindingContext(bindingContext);
|
this.jetTypeMapper.setBindingContext(bindingContext);
|
||||||
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
|
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
|
||||||
@@ -90,6 +104,10 @@ public class InjectorForJvmCodegen {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
public JetStandardLibrary getJetStandardLibrary() {
|
public JetStandardLibrary getJetStandardLibrary() {
|
||||||
return this.jetStandardLibrary;
|
return this.jetStandardLibrary;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,4 +95,4 @@ CPSELECT="-cp "
|
|||||||
$JAVA_OPTS \
|
$JAVA_OPTS \
|
||||||
"${java_args[@]}" \
|
"${java_args[@]}" \
|
||||||
${CPSELECT}${TOOL_CLASSPATH} \
|
${CPSELECT}${TOOL_CLASSPATH} \
|
||||||
org.jetbrains.jet.cli.KotlinCompiler "$@"
|
org.jetbrains.jet.cli.jvm.K2JVMCompiler "$@"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ if "%_TOOL_CLASSPATH%"=="" (
|
|||||||
for /d %%f in ("%_KOTLIN_HOME%\lib\*") do call :add_cpath "%%f"
|
for /d %%f in ("%_KOTLIN_HOME%\lib\*") do call :add_cpath "%%f"
|
||||||
)
|
)
|
||||||
|
|
||||||
"%_JAVACMD%" %_JAVA_OPTS% -cp "%_TOOL_CLASSPATH%" org.jetbrains.jet.cli.KotlinCompiler %*
|
"%_JAVACMD%" %_JAVA_OPTS% -cp "%_TOOL_CLASSPATH%" org.jetbrains.jet.cli.jvm.K2JVMCompiler %*
|
||||||
goto end
|
goto end
|
||||||
|
|
||||||
rem ##########################################################################
|
rem ##########################################################################
|
||||||
|
|||||||
@@ -1,296 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.cli;
|
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.intellij.openapi.Disposable;
|
|
||||||
import com.intellij.openapi.util.Disposer;
|
|
||||||
import com.sampullara.cli.Args;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.compiler.*;
|
|
||||||
import org.jetbrains.jet.compiler.messages.CompilerMessageLocation;
|
|
||||||
import org.jetbrains.jet.compiler.messages.CompilerMessageSeverity;
|
|
||||||
import org.jetbrains.jet.compiler.messages.MessageCollector;
|
|
||||||
import org.jetbrains.jet.compiler.messages.MessageRenderer;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.cli.KotlinCompiler.ExitCode.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author yole
|
|
||||||
* @author alex.tkachman
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
|
||||||
public class KotlinCompiler {
|
|
||||||
|
|
||||||
public enum ExitCode {
|
|
||||||
OK(0),
|
|
||||||
COMPILATION_ERROR(1),
|
|
||||||
INTERNAL_ERROR(2);
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
|
|
||||||
private ExitCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String... args) {
|
|
||||||
doMain(new KotlinCompiler(), args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Useful main for derived command line tools
|
|
||||||
*/
|
|
||||||
public static void doMain(KotlinCompiler compiler, String[] args) {
|
|
||||||
try {
|
|
||||||
ExitCode rc = compiler.exec(System.out, args);
|
|
||||||
if (rc != OK) {
|
|
||||||
System.err.println("exec() finished with " + rc + " return code");
|
|
||||||
System.exit(rc.getCode());
|
|
||||||
}
|
|
||||||
} catch (CompileEnvironmentException e) {
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
System.exit(INTERNAL_ERROR.getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExitCode exec(PrintStream errStream, String... args) {
|
|
||||||
CompilerArguments arguments = createArguments();
|
|
||||||
if (!parseArguments(errStream, arguments, args)) {
|
|
||||||
return INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
return exec(errStream, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the compiler on the parsed arguments
|
|
||||||
*/
|
|
||||||
public ExitCode exec(final PrintStream errStream, CompilerArguments arguments) {
|
|
||||||
if (arguments.help) {
|
|
||||||
usage(errStream);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
System.setProperty("java.awt.headless", "true");
|
|
||||||
|
|
||||||
final MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
|
|
||||||
|
|
||||||
if (arguments.version) {
|
|
||||||
errStream.println(messageRenderer.render(CompilerMessageSeverity.INFO, "Kotlin Compiler version " + CompilerVersion.VERSION, CompilerMessageLocation.NO_LOCATION));
|
|
||||||
}
|
|
||||||
|
|
||||||
CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
|
|
||||||
|
|
||||||
File jdkHeadersJar;
|
|
||||||
if (mode.includeJdkHeaders()) {
|
|
||||||
if (arguments.jdkHeaders != null) {
|
|
||||||
jdkHeadersJar = new File(arguments.jdkHeaders);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
jdkHeadersJar = PathUtil.getAltHeadersPath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
jdkHeadersJar = null;
|
|
||||||
}
|
|
||||||
File runtimeJar;
|
|
||||||
|
|
||||||
if (mode.includeKotlinRuntime()) {
|
|
||||||
if (arguments.stdlib != null) {
|
|
||||||
runtimeJar = new File(arguments.stdlib);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
runtimeJar = PathUtil.getDefaultRuntimePath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
runtimeJar = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompilerDependencies dependencies = new CompilerDependencies(mode, jdkHeadersJar, runtimeJar);
|
|
||||||
PrintingMessageCollector messageCollector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
|
|
||||||
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
|
|
||||||
|
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, dependencies);
|
|
||||||
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
|
|
||||||
try {
|
|
||||||
configureEnvironment(configuration, arguments);
|
|
||||||
|
|
||||||
boolean noErrors;
|
|
||||||
if (arguments.module != null) {
|
|
||||||
noErrors = KotlinToJVMBytecodeCompiler.compileModuleScript(configuration,
|
|
||||||
arguments.module, arguments.jar, arguments.outputDir,
|
|
||||||
arguments.includeRuntime);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// TODO ideally we'd unify to just having a single field that supports multiple files/dirs
|
|
||||||
if (arguments.getSourceDirs() != null) {
|
|
||||||
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration,
|
|
||||||
arguments.getSourceDirs(), arguments.jar, arguments.outputDir, arguments.includeRuntime);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration,
|
|
||||||
arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return noErrors ? OK : COMPILATION_ERROR;
|
|
||||||
}
|
|
||||||
catch (Throwable t) {
|
|
||||||
errStream.println(messageRenderer.renderException(t));
|
|
||||||
return INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
Disposer.dispose(rootDisposable);
|
|
||||||
messageCollector.printToErrStream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private CompilerSpecialMode parseCompilerSpecialMode(@NotNull CompilerArguments arguments) {
|
|
||||||
if (arguments.mode == null) {
|
|
||||||
return CompilerSpecialMode.REGULAR;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (CompilerSpecialMode variant : CompilerSpecialMode.values()) {
|
|
||||||
if (arguments.mode.equalsIgnoreCase(variant.name().replaceAll("_", ""))) {
|
|
||||||
return variant;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: report properly
|
|
||||||
throw new IllegalArgumentException("unknown compiler mode: " + arguments.mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the arguments can be parsed correctly
|
|
||||||
*/
|
|
||||||
protected boolean parseArguments(PrintStream errStream, CompilerArguments arguments, String[] args) {
|
|
||||||
try {
|
|
||||||
Args.parse(arguments, args);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
usage(errStream);
|
|
||||||
}
|
|
||||||
catch (Throwable t) {
|
|
||||||
// Always use tags
|
|
||||||
errStream.println(MessageRenderer.TAGS.renderException(t));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void usage(PrintStream target) {
|
|
||||||
// We should say something like
|
|
||||||
// Args.usage(target, CompilerArguments.class);
|
|
||||||
// but currently cli-parser we are using does not support that
|
|
||||||
// a corresponding patch has been sent to the authors
|
|
||||||
// For now, we are using this:
|
|
||||||
|
|
||||||
PrintStream oldErr = System.err;
|
|
||||||
System.setErr(target);
|
|
||||||
try {
|
|
||||||
// TODO: use proper argv0
|
|
||||||
Args.usage(new CompilerArguments());
|
|
||||||
} finally {
|
|
||||||
System.setErr(oldErr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow derived classes to add additional command line arguments
|
|
||||||
*/
|
|
||||||
protected CompilerArguments createArguments() {
|
|
||||||
return new CompilerArguments();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strategy method to configure the environment, allowing compiler
|
|
||||||
* based tools to customise their own plugins
|
|
||||||
*/
|
|
||||||
protected void configureEnvironment(CompileEnvironmentConfiguration configuration, CompilerArguments arguments) {
|
|
||||||
// install any compiler plugins
|
|
||||||
List<CompilerPlugin> plugins = arguments.getCompilerPlugins();
|
|
||||||
if (plugins != null) {
|
|
||||||
configuration.getCompilerPlugins().addAll(plugins);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
|
||||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arguments.classpath != null) {
|
|
||||||
final Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
|
|
||||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class PrintingMessageCollector implements MessageCollector {
|
|
||||||
private final boolean verbose;
|
|
||||||
private final PrintStream errStream;
|
|
||||||
private final MessageRenderer messageRenderer;
|
|
||||||
|
|
||||||
// File path (nullable) -> error message
|
|
||||||
private final Multimap<String, String> groupedMessages = LinkedHashMultimap.create();
|
|
||||||
|
|
||||||
public PrintingMessageCollector(PrintStream errStream,
|
|
||||||
MessageRenderer messageRenderer,
|
|
||||||
boolean verbose) {
|
|
||||||
this.verbose = verbose;
|
|
||||||
this.errStream = errStream;
|
|
||||||
this.messageRenderer = messageRenderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void report(@NotNull CompilerMessageSeverity severity,
|
|
||||||
@NotNull String message,
|
|
||||||
@NotNull CompilerMessageLocation location) {
|
|
||||||
String text = messageRenderer.render(severity, message, location);
|
|
||||||
if (severity == CompilerMessageSeverity.LOGGING) {
|
|
||||||
if (!verbose) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errStream.println(text);
|
|
||||||
}
|
|
||||||
groupedMessages.put(location.getPath(), text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void printToErrStream() {
|
|
||||||
if (!groupedMessages.isEmpty()) {
|
|
||||||
for (String path : groupedMessages.keySet()) {
|
|
||||||
Collection<String> messageTexts = groupedMessages.get(path);
|
|
||||||
for (String text : messageTexts) {
|
|
||||||
errStream.println(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.common;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple interface for compiler plugins to run after the compiler has finished such as for things like
|
* A simple interface for compiler plugins to run after the compiler has finished such as for things like
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.common;
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public enum ExitCode {
|
||||||
|
OK(0),
|
||||||
|
COMPILATION_ERROR(1),
|
||||||
|
INTERNAL_ERROR(2);
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
ExitCode(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
+151
@@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.common.messages;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.PsiErrorElement;
|
||||||
|
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
|
||||||
|
import jet.Function0;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.*;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public final class AnalyzerWithCompilerReport {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static CompilerMessageSeverity convertSeverity(@NotNull Severity severity) {
|
||||||
|
switch (severity) {
|
||||||
|
case INFO:
|
||||||
|
return CompilerMessageSeverity.INFO;
|
||||||
|
case ERROR:
|
||||||
|
return CompilerMessageSeverity.ERROR;
|
||||||
|
case WARNING:
|
||||||
|
return CompilerMessageSeverity.WARNING;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Unknown severity: " + severity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static final SimpleDiagnosticFactory<PsiErrorElement> SYNTAX_ERROR_FACTORY = SimpleDiagnosticFactory.create(Severity.ERROR);
|
||||||
|
|
||||||
|
private boolean hasErrors = false;
|
||||||
|
@NotNull
|
||||||
|
private final MessageCollector messageCollectorWrapper;
|
||||||
|
@Nullable
|
||||||
|
private AnalyzeExhaust analyzeExhaust = null;
|
||||||
|
|
||||||
|
public AnalyzerWithCompilerReport(@NotNull final MessageCollector collector) {
|
||||||
|
messageCollectorWrapper = new MessageCollector() {
|
||||||
|
@Override
|
||||||
|
public void report(@NotNull CompilerMessageSeverity severity,
|
||||||
|
@NotNull String message,
|
||||||
|
@NotNull CompilerMessageLocation location) {
|
||||||
|
if (CompilerMessageSeverity.ERRORS.contains(severity)) {
|
||||||
|
hasErrors = true;
|
||||||
|
}
|
||||||
|
collector.report(severity, message, location);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportDiagnostic(@NotNull Diagnostic diagnostic) {
|
||||||
|
DiagnosticUtils.LineAndColumn lineAndColumn = DiagnosticUtils.getLineAndColumn(diagnostic);
|
||||||
|
VirtualFile virtualFile = diagnostic.getPsiFile().getVirtualFile();
|
||||||
|
String path = virtualFile == null ? null : virtualFile.getPath();
|
||||||
|
String render;
|
||||||
|
if (diagnostic.getFactory() == SYNTAX_ERROR_FACTORY) {
|
||||||
|
render = ((SyntaxErrorDiagnostic)diagnostic).message;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
render = DefaultErrorMessages.RENDERER.render(diagnostic);
|
||||||
|
}
|
||||||
|
messageCollectorWrapper.report(convertSeverity(diagnostic.getSeverity()), render,
|
||||||
|
CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportIncompleteHierarchies() {
|
||||||
|
assert analyzeExhaust != null;
|
||||||
|
Collection<ClassDescriptor> incompletes = analyzeExhaust.getBindingContext().getKeys(BindingContext.INCOMPLETE_HIERARCHY);
|
||||||
|
if (!incompletes.isEmpty()) {
|
||||||
|
StringBuilder message = new StringBuilder("The following classes have incomplete hierarchies:\n");
|
||||||
|
for (ClassDescriptor incomplete : incompletes) {
|
||||||
|
String fqName = DescriptorUtils.getFQName(incomplete).getFqName();
|
||||||
|
message.append(" ").append(fqName).append("\n");
|
||||||
|
}
|
||||||
|
messageCollectorWrapper.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportDiagnostics() {
|
||||||
|
assert analyzeExhaust != null;
|
||||||
|
for (Diagnostic diagnostic : analyzeExhaust.getBindingContext().getDiagnostics()) {
|
||||||
|
reportDiagnostic(diagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportSyntaxErrors(@NotNull Collection<JetFile> files) {
|
||||||
|
for (JetFile file : files) {
|
||||||
|
file.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||||
|
@Override
|
||||||
|
public void visitErrorElement(PsiErrorElement element) {
|
||||||
|
String description = element.getErrorDescription();
|
||||||
|
String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
|
||||||
|
Diagnostic diagnostic = new SyntaxErrorDiagnostic(element, Severity.ERROR, message);
|
||||||
|
reportDiagnostic(diagnostic);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public AnalyzeExhaust getAnalyzeExhaust() {
|
||||||
|
return analyzeExhaust;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasErrors() {
|
||||||
|
return hasErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void analyzeAndReport(@NotNull Function0<AnalyzeExhaust> analyzer, @NotNull Collection<JetFile> files) {
|
||||||
|
reportSyntaxErrors(files);
|
||||||
|
analyzeExhaust = analyzer.invoke();
|
||||||
|
reportDiagnostics();
|
||||||
|
reportIncompleteHierarchies();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class SyntaxErrorDiagnostic extends SimpleDiagnostic<PsiErrorElement> {
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public SyntaxErrorDiagnostic(@NotNull PsiErrorElement psiElement, @NotNull Severity severity, String message) {
|
||||||
|
super(psiElement, SYNTAX_ERROR_FACTORY, severity);
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler.messages;
|
package org.jetbrains.jet.cli.common.messages;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler.messages;
|
package org.jetbrains.jet.cli.common.messages;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler.messages;
|
package org.jetbrains.jet.cli.common.messages;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
+30
-3
@@ -14,8 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler.messages;
|
package org.jetbrains.jet.cli.common.messages;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -27,30 +28,49 @@ import java.io.StringWriter;
|
|||||||
public interface MessageRenderer {
|
public interface MessageRenderer {
|
||||||
|
|
||||||
MessageRenderer TAGS = new MessageRenderer() {
|
MessageRenderer TAGS = new MessageRenderer() {
|
||||||
|
@Override
|
||||||
|
public String renderPreamble() {
|
||||||
|
return "<MESSAGES>";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
out.append("<").append(severity.toString());
|
out.append("<").append(severity.toString());
|
||||||
if (location.getPath() != null) {
|
if (location.getPath() != null) {
|
||||||
out.append(" path=\"").append(location.getPath()).append("\"");
|
out.append(" path=\"").append(e(location.getPath())).append("\"");
|
||||||
out.append(" line=\"").append(location.getLine()).append("\"");
|
out.append(" line=\"").append(location.getLine()).append("\"");
|
||||||
out.append(" column=\"").append(location.getColumn()).append("\"");
|
out.append(" column=\"").append(location.getColumn()).append("\"");
|
||||||
}
|
}
|
||||||
out.append(">\n");
|
out.append(">\n");
|
||||||
|
|
||||||
out.append(message);
|
out.append(e(message));
|
||||||
|
|
||||||
out.append("</").append(severity.toString()).append(">\n");
|
out.append("</").append(severity.toString()).append(">\n");
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String e(String str) {
|
||||||
|
return StringUtil.escapeXml(str);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String renderException(@NotNull Throwable e) {
|
public String renderException(@NotNull Throwable e) {
|
||||||
return render(CompilerMessageSeverity.EXCEPTION, PLAIN.renderException(e), CompilerMessageLocation.NO_LOCATION);
|
return render(CompilerMessageSeverity.EXCEPTION, PLAIN.renderException(e), CompilerMessageLocation.NO_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String renderConclusion() {
|
||||||
|
return "</MESSAGES>";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageRenderer PLAIN = new MessageRenderer() {
|
MessageRenderer PLAIN = new MessageRenderer() {
|
||||||
|
@Override
|
||||||
|
public String renderPreamble() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
||||||
String path = location.getPath();
|
String path = location.getPath();
|
||||||
@@ -65,8 +85,15 @@ public interface MessageRenderer {
|
|||||||
e.printStackTrace(new PrintWriter(out));
|
e.printStackTrace(new PrintWriter(out));
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String renderConclusion() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
String renderPreamble();
|
||||||
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
|
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
|
||||||
String renderException(@NotNull Throwable e);
|
String renderException(@NotNull Throwable e);
|
||||||
|
String renderConclusion();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.common.messages;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class MessageUtil {
|
||||||
|
public static CompilerMessageLocation psiElementToMessageLocation(PsiElement element) {
|
||||||
|
PsiFile file = element.getContainingFile();
|
||||||
|
DiagnosticUtils.LineAndColumn lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange());
|
||||||
|
return CompilerMessageLocation.create(file.getVirtualFile().getPath(), lineAndColumn.getLine(), lineAndColumn.getColumn());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.common.messages;
|
||||||
|
|
||||||
|
import com.google.common.collect.LinkedHashMultimap;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public class PrintingMessageCollector implements MessageCollector {
|
||||||
|
private final boolean verbose;
|
||||||
|
private final PrintStream errStream;
|
||||||
|
private final MessageRenderer messageRenderer;
|
||||||
|
|
||||||
|
// File path (nullable) -> error message
|
||||||
|
private final Multimap<String, String> groupedMessages = LinkedHashMultimap.create();
|
||||||
|
|
||||||
|
public PrintingMessageCollector(PrintStream errStream,
|
||||||
|
MessageRenderer messageRenderer,
|
||||||
|
boolean verbose) {
|
||||||
|
this.verbose = verbose;
|
||||||
|
this.errStream = errStream;
|
||||||
|
this.messageRenderer = messageRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void report(@NotNull CompilerMessageSeverity severity,
|
||||||
|
@NotNull String message,
|
||||||
|
@NotNull CompilerMessageLocation location) {
|
||||||
|
String text = messageRenderer.render(severity, message, location);
|
||||||
|
if (severity == CompilerMessageSeverity.LOGGING) {
|
||||||
|
if (!verbose) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errStream.println(text);
|
||||||
|
}
|
||||||
|
groupedMessages.put(location.getPath(), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printToErrStream() {
|
||||||
|
if (!groupedMessages.isEmpty()) {
|
||||||
|
for (String path : groupedMessages.keySet()) {
|
||||||
|
Collection<String> messageTexts = groupedMessages.get(path);
|
||||||
|
for (String text : messageTexts) {
|
||||||
|
errStream.println(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.js;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public final class K2JSCompiler {
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.js;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
//TODO
|
||||||
|
public class K2JSCompilerArguments {
|
||||||
|
}
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.jvm;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.intellij.openapi.Disposable;
|
||||||
|
import com.intellij.openapi.util.Disposer;
|
||||||
|
import com.sampullara.cli.Args;
|
||||||
|
import jet.modules.Module;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||||
|
import org.jetbrains.jet.cli.common.ExitCode;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.PrintingMessageCollector;
|
||||||
|
import org.jetbrains.jet.codegen.CompilationException;
|
||||||
|
import org.jetbrains.jet.cli.jvm.compiler.*;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.cli.common.ExitCode.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yole
|
||||||
|
* @author alex.tkachman
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||||
|
public class K2JVMCompiler {
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
doMain(new K2JVMCompiler(), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Useful main for derived command line tools
|
||||||
|
*/
|
||||||
|
public static void doMain(K2JVMCompiler compiler, String[] args) {
|
||||||
|
try {
|
||||||
|
ExitCode rc = compiler.exec(System.out, args);
|
||||||
|
if (rc != OK) {
|
||||||
|
System.err.println("exec() finished with " + rc + " return code");
|
||||||
|
System.exit(rc.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (CompileEnvironmentException e) {
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
System.exit(INTERNAL_ERROR.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExitCode exec(PrintStream errStream, String... args) {
|
||||||
|
K2JVMCompilerArguments arguments = createArguments();
|
||||||
|
if (!parseArguments(errStream, arguments, args)) {
|
||||||
|
return INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
return exec(errStream, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the compiler on the parsed arguments
|
||||||
|
*/
|
||||||
|
public ExitCode exec(final PrintStream errStream, K2JVMCompilerArguments arguments) {
|
||||||
|
if (arguments.help) {
|
||||||
|
usage(errStream);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
System.setProperty("java.awt.headless", "true");
|
||||||
|
|
||||||
|
final MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
|
||||||
|
|
||||||
|
errStream.print(messageRenderer.renderPreamble());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (arguments.version) {
|
||||||
|
errStream.println(messageRenderer.render(CompilerMessageSeverity.INFO, "Kotlin Compiler version " + K2JVMCompilerVersion.VERSION, CompilerMessageLocation.NO_LOCATION));
|
||||||
|
}
|
||||||
|
|
||||||
|
CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
|
||||||
|
|
||||||
|
File jdkHeadersJar;
|
||||||
|
if (mode.includeJdkHeaders()) {
|
||||||
|
if (arguments.jdkHeaders != null) {
|
||||||
|
jdkHeadersJar = new File(arguments.jdkHeaders);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jdkHeadersJar = PathUtil.getAltHeadersPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jdkHeadersJar = null;
|
||||||
|
}
|
||||||
|
File runtimeJar;
|
||||||
|
|
||||||
|
if (mode.includeKotlinRuntime()) {
|
||||||
|
if (arguments.stdlib != null) {
|
||||||
|
runtimeJar = new File(arguments.stdlib);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
runtimeJar = PathUtil.getDefaultRuntimePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
runtimeJar = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkHeadersJar, runtimeJar);
|
||||||
|
PrintingMessageCollector messageCollector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
|
||||||
|
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
|
||||||
|
|
||||||
|
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, dependencies);
|
||||||
|
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
|
||||||
|
|
||||||
|
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
||||||
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
|
try {
|
||||||
|
configureEnvironment(configuration, arguments);
|
||||||
|
|
||||||
|
boolean noErrors;
|
||||||
|
if (arguments.module != null) {
|
||||||
|
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(arguments.module, new PrintingMessageCollector(errStream, messageRenderer, false));
|
||||||
|
File directory = new File(arguments.module).getParentFile();
|
||||||
|
noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
|
||||||
|
directory, arguments.jar, arguments.outputDir,
|
||||||
|
arguments.includeRuntime);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TODO ideally we'd unify to just having a single field that supports multiple files/dirs
|
||||||
|
if (arguments.getSourceDirs() != null) {
|
||||||
|
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration,
|
||||||
|
arguments.getSourceDirs(), arguments.jar, arguments.outputDir, arguments.includeRuntime);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration,
|
||||||
|
arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return noErrors ? OK : COMPILATION_ERROR;
|
||||||
|
}
|
||||||
|
catch (CompilationException e) {
|
||||||
|
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e),
|
||||||
|
MessageUtil.psiElementToMessageLocation(e.getElement()));
|
||||||
|
return INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t), CompilerMessageLocation.NO_LOCATION);
|
||||||
|
return INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Disposer.dispose(rootDisposable);
|
||||||
|
messageCollector.printToErrStream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
errStream.print(messageRenderer.renderConclusion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private CompilerSpecialMode parseCompilerSpecialMode(@NotNull K2JVMCompilerArguments arguments) {
|
||||||
|
if (arguments.mode == null) {
|
||||||
|
return CompilerSpecialMode.REGULAR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (CompilerSpecialMode variant : CompilerSpecialMode.values()) {
|
||||||
|
if (arguments.mode.equalsIgnoreCase(variant.name().replaceAll("_", ""))) {
|
||||||
|
return variant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: report properly
|
||||||
|
throw new IllegalArgumentException("unknown compiler mode: " + arguments.mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the arguments can be parsed correctly
|
||||||
|
*/
|
||||||
|
protected boolean parseArguments(PrintStream errStream, K2JVMCompilerArguments arguments, String[] args) {
|
||||||
|
try {
|
||||||
|
Args.parse(arguments, args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e) {
|
||||||
|
usage(errStream);
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
// Always use tags
|
||||||
|
errStream.println(MessageRenderer.TAGS.renderException(t));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void usage(PrintStream target) {
|
||||||
|
// We should say something like
|
||||||
|
// Args.usage(target, K2JVMCompilerArguments.class);
|
||||||
|
// but currently cli-parser we are using does not support that
|
||||||
|
// a corresponding patch has been sent to the authors
|
||||||
|
// For now, we are using this:
|
||||||
|
|
||||||
|
PrintStream oldErr = System.err;
|
||||||
|
System.setErr(target);
|
||||||
|
try {
|
||||||
|
// TODO: use proper argv0
|
||||||
|
Args.usage(new K2JVMCompilerArguments());
|
||||||
|
} finally {
|
||||||
|
System.setErr(oldErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow derived classes to add additional command line arguments
|
||||||
|
*/
|
||||||
|
protected K2JVMCompilerArguments createArguments() {
|
||||||
|
return new K2JVMCompilerArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strategy method to configure the environment, allowing compiler
|
||||||
|
* based tools to customise their own plugins
|
||||||
|
*/
|
||||||
|
protected void configureEnvironment(CompileEnvironmentConfiguration configuration, K2JVMCompilerArguments arguments) {
|
||||||
|
// install any compiler plugins
|
||||||
|
List<CompilerPlugin> plugins = arguments.getCompilerPlugins();
|
||||||
|
if (plugins != null) {
|
||||||
|
configuration.getCompilerPlugins().addAll(plugins);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
||||||
|
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.classpath != null) {
|
||||||
|
final Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
|
||||||
|
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-5
@@ -15,18 +15,18 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.jet.cli;
|
package org.jetbrains.jet.cli.jvm;
|
||||||
|
|
||||||
import com.sampullara.cli.Argument;
|
import com.sampullara.cli.Argument;
|
||||||
import org.jetbrains.jet.compiler.CompilerPlugin;
|
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command line arguments for the {@link KotlinCompiler}
|
* Command line arguments for the {@link K2JVMCompiler}
|
||||||
*/
|
*/
|
||||||
public class CompilerArguments {
|
public class K2JVMCompilerArguments {
|
||||||
private List<CompilerPlugin> compilerPlugins = new ArrayList<CompilerPlugin>();
|
private List<CompilerPlugin> compilerPlugins = new ArrayList<CompilerPlugin>();
|
||||||
|
|
||||||
// TODO ideally we'd unify this with 'src' to just having a single field that supports multiple files/dirs
|
// TODO ideally we'd unify this with 'src' to just having a single field that supports multiple files/dirs
|
||||||
@@ -157,7 +157,7 @@ public class CompilerArguments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the compiler plugins to be used when working with the {@link KotlinCompiler}
|
* Sets the compiler plugins to be used when working with the {@link K2JVMCompiler}
|
||||||
*/
|
*/
|
||||||
public void setCompilerPlugins(List<CompilerPlugin> compilerPlugins) {
|
public void setCompilerPlugins(List<CompilerPlugin> compilerPlugins) {
|
||||||
this.compilerPlugins = compilerPlugins;
|
this.compilerPlugins = compilerPlugins;
|
||||||
+2
-2
@@ -14,12 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.cli;
|
package org.jetbrains.jet.cli.jvm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class CompilerVersion {
|
public class K2JVMCompilerVersion {
|
||||||
// The value of this constant is generated by the build script
|
// The value of this constant is generated by the build script
|
||||||
// DON'T MODIFY IT
|
// DON'T MODIFY IT
|
||||||
public static final String VERSION = "@snapshot@";
|
public static final String VERSION = "@snapshot@";
|
||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
/*
|
/*
|
||||||
* @author max
|
* @author max
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
+3
-2
@@ -14,12 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.compiler.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
+32
-29
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
@@ -25,10 +25,10 @@ import com.intellij.util.Processor;
|
|||||||
import jet.modules.AllModules;
|
import jet.modules.AllModules;
|
||||||
import jet.modules.Module;
|
import jet.modules.Module;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
||||||
import org.jetbrains.jet.codegen.GenerationState;
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
import org.jetbrains.jet.compiler.messages.MessageCollector;
|
|
||||||
import org.jetbrains.jet.lang.resolve.FqName;
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
@@ -78,10 +78,6 @@ public class CompileEnvironmentUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static void ensureRuntime(@NotNull JetCoreEnvironment env) {
|
|
||||||
// ensureJdkRuntime(env);
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static void ensureKotlinRuntime(JetCoreEnvironment env) {
|
public static void ensureKotlinRuntime(JetCoreEnvironment env) {
|
||||||
if (JavaPsiFacade.getInstance(env.getProject()).findClass("jet.JetObject", GlobalSearchScope.allScope(env.getProject())) == null) {
|
if (JavaPsiFacade.getInstance(env.getProject()).findClass("jet.JetObject", GlobalSearchScope.allScope(env.getProject())) == null) {
|
||||||
// TODO: prepend
|
// TODO: prepend
|
||||||
@@ -97,8 +93,10 @@ public class CompileEnvironmentUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void ensureJdkRuntime(JetCoreEnvironment env) {
|
public static void ensureJdkRuntime(JetCoreEnvironment env) {
|
||||||
if (JavaPsiFacade.getInstance(env.getProject()).findClass("java.lang.Object", GlobalSearchScope.allScope(env.getProject())) == null) {
|
if (JavaPsiFacade.getInstance(env.getProject()).findClass("java.lang.Object", GlobalSearchScope.allScope(env.getProject())) ==
|
||||||
|
null) {
|
||||||
// TODO: prepend
|
// TODO: prepend
|
||||||
env.addToClasspath(findRtJar());
|
env.addToClasspath(findRtJar());
|
||||||
}
|
}
|
||||||
@@ -151,16 +149,7 @@ public class CompileEnvironmentUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private CompileEnvironment copyEnvironment(boolean verbose) {
|
public static List<Module> loadModuleScript(String moduleScriptFile, MessageCollector messageCollector) {
|
||||||
// CompileEnvironment compileEnvironment = new CompileEnvironment(messageRenderer, verbose, compilerDependencies);
|
|
||||||
// compileEnvironment.setIgnoreErrors(ignoreErrors);
|
|
||||||
// compileEnvironment.setErrorStream(errorStream);
|
|
||||||
// // copy across any compiler plugins
|
|
||||||
// compileEnvironment.getEnvironment().getCompilerPlugins().addAll(environment.getCompilerPlugins());
|
|
||||||
// return compileEnvironment;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
public static List<Module> loadModuleScript(String moduleFile, MessageCollector messageCollector) {
|
|
||||||
Disposable disposable = new Disposable() {
|
Disposable disposable = new Disposable() {
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
@@ -170,7 +159,7 @@ public class CompileEnvironmentUtil {
|
|||||||
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
||||||
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, dependencies);
|
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, dependencies);
|
||||||
ensureRuntime(scriptEnvironment, dependencies);
|
ensureRuntime(scriptEnvironment, dependencies);
|
||||||
scriptEnvironment.addSources(moduleFile);
|
scriptEnvironment.addSources(moduleScriptFile);
|
||||||
|
|
||||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
||||||
@@ -178,9 +167,17 @@ public class CompileEnvironmentUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Module> modules = runDefineModules(dependencies, moduleFile, generationState.getFactory());
|
List<Module> modules = runDefineModules(dependencies, moduleScriptFile, generationState.getFactory());
|
||||||
|
|
||||||
Disposer.dispose(disposable);
|
Disposer.dispose(disposable);
|
||||||
|
|
||||||
|
if (modules == null) {
|
||||||
|
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " compilation failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modules.isEmpty()) {
|
||||||
|
throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
|
||||||
|
}
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,8 +186,10 @@ public class CompileEnvironmentUtil {
|
|||||||
GeneratedClassLoader loader;
|
GeneratedClassLoader loader;
|
||||||
if (stdlibJar != null) {
|
if (stdlibJar != null) {
|
||||||
try {
|
try {
|
||||||
loader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{stdlibJar.toURI().toURL()}, AllModules.class.getClassLoader()));
|
loader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{stdlibJar.toURI().toURL()},
|
||||||
} catch (MalformedURLException e) {
|
AllModules.class.getClassLoader()));
|
||||||
|
}
|
||||||
|
catch (MalformedURLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,8 +241,8 @@ public class CompileEnvironmentUtil {
|
|||||||
stream.close();
|
stream.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new CompileEnvironmentException("Failed to generate jar file", e);
|
throw new CompileEnvironmentException("Failed to generate jar file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +287,8 @@ public class CompileEnvironmentUtil {
|
|||||||
FileUtil.copy(jis, stream);
|
FileUtil.copy(jis, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
jis.close();
|
jis.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,7 +304,8 @@ public class CompileEnvironmentUtil {
|
|||||||
File target = new File(outputDir, file);
|
File target = new File(outputDir, file);
|
||||||
try {
|
try {
|
||||||
FileUtil.writeToFile(target, factory.asBytes(file));
|
FileUtil.writeToFile(target, factory.asBytes(file));
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e) {
|
||||||
throw new CompileEnvironmentException(e);
|
throw new CompileEnvironmentException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,10 +313,11 @@ public class CompileEnvironmentUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add path specified to the compilation environment.
|
* Add path specified to the compilation environment.
|
||||||
|
*
|
||||||
* @param environment compilation environment to add to
|
* @param environment compilation environment to add to
|
||||||
* @param paths paths to add
|
* @param paths paths to add
|
||||||
*/
|
*/
|
||||||
public static void addToClasspath(JetCoreEnvironment environment, File ... paths) {
|
public static void addToClasspath(JetCoreEnvironment environment, File... paths) {
|
||||||
for (File path : paths) {
|
for (File path : paths) {
|
||||||
if (!path.exists()) {
|
if (!path.exists()) {
|
||||||
throw new CompileEnvironmentException("'" + path + "' does not exist");
|
throw new CompileEnvironmentException("'" + path + "' does not exist");
|
||||||
@@ -326,10 +328,11 @@ public class CompileEnvironmentUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add path specified to the compilation environment.
|
* Add path specified to the compilation environment.
|
||||||
|
*
|
||||||
* @param environment compilation environment to add to
|
* @param environment compilation environment to add to
|
||||||
* @param paths paths to add
|
* @param paths paths to add
|
||||||
*/
|
*/
|
||||||
public static void addToClasspath(JetCoreEnvironment environment, String ... paths) {
|
public static void addToClasspath(JetCoreEnvironment environment, String... paths) {
|
||||||
for (String path : paths) {
|
for (String path : paths) {
|
||||||
addToClasspath(environment, new File(path));
|
addToClasspath(environment, new File(path));
|
||||||
}
|
}
|
||||||
+3
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
import com.intellij.core.JavaCoreEnvironment;
|
import com.intellij.core.JavaCoreEnvironment;
|
||||||
import com.intellij.lang.java.JavaParserDefinition;
|
import com.intellij.lang.java.JavaParserDefinition;
|
||||||
@@ -64,6 +64,8 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
|
|
||||||
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
||||||
|
|
||||||
|
addToClasspath(compilerDependencies.getJdkJar());
|
||||||
|
|
||||||
if (compilerSpecialMode.includeJdkHeaders()) {
|
if (compilerSpecialMode.includeJdkHeaders()) {
|
||||||
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
|
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
|
||||||
addLibraryRoot(root);
|
addLibraryRoot(root);
|
||||||
+56
-124
@@ -14,37 +14,28 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Ref;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import com.intellij.psi.PsiErrorElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
|
|
||||||
import com.intellij.testFramework.LightVirtualFile;
|
import com.intellij.testFramework.LightVirtualFile;
|
||||||
import com.intellij.util.LocalTimeCounter;
|
import com.intellij.util.LocalTimeCounter;
|
||||||
|
import jet.Function0;
|
||||||
import jet.modules.Module;
|
import jet.modules.Module;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
|
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||||
|
import org.jetbrains.jet.cli.common.CompilerPluginContext;
|
||||||
import org.jetbrains.jet.codegen.*;
|
import org.jetbrains.jet.codegen.*;
|
||||||
import org.jetbrains.jet.compiler.messages.CompilerMessageLocation;
|
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
||||||
import org.jetbrains.jet.compiler.messages.CompilerMessageSeverity;
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||||
import org.jetbrains.jet.compiler.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
|
||||||
import org.jetbrains.jet.lang.resolve.FqName;
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
@@ -55,7 +46,6 @@ import org.jetbrains.jet.utils.Progress;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,11 +54,14 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class KotlinToJVMBytecodeCompiler {
|
public class KotlinToJVMBytecodeCompiler {
|
||||||
|
|
||||||
|
private KotlinToJVMBytecodeCompiler() {
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ClassFileFactory compileModule(
|
public static ClassFileFactory compileModule(
|
||||||
CompileEnvironmentConfiguration configuration,
|
CompileEnvironmentConfiguration configuration,
|
||||||
Module moduleBuilder,
|
Module moduleBuilder,
|
||||||
String directory
|
File directory
|
||||||
) {
|
) {
|
||||||
if (moduleBuilder.getSourceFiles().isEmpty()) {
|
if (moduleBuilder.getSourceFiles().isEmpty()) {
|
||||||
throw new CompileEnvironmentException("No source files where defined");
|
throw new CompileEnvironmentException("No source files where defined");
|
||||||
@@ -99,30 +92,23 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
return generationState.getFactory();
|
return generationState.getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean compileModuleScript(
|
public static boolean compileModules(
|
||||||
CompileEnvironmentConfiguration configuration,
|
CompileEnvironmentConfiguration configuration,
|
||||||
|
|
||||||
@NotNull String moduleScriptFile,
|
@NotNull List<Module> modules,
|
||||||
|
|
||||||
|
@NotNull File directory,
|
||||||
@Nullable String jarPath,
|
@Nullable String jarPath,
|
||||||
@Nullable String outputDir,
|
@Nullable String outputDir,
|
||||||
boolean jarRuntime) {
|
boolean jarRuntime) {
|
||||||
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(moduleScriptFile, configuration.getMessageCollector());
|
|
||||||
|
|
||||||
if (modules == null) {
|
|
||||||
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " compilation failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modules.isEmpty()) {
|
|
||||||
throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String directory = new File(moduleScriptFile).getParent();
|
|
||||||
for (Module moduleBuilder : modules) {
|
for (Module moduleBuilder : modules) {
|
||||||
// TODO: this should be done only once for the environment
|
// TODO: this should be done only once for the environment
|
||||||
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
||||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
CompileEnvironmentUtil
|
||||||
|
.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
||||||
}
|
}
|
||||||
ClassFileFactory moduleFactory = KotlinToJVMBytecodeCompiler.compileModule(configuration, moduleBuilder, directory);
|
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
|
||||||
if (moduleFactory == null) {
|
if (moduleFactory == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -144,7 +130,6 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
private static boolean compileBunchOfSources(
|
private static boolean compileBunchOfSources(
|
||||||
CompileEnvironmentConfiguration configuration,
|
CompileEnvironmentConfiguration configuration,
|
||||||
|
|
||||||
String jar,
|
String jar,
|
||||||
String outputDir,
|
String outputDir,
|
||||||
boolean includeRuntime
|
boolean includeRuntime
|
||||||
@@ -165,21 +150,27 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassFileFactory factory = generationState.getFactory();
|
try {
|
||||||
if (jar != null) {
|
ClassFileFactory factory = generationState.getFactory();
|
||||||
try {
|
if (jar != null) {
|
||||||
CompileEnvironmentUtil.writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
|
try {
|
||||||
} catch (FileNotFoundException e) {
|
CompileEnvironmentUtil.writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
|
||||||
throw new CompileEnvironmentException("Invalid jar path " + jar, e);
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
throw new CompileEnvironmentException("Invalid jar path " + jar, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (outputDir != null) {
|
||||||
|
CompileEnvironmentUtil.writeToOutputDirectory(factory, outputDir);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new CompileEnvironmentException("Output directory or jar file is not specified - no files will be saved to the disk");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if (outputDir != null) {
|
finally {
|
||||||
CompileEnvironmentUtil.writeToOutputDirectory(factory, outputDir);
|
generationState.destroy();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
throw new CompileEnvironmentException("Output directory or jar file is not specified - no files will be saved to the disk");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean compileBunchOfSources(
|
public static boolean compileBunchOfSources(
|
||||||
@@ -205,9 +196,9 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static ClassLoader compileText(
|
public static ClassLoader compileText(
|
||||||
CompileEnvironmentConfiguration configuration,
|
CompileEnvironmentConfiguration configuration,
|
||||||
|
|
||||||
String code) {
|
String code) {
|
||||||
configuration.getEnvironment().addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
|
configuration.getEnvironment()
|
||||||
|
.addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
|
||||||
|
|
||||||
GenerationState generationState = analyzeAndGenerate(configuration);
|
GenerationState generationState = analyzeAndGenerate(configuration);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
@@ -224,7 +215,6 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static GenerationState analyzeAndGenerate(
|
public static GenerationState analyzeAndGenerate(
|
||||||
CompileEnvironmentConfiguration configuration,
|
CompileEnvironmentConfiguration configuration,
|
||||||
|
|
||||||
boolean stubs
|
boolean stubs
|
||||||
) {
|
) {
|
||||||
AnalyzeExhaust exhaust = analyze(configuration, stubs);
|
AnalyzeExhaust exhaust = analyze(configuration, stubs);
|
||||||
@@ -241,59 +231,31 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private static AnalyzeExhaust analyze(
|
private static AnalyzeExhaust analyze(
|
||||||
final CompileEnvironmentConfiguration configuration,
|
final CompileEnvironmentConfiguration configuration,
|
||||||
|
|
||||||
boolean stubs) {
|
boolean stubs) {
|
||||||
final Ref<Boolean> hasErrors = new Ref<Boolean>(false);
|
final JetCoreEnvironment environment = configuration.getEnvironment();
|
||||||
final MessageCollector messageCollectorWrapper = new MessageCollector() {
|
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector());
|
||||||
|
final Predicate<PsiFile> filesToAnalyzeCompletely =
|
||||||
@Override
|
|
||||||
public void report(@NotNull CompilerMessageSeverity severity,
|
|
||||||
@NotNull String message,
|
|
||||||
@NotNull CompilerMessageLocation location) {
|
|
||||||
if (CompilerMessageSeverity.ERRORS.contains(severity)) {
|
|
||||||
hasErrors.set(true);
|
|
||||||
}
|
|
||||||
configuration.getMessageCollector().report(severity, message, location);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
JetCoreEnvironment environment = configuration.getEnvironment();
|
|
||||||
|
|
||||||
// Report syntax errors
|
|
||||||
for (JetFile file : environment.getSourceFiles()) {
|
|
||||||
file.accept(new PsiRecursiveElementWalkingVisitor() {
|
|
||||||
@Override
|
|
||||||
public void visitErrorElement(PsiErrorElement element) {
|
|
||||||
String description = element.getErrorDescription();
|
|
||||||
String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
|
|
||||||
Diagnostic diagnostic = DiagnosticFactory.create(Severity.ERROR, message).on(element);
|
|
||||||
reportDiagnostic(messageCollectorWrapper, diagnostic);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Analyze and report semantic errors
|
|
||||||
Predicate<PsiFile> filesToAnalyzeCompletely =
|
|
||||||
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
|
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
|
||||||
AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
analyzerWithCompilerReport.analyzeAndReport(
|
||||||
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY,
|
new Function0<AnalyzeExhaust>() {
|
||||||
configuration.getCompilerDependencies());
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public AnalyzeExhaust invoke() {
|
||||||
|
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||||
|
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely,
|
||||||
|
JetControlFlowDataTraceFactory.EMPTY,
|
||||||
|
configuration.getCompilerDependencies());
|
||||||
|
}
|
||||||
|
}, environment.getSourceFiles()
|
||||||
|
);
|
||||||
|
|
||||||
for (Diagnostic diagnostic : exhaust.getBindingContext().getDiagnostics()) {
|
return analyzerWithCompilerReport.hasErrors() ? null : analyzerWithCompilerReport.getAnalyzeExhaust();
|
||||||
reportDiagnostic(messageCollectorWrapper, diagnostic);
|
|
||||||
}
|
|
||||||
|
|
||||||
reportIncompleteHierarchies(messageCollectorWrapper, exhaust);
|
|
||||||
|
|
||||||
return hasErrors.get() ? null : exhaust;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static GenerationState generate(
|
private static GenerationState generate(
|
||||||
final CompileEnvironmentConfiguration configuration,
|
final CompileEnvironmentConfiguration configuration,
|
||||||
|
|
||||||
AnalyzeExhaust exhaust,
|
AnalyzeExhaust exhaust,
|
||||||
|
|
||||||
boolean stubs) {
|
boolean stubs) {
|
||||||
JetCoreEnvironment environment = configuration.getEnvironment();
|
JetCoreEnvironment environment = configuration.getEnvironment();
|
||||||
Project project = environment.getProject();
|
Project project = environment.getProject();
|
||||||
@@ -304,7 +266,8 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
||||||
exhaust, environment.getSourceFiles(), configuration.getCompilerDependencies().getCompilerSpecialMode());
|
exhaust, environment.getSourceFiles(),
|
||||||
|
configuration.getCompilerDependencies().getCompilerSpecialMode());
|
||||||
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
|
|
||||||
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();
|
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();
|
||||||
@@ -316,35 +279,4 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
}
|
}
|
||||||
return generationState;
|
return generationState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void reportDiagnostic(MessageCollector collector, Diagnostic diagnostic) {
|
|
||||||
DiagnosticUtils.LineAndColumn lineAndColumn = DiagnosticUtils.getLineAndColumn(diagnostic);
|
|
||||||
VirtualFile virtualFile = diagnostic.getPsiFile().getVirtualFile();
|
|
||||||
String path = virtualFile == null ? null : virtualFile.getPath();
|
|
||||||
collector.report(convertSeverity(diagnostic.getSeverity()), diagnostic.getMessage(), CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CompilerMessageSeverity convertSeverity(Severity severity) {
|
|
||||||
switch (severity) {
|
|
||||||
case INFO:
|
|
||||||
return CompilerMessageSeverity.INFO;
|
|
||||||
case ERROR:
|
|
||||||
return CompilerMessageSeverity.ERROR;
|
|
||||||
case WARNING:
|
|
||||||
return CompilerMessageSeverity.WARNING;
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Unknown severity: " + severity);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void reportIncompleteHierarchies(MessageCollector collector, AnalyzeExhaust exhaust) {
|
|
||||||
Collection<ClassDescriptor> incompletes = exhaust.getBindingContext().getKeys(BindingContext.INCOMPLETE_HIERARCHY);
|
|
||||||
if (!incompletes.isEmpty()) {
|
|
||||||
StringBuilder message = new StringBuilder("The following classes have incomplete hierarchies:\n");
|
|
||||||
for (ClassDescriptor incomplete : incompletes) {
|
|
||||||
String fqName = DescriptorUtils.getFQName(incomplete).getFqName();
|
|
||||||
message.append(" ").append(fqName).append("\n");
|
|
||||||
}
|
|
||||||
collector.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
+17
-5
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.NamespaceFactoryImpl;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||||
public class InjectorForJavaSemanticServices {
|
public class InjectorForJavaSemanticServices {
|
||||||
@@ -38,8 +39,14 @@ public class InjectorForJavaSemanticServices {
|
|||||||
private JavaSemanticServices javaSemanticServices;
|
private JavaSemanticServices javaSemanticServices;
|
||||||
private JavaDescriptorResolver javaDescriptorResolver;
|
private JavaDescriptorResolver javaDescriptorResolver;
|
||||||
private BindingTrace bindingTrace;
|
private BindingTrace bindingTrace;
|
||||||
|
private JavaBridgeConfiguration javaBridgeConfiguration;
|
||||||
private PsiClassFinderForJvm psiClassFinderForJvm;
|
private PsiClassFinderForJvm psiClassFinderForJvm;
|
||||||
|
private ModuleDescriptor moduleDescriptor;
|
||||||
|
private final CompilerDependencies compilerDependencies;
|
||||||
|
private CompilerSpecialMode compilerSpecialMode;
|
||||||
private final Project project;
|
private final Project project;
|
||||||
|
private JavaTypeTransformer javaTypeTransformer;
|
||||||
|
private NamespaceFactoryImpl namespaceFactoryImpl;
|
||||||
|
|
||||||
public InjectorForJavaSemanticServices(
|
public InjectorForJavaSemanticServices(
|
||||||
@NotNull CompilerDependencies compilerDependencies,
|
@NotNull CompilerDependencies compilerDependencies,
|
||||||
@@ -48,13 +55,14 @@ public class InjectorForJavaSemanticServices {
|
|||||||
this.javaSemanticServices = new JavaSemanticServices();
|
this.javaSemanticServices = new JavaSemanticServices();
|
||||||
this.javaDescriptorResolver = new JavaDescriptorResolver();
|
this.javaDescriptorResolver = new JavaDescriptorResolver();
|
||||||
this.bindingTrace = new org.jetbrains.jet.lang.resolve.BindingTraceContext();
|
this.bindingTrace = new org.jetbrains.jet.lang.resolve.BindingTraceContext();
|
||||||
JavaBridgeConfiguration javaBridgeConfiguration = new JavaBridgeConfiguration();
|
this.javaBridgeConfiguration = new JavaBridgeConfiguration();
|
||||||
this.psiClassFinderForJvm = new PsiClassFinderForJvm();
|
this.psiClassFinderForJvm = new PsiClassFinderForJvm();
|
||||||
ModuleDescriptor moduleDescriptor = new org.jetbrains.jet.lang.descriptors.ModuleDescriptor("<dummy>");
|
this.moduleDescriptor = new org.jetbrains.jet.lang.descriptors.ModuleDescriptor("<dummy>");
|
||||||
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
this.compilerDependencies = compilerDependencies;
|
||||||
|
this.compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
||||||
this.project = project;
|
this.project = project;
|
||||||
JavaTypeTransformer javaTypeTransformer = new JavaTypeTransformer();
|
this.javaTypeTransformer = new JavaTypeTransformer();
|
||||||
NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
|
this.namespaceFactoryImpl = new NamespaceFactoryImpl();
|
||||||
|
|
||||||
this.javaSemanticServices.setDescriptorResolver(javaDescriptorResolver);
|
this.javaSemanticServices.setDescriptorResolver(javaDescriptorResolver);
|
||||||
this.javaSemanticServices.setPsiClassFinder(psiClassFinderForJvm);
|
this.javaSemanticServices.setPsiClassFinder(psiClassFinderForJvm);
|
||||||
@@ -87,6 +95,10 @@ public class InjectorForJavaSemanticServices {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
public JavaSemanticServices getJavaSemanticServices() {
|
public JavaSemanticServices getJavaSemanticServices() {
|
||||||
return this.javaSemanticServices;
|
return this.javaSemanticServices;
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-18
@@ -55,6 +55,7 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
|||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||||
public class InjectorForTopDownAnalyzerForJvm {
|
public class InjectorForTopDownAnalyzerForJvm {
|
||||||
@@ -68,7 +69,28 @@ public class InjectorForTopDownAnalyzerForJvm {
|
|||||||
private final Project project;
|
private final Project project;
|
||||||
private final TopDownAnalysisParameters topDownAnalysisParameters;
|
private final TopDownAnalysisParameters topDownAnalysisParameters;
|
||||||
private final ObservableBindingTrace observableBindingTrace;
|
private final ObservableBindingTrace observableBindingTrace;
|
||||||
|
private final ModuleDescriptor moduleDescriptor;
|
||||||
|
private final JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory;
|
||||||
|
private final CompilerDependencies compilerDependencies;
|
||||||
|
private CompilerSpecialMode compilerSpecialMode;
|
||||||
private JavaBridgeConfiguration javaBridgeConfiguration;
|
private JavaBridgeConfiguration javaBridgeConfiguration;
|
||||||
|
private PsiClassFinderForJvm psiClassFinderForJvm;
|
||||||
|
private DeclarationResolver declarationResolver;
|
||||||
|
private AnnotationResolver annotationResolver;
|
||||||
|
private CallResolver callResolver;
|
||||||
|
private ExpressionTypingServices expressionTypingServices;
|
||||||
|
private TypeResolver typeResolver;
|
||||||
|
private QualifiedExpressionResolver qualifiedExpressionResolver;
|
||||||
|
private OverloadingConflictResolver overloadingConflictResolver;
|
||||||
|
private ImportsResolver importsResolver;
|
||||||
|
private DelegationResolver delegationResolver;
|
||||||
|
private NamespaceFactoryImpl namespaceFactoryImpl;
|
||||||
|
private OverloadResolver overloadResolver;
|
||||||
|
private OverrideResolver overrideResolver;
|
||||||
|
private TypeHierarchyResolver typeHierarchyResolver;
|
||||||
|
private JavaSemanticServices javaSemanticServices;
|
||||||
|
private JavaDescriptorResolver javaDescriptorResolver;
|
||||||
|
private JavaTypeTransformer javaTypeTransformer;
|
||||||
|
|
||||||
public InjectorForTopDownAnalyzerForJvm(
|
public InjectorForTopDownAnalyzerForJvm(
|
||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
@@ -87,25 +109,28 @@ public class InjectorForTopDownAnalyzerForJvm {
|
|||||||
this.project = project;
|
this.project = project;
|
||||||
this.topDownAnalysisParameters = topDownAnalysisParameters;
|
this.topDownAnalysisParameters = topDownAnalysisParameters;
|
||||||
this.observableBindingTrace = observableBindingTrace;
|
this.observableBindingTrace = observableBindingTrace;
|
||||||
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
this.moduleDescriptor = moduleDescriptor;
|
||||||
|
this.jetControlFlowDataTraceFactory = jetControlFlowDataTraceFactory;
|
||||||
|
this.compilerDependencies = compilerDependencies;
|
||||||
|
this.compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
||||||
this.javaBridgeConfiguration = new JavaBridgeConfiguration();
|
this.javaBridgeConfiguration = new JavaBridgeConfiguration();
|
||||||
PsiClassFinderForJvm psiClassFinderForJvm = new PsiClassFinderForJvm();
|
this.psiClassFinderForJvm = new PsiClassFinderForJvm();
|
||||||
DeclarationResolver declarationResolver = new DeclarationResolver();
|
this.declarationResolver = new DeclarationResolver();
|
||||||
AnnotationResolver annotationResolver = new AnnotationResolver();
|
this.annotationResolver = new AnnotationResolver();
|
||||||
CallResolver callResolver = new CallResolver();
|
this.callResolver = new CallResolver();
|
||||||
ExpressionTypingServices expressionTypingServices = new ExpressionTypingServices();
|
this.expressionTypingServices = new ExpressionTypingServices();
|
||||||
TypeResolver typeResolver = new TypeResolver();
|
this.typeResolver = new TypeResolver();
|
||||||
QualifiedExpressionResolver qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
||||||
OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
|
this.overloadingConflictResolver = new OverloadingConflictResolver();
|
||||||
ImportsResolver importsResolver = new ImportsResolver();
|
this.importsResolver = new ImportsResolver();
|
||||||
DelegationResolver delegationResolver = new DelegationResolver();
|
this.delegationResolver = new DelegationResolver();
|
||||||
NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
|
this.namespaceFactoryImpl = new NamespaceFactoryImpl();
|
||||||
OverloadResolver overloadResolver = new OverloadResolver();
|
this.overloadResolver = new OverloadResolver();
|
||||||
OverrideResolver overrideResolver = new OverrideResolver();
|
this.overrideResolver = new OverrideResolver();
|
||||||
TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver();
|
this.typeHierarchyResolver = new TypeHierarchyResolver();
|
||||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices();
|
this.javaSemanticServices = new JavaSemanticServices();
|
||||||
JavaDescriptorResolver javaDescriptorResolver = new JavaDescriptorResolver();
|
this.javaDescriptorResolver = new JavaDescriptorResolver();
|
||||||
JavaTypeTransformer javaTypeTransformer = new JavaTypeTransformer();
|
this.javaTypeTransformer = new JavaTypeTransformer();
|
||||||
|
|
||||||
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
||||||
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
||||||
@@ -217,6 +242,10 @@ public class InjectorForTopDownAnalyzerForJvm {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
public TopDownAnalyzer getTopDownAnalyzer() {
|
public TopDownAnalyzer getTopDownAnalyzer() {
|
||||||
return this.topDownAnalyzer;
|
return this.topDownAnalyzer;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -95,9 +95,13 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
compilerDependencies);
|
compilerDependencies);
|
||||||
|
|
||||||
|
|
||||||
injector.getTopDownAnalyzer().analyzeFiles(files);
|
try {
|
||||||
|
injector.getTopDownAnalyzer().analyzeFiles(files);
|
||||||
|
|
||||||
return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
|
return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
|
||||||
|
} finally {
|
||||||
|
injector.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnalyzeExhaust shallowAnalyzeFiles(Collection<JetFile> files,
|
public static AnalyzeExhaust shallowAnalyzeFiles(Collection<JetFile> files,
|
||||||
|
|||||||
+37
-1
@@ -33,12 +33,15 @@ public class CompilerDependencies {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final CompilerSpecialMode compilerSpecialMode;
|
private final CompilerSpecialMode compilerSpecialMode;
|
||||||
@Nullable
|
@Nullable
|
||||||
|
private final File jdkJar;
|
||||||
|
@Nullable
|
||||||
private final File jdkHeadersJar;
|
private final File jdkHeadersJar;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final File runtimeJar;
|
private final File runtimeJar;
|
||||||
|
|
||||||
public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
|
public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
|
||||||
this.compilerSpecialMode = compilerSpecialMode;
|
this.compilerSpecialMode = compilerSpecialMode;
|
||||||
|
this.jdkJar = jdkJar;
|
||||||
this.jdkHeadersJar = jdkHeadersJar;
|
this.jdkHeadersJar = jdkHeadersJar;
|
||||||
this.runtimeJar = runtimeJar;
|
this.runtimeJar = runtimeJar;
|
||||||
|
|
||||||
@@ -59,6 +62,11 @@ public class CompilerDependencies {
|
|||||||
return compilerSpecialMode;
|
return compilerSpecialMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public File getJdkJar() {
|
||||||
|
return jdkJar;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public File getJdkHeadersJar() {
|
public File getJdkHeadersJar() {
|
||||||
return jdkHeadersJar;
|
return jdkHeadersJar;
|
||||||
@@ -93,8 +101,36 @@ public class CompilerDependencies {
|
|||||||
public static CompilerDependencies compilerDependenciesForProduction(@NotNull CompilerSpecialMode compilerSpecialMode) {
|
public static CompilerDependencies compilerDependenciesForProduction(@NotNull CompilerSpecialMode compilerSpecialMode) {
|
||||||
return new CompilerDependencies(
|
return new CompilerDependencies(
|
||||||
compilerSpecialMode,
|
compilerSpecialMode,
|
||||||
|
findRtJar(),
|
||||||
compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersPath() : null,
|
compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersPath() : null,
|
||||||
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
|
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File findRtJar() {
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
if ("jre".equals(new File(javaHome).getName())) {
|
||||||
|
javaHome = new File(javaHome).getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
File rtJar = findRtJar(javaHome);
|
||||||
|
|
||||||
|
if (rtJar == null || !rtJar.exists()) {
|
||||||
|
throw new IllegalArgumentException("No JDK rt.jar found under " + javaHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File findRtJar(String javaHome) {
|
||||||
|
File rtJar = new File(javaHome, "jre/lib/rt.jar");
|
||||||
|
if (rtJar.exists()) {
|
||||||
|
return rtJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar");
|
||||||
|
if (classesJar.exists()) {
|
||||||
|
return classesJar;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-13
@@ -76,7 +76,6 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
|||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.FqName;
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.NamespaceFactory;
|
import org.jetbrains.jet.lang.resolve.NamespaceFactory;
|
||||||
@@ -93,7 +92,6 @@ import org.jetbrains.jet.lang.resolve.constants.NullValue;
|
|||||||
import org.jetbrains.jet.lang.resolve.constants.ShortValue;
|
import org.jetbrains.jet.lang.resolve.constants.ShortValue;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||||
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
|
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
|
||||||
import org.jetbrains.jet.lang.types.DeferredType;
|
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||||
@@ -105,7 +103,6 @@ import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
|||||||
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
|
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
|
||||||
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
||||||
import org.jetbrains.jet.rt.signature.JetSignatureVisitor;
|
import org.jetbrains.jet.rt.signature.JetSignatureVisitor;
|
||||||
import org.jetbrains.jet.util.lazy.LazyValue;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -209,11 +206,9 @@ public class JavaDescriptorResolver {
|
|||||||
final PsiClass psiClass;
|
final PsiClass psiClass;
|
||||||
@Nullable
|
@Nullable
|
||||||
final PsiPackage psiPackage;
|
final PsiPackage psiPackage;
|
||||||
@NotNull
|
|
||||||
final FqName fqName;
|
final FqName fqName;
|
||||||
final boolean staticMembers;
|
final boolean staticMembers;
|
||||||
final boolean kotlin;
|
final boolean kotlin;
|
||||||
@NotNull
|
|
||||||
final ClassOrNamespaceDescriptor classOrNamespaceDescriptor;
|
final ClassOrNamespaceDescriptor classOrNamespaceDescriptor;
|
||||||
|
|
||||||
protected ResolverScopeData(@Nullable PsiClass psiClass, @Nullable PsiPackage psiPackage, @NotNull FqName fqName, boolean staticMembers, @NotNull ClassOrNamespaceDescriptor descriptor) {
|
protected ResolverScopeData(@Nullable PsiClass psiClass, @Nullable PsiPackage psiPackage, @NotNull FqName fqName, boolean staticMembers, @NotNull ClassOrNamespaceDescriptor descriptor) {
|
||||||
@@ -237,6 +232,22 @@ public class JavaDescriptorResolver {
|
|||||||
classOrNamespaceDescriptor = descriptor;
|
classOrNamespaceDescriptor = descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ResolverScopeData(boolean negative) {
|
||||||
|
if (!negative) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
this.psiClass = null;
|
||||||
|
this.psiPackage = null;
|
||||||
|
this.fqName = null;
|
||||||
|
this.staticMembers = false;
|
||||||
|
this.kotlin = false;
|
||||||
|
this.classOrNamespaceDescriptor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPositive() {
|
||||||
|
return this.classOrNamespaceDescriptor != null;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PsiElement getPsiPackageOrPsiClass() {
|
public PsiElement getPsiPackageOrPsiClass() {
|
||||||
if (psiPackage != null) {
|
if (psiPackage != null) {
|
||||||
@@ -262,6 +273,13 @@ public class JavaDescriptorResolver {
|
|||||||
this.classDescriptor = classDescriptor;
|
this.classDescriptor = classDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ResolverBinaryClassData(boolean negative) {
|
||||||
|
super(negative);
|
||||||
|
this.classDescriptor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final ResolverBinaryClassData NEGATIVE = new ResolverBinaryClassData(true);
|
||||||
|
|
||||||
List<TypeParameterDescriptorInitialization> typeParameters;
|
List<TypeParameterDescriptorInitialization> typeParameters;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -286,6 +304,13 @@ public class JavaDescriptorResolver {
|
|||||||
this.namespaceDescriptor = namespaceDescriptor;
|
this.namespaceDescriptor = namespaceDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ResolverNamespaceData(boolean negative) {
|
||||||
|
super(negative);
|
||||||
|
this.namespaceDescriptor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final ResolverNamespaceData NEGATIVE = new ResolverNamespaceData(true);
|
||||||
|
|
||||||
private JavaPackageScope memberScope;
|
private JavaPackageScope memberScope;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -374,13 +399,18 @@ public class JavaDescriptorResolver {
|
|||||||
if (classData == null) {
|
if (classData == null) {
|
||||||
PsiClass psiClass = psiClassFinder.findPsiClass(qualifiedName, PsiClassFinder.RuntimeClassesHandleMode.THROW);
|
PsiClass psiClass = psiClassFinder.findPsiClass(qualifiedName, PsiClassFinder.RuntimeClassesHandleMode.THROW);
|
||||||
if (psiClass == null) {
|
if (psiClass == null) {
|
||||||
|
ResolverBinaryClassData oldValue = classDescriptorCache.put(qualifiedName, ResolverBinaryClassData.NEGATIVE);
|
||||||
|
if (oldValue != null) {
|
||||||
|
throw new IllegalStateException("rewrite at " + qualifiedName);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
classData = createJavaClassDescriptor(psiClass, tasks);
|
classData = createJavaClassDescriptor(psiClass, tasks);
|
||||||
}
|
}
|
||||||
return classData.getClassDescriptor();
|
return classData.classDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private ResolverBinaryClassData createJavaClassDescriptor(@NotNull final PsiClass psiClass, List<Runnable> taskList) {
|
private ResolverBinaryClassData createJavaClassDescriptor(@NotNull final PsiClass psiClass, List<Runnable> taskList) {
|
||||||
FqName fqName = new FqName(psiClass.getQualifiedName());
|
FqName fqName = new FqName(psiClass.getQualifiedName());
|
||||||
if (classDescriptorCache.containsKey(fqName)) {
|
if (classDescriptorCache.containsKey(fqName)) {
|
||||||
@@ -392,18 +422,21 @@ public class JavaDescriptorResolver {
|
|||||||
String name = psiClass.getName();
|
String name = psiClass.getName();
|
||||||
ClassKind kind = psiClass.isInterface() ? (psiClass.isAnnotationType() ? ClassKind.ANNOTATION_CLASS : ClassKind.TRAIT) : ClassKind.CLASS;
|
ClassKind kind = psiClass.isInterface() ? (psiClass.isAnnotationType() ? ClassKind.ANNOTATION_CLASS : ClassKind.TRAIT) : ClassKind.CLASS;
|
||||||
ClassOrNamespaceDescriptor containingDeclaration = resolveParentDescriptor(psiClass);
|
ClassOrNamespaceDescriptor containingDeclaration = resolveParentDescriptor(psiClass);
|
||||||
ResolverBinaryClassData classData = new ResolverBinaryClassData(psiClass, fqName, new MutableClassDescriptorLite(containingDeclaration, kind));
|
|
||||||
|
// class may be resolved during resolution of parent
|
||||||
|
ResolverBinaryClassData classData = classDescriptorCache.get(fqName);
|
||||||
|
if (classData != null) {
|
||||||
|
return classData;
|
||||||
|
}
|
||||||
|
|
||||||
|
classData = new ResolverBinaryClassData(psiClass, fqName, new MutableClassDescriptorLite(containingDeclaration, kind));
|
||||||
classDescriptorCache.put(fqName, classData);
|
classDescriptorCache.put(fqName, classData);
|
||||||
classData.classDescriptor.setName(name);
|
classData.classDescriptor.setName(name);
|
||||||
classData.classDescriptor.setAnnotations(resolveAnnotations(psiClass, taskList));
|
classData.classDescriptor.setAnnotations(resolveAnnotations(psiClass, taskList));
|
||||||
|
|
||||||
List<JetType> supertypes = new ArrayList<JetType>();
|
List<JetType> supertypes = new ArrayList<JetType>();
|
||||||
|
|
||||||
TypeVariableResolver outerTypeVariableByNameResolver = TypeVariableResolvers.classTypeVariableResolver(
|
classData.typeParameters = createUninitializedClassTypeParameters(psiClass, classData);
|
||||||
(ClassOrNamespaceDescriptor) classData.classDescriptor.getContainingDeclaration(),
|
|
||||||
"class " + psiClass.getQualifiedName());
|
|
||||||
|
|
||||||
classData.typeParameters = createUninitializedClassTypeParameters(psiClass, classData, outerTypeVariableByNameResolver);
|
|
||||||
|
|
||||||
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>();
|
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>();
|
||||||
for (TypeParameterDescriptorInitialization typeParameter : classData.typeParameters) {
|
for (TypeParameterDescriptorInitialization typeParameter : classData.typeParameters) {
|
||||||
@@ -583,7 +616,7 @@ public class JavaDescriptorResolver {
|
|||||||
return classData.classDescriptor;
|
return classData.classDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TypeParameterDescriptorInitialization> createUninitializedClassTypeParameters(PsiClass psiClass, ResolverBinaryClassData classData, TypeVariableResolver typeVariableResolver) {
|
private List<TypeParameterDescriptorInitialization> createUninitializedClassTypeParameters(PsiClass psiClass, ResolverBinaryClassData classData) {
|
||||||
JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass);
|
JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass);
|
||||||
|
|
||||||
if (jetClassAnnotation.signature().length() > 0) {
|
if (jetClassAnnotation.signature().length() > 0) {
|
||||||
@@ -974,6 +1007,10 @@ public class JavaDescriptorResolver {
|
|||||||
break lookingForPsi;
|
break lookingForPsi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResolverNamespaceData oldValue = namespaceDescriptorCacheByFqn.put(fqName, ResolverNamespaceData.NEGATIVE);
|
||||||
|
if (oldValue != null) {
|
||||||
|
throw new IllegalStateException("rewrite at " + fqName);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -320,12 +320,6 @@ public class CheckerTestUtil {
|
|||||||
return SyntaxErrorDiagnosticFactory.instance;
|
return SyntaxErrorDiagnosticFactory.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Severity getSeverity() {
|
public Severity getSeverity() {
|
||||||
|
|||||||
@@ -27,24 +27,31 @@ import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
|
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||||
public class InjectorForMacros {
|
public class InjectorForMacros {
|
||||||
|
|
||||||
private ExpressionTypingServices expressionTypingServices;
|
private ExpressionTypingServices expressionTypingServices;
|
||||||
private final Project project;
|
private final Project project;
|
||||||
|
private CallResolver callResolver;
|
||||||
|
private DescriptorResolver descriptorResolver;
|
||||||
|
private AnnotationResolver annotationResolver;
|
||||||
|
private TypeResolver typeResolver;
|
||||||
|
private QualifiedExpressionResolver qualifiedExpressionResolver;
|
||||||
|
private OverloadingConflictResolver overloadingConflictResolver;
|
||||||
|
|
||||||
public InjectorForMacros(
|
public InjectorForMacros(
|
||||||
@NotNull Project project
|
@NotNull Project project
|
||||||
) {
|
) {
|
||||||
this.expressionTypingServices = new ExpressionTypingServices();
|
this.expressionTypingServices = new ExpressionTypingServices();
|
||||||
this.project = project;
|
this.project = project;
|
||||||
CallResolver callResolver = new CallResolver();
|
this.callResolver = new CallResolver();
|
||||||
DescriptorResolver descriptorResolver = new DescriptorResolver();
|
this.descriptorResolver = new DescriptorResolver();
|
||||||
AnnotationResolver annotationResolver = new AnnotationResolver();
|
this.annotationResolver = new AnnotationResolver();
|
||||||
TypeResolver typeResolver = new TypeResolver();
|
this.typeResolver = new TypeResolver();
|
||||||
QualifiedExpressionResolver qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
||||||
OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
|
this.overloadingConflictResolver = new OverloadingConflictResolver();
|
||||||
|
|
||||||
this.expressionTypingServices.setCallResolver(callResolver);
|
this.expressionTypingServices.setCallResolver(callResolver);
|
||||||
this.expressionTypingServices.setDescriptorResolver(descriptorResolver);
|
this.expressionTypingServices.setDescriptorResolver(descriptorResolver);
|
||||||
@@ -69,6 +76,10 @@ public class InjectorForMacros {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
public ExpressionTypingServices getExpressionTypingServices() {
|
public ExpressionTypingServices getExpressionTypingServices() {
|
||||||
return this.expressionTypingServices;
|
return this.expressionTypingServices;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
|||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||||
public class InjectorForTopDownAnalyzerBasic {
|
public class InjectorForTopDownAnalyzerBasic {
|
||||||
@@ -62,6 +63,22 @@ public class InjectorForTopDownAnalyzerBasic {
|
|||||||
private final Project project;
|
private final Project project;
|
||||||
private final TopDownAnalysisParameters topDownAnalysisParameters;
|
private final TopDownAnalysisParameters topDownAnalysisParameters;
|
||||||
private final ObservableBindingTrace observableBindingTrace;
|
private final ObservableBindingTrace observableBindingTrace;
|
||||||
|
private final ModuleDescriptor moduleDescriptor;
|
||||||
|
private final JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory;
|
||||||
|
private final ModuleConfiguration moduleConfiguration;
|
||||||
|
private DeclarationResolver declarationResolver;
|
||||||
|
private AnnotationResolver annotationResolver;
|
||||||
|
private CallResolver callResolver;
|
||||||
|
private ExpressionTypingServices expressionTypingServices;
|
||||||
|
private TypeResolver typeResolver;
|
||||||
|
private QualifiedExpressionResolver qualifiedExpressionResolver;
|
||||||
|
private OverloadingConflictResolver overloadingConflictResolver;
|
||||||
|
private ImportsResolver importsResolver;
|
||||||
|
private DelegationResolver delegationResolver;
|
||||||
|
private NamespaceFactoryImpl namespaceFactoryImpl;
|
||||||
|
private OverloadResolver overloadResolver;
|
||||||
|
private OverrideResolver overrideResolver;
|
||||||
|
private TypeHierarchyResolver typeHierarchyResolver;
|
||||||
|
|
||||||
public InjectorForTopDownAnalyzerBasic(
|
public InjectorForTopDownAnalyzerBasic(
|
||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
@@ -80,19 +97,22 @@ public class InjectorForTopDownAnalyzerBasic {
|
|||||||
this.project = project;
|
this.project = project;
|
||||||
this.topDownAnalysisParameters = topDownAnalysisParameters;
|
this.topDownAnalysisParameters = topDownAnalysisParameters;
|
||||||
this.observableBindingTrace = observableBindingTrace;
|
this.observableBindingTrace = observableBindingTrace;
|
||||||
DeclarationResolver declarationResolver = new DeclarationResolver();
|
this.moduleDescriptor = moduleDescriptor;
|
||||||
AnnotationResolver annotationResolver = new AnnotationResolver();
|
this.jetControlFlowDataTraceFactory = jetControlFlowDataTraceFactory;
|
||||||
CallResolver callResolver = new CallResolver();
|
this.moduleConfiguration = moduleConfiguration;
|
||||||
ExpressionTypingServices expressionTypingServices = new ExpressionTypingServices();
|
this.declarationResolver = new DeclarationResolver();
|
||||||
TypeResolver typeResolver = new TypeResolver();
|
this.annotationResolver = new AnnotationResolver();
|
||||||
QualifiedExpressionResolver qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
this.callResolver = new CallResolver();
|
||||||
OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
|
this.expressionTypingServices = new ExpressionTypingServices();
|
||||||
ImportsResolver importsResolver = new ImportsResolver();
|
this.typeResolver = new TypeResolver();
|
||||||
DelegationResolver delegationResolver = new DelegationResolver();
|
this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
||||||
NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
|
this.overloadingConflictResolver = new OverloadingConflictResolver();
|
||||||
OverloadResolver overloadResolver = new OverloadResolver();
|
this.importsResolver = new ImportsResolver();
|
||||||
OverrideResolver overrideResolver = new OverrideResolver();
|
this.delegationResolver = new DelegationResolver();
|
||||||
TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver();
|
this.namespaceFactoryImpl = new NamespaceFactoryImpl();
|
||||||
|
this.overloadResolver = new OverloadResolver();
|
||||||
|
this.overrideResolver = new OverrideResolver();
|
||||||
|
this.typeHierarchyResolver = new TypeHierarchyResolver();
|
||||||
|
|
||||||
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
||||||
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
||||||
@@ -179,6 +199,10 @@ public class InjectorForTopDownAnalyzerBasic {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
public TopDownAnalyzer getTopDownAnalyzer() {
|
public TopDownAnalyzer getTopDownAnalyzer() {
|
||||||
return this.topDownAnalyzer;
|
return this.topDownAnalyzer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractDiagnostic<E extends PsiElement> implements ParametrizedDiagnostic<E> {
|
public abstract class AbstractDiagnostic<E extends PsiElement> implements ParametrizedDiagnostic<E> {
|
||||||
private final E psiElement;
|
private final E psiElement;
|
||||||
private final String message;
|
|
||||||
private final AbstractDiagnosticFactory factory;
|
private final AbstractDiagnosticFactory factory;
|
||||||
private final Severity severity;
|
private final Severity severity;
|
||||||
|
|
||||||
public AbstractDiagnostic(@NotNull E psiElement, @NotNull AbstractDiagnosticFactory factory, @NotNull Severity severity, @NotNull String message) {
|
public AbstractDiagnostic(@NotNull E psiElement,
|
||||||
|
@NotNull AbstractDiagnosticFactory factory,
|
||||||
|
@NotNull Severity severity) {
|
||||||
this.psiElement = psiElement;
|
this.psiElement = psiElement;
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.severity = severity;
|
this.severity = severity;
|
||||||
this.message = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -48,19 +48,12 @@ public abstract class AbstractDiagnostic<E extends PsiElement> implements Parame
|
|||||||
return psiElement.getContainingFile();
|
return psiElement.getContainingFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Severity getSeverity() {
|
public Severity getSeverity() {
|
||||||
return severity;
|
return severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public E getPsiElement() {
|
public E getPsiElement() {
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class AbstractDiagnosticFactory {
|
public abstract class AbstractDiagnosticFactory {
|
||||||
|
|
||||||
private String name = null;
|
private String name = null;
|
||||||
|
|
||||||
|
|||||||
+4
-20
@@ -17,11 +17,8 @@
|
|||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -29,24 +26,11 @@ import java.util.Collection;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class AmbiguousDescriptorDiagnosticFactory extends DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<? extends CallableDescriptor>>> {
|
public class AmbiguousDescriptorDiagnosticFactory extends DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<? extends CallableDescriptor>>> {
|
||||||
public static AmbiguousDescriptorDiagnosticFactory create(String messageTemplate) {
|
public static AmbiguousDescriptorDiagnosticFactory create() {
|
||||||
return new AmbiguousDescriptorDiagnosticFactory(messageTemplate);
|
return new AmbiguousDescriptorDiagnosticFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AmbiguousDescriptorDiagnosticFactory(String messageTemplate) {
|
public AmbiguousDescriptorDiagnosticFactory() {
|
||||||
super(Severity.ERROR, messageTemplate, PositioningStrategies.DEFAULT, AMBIGUOUS_DESCRIPTOR_RENDERER);
|
super(Severity.ERROR, PositioningStrategies.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Renderer<Collection<? extends ResolvedCall<? extends CallableDescriptor>>> AMBIGUOUS_DESCRIPTOR_RENDERER =
|
|
||||||
new Renderer<Collection<? extends ResolvedCall<? extends CallableDescriptor>>>() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String render(@Nullable Collection<? extends ResolvedCall<? extends CallableDescriptor>> argument) {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder("\n");
|
|
||||||
for (ResolvedCall<? extends CallableDescriptor> call : argument) {
|
|
||||||
stringBuilder.append(DescriptorRenderer.TEXT.render(call.getResultingDescriptor())).append("\n");
|
|
||||||
}
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ public interface Diagnostic {
|
|||||||
@NotNull
|
@NotNull
|
||||||
AbstractDiagnosticFactory getFactory();
|
AbstractDiagnosticFactory getFactory();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
String getMessage();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Severity getSeverity();
|
Severity getSeverity();
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.lang.diagnostics;
|
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author svtk
|
|
||||||
*/
|
|
||||||
public class DiagnosticFactory<E extends PsiElement> extends DiagnosticFactoryWithPsiElement<E> {
|
|
||||||
protected final String message;
|
|
||||||
|
|
||||||
protected DiagnosticFactory(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy) {
|
|
||||||
super(severity, positioningStrategy);
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement> DiagnosticFactory<T> create(Severity severity, String message) {
|
|
||||||
return create(severity, message, PositioningStrategies.DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement> DiagnosticFactory<T> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy) {
|
|
||||||
return new DiagnosticFactory<T>(severity, message, positioningStrategy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public ParametrizedDiagnostic<E> on(@NotNull E element) {
|
|
||||||
return new DiagnosticWithPsiElement<E>(element, this, severity, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,40 +22,21 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class DiagnosticFactory1<E extends PsiElement, A> extends DiagnosticFactoryWithMessageFormat<E> {
|
public class DiagnosticFactory1<E extends PsiElement, A> extends DiagnosticFactoryWithPsiElement<E> {
|
||||||
private final Renderer<? super A> renderer;
|
|
||||||
|
|
||||||
protected String makeMessage(@NotNull A argument) {
|
|
||||||
return messageFormat.format(new Object[]{makeMessageFor(argument)});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String makeMessageFor(@NotNull A argument) {
|
|
||||||
return renderer.render(argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A argument) {
|
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A argument) {
|
||||||
return new DiagnosticWithPsiElement<E>(element, this, severity, makeMessage(argument));
|
return new DiagnosticWithParameters1<E, A>(element, argument, this, severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DiagnosticFactory1(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy, Renderer<? super A> renderer) {
|
protected DiagnosticFactory1(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
|
||||||
super(severity, message, positioningStrategy);
|
super(severity, positioningStrategy);
|
||||||
this.renderer = renderer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> renderer) {
|
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, PositioningStrategy<? super T> positioningStrategy) {
|
||||||
return new DiagnosticFactory1<T, A>(severity, message, positioningStrategy, renderer);
|
return new DiagnosticFactory1<T, A>(severity, positioningStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy) {
|
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity) {
|
||||||
return create(severity, message, positioningStrategy, Renderers.TO_STRING);
|
return create(severity, PositioningStrategies.DEFAULT);
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message, Renderer<? super A> renderer) {
|
|
||||||
return create(severity, message, PositioningStrategies.DEFAULT, renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message) {
|
|
||||||
return create(severity, message, PositioningStrategies.DEFAULT, Renderers.TO_STRING);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,48 +22,23 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class DiagnosticFactory2<E extends PsiElement, A, B> extends DiagnosticFactoryWithMessageFormat<E> {
|
public class DiagnosticFactory2<E extends PsiElement, A, B> extends DiagnosticFactoryWithPsiElement<E> {
|
||||||
private final Renderer<? super A> rendererForA;
|
|
||||||
private final Renderer<? super B> rendererForB;
|
|
||||||
|
|
||||||
private String makeMessage(@NotNull A a, @NotNull B b) {
|
|
||||||
return messageFormat.format(new Object[] {makeMessageForA(a), makeMessageForB(b)});
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeMessageForA(@NotNull A a) {
|
|
||||||
return rendererForA.render(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeMessageForB(@NotNull B b) {
|
|
||||||
return rendererForB.render(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b) {
|
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b) {
|
||||||
return new DiagnosticWithPsiElement<E>(element, this, severity, makeMessage(a, b));
|
return new DiagnosticWithParameters2<E, A, B>(element, a, b, this, severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DiagnosticFactory2(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
|
||||||
private DiagnosticFactory2(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
|
super(severity, positioningStrategy);
|
||||||
super(severity, message, positioningStrategy);
|
|
||||||
this.rendererForA = rendererForA;
|
|
||||||
this.rendererForB = rendererForB;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
|
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, PositioningStrategy<? super T> positioningStrategy) {
|
||||||
return new DiagnosticFactory2<T, A, B>(severity, messageStub, positioningStrategy, rendererForA, rendererForB);
|
return new DiagnosticFactory2<T, A, B>(severity, positioningStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy) {
|
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity) {
|
||||||
return new DiagnosticFactory2<T, A, B>(severity, messageStub, positioningStrategy, Renderers.TO_STRING, Renderers.TO_STRING);
|
return new DiagnosticFactory2<T, A, B>(severity, PositioningStrategies.DEFAULT);
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
|
|
||||||
return new DiagnosticFactory2<T, A, B>(severity, messageStub, PositioningStrategies.DEFAULT, rendererForA, rendererForB);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub) {
|
|
||||||
return new DiagnosticFactory2<T, A, B>(severity, messageStub, PositioningStrategies.DEFAULT, Renderers.TO_STRING, Renderers.TO_STRING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,51 +22,22 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class DiagnosticFactory3<E extends PsiElement, A, B, C> extends DiagnosticFactoryWithMessageFormat<E> {
|
public class DiagnosticFactory3<E extends PsiElement, A, B, C> extends DiagnosticFactoryWithPsiElement<E> {
|
||||||
private final Renderer<? super A> rendererForA;
|
|
||||||
private final Renderer<? super B> rendererForB;
|
|
||||||
private final Renderer<? super C> rendererForC;
|
|
||||||
|
|
||||||
protected DiagnosticFactory3(Severity severity, String messageStub, PositioningStrategy<? super E> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
|
protected DiagnosticFactory3(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
|
||||||
super(severity, messageStub, positioningStrategy);
|
super(severity, positioningStrategy);
|
||||||
this.rendererForA = rendererForA;
|
|
||||||
this.rendererForB = rendererForB;
|
|
||||||
this.rendererForC = rendererForC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub) {
|
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity) {
|
||||||
return create(severity, messageStub, PositioningStrategies.DEFAULT);
|
return create(severity, PositioningStrategies.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy) {
|
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, PositioningStrategy<? super T> positioningStrategy) {
|
||||||
return create(severity, messageStub, positioningStrategy, Renderers.TO_STRING, Renderers.TO_STRING, Renderers.TO_STRING);
|
return new DiagnosticFactory3<T, A, B, C>(severity, positioningStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
|
|
||||||
return create(severity, messageStub, PositioningStrategies.DEFAULT, rendererForA, rendererForB, rendererForC);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
|
|
||||||
return new DiagnosticFactory3<T, A, B, C>(severity, messageStub, positioningStrategy, rendererForA, rendererForB, rendererForC);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeMessage(@NotNull A a, @NotNull B b, @NotNull C c) {
|
|
||||||
return messageFormat.format(new Object[]{makeMessageForA(a), makeMessageForB(b), makeMessageForC(c)});
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeMessageForA(@NotNull A a) {
|
|
||||||
return rendererForA.render(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeMessageForB(@NotNull B b) {
|
|
||||||
return rendererForB.render(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeMessageForC(@NotNull C c) {
|
|
||||||
return rendererForC.render(c);
|
|
||||||
}
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||||
return new DiagnosticWithPsiElement<E>(element, this, severity, makeMessage(a, b, c));
|
return new DiagnosticWithParameters3<E, A, B, C>(element, a, b, c, this, severity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-37
@@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.lang.diagnostics;
|
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author abreslav
|
|
||||||
*/
|
|
||||||
public abstract class DiagnosticFactoryWithMessageFormat<E extends PsiElement> extends DiagnosticFactoryWithPsiElement<E> {
|
|
||||||
protected final MessageFormat messageFormat;
|
|
||||||
|
|
||||||
public DiagnosticFactoryWithMessageFormat(Severity severity, String message) {
|
|
||||||
this(severity, message, PositioningStrategies.DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiagnosticFactoryWithMessageFormat(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy) {
|
|
||||||
super(severity, positioningStrategy);
|
|
||||||
this.messageFormat = new MessageFormat(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ public interface DiagnosticHolder {
|
|||||||
if (diagnostic.getSeverity() == Severity.ERROR) {
|
if (diagnostic.getSeverity() == Severity.ERROR) {
|
||||||
PsiFile psiFile = diagnostic.getPsiFile();
|
PsiFile psiFile = diagnostic.getPsiFile();
|
||||||
List<TextRange> textRanges = diagnostic.getTextRanges();
|
List<TextRange> textRanges = diagnostic.getTextRanges();
|
||||||
throw new IllegalStateException(diagnostic.getMessage() + DiagnosticUtils.atLocation(psiFile, textRanges.get(0)));
|
throw new IllegalStateException(diagnostic.getFactory().getName() + DiagnosticUtils.atLocation(psiFile, textRanges.get(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -80,11 +80,16 @@ public class DiagnosticUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static LineAndColumn getLineAndColumn(@NotNull Diagnostic diagnostic) {
|
public static LineAndColumn getLineAndColumn(@NotNull Diagnostic diagnostic) {
|
||||||
PsiFile file = diagnostic.getPsiFile();
|
PsiFile file = diagnostic.getPsiFile();
|
||||||
Document document = file.getViewProvider().getDocument();
|
|
||||||
List<TextRange> textRanges = diagnostic.getTextRanges();
|
List<TextRange> textRanges = diagnostic.getTextRanges();
|
||||||
if (textRanges.isEmpty()) return LineAndColumn.NONE;
|
if (textRanges.isEmpty()) return LineAndColumn.NONE;
|
||||||
TextRange firstRange = textRanges.iterator().next();
|
TextRange firstRange = textRanges.iterator().next();
|
||||||
return offsetToLineAndColumn(document, firstRange.getStartOffset());
|
return getLineAndColumnInPsiFile(file, firstRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static LineAndColumn getLineAndColumnInPsiFile(PsiFile file, TextRange range) {
|
||||||
|
Document document = file.getViewProvider().getDocument();
|
||||||
|
return offsetToLineAndColumn(document, range.getStartOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/11/12
|
||||||
|
*/
|
||||||
|
public class DiagnosticWithParameters1<E extends PsiElement, A> extends AbstractDiagnostic<E> {
|
||||||
|
private A a;
|
||||||
|
|
||||||
|
public DiagnosticWithParameters1(@NotNull E psiElement,
|
||||||
|
@NotNull A a,
|
||||||
|
@NotNull DiagnosticFactory1<E, A> factory,
|
||||||
|
@NotNull Severity severity) {
|
||||||
|
super(psiElement, factory, severity);
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DiagnosticFactory1<E, A> getFactory() {
|
||||||
|
return (DiagnosticFactory1<E, A>)super.getFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<TextRange> getTextRanges() {
|
||||||
|
return getFactory().getTextRanges(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public A getA() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
-17
@@ -17,37 +17,48 @@
|
|||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/11/12
|
||||||
*/
|
*/
|
||||||
public class UnresolvedReferenceDiagnostic extends AbstractDiagnostic<JetReferenceExpression> {
|
public class DiagnosticWithParameters2<E extends PsiElement, A, B> extends AbstractDiagnostic<E> {
|
||||||
|
private A a;
|
||||||
|
private B b;
|
||||||
|
|
||||||
public UnresolvedReferenceDiagnostic(JetReferenceExpression referenceExpression, String message) {
|
public DiagnosticWithParameters2(@NotNull E psiElement,
|
||||||
super(referenceExpression, Errors.UNRESOLVED_REFERENCE, ERROR, message);
|
@NotNull A a,
|
||||||
|
@NotNull B b,
|
||||||
|
@NotNull DiagnosticFactory2<E, A, B> factory,
|
||||||
|
@NotNull Severity severity) {
|
||||||
|
super(psiElement, factory, severity);
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public DiagnosticFactory2<E, A, B> getFactory() {
|
||||||
return super.getMessage() + ": " + getPsiElement().getText();
|
return (DiagnosticFactory2<E, A, B>)super.getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public List<TextRange> getTextRanges() {
|
public List<TextRange> getTextRanges() {
|
||||||
JetReferenceExpression element = getPsiElement();
|
return getFactory().getTextRanges(this);
|
||||||
if (element instanceof JetArrayAccessExpression) {
|
}
|
||||||
return ((JetArrayAccessExpression) element).getBracketRanges();
|
|
||||||
}
|
@NotNull
|
||||||
return Collections.singletonList(element.getTextRange());
|
public A getA() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public B getB() {
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/11/12
|
||||||
|
*/
|
||||||
|
public class DiagnosticWithParameters3<E extends PsiElement, A, B, C> extends AbstractDiagnostic<E> {
|
||||||
|
private A a;
|
||||||
|
private B b;
|
||||||
|
private C c;
|
||||||
|
|
||||||
|
public DiagnosticWithParameters3(@NotNull E psiElement,
|
||||||
|
@NotNull A a,
|
||||||
|
@NotNull B b,
|
||||||
|
@NotNull C c,
|
||||||
|
@NotNull DiagnosticFactory3<E, A, B, C> factory,
|
||||||
|
@NotNull Severity severity) {
|
||||||
|
super(psiElement, factory, severity);
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DiagnosticFactory3<E, A, B, C> getFactory() {
|
||||||
|
return (DiagnosticFactory3<E, A, B, C>)super.getFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<TextRange> getTextRanges() {
|
||||||
|
return getFactory().getTextRanges(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public A getA() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public B getB() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public C getC() {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,267 +21,259 @@ import com.intellij.psi.PsiElement;
|
|||||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.inference.SolutionStatus;
|
import org.jetbrains.jet.lang.resolve.calls.inference.SolutionStatus;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Renderers.*;
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING;
|
import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* For error messages, see DefaultErrorMessages and IdeErrorMessages.
|
||||||
|
*
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public interface Errors {
|
public interface Errors {
|
||||||
|
|
||||||
DiagnosticFactory1<JetFile, Throwable> EXCEPTION_WHILE_ANALYZING = DiagnosticFactory1.create(ERROR, "{0}", new Renderer<Throwable>() {
|
DiagnosticFactory1<JetFile, Throwable> EXCEPTION_WHILE_ANALYZING = DiagnosticFactory1.create(ERROR);
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String render(@Nullable Throwable e) {
|
|
||||||
return e.getClass().getSimpleName() + ": " + e.getMessage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create("Unresolved reference");
|
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create();
|
||||||
|
|
||||||
//Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error
|
//Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error
|
||||||
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_REFERENCE = DiagnosticFactory2.create(ERROR, "Cannot access ''{0}'' in ''{1}''", NAME, NAME);
|
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_REFERENCE =
|
||||||
DiagnosticFactory2<PsiElement, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR, "Cannot access ''{0}'' in ''{1}''", NAME, NAME);
|
DiagnosticFactory2.create(ERROR);
|
||||||
|
DiagnosticFactory2<PsiElement, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR);
|
||||||
|
|
||||||
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.REDECLARATION;
|
RedeclarationDiagnosticFactory REDECLARATION = new RedeclarationDiagnosticFactory(ERROR);
|
||||||
RedeclarationDiagnosticFactory NAME_SHADOWING = RedeclarationDiagnosticFactory.NAME_SHADOWING;
|
RedeclarationDiagnosticFactory NAME_SHADOWING = new RedeclarationDiagnosticFactory(WARNING);
|
||||||
|
|
||||||
DiagnosticFactory2<PsiElement, JetType, JetType> TYPE_MISMATCH = DiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected",
|
DiagnosticFactory2<PsiElement, JetType, JetType> TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||||
RENDER_TYPE, RENDER_TYPE);
|
DiagnosticFactory1<PsiElement, Collection<JetKeywordToken>> INCOMPATIBLE_MODIFIERS = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, Collection<JetKeywordToken>> INCOMPATIBLE_MODIFIERS =
|
DiagnosticFactory1<PsiElement, JetKeywordToken> ILLEGAL_MODIFIER = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1.create(ERROR, "Incompatible modifiers: ''{0}''",
|
|
||||||
new Renderer<Collection<JetKeywordToken>>() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String render(@Nullable Collection<JetKeywordToken> element) {
|
|
||||||
assert element != null;
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (Iterator<JetKeywordToken> iterator = element.iterator(); iterator.hasNext(); ) {
|
|
||||||
JetKeywordToken modifier = iterator.next();
|
|
||||||
sb.append(modifier.getValue());
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
sb.append(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
DiagnosticFactory1<PsiElement, JetKeywordToken> ILLEGAL_MODIFIER = DiagnosticFactory1.create(ERROR, "Illegal modifier ''{0}''");
|
|
||||||
|
|
||||||
DiagnosticFactory2<PsiElement, JetKeywordToken, JetKeywordToken> REDUNDANT_MODIFIER = DiagnosticFactory2.create(Severity.WARNING, "Modifier {0} is redundant because {1} is present");
|
DiagnosticFactory2<PsiElement, JetKeywordToken, JetKeywordToken> REDUNDANT_MODIFIER = DiagnosticFactory2.create(Severity.WARNING);
|
||||||
DiagnosticFactory<JetModifierListOwner> ABSTRACT_MODIFIER_IN_TRAIT = DiagnosticFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
SimpleDiagnosticFactory<JetModifierListOwner> ABSTRACT_MODIFIER_IN_TRAIT = SimpleDiagnosticFactory
|
||||||
DiagnosticFactory<JetModifierListOwner> OPEN_MODIFIER_IN_TRAIT = DiagnosticFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD));
|
.create(WARNING, PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
||||||
DiagnosticFactory<PsiElement> REDUNDANT_MODIFIER_IN_GETTER = DiagnosticFactory.create(WARNING, "Visibility modifiers are redundant in getter");
|
SimpleDiagnosticFactory<JetModifierListOwner> OPEN_MODIFIER_IN_TRAIT = SimpleDiagnosticFactory
|
||||||
DiagnosticFactory<PsiElement> TRAIT_CAN_NOT_BE_FINAL = DiagnosticFactory.create(ERROR, "Trait can not be final");
|
.create(WARNING, PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD));
|
||||||
DiagnosticFactory<JetExpression> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = DiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message
|
SimpleDiagnosticFactory<PsiElement>
|
||||||
DiagnosticFactory<JetReturnExpression> RETURN_NOT_ALLOWED = DiagnosticFactory.create(ERROR, "'return' is not allowed here");
|
REDUNDANT_MODIFIER_IN_GETTER = SimpleDiagnosticFactory.create(WARNING);
|
||||||
DiagnosticFactory<JetTypeProjection> PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE = DiagnosticFactory.create(ERROR, "Projections are not allowed for immediate arguments of a supertype", new PositioningStrategy<JetTypeProjection>() {
|
SimpleDiagnosticFactory<PsiElement> TRAIT_CAN_NOT_BE_FINAL = SimpleDiagnosticFactory.create(ERROR);
|
||||||
@NotNull
|
SimpleDiagnosticFactory<JetExpression> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR);
|
||||||
@Override
|
SimpleDiagnosticFactory<JetReturnExpression> RETURN_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR);
|
||||||
public List<TextRange> mark(@NotNull JetTypeProjection element) {
|
SimpleDiagnosticFactory<JetTypeProjection> PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE =
|
||||||
return markNode(element.getProjectionNode());
|
SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.PROJECTION_MODIFIER);
|
||||||
}
|
SimpleDiagnosticFactory<JetSimpleNameExpression>LABEL_NAME_CLASH = SimpleDiagnosticFactory.create(WARNING);
|
||||||
});
|
SimpleDiagnosticFactory<JetSimpleNameExpression> EXPRESSION_EXPECTED_NAMESPACE_FOUND = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetSimpleNameExpression> LABEL_NAME_CLASH = DiagnosticFactory.create(WARNING, "There is more than one label with such a name in this scope");
|
|
||||||
DiagnosticFactory<JetSimpleNameExpression> EXPRESSION_EXPECTED_NAMESPACE_FOUND = DiagnosticFactory.create(ERROR, "Expression expected, but a namespace name found");
|
|
||||||
|
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR, "Cannot import from ''{0}''", NAME);
|
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
|
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> USELESS_HIDDEN_IMPORT = DiagnosticFactory.create(WARNING, "Useless import, it is hidden further");
|
SimpleDiagnosticFactory<JetExpression>USELESS_HIDDEN_IMPORT = SimpleDiagnosticFactory.create(WARNING);
|
||||||
DiagnosticFactory<JetExpression> USELESS_SIMPLE_IMPORT = DiagnosticFactory.create(WARNING, "Useless import, does nothing");
|
SimpleDiagnosticFactory<JetExpression> USELESS_SIMPLE_IMPORT = SimpleDiagnosticFactory.create(WARNING);
|
||||||
|
|
||||||
DiagnosticFactory<JetParameter> CANNOT_INFER_PARAMETER_TYPE = DiagnosticFactory.create(ERROR, "Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
|
SimpleDiagnosticFactory<JetParameter> CANNOT_INFER_PARAMETER_TYPE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetElement> NO_BACKING_FIELD_ABSTRACT_PROPERTY = DiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it's abstract");
|
SimpleDiagnosticFactory<JetElement> NO_BACKING_FIELD_ABSTRACT_PROPERTY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetElement> NO_BACKING_FIELD_CUSTOM_ACCESSORS = DiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it has custom accessors without reference to the backing field");
|
SimpleDiagnosticFactory<JetElement> NO_BACKING_FIELD_CUSTOM_ACCESSORS = SimpleDiagnosticFactory.create(ERROR
|
||||||
DiagnosticFactory<JetElement> INACCESSIBLE_BACKING_FIELD = DiagnosticFactory.create(ERROR, "The backing field is not accessible here");
|
);
|
||||||
DiagnosticFactory<JetElement> NOT_PROPERTY_BACKING_FIELD = DiagnosticFactory.create(ERROR, "The referenced variable is not a property and doesn't have backing field");
|
SimpleDiagnosticFactory<JetElement> INACCESSIBLE_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
SimpleDiagnosticFactory<JetElement> NOT_PROPERTY_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<PsiElement> MIXING_NAMED_AND_POSITIONED_ARGUMENTS = DiagnosticFactory.create(ERROR, "Mixing named and positioned arguments in not allowed");
|
SimpleDiagnosticFactory<PsiElement> MIXING_NAMED_AND_POSITIONED_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetReferenceExpression> ARGUMENT_PASSED_TWICE = DiagnosticFactory.create(ERROR, "An argument is already passed for this parameter");
|
SimpleDiagnosticFactory<JetReferenceExpression> ARGUMENT_PASSED_TWICE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
UnresolvedReferenceDiagnosticFactory NAMED_PARAMETER_NOT_FOUND = UnresolvedReferenceDiagnosticFactory.create("Cannot find a parameter with this name");
|
UnresolvedReferenceDiagnosticFactory NAMED_PARAMETER_NOT_FOUND = UnresolvedReferenceDiagnosticFactory.create();
|
||||||
DiagnosticFactory<JetExpression> VARARG_OUTSIDE_PARENTHESES = DiagnosticFactory.create(ERROR, "Passing value as a vararg is only allowed inside a parenthesized argument list");
|
SimpleDiagnosticFactory<JetExpression> VARARG_OUTSIDE_PARENTHESES = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<LeafPsiElement> NON_VARARG_SPREAD = DiagnosticFactory.create(ERROR, "The spread operator (*foo) may only be applied in a vararg position");
|
SimpleDiagnosticFactory<LeafPsiElement> NON_VARARG_SPREAD = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetExpression> MANY_FUNCTION_LITERAL_ARGUMENTS = DiagnosticFactory.create(ERROR, "Only one function literal is allowed outside a parenthesized argument list");
|
SimpleDiagnosticFactory<JetExpression> MANY_FUNCTION_LITERAL_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory.create(ERROR, "This property must either have a type annotation or be initialized");
|
SimpleDiagnosticFactory<PsiElement> PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = DiagnosticFactory.create(ERROR, "This property cannot be declared abstract", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
SimpleDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimpleDiagnosticFactory
|
||||||
DiagnosticFactory<JetProperty> ABSTRACT_PROPERTY_NOT_IN_CLASS = DiagnosticFactory.create(ERROR, "A property may be abstract only when defined in a class or trait", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
.create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
||||||
DiagnosticFactory<JetExpression> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticFactory.create(ERROR, "Property with initializer cannot be abstract");
|
SimpleDiagnosticFactory<JetProperty> ABSTRACT_PROPERTY_NOT_IN_CLASS = SimpleDiagnosticFactory.create(ERROR,
|
||||||
DiagnosticFactory<JetPropertyAccessor> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticFactory.create(ERROR, "Property with getter implementation cannot be abstract");
|
PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
||||||
DiagnosticFactory<JetPropertyAccessor> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticFactory.create(ERROR, "Property with setter implementation cannot be abstract");
|
SimpleDiagnosticFactory<JetExpression> ABSTRACT_PROPERTY_WITH_INITIALIZER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
SimpleDiagnosticFactory<JetPropertyAccessor> ABSTRACT_PROPERTY_WITH_GETTER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
SimpleDiagnosticFactory<JetPropertyAccessor>ABSTRACT_PROPERTY_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<PsiElement> PACKAGE_MEMBER_CANNOT_BE_PROTECTED = DiagnosticFactory.create(ERROR, "Package member cannot be protected");
|
SimpleDiagnosticFactory<PsiElement> PACKAGE_MEMBER_CANNOT_BE_PROTECTED = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<PsiElement> GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = DiagnosticFactory.create(ERROR, "Getter visibility must be the same as property visibility");
|
SimpleDiagnosticFactory<PsiElement> GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetProperty> BACKING_FIELD_IN_TRAIT = DiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field", PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
SimpleDiagnosticFactory<JetProperty> BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR,
|
||||||
DiagnosticFactory<JetProperty> MUST_BE_INITIALIZED = DiagnosticFactory.create(ERROR, "Property must be initialized", PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
DiagnosticFactory<JetProperty> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = DiagnosticFactory.create(ERROR, "Property must be initialized or be abstract", PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
SimpleDiagnosticFactory<JetProperty> MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR,
|
||||||
DiagnosticFactory<JetExpression> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticFactory.create(ERROR, "Property initializers are not allowed in traits");
|
PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
DiagnosticFactory<JetExpression> PROPERTY_INITIALIZER_NO_BACKING_FIELD = DiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
|
SimpleDiagnosticFactory<JetProperty> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimpleDiagnosticFactory.create(ERROR,
|
||||||
DiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = DiagnosticFactory3.create(ERROR, "Abstract property {0} in non-abstract class {1}", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
DiagnosticFactory3<JetFunction, String, ClassDescriptor, JetClass> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = DiagnosticFactory3.create(ERROR, "Abstract function {0} in non-abstract class {1}", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
SimpleDiagnosticFactory<JetExpression>PROPERTY_INITIALIZER_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = DiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
SimpleDiagnosticFactory<JetExpression> PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = DiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract", PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
DiagnosticFactory2<JetModifierListOwner, String, ClassDescriptor> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS =
|
||||||
DiagnosticFactory1<JetModifierListOwner, SimpleFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = DiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
DiagnosticFactory2.create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
||||||
|
DiagnosticFactory2<JetFunction, String, ClassDescriptor> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS =
|
||||||
|
DiagnosticFactory2.create(ERROR,PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
||||||
|
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY =
|
||||||
|
DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
||||||
|
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY =
|
||||||
|
DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
|
DiagnosticFactory1<JetModifierListOwner, SimpleFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION =
|
||||||
|
DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
|
||||||
|
|
||||||
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = DiagnosticFactory1.create(ERROR, "Function {0} must have a body", PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY =
|
||||||
DiagnosticFactory<JetNamedDeclaration> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticFactory.create(ERROR, "Non final member in a final class", PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD));
|
DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
|
SimpleDiagnosticFactory<JetNamedDeclaration> NON_FINAL_MEMBER_IN_FINAL_CLASS =
|
||||||
|
SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD));
|
||||||
|
|
||||||
DiagnosticFactory<JetNamedDeclaration> PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE = DiagnosticFactory.create(ERROR, "Public or protected member should specify a type", PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
SimpleDiagnosticFactory<JetNamedDeclaration> PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE =
|
||||||
|
SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
|
|
||||||
DiagnosticFactory<JetTypeProjection> PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = DiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning
|
SimpleDiagnosticFactory<JetTypeProjection> PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT =
|
||||||
DiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED = DiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here");
|
SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.PROJECTION_MODIFIER);
|
||||||
DiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED_DEFAULT = DiagnosticFactory.create(ERROR, "Constructor invocation should be explicitly specified");
|
SimpleDiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY = DiagnosticFactory.create(ERROR, "A secondary constructor may appear only in a class that has a primary constructor");
|
SimpleDiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED_DEFAULT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST = DiagnosticFactory.create(ERROR, "Secondary constructors must have an initializer list");
|
SimpleDiagnosticFactory<PsiElement> SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetDelegatorByExpressionSpecifier> BY_IN_SECONDARY_CONSTRUCTOR = DiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
|
SimpleDiagnosticFactory<PsiElement> SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetDelegatorToSuperClass> INITIALIZER_WITH_NO_ARGUMENTS = DiagnosticFactory.create(ERROR, "Constructor arguments required");
|
SimpleDiagnosticFactory<JetDelegatorByExpressionSpecifier> BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetDelegationSpecifier> MANY_CALLS_TO_THIS = DiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
|
SimpleDiagnosticFactory<JetDelegatorToSuperClass> INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<JetModifierListOwner, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = DiagnosticFactory1.create(ERROR, "{0} overrides nothing", PositioningStrategies.POSITION_OVERRIDE_MODIFIER, DescriptorRenderer.TEXT);
|
SimpleDiagnosticFactory<JetDelegationSpecifier> MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory3<PsiNameIdentifierOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN =
|
DiagnosticFactory1<JetModifierListOwner, CallableMemberDescriptor> NOTHING_TO_OVERRIDE =
|
||||||
DiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", PositioningStrategies.POSITION_NAME_IDENTIFIER, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
|
DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_OVERRIDE_MODIFIER);
|
||||||
|
DiagnosticFactory3<PsiNameIdentifierOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor>
|
||||||
|
VIRTUAL_MEMBER_HIDDEN = DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
DiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableDescriptor, DeclarationDescriptor> CANNOT_OVERRIDE_INVISIBLE_MEMBER =
|
DiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableDescriptor, DeclarationDescriptor> CANNOT_OVERRIDE_INVISIBLE_MEMBER =
|
||||||
DiagnosticFactory3.create(ERROR, "''{0}'' cannot has no access to ''{1}'' in class {2}, so it cannot override it", PositioningStrategies.POSITION_OVERRIDE_MODIFIER, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
|
DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_OVERRIDE_MODIFIER);
|
||||||
DiagnosticFactory<JetModifierListOwner> CANNOT_INFER_VISIBILITY = DiagnosticFactory.create(ERROR, "Cannot infer visibility. Please specify it explicitly", PositioningStrategies.POSITION_OVERRIDE_MODIFIER);
|
SimpleDiagnosticFactory<JetModifierListOwner> CANNOT_INFER_VISIBILITY = SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_OVERRIDE_MODIFIER);
|
||||||
|
|
||||||
DiagnosticFactory1<JetClass, ClassDescriptor> ENUM_ENTRY_SHOULD_BE_INITIALIZED = DiagnosticFactory1.create(ERROR, "Missing delegation specifier ''{0}''", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
|
DiagnosticFactory1<JetClass, ClassDescriptor> ENUM_ENTRY_SHOULD_BE_INITIALIZED =
|
||||||
DiagnosticFactory1<JetTypeReference, ClassDescriptor> ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR, "The type constructor of enum entry should be ''{0}''", NAME);
|
DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
|
DiagnosticFactory1<JetTypeReference, ClassDescriptor> ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, VariableDescriptor> UNINITIALIZED_VARIABLE = DiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
|
DiagnosticFactory1<JetSimpleNameExpression, VariableDescriptor> UNINITIALIZED_VARIABLE = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, ValueParameterDescriptor> UNINITIALIZED_PARAMETER = DiagnosticFactory1.create(ERROR, "Parameter ''{0}'' is uninitialized here", NAME);
|
DiagnosticFactory1<JetSimpleNameExpression, ValueParameterDescriptor> UNINITIALIZED_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||||
UnusedElementDiagnosticFactory<JetProperty, VariableDescriptor> UNUSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is never used", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
|
UnusedElementDiagnosticFactory<JetProperty, VariableDescriptor> UNUSED_VARIABLE =
|
||||||
UnusedElementDiagnosticFactory<JetParameter, VariableDescriptor> UNUSED_PARAMETER = UnusedElementDiagnosticFactory.create(WARNING, "Parameter ''{0}'' is never used", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
|
UnusedElementDiagnosticFactory.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
UnusedElementDiagnosticFactory<JetNamedDeclaration, DeclarationDescriptor> ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is assigned but never accessed", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
|
UnusedElementDiagnosticFactory<JetParameter, VariableDescriptor> UNUSED_PARAMETER =
|
||||||
DiagnosticFactory1<JetExpression, DeclarationDescriptor> VARIABLE_WITH_REDUNDANT_INITIALIZER = DiagnosticFactory1.create(WARNING, "Variable ''{0}'' initializer is redundant", NAME);
|
UnusedElementDiagnosticFactory.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
DiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> UNUSED_VALUE = DiagnosticFactory2.create(WARNING, "The value ''{0}'' assigned to ''{1}'' is never used", ELEMENT_TEXT, TO_STRING);
|
UnusedElementDiagnosticFactory<JetNamedDeclaration, DeclarationDescriptor> ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE =
|
||||||
DiagnosticFactory1<JetElement, JetElement> UNUSED_CHANGED_VALUE = DiagnosticFactory1.create(WARNING, "The value changed at ''{0}'' is never used", ELEMENT_TEXT);
|
UnusedElementDiagnosticFactory.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||||
DiagnosticFactory<JetElement> UNUSED_EXPRESSION = DiagnosticFactory.create(WARNING, "The expression is unused");
|
DiagnosticFactory1<JetExpression, DeclarationDescriptor> VARIABLE_WITH_REDUNDANT_INITIALIZER = DiagnosticFactory1.create(WARNING);
|
||||||
DiagnosticFactory<JetFunctionLiteralExpression> UNUSED_FUNCTION_LITERAL = DiagnosticFactory.create(WARNING, "The function literal is unused. If you mean block, you can use 'run { ... }'");
|
DiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> UNUSED_VALUE = DiagnosticFactory2.create(WARNING);
|
||||||
|
DiagnosticFactory1<JetElement, JetElement> UNUSED_CHANGED_VALUE = DiagnosticFactory1.create(WARNING);
|
||||||
|
SimpleDiagnosticFactory<JetElement> UNUSED_EXPRESSION = SimpleDiagnosticFactory.create(WARNING);
|
||||||
|
SimpleDiagnosticFactory<JetFunctionLiteralExpression> UNUSED_FUNCTION_LITERAL = SimpleDiagnosticFactory.create(WARNING);
|
||||||
|
|
||||||
DiagnosticFactory1<JetExpression, DeclarationDescriptor> VAL_REASSIGNMENT = DiagnosticFactory1.create(ERROR, "Val can not be reassigned", NAME);
|
DiagnosticFactory1<JetExpression, DeclarationDescriptor> VAL_REASSIGNMENT = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_BEFORE_DECLARATION = DiagnosticFactory1.create(ERROR, "Variable cannot be initialized before declaration", NAME);
|
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_BEFORE_DECLARATION = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> VARIABLE_EXPECTED = DiagnosticFactory.create(ERROR, "Variable expected");
|
SimpleDiagnosticFactory<JetExpression> VARIABLE_EXPECTED = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER = DiagnosticFactory1.create(ERROR, "This property has a custom setter, so initialization using backing field required", NAME);
|
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER = DiagnosticFactory1.create(ERROR, "Setter of this property can be overridden, so initialization using backing field required", NAME);
|
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> FUNCTION_PARAMETERS_OF_INLINE_FUNCTION = DiagnosticFactory1.create(ERROR, "Function parameters of inline function can only be invoked", NAME);
|
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> FUNCTION_PARAMETERS_OF_INLINE_FUNCTION = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetElement> UNREACHABLE_CODE = DiagnosticFactory.create(ERROR, "Unreachable code");
|
SimpleDiagnosticFactory<JetElement> UNREACHABLE_CODE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetClassObject> MANY_CLASS_OBJECTS = DiagnosticFactory.create(ERROR, "Only one class object is allowed per class");
|
SimpleDiagnosticFactory<JetClassObject> MANY_CLASS_OBJECTS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetClassObject> CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory.create(ERROR, "A class object is not allowed here");
|
SimpleDiagnosticFactory<JetClassObject> CLASS_OBJECT_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetDelegatorByExpressionSpecifier> DELEGATION_IN_TRAIT = DiagnosticFactory.create(ERROR, "Traits cannot use delegation");
|
SimpleDiagnosticFactory<JetDelegatorByExpressionSpecifier> DELEGATION_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetTypeReference> DELEGATION_NOT_TO_TRAIT = DiagnosticFactory.create(ERROR, "Only traits can be delegated to");
|
SimpleDiagnosticFactory<JetTypeReference> DELEGATION_NOT_TO_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> NO_CONSTRUCTOR = DiagnosticFactory.create(ERROR, "This class does not have a constructor");
|
SimpleDiagnosticFactory<PsiElement> NO_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> NOT_A_CLASS = DiagnosticFactory.create(ERROR, "Not a class");
|
SimpleDiagnosticFactory<JetExpression> NOT_A_CLASS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetEscapeStringTemplateEntry> ILLEGAL_ESCAPE_SEQUENCE = DiagnosticFactory.create(ERROR, "Illegal escape sequence");
|
SimpleDiagnosticFactory<JetEscapeStringTemplateEntry> ILLEGAL_ESCAPE_SEQUENCE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetTypeReference> LOCAL_EXTENSION_PROPERTY = DiagnosticFactory.create(ERROR, "Local extension properties are not allowed");
|
SimpleDiagnosticFactory<JetTypeReference> LOCAL_EXTENSION_PROPERTY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetPropertyAccessor> LOCAL_VARIABLE_WITH_GETTER = DiagnosticFactory.create(ERROR, "Local variables are not allowed to have getters");
|
SimpleDiagnosticFactory<JetPropertyAccessor> LOCAL_VARIABLE_WITH_GETTER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetPropertyAccessor> LOCAL_VARIABLE_WITH_SETTER = DiagnosticFactory.create(ERROR, "Local variables are not allowed to have setters");
|
SimpleDiagnosticFactory<JetPropertyAccessor> LOCAL_VARIABLE_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetPropertyAccessor> VAL_WITH_SETTER = DiagnosticFactory.create(ERROR, "A 'val'-property cannot have a setter");
|
SimpleDiagnosticFactory<JetPropertyAccessor> VAL_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetArrayAccessExpression> NO_GET_METHOD = DiagnosticFactory.create(ERROR, "No get method providing array access", PositioningStrategies.POSITION_ARRAY_ACCESS);
|
SimpleDiagnosticFactory<JetArrayAccessExpression> NO_GET_METHOD =
|
||||||
DiagnosticFactory<JetArrayAccessExpression> NO_SET_METHOD = DiagnosticFactory.create(ERROR, "No set method providing array access", PositioningStrategies.POSITION_ARRAY_ACCESS);
|
SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_ARRAY_ACCESS);
|
||||||
|
SimpleDiagnosticFactory<JetArrayAccessExpression> NO_SET_METHOD =
|
||||||
|
SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_ARRAY_ACCESS);
|
||||||
|
|
||||||
DiagnosticFactory<JetSimpleNameExpression> INC_DEC_SHOULD_NOT_RETURN_UNIT = DiagnosticFactory.create(ERROR, "Functions inc(), dec() shouldn't return Unit to be used by operators ++, --");
|
SimpleDiagnosticFactory<JetSimpleNameExpression> INC_DEC_SHOULD_NOT_RETURN_UNIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, JetSimpleNameExpression> ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT =
|
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, JetSimpleNameExpression> ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT =
|
||||||
DiagnosticFactory2.create(ERROR, "Function ''{0}'' should return Unit to be used by corresponding operator ''{1}''", NAME, ELEMENT_TEXT);
|
DiagnosticFactory2.create(ERROR);
|
||||||
AmbiguousDescriptorDiagnosticFactory ASSIGN_OPERATOR_AMBIGUITY = AmbiguousDescriptorDiagnosticFactory.create("Assignment operators ambiguity: {0}");
|
AmbiguousDescriptorDiagnosticFactory ASSIGN_OPERATOR_AMBIGUITY = AmbiguousDescriptorDiagnosticFactory.create();
|
||||||
|
|
||||||
DiagnosticFactory<JetSimpleNameExpression> EQUALS_MISSING = DiagnosticFactory.create(ERROR, "No method 'equals(Any?) : Boolean' available");
|
SimpleDiagnosticFactory<JetSimpleNameExpression> EQUALS_MISSING = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetBinaryExpression> ASSIGNMENT_IN_EXPRESSION_CONTEXT = DiagnosticFactory.create(ERROR, "Assignments are not expressions, and only expressions are allowed in this context");
|
SimpleDiagnosticFactory<JetBinaryExpression> ASSIGNMENT_IN_EXPRESSION_CONTEXT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetRootNamespaceExpression> NAMESPACE_IS_NOT_AN_EXPRESSION = DiagnosticFactory.create(ERROR, "'namespace' is not an expression, it can only be used on the left-hand side of a dot ('.')");
|
SimpleDiagnosticFactory<JetRootNamespaceExpression> NAMESPACE_IS_NOT_AN_EXPRESSION = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<JetSuperExpression, String> SUPER_IS_NOT_AN_EXPRESSION = DiagnosticFactory1.create(ERROR, "{0} is not an expression, it can only be used on the left-hand side of a dot ('.')");
|
DiagnosticFactory1<JetSuperExpression, String> SUPER_IS_NOT_AN_EXPRESSION = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory<JetDeclaration> DECLARATION_IN_ILLEGAL_CONTEXT = DiagnosticFactory.create(ERROR, "Declarations are not allowed in this position");
|
SimpleDiagnosticFactory<JetDeclaration> DECLARATION_IN_ILLEGAL_CONTEXT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> SETTER_PARAMETER_WITH_DEFAULT_VALUE = DiagnosticFactory.create(ERROR, "Setter parameters can not have default values");
|
SimpleDiagnosticFactory<JetExpression> SETTER_PARAMETER_WITH_DEFAULT_VALUE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetThisExpression> NO_THIS = DiagnosticFactory.create(ERROR, "'this' is not defined in this context");
|
SimpleDiagnosticFactory<JetThisExpression> NO_THIS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetSuperExpression> SUPER_NOT_AVAILABLE = DiagnosticFactory.create(ERROR, "No supertypes are accessible in this context");
|
SimpleDiagnosticFactory<JetSuperExpression> SUPER_NOT_AVAILABLE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetSuperExpression> AMBIGUOUS_SUPER = DiagnosticFactory.create(ERROR, "Many supertypes available, please specify the one you mean in angle brackets, e.g. 'super<Foo>'");
|
SimpleDiagnosticFactory<JetSuperExpression> AMBIGUOUS_SUPER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> ABSTRACT_SUPER_CALL = DiagnosticFactory.create(ERROR, "Abstract member cannot be accessed directly");
|
SimpleDiagnosticFactory<JetExpression> ABSTRACT_SUPER_CALL = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetTypeReference> NOT_A_SUPERTYPE = DiagnosticFactory.create(ERROR, "Not a supertype");
|
SimpleDiagnosticFactory<JetTypeReference> NOT_A_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER = DiagnosticFactory.create(WARNING, "Type arguments do not need to be specified in a 'super' qualifier");
|
SimpleDiagnosticFactory<PsiElement> TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER = SimpleDiagnosticFactory.create(WARNING);
|
||||||
DiagnosticFactory<JetSimpleNameExpression> USELESS_CAST_STATIC_ASSERT_IS_FINE = DiagnosticFactory.create(WARNING, "No cast needed, use ':' instead");
|
SimpleDiagnosticFactory<JetSimpleNameExpression> USELESS_CAST_STATIC_ASSERT_IS_FINE = SimpleDiagnosticFactory.create(WARNING);
|
||||||
DiagnosticFactory<JetSimpleNameExpression> USELESS_CAST = DiagnosticFactory.create(WARNING, "No cast needed");
|
SimpleDiagnosticFactory<JetSimpleNameExpression> USELESS_CAST = SimpleDiagnosticFactory.create(WARNING);
|
||||||
DiagnosticFactory<JetSimpleNameExpression> CAST_NEVER_SUCCEEDS = DiagnosticFactory.create(WARNING, "This cast can never succeed");
|
SimpleDiagnosticFactory<JetSimpleNameExpression> CAST_NEVER_SUCCEEDS = SimpleDiagnosticFactory.create(WARNING);
|
||||||
DiagnosticFactory1<JetTypeReference, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticFactory1.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", RENDER_TYPE);//, DiagnosticParameters.TYPE);
|
DiagnosticFactory2<JetTypeReference, JetType, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory1<JetTypeReference, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticFactory1.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", RENDER_TYPE);//, DiagnosticParameters.TYPE);
|
DiagnosticFactory2<JetTypeReference, JetType, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_CLASS_OBJECT = DiagnosticFactory1.create(ERROR, "Please specify constructor invocation; classifier {0} does not have a class object", NAME);
|
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_CLASS_OBJECT = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> NO_GENERICS_IN_SUPERTYPE_SPECIFIER = DiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified");
|
SimpleDiagnosticFactory<PsiElement> NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetExpression> HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = DiagnosticFactory.create(ERROR, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property");
|
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> HAS_NEXT_MISSING = DiagnosticFactory.create(ERROR, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
|
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_MISSING = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> HAS_NEXT_FUNCTION_AMBIGUITY = DiagnosticFactory.create(ERROR, "Function 'iterator().hasNext()' is ambiguous for this expression");
|
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> HAS_NEXT_MUST_BE_READABLE = DiagnosticFactory.create(ERROR, "The 'iterator().hasNext' property of the loop range must be readable");
|
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_MUST_BE_READABLE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<JetExpression, JetType> HAS_NEXT_PROPERTY_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "The 'iterator().hasNext' property of the loop range must return Boolean, but returns {0}", RENDER_TYPE);
|
DiagnosticFactory1<JetExpression, JetType> HAS_NEXT_PROPERTY_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetExpression, JetType> HAS_NEXT_FUNCTION_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "The 'iterator().hasNext()' function of the loop range must return Boolean, but returns {0}", RENDER_TYPE);
|
DiagnosticFactory1<JetExpression, JetType> HAS_NEXT_FUNCTION_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> NEXT_AMBIGUITY = DiagnosticFactory.create(ERROR, "Function 'iterator().next()' is ambiguous for this expression");
|
SimpleDiagnosticFactory<JetExpression> NEXT_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> NEXT_MISSING = DiagnosticFactory.create(ERROR, "Loop range must have an 'iterator().next()' function");
|
SimpleDiagnosticFactory<JetExpression> NEXT_MISSING = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetExpression> ITERATOR_MISSING = DiagnosticFactory.create(ERROR, "For-loop range must have an iterator() method");
|
SimpleDiagnosticFactory<JetExpression> ITERATOR_MISSING = SimpleDiagnosticFactory.create(ERROR);
|
||||||
AmbiguousDescriptorDiagnosticFactory ITERATOR_AMBIGUITY = AmbiguousDescriptorDiagnosticFactory.create("Method 'iterator()' is ambiguous for this expression: {0}");
|
AmbiguousDescriptorDiagnosticFactory ITERATOR_AMBIGUITY = AmbiguousDescriptorDiagnosticFactory.create();
|
||||||
|
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, JetType> COMPARE_TO_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "compareTo() must return Int, but returns {0}", RENDER_TYPE);
|
DiagnosticFactory1<JetSimpleNameExpression, JetType> COMPARE_TO_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetExpression, JetType> CALLEE_NOT_A_FUNCTION = DiagnosticFactory1.create(ERROR, "Expecting a function type, but found {0}", RENDER_TYPE);
|
DiagnosticFactory1<JetExpression, JetType> CALLEE_NOT_A_FUNCTION = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetReturnExpression> RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY = DiagnosticFactory.create(ERROR, "Returns are not allowed for functions with expression body. Use block body in '{...}'");
|
SimpleDiagnosticFactory<JetReturnExpression> RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetDeclarationWithBody> NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = DiagnosticFactory.create(ERROR, "A 'return' expression required in a function with a block body ('{...}')", new PositioningStrategy<JetDeclarationWithBody>() {
|
SimpleDiagnosticFactory<JetDeclarationWithBody> NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY =
|
||||||
@NotNull
|
SimpleDiagnosticFactory.create(ERROR,
|
||||||
@Override
|
new PositioningStrategy<JetDeclarationWithBody>() {
|
||||||
public List<TextRange> mark(@NotNull JetDeclarationWithBody element) {
|
@NotNull
|
||||||
JetExpression bodyExpression = element.getBodyExpression();
|
@Override
|
||||||
if (!(bodyExpression instanceof JetBlockExpression)) return Collections.emptyList();
|
public List<TextRange> mark(@NotNull JetDeclarationWithBody element) {
|
||||||
JetBlockExpression blockExpression = (JetBlockExpression) bodyExpression;
|
JetExpression bodyExpression = element.getBodyExpression();
|
||||||
TextRange lastBracketRange = blockExpression.getLastBracketRange();
|
if (!(bodyExpression instanceof JetBlockExpression)) {
|
||||||
if (lastBracketRange == null) return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
return markRange(lastBracketRange);
|
}
|
||||||
}
|
JetBlockExpression blockExpression = (JetBlockExpression)bodyExpression;
|
||||||
});
|
TextRange lastBracketRange = blockExpression.getLastBracketRange();
|
||||||
DiagnosticFactory1<JetExpression, JetType> RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "This function must return a value of type {0}", RENDER_TYPE);
|
if (lastBracketRange == null) {
|
||||||
DiagnosticFactory1<JetExpression, JetType> EXPECTED_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "Expected a value of type {0}", RENDER_TYPE);
|
return Collections.emptyList();
|
||||||
DiagnosticFactory1<JetBinaryExpression, JetType> ASSIGNMENT_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "Expected a value of type {0}. Assignment operation is not an expression, so it does not return any value", RENDER_TYPE);
|
}
|
||||||
DiagnosticFactory1<JetExpression, JetType> IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING, "Type was casted to ''{0}''. Please specify ''{0}'' as expected type, if you mean such cast", RENDER_TYPE);
|
return markRange(lastBracketRange);
|
||||||
DiagnosticFactory1<JetExpression, JetExpression> EXPRESSION_EXPECTED = DiagnosticFactory1.create(ERROR, "{0} is not an expression, and only expression are allowed here", new Renderer<JetExpression>() {
|
}
|
||||||
@NotNull
|
});
|
||||||
@Override
|
DiagnosticFactory1<JetExpression, JetType> RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||||
public String render(@Nullable JetExpression expression) {
|
DiagnosticFactory1<JetExpression, JetType> EXPECTED_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||||
assert expression != null;
|
DiagnosticFactory1<JetBinaryExpression, JetType> ASSIGNMENT_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||||
String expressionType = expression.toString();
|
DiagnosticFactory1<JetExpression, JetType> IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING);
|
||||||
return expressionType.substring(0, 1) + expressionType.substring(1).toLowerCase();
|
DiagnosticFactory1<JetExpression, JetExpression> EXPRESSION_EXPECTED = DiagnosticFactory1.create(ERROR);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DiagnosticFactory1<JetTypeReference, JetType> UPPER_BOUND_VIOLATED = DiagnosticFactory1.create(ERROR, "An upper bound {0} is violated", RENDER_TYPE); // TODO : Message
|
DiagnosticFactory2<JetTypeReference, JetType, JetType> UPPER_BOUND_VIOLATED = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_CLASS_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR, "{0} is a final type, and thus a class object cannot extend it", RENDER_TYPE);
|
DiagnosticFactory1<JetTypeReference, JetType> FINAL_CLASS_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING, "{0} is a final type, and thus a value of the type parameter is predetermined", RENDER_TYPE);
|
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
|
||||||
DiagnosticFactory1<JetExpression, JetType> USELESS_ELVIS = DiagnosticFactory1.create(WARNING, "Elvis operator (?:) always returns the left operand of non-nullable type {0}", RENDER_TYPE);
|
DiagnosticFactory1<JetExpression, JetType> USELESS_ELVIS = DiagnosticFactory1.create(WARNING);
|
||||||
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS = DiagnosticFactory1.create(ERROR, "Upper bounds of {0} have empty intersection", NAME);
|
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS = DiagnosticFactory1.create(ERROR, "Class object upper bounds of {0} have empty intersection", NAME);
|
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory1<PsiElement, CallableDescriptor> TOO_MANY_ARGUMENTS = DiagnosticFactory1.create(ERROR, "Too many arguments for {0}");
|
DiagnosticFactory1<PsiElement, CallableDescriptor> TOO_MANY_ARGUMENTS = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, String> ERROR_COMPILE_TIME_VALUE = DiagnosticFactory1.create(ERROR, "{0}");
|
DiagnosticFactory1<PsiElement, String> ERROR_COMPILE_TIME_VALUE = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetWhenEntry> ELSE_MISPLACED_IN_WHEN = DiagnosticFactory.create(
|
SimpleDiagnosticFactory<JetWhenEntry> ELSE_MISPLACED_IN_WHEN = SimpleDiagnosticFactory.create(ERROR, new PositioningStrategy<JetWhenEntry>() {
|
||||||
ERROR, "'else' entry must be the last one in a when-expression", new PositioningStrategy<JetWhenEntry>() {
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<TextRange> mark(@NotNull JetWhenEntry entry) {
|
public List<TextRange> mark(@NotNull JetWhenEntry entry) {
|
||||||
@@ -291,7 +283,8 @@ public interface Errors {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DiagnosticFactory<JetWhenExpression> NO_ELSE_IN_WHEN = new DiagnosticFactory<JetWhenExpression>(ERROR, "'when' expression must contain 'else' branch", new PositioningStrategy<JetWhenExpression>() {
|
SimpleDiagnosticFactory<JetWhenExpression>
|
||||||
|
NO_ELSE_IN_WHEN = new SimpleDiagnosticFactory<JetWhenExpression>(ERROR, new PositioningStrategy<JetWhenExpression>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<TextRange> mark(@NotNull JetWhenExpression element) {
|
public List<TextRange> mark(@NotNull JetWhenExpression element) {
|
||||||
@@ -299,170 +292,148 @@ public interface Errors {
|
|||||||
return markElement(element.getWhenKeywordElement());
|
return markElement(element.getWhenKeywordElement());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
DiagnosticFactory<JetWhenConditionInRange> TYPE_MISMATCH_IN_RANGE = new DiagnosticFactory<JetWhenConditionInRange>(ERROR, "Type mismatch: incompatible types of range and element checked in it", new PositioningStrategy<JetWhenConditionInRange>() {
|
SimpleDiagnosticFactory<JetWhenConditionInRange> TYPE_MISMATCH_IN_RANGE =
|
||||||
@NotNull
|
new SimpleDiagnosticFactory<JetWhenConditionInRange>(ERROR,
|
||||||
@Override
|
new PositioningStrategy<JetWhenConditionInRange>() {
|
||||||
public List<TextRange> mark(@NotNull JetWhenConditionInRange condition) {
|
@NotNull
|
||||||
return markElement(condition.getOperationReference());
|
@Override
|
||||||
}
|
public List<TextRange> mark(@NotNull JetWhenConditionInRange condition) {
|
||||||
});
|
return markElement(condition.getOperationReference());
|
||||||
DiagnosticFactory<PsiElement> CYCLIC_INHERITANCE_HIERARCHY = DiagnosticFactory.create(ERROR, "There's a cycle in the inheritance hierarchy for this type");
|
}
|
||||||
|
});
|
||||||
|
SimpleDiagnosticFactory<PsiElement> CYCLIC_INHERITANCE_HIERARCHY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory.create(ERROR, "Only one class may appear in a supertype list");
|
SimpleDiagnosticFactory<JetTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetTypeReference> SUPERTYPE_NOT_A_CLASS_OR_TRAIT = DiagnosticFactory.create(ERROR, "Only classes and traits may serve as supertypes");
|
SimpleDiagnosticFactory<JetTypeReference> SUPERTYPE_NOT_A_CLASS_OR_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> SUPERTYPE_INITIALIZED_IN_TRAIT = DiagnosticFactory.create(ERROR, "Traits cannot initialize supertypes");
|
SimpleDiagnosticFactory<PsiElement> SUPERTYPE_INITIALIZED_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<PsiElement> CONSTRUCTOR_IN_TRAIT = DiagnosticFactory.create(ERROR, "A trait may not have a constructor");
|
SimpleDiagnosticFactory<PsiElement> CONSTRUCTOR_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetSecondaryConstructor> SECONDARY_CONSTRUCTORS_ARE_NOT_SUPPORTED = DiagnosticFactory.create(WARNING, "Secondary constructors are not supported");
|
SimpleDiagnosticFactory<JetSecondaryConstructor> SECONDARY_CONSTRUCTORS_ARE_NOT_SUPPORTED = SimpleDiagnosticFactory.create(WARNING);
|
||||||
DiagnosticFactory<JetTypeReference> SUPERTYPE_APPEARS_TWICE = DiagnosticFactory.create(ERROR, "A supertype appears twice");
|
SimpleDiagnosticFactory<JetTypeReference> SUPERTYPE_APPEARS_TWICE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetTypeReference> FINAL_SUPERTYPE = DiagnosticFactory.create(ERROR, "This type is final, so it cannot be inherited from");
|
SimpleDiagnosticFactory<JetTypeReference> FINAL_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory1<JetExpression, String> ILLEGAL_SELECTOR = DiagnosticFactory1.create(ERROR, "Expression ''{0}'' cannot be a selector (occur after a dot)");
|
DiagnosticFactory1<JetExpression, String> ILLEGAL_SELECTOR = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory.create(ERROR, "A type annotation is required on a value parameter");
|
SimpleDiagnosticFactory<JetParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetLabelQualifiedExpression> BREAK_OR_CONTINUE_OUTSIDE_A_LOOP = DiagnosticFactory.create(ERROR, "'break' and 'continue' are only allowed inside a loop");
|
SimpleDiagnosticFactory<JetLabelQualifiedExpression> BREAK_OR_CONTINUE_OUTSIDE_A_LOOP = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<JetLabelQualifiedExpression, String> NOT_A_LOOP_LABEL = DiagnosticFactory1.create(ERROR, "The label ''{0}'' does not denote a loop");
|
DiagnosticFactory1<JetLabelQualifiedExpression, String> NOT_A_LOOP_LABEL = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetReturnExpression, String> NOT_A_RETURN_LABEL = DiagnosticFactory1.create(ERROR, "The label ''{0}'' does not reference to a context from which we can return");
|
DiagnosticFactory1<JetReturnExpression, String> NOT_A_RETURN_LABEL = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetClassInitializer> ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR = DiagnosticFactory.create(ERROR, "Anonymous initializers are only allowed in the presence of a primary constructor");
|
SimpleDiagnosticFactory<JetClassInitializer> ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory<JetNullableType> NULLABLE_SUPERTYPE = DiagnosticFactory.create(ERROR, "A supertype cannot be nullable", new PositioningStrategy<JetNullableType>() {
|
SimpleDiagnosticFactory<JetNullableType> NULLABLE_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR,
|
||||||
@NotNull
|
new PositioningStrategy<JetNullableType>() {
|
||||||
@Override
|
@NotNull
|
||||||
public List<TextRange> mark(@NotNull JetNullableType element) {
|
@Override
|
||||||
return markNode(element.getQuestionMarkNode());
|
public List<TextRange> mark(@NotNull JetNullableType element) {
|
||||||
}
|
return markNode(
|
||||||
});
|
element.getQuestionMarkNode());
|
||||||
DiagnosticFactory1<PsiElement, JetType> UNSAFE_CALL = DiagnosticFactory1.create(ERROR, "Only safe calls (?.) are allowed on a nullable receiver of type {0}", RENDER_TYPE);
|
}
|
||||||
DiagnosticFactory<JetSimpleNameExpression> AMBIGUOUS_LABEL = DiagnosticFactory.create(ERROR, "Ambiguous label");
|
});
|
||||||
DiagnosticFactory1<PsiElement, String> UNSUPPORTED = DiagnosticFactory1.create(ERROR, "Unsupported [{0}]");
|
DiagnosticFactory1<PsiElement, JetType> UNSAFE_CALL = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, JetType> UNNECESSARY_SAFE_CALL = DiagnosticFactory1.create(WARNING, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE);
|
SimpleDiagnosticFactory<JetSimpleNameExpression> AMBIGUOUS_LABEL = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, JetType> UNNECESSARY_NOT_NULL_ASSERTION = DiagnosticFactory1.create(WARNING, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE);
|
DiagnosticFactory1<PsiElement, String> UNSUPPORTED = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory2<JetSimpleNameExpression, JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER = DiagnosticFactory2.create(ERROR, "{0} does not refer to a type parameter of {1}", new Renderer<JetTypeConstraint>() {
|
DiagnosticFactory1<PsiElement, JetType> UNNECESSARY_SAFE_CALL = DiagnosticFactory1.create(WARNING);
|
||||||
@NotNull
|
DiagnosticFactory1<PsiElement, JetType> UNNECESSARY_NOT_NULL_ASSERTION = DiagnosticFactory1.create(WARNING);
|
||||||
@Override
|
DiagnosticFactory2<JetSimpleNameExpression, JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER =
|
||||||
public String render(@Nullable JetTypeConstraint typeConstraint) {
|
DiagnosticFactory2.create(ERROR);
|
||||||
assert typeConstraint != null;
|
DiagnosticFactory2<JetExpression, JetType, String> AUTOCAST_IMPOSSIBLE = DiagnosticFactory2.create(ERROR);
|
||||||
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
|
|
||||||
}
|
|
||||||
}, NAME);
|
|
||||||
DiagnosticFactory2<JetExpression, JetType, String> AUTOCAST_IMPOSSIBLE = DiagnosticFactory2.create(ERROR, "Automatic cast to {0} is impossible, because {1} could have changed since the is-check", RENDER_TYPE, NAME);
|
|
||||||
|
|
||||||
DiagnosticFactory2<JetTypeReference, JetType, JetType> TYPE_MISMATCH_IN_FOR_LOOP = DiagnosticFactory2.create(ERROR, "The loop iterates over values of type {0} but the parameter is declared to be {1}", RENDER_TYPE, RENDER_TYPE);
|
DiagnosticFactory2<JetTypeReference, JetType, JetType> TYPE_MISMATCH_IN_FOR_LOOP = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory1<JetElement, JetType> TYPE_MISMATCH_IN_CONDITION = DiagnosticFactory1.create(ERROR, "Condition must be of type Boolean, but was of type {0}", RENDER_TYPE);
|
DiagnosticFactory1<JetElement, JetType> TYPE_MISMATCH_IN_CONDITION = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory2<JetTuplePattern, JetType, Integer> TYPE_MISMATCH_IN_TUPLE_PATTERN = DiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}", RENDER_TYPE, TO_STRING); // TODO: message
|
DiagnosticFactory2<JetTuplePattern, JetType, Integer> TYPE_MISMATCH_IN_TUPLE_PATTERN = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory2<JetTypeReference, JetType, JetType> TYPE_MISMATCH_IN_BINDING_PATTERN = DiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}", RENDER_TYPE, RENDER_TYPE);
|
DiagnosticFactory2<JetTypeReference, JetType, JetType> TYPE_MISMATCH_IN_BINDING_PATTERN = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory2<JetElement, JetType, JetType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}", RENDER_TYPE, RENDER_TYPE);
|
DiagnosticFactory2<JetElement, JetType, JetType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory<JetWhenCondition> EXPECTED_CONDITION = DiagnosticFactory.create(ERROR, "Expected condition of Boolean type");
|
SimpleDiagnosticFactory<JetWhenCondition> EXPECTED_CONDITION = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory1<JetElement, JetType> CANNOT_CHECK_FOR_ERASED = DiagnosticFactory1.create(ERROR, "Cannot check for instance of erased type: {0}", RENDER_TYPE);
|
DiagnosticFactory1<JetElement, JetType> CANNOT_CHECK_FOR_ERASED = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory2<JetBinaryExpressionWithTypeRHS, JetType, JetType> UNCHECKED_CAST = DiagnosticFactory2.create(WARNING, "Unchecked cast: {0} to {1}", RENDER_TYPE, RENDER_TYPE);
|
DiagnosticFactory2<JetBinaryExpressionWithTypeRHS, JetType, JetType> UNCHECKED_CAST = DiagnosticFactory2.create(WARNING);
|
||||||
|
|
||||||
DiagnosticFactory3<JetDelegationSpecifierList, TypeParameterDescriptor, ClassDescriptor, Collection<JetType>> INCONSISTENT_TYPE_PARAMETER_VALUES =
|
DiagnosticFactory3<JetDelegationSpecifierList, TypeParameterDescriptor, ClassDescriptor, Collection<JetType>>
|
||||||
DiagnosticFactory3.create(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}", NAME, DescriptorRenderer.TEXT, new Renderer<Collection<JetType>>() {
|
INCONSISTENT_TYPE_PARAMETER_VALUES = DiagnosticFactory3.create(ERROR);
|
||||||
|
|
||||||
|
DiagnosticFactory3<JetBinaryExpression, JetSimpleNameExpression, JetType, JetType> EQUALITY_NOT_APPLICABLE =
|
||||||
|
DiagnosticFactory3.create(ERROR);
|
||||||
|
|
||||||
|
DiagnosticFactory2<JetBinaryExpression, JetBinaryExpression, Boolean> SENSELESS_COMPARISON = DiagnosticFactory2.create(WARNING);
|
||||||
|
|
||||||
|
DiagnosticFactory2<PsiElement, CallableMemberDescriptor, DeclarationDescriptor> OVERRIDING_FINAL_MEMBER =
|
||||||
|
DiagnosticFactory2.create(ERROR);
|
||||||
|
DiagnosticFactory3<JetModifierListOwner, Visibility, CallableMemberDescriptor, DeclarationDescriptor> CANNOT_WEAKEN_ACCESS_PRIVILEGE =
|
||||||
|
DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_VISIBILITY_MODIFIER);
|
||||||
|
DiagnosticFactory3<JetModifierListOwner, Visibility, CallableMemberDescriptor, DeclarationDescriptor> CANNOT_CHANGE_ACCESS_PRIVILEGE =
|
||||||
|
DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_VISIBILITY_MODIFIER);
|
||||||
|
|
||||||
|
DiagnosticFactory2<JetNamedDeclaration, CallableMemberDescriptor, CallableMemberDescriptor> RETURN_TYPE_MISMATCH_ON_OVERRIDE =
|
||||||
|
DiagnosticFactory2.create(ERROR, PositioningStrategies.POSITION_DECLARATION);
|
||||||
|
|
||||||
|
DiagnosticFactory2<JetProperty, PropertyDescriptor, PropertyDescriptor> VAR_OVERRIDDEN_BY_VAL =
|
||||||
|
DiagnosticFactory2.create(ERROR, new PositioningStrategy<JetProperty>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(@Nullable Collection<JetType> types) {
|
public List<TextRange> mark(@NotNull JetProperty property) {
|
||||||
StringBuilder builder = new StringBuilder();
|
return markNode(property.getValOrVarNode());
|
||||||
for (Iterator<JetType> iterator = types.iterator(); iterator.hasNext(); ) {
|
|
||||||
JetType jetType = iterator.next();
|
|
||||||
builder.append(jetType);
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
builder.append(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DiagnosticFactory3<JetBinaryExpression, JetSimpleNameExpression, JetType, JetType> EQUALITY_NOT_APPLICABLE = DiagnosticFactory3.create(ERROR, "Operator {0} cannot be applied to {1} and {2}", new Renderer<JetSimpleNameExpression>() {
|
DiagnosticFactory2<PsiElement, JetClassOrObject, CallableMemberDescriptor> ABSTRACT_MEMBER_NOT_IMPLEMENTED =
|
||||||
@NotNull
|
DiagnosticFactory2.create(ERROR);
|
||||||
@Override
|
|
||||||
public String render(@Nullable JetSimpleNameExpression nameExpression) {
|
|
||||||
return nameExpression.getReferencedName();
|
|
||||||
}
|
|
||||||
}, TO_STRING, TO_STRING);
|
|
||||||
|
|
||||||
DiagnosticFactory2<JetBinaryExpression, JetBinaryExpression, Boolean> SENSELESS_COMPARISON = DiagnosticFactory2.create(WARNING, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING);
|
DiagnosticFactory2<PsiElement, JetClassOrObject, CallableMemberDescriptor> MANY_IMPL_MEMBER_NOT_IMPLEMENTED =
|
||||||
|
DiagnosticFactory2.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory2<PsiElement, CallableMemberDescriptor, DeclarationDescriptor> OVERRIDING_FINAL_MEMBER = DiagnosticFactory2.create(ERROR, "''{0}'' in ''{1}'' is final and cannot be overridden", NAME, NAME);
|
DiagnosticFactory2<JetDeclaration, CallableMemberDescriptor, String> CONFLICTING_OVERLOADS =
|
||||||
DiagnosticFactory3<JetModifierListOwner, Visibility, CallableMemberDescriptor, DeclarationDescriptor> CANNOT_WEAKEN_ACCESS_PRIVILEGE = DiagnosticFactory3.create(ERROR, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", PositioningStrategies.POSITION_VISIBILITY_MODIFIER, TO_STRING, NAME, NAME);
|
DiagnosticFactory2.create(ERROR, new PositioningStrategy<JetDeclaration>() {
|
||||||
DiagnosticFactory3<JetModifierListOwner, Visibility, CallableMemberDescriptor, DeclarationDescriptor> CANNOT_CHANGE_ACCESS_PRIVILEGE = DiagnosticFactory3.create(ERROR, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", PositioningStrategies.POSITION_VISIBILITY_MODIFIER, TO_STRING, NAME, NAME);
|
@NotNull
|
||||||
|
@Override
|
||||||
DiagnosticFactory2<JetNamedDeclaration, CallableMemberDescriptor, CallableMemberDescriptor> RETURN_TYPE_MISMATCH_ON_OVERRIDE =
|
public List<TextRange> mark(@NotNull JetDeclaration jetDeclaration) {
|
||||||
DiagnosticFactory2.create(ERROR, "Return type of {0} is not a subtype of the return type overridden member {1}", PositioningStrategies.POSITION_DECLARATION, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
|
if (jetDeclaration instanceof JetNamedFunction) {
|
||||||
|
JetNamedFunction functionElement = (JetNamedFunction)jetDeclaration;
|
||||||
DiagnosticFactory2<JetProperty, PropertyDescriptor, PropertyDescriptor> VAR_OVERRIDDEN_BY_VAL = DiagnosticFactory2.create(ERROR, "Var-property {0} cannot be overridden by val-property {1}", new PositioningStrategy<JetProperty>() {
|
return markRange(new TextRange(
|
||||||
@NotNull
|
functionElement.getStartOfSignatureElement().getTextRange().getStartOffset(),
|
||||||
@Override
|
functionElement.getEndOfSignatureElement().getTextRange().getEndOffset()
|
||||||
public List<TextRange> mark(@NotNull JetProperty property) {
|
));
|
||||||
return markNode(property.getValOrVarNode());
|
}
|
||||||
}
|
else if (jetDeclaration instanceof JetClass) {
|
||||||
}, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
|
// primary constructor
|
||||||
|
JetClass klass = (JetClass)jetDeclaration;
|
||||||
DiagnosticFactory2<PsiElement, JetClassOrObject, CallableMemberDescriptor> ABSTRACT_MEMBER_NOT_IMPLEMENTED = DiagnosticFactory2.create(ERROR, "{0} must be declared abstract or implement abstract member {1}", RENDER_CLASS_OR_OBJECT, DescriptorRenderer.TEXT);
|
PsiElement nameAsDeclaration = klass.getNameIdentifier();
|
||||||
|
if (nameAsDeclaration == null) {
|
||||||
DiagnosticFactory2<PsiElement, JetClassOrObject, CallableMemberDescriptor> MANY_IMPL_MEMBER_NOT_IMPLEMENTED = DiagnosticFactory2.create(ERROR, "{0} must override {1} because it inherits many implementations of it", RENDER_CLASS_OR_OBJECT, DescriptorRenderer.TEXT);
|
return markRange(klass.getTextRange());
|
||||||
|
}
|
||||||
DiagnosticFactory2<JetDeclaration, CallableMemberDescriptor, String> CONFLICTING_OVERLOADS = DiagnosticFactory2.create(ERROR, "{1} is already defined in ''{0}''", new PositioningStrategy<JetDeclaration>() {
|
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
|
||||||
@NotNull
|
if (primaryConstructorParameterList == null) {
|
||||||
@Override
|
return markRange(nameAsDeclaration.getTextRange());
|
||||||
public List<TextRange> mark(@NotNull JetDeclaration jetDeclaration) {
|
}
|
||||||
if (jetDeclaration instanceof JetNamedFunction) {
|
return markRange(new TextRange(
|
||||||
JetNamedFunction functionElement = (JetNamedFunction) jetDeclaration;
|
nameAsDeclaration.getTextRange().getStartOffset(),
|
||||||
return markRange(new TextRange(
|
primaryConstructorParameterList.getTextRange().getEndOffset()
|
||||||
functionElement.getStartOfSignatureElement().getTextRange().getStartOffset(),
|
));
|
||||||
functionElement.getEndOfSignatureElement().getTextRange().getEndOffset()
|
}
|
||||||
));
|
else {
|
||||||
}
|
// safe way
|
||||||
else if (jetDeclaration instanceof JetClass) {
|
return markRange(jetDeclaration.getTextRange());
|
||||||
// primary constructor
|
}
|
||||||
JetClass klass = (JetClass) jetDeclaration;
|
|
||||||
PsiElement nameAsDeclaration = klass.getNameIdentifier();
|
|
||||||
if (nameAsDeclaration == null) {
|
|
||||||
return markRange(klass.getTextRange());
|
|
||||||
}
|
}
|
||||||
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
|
});
|
||||||
if (primaryConstructorParameterList == null) {
|
|
||||||
return markRange(nameAsDeclaration.getTextRange());
|
|
||||||
}
|
|
||||||
return markRange(new TextRange(
|
|
||||||
nameAsDeclaration.getTextRange().getStartOffset(),
|
|
||||||
primaryConstructorParameterList.getTextRange().getEndOffset()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// safe way
|
|
||||||
return markRange(jetDeclaration.getTextRange());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, DescriptorRenderer.TEXT, TO_STRING);
|
|
||||||
|
|
||||||
|
|
||||||
DiagnosticFactory3<JetExpression, String, JetType, JetType> RESULT_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR, "{0} must return {1} but returns {2}", TO_STRING, RENDER_TYPE, RENDER_TYPE);
|
DiagnosticFactory3<JetExpression, String, JetType, JetType> RESULT_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR);
|
||||||
DiagnosticFactory3<JetReferenceExpression, String, String, String> UNSAFE_INFIX_CALL = DiagnosticFactory3.create(ERROR, "Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. Use '?.'-qualified call instead");
|
DiagnosticFactory3<JetReferenceExpression, String, String, String> UNSAFE_INFIX_CALL = DiagnosticFactory3.create(ERROR);
|
||||||
|
|
||||||
AmbiguousDescriptorDiagnosticFactory OVERLOAD_RESOLUTION_AMBIGUITY = new AmbiguousDescriptorDiagnosticFactory("Overload resolution ambiguity: {0}");
|
AmbiguousDescriptorDiagnosticFactory OVERLOAD_RESOLUTION_AMBIGUITY = new AmbiguousDescriptorDiagnosticFactory();
|
||||||
AmbiguousDescriptorDiagnosticFactory NONE_APPLICABLE = new AmbiguousDescriptorDiagnosticFactory("None of the following functions can be called with the arguments supplied: {0}");
|
AmbiguousDescriptorDiagnosticFactory NONE_APPLICABLE = new AmbiguousDescriptorDiagnosticFactory();
|
||||||
DiagnosticFactory1<PsiElement, ValueParameterDescriptor> NO_VALUE_FOR_PARAMETER = DiagnosticFactory1.create(ERROR, "No value passed for parameter {0}", DescriptorRenderer.TEXT);
|
DiagnosticFactory1<PsiElement, ValueParameterDescriptor> NO_VALUE_FOR_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetReferenceExpression, JetType> MISSING_RECEIVER = DiagnosticFactory1.create(ERROR, "A receiver of type {0} is required", RENDER_TYPE);
|
DiagnosticFactory1<JetReferenceExpression, JetType> MISSING_RECEIVER = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory<JetReferenceExpression> NO_RECEIVER_ADMITTED = DiagnosticFactory.create(ERROR, "No receiver can be passed to this function or property");
|
SimpleDiagnosticFactory<JetReferenceExpression> NO_RECEIVER_ADMITTED = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<PsiElement> CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS = DiagnosticFactory.create(ERROR, "Can not create an instance of an abstract class");
|
SimpleDiagnosticFactory<PsiElement> CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS = SimpleDiagnosticFactory.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, SolutionStatus> TYPE_INFERENCE_FAILED = DiagnosticFactory1.create(ERROR, "Type inference failed: {0}");
|
DiagnosticFactory1<PsiElement, SolutionStatus> TYPE_INFERENCE_FAILED = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetElement, Integer> WRONG_NUMBER_OF_TYPE_ARGUMENTS = DiagnosticFactory1.create(ERROR, "{0} type arguments expected", new Renderer<Integer>() {
|
DiagnosticFactory1<JetElement, Integer> WRONG_NUMBER_OF_TYPE_ARGUMENTS = DiagnosticFactory1.create(ERROR);
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String render(@Nullable Integer argument) {
|
|
||||||
assert argument != null;
|
|
||||||
return argument == 0 ? "No" : argument.toString();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DiagnosticFactory1<JetIdeTemplateExpression, String> UNRESOLVED_IDE_TEMPLATE = DiagnosticFactory1.create(ERROR, "Unresolved IDE template: {0}");
|
DiagnosticFactory1<JetIdeTemplateExpression, String> UNRESOLVED_IDE_TEMPLATE = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory<JetExpression> DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED = DiagnosticFactory.create(WARNING, "This expression is treated as an argument to the function call on the previous line. " +
|
SimpleDiagnosticFactory<JetExpression> DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED = SimpleDiagnosticFactory.create(WARNING);
|
||||||
"Separate it with a semicolon (;) if it is not intended to be an argument.");
|
|
||||||
|
|
||||||
DiagnosticFactory1<JetAnnotationEntry, String> NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR, "{0} is not an annotation class");
|
DiagnosticFactory1<JetAnnotationEntry, String> NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
|
|
||||||
// This field is needed to make the Initializer class load (interfaces cannot have static initializers)
|
// This field is needed to make the Initializer class load (interfaces cannot have static initializers)
|
||||||
@@ -476,10 +447,11 @@ public interface Errors {
|
|||||||
try {
|
try {
|
||||||
Object value = field.get(null);
|
Object value = field.get(null);
|
||||||
if (value instanceof AbstractDiagnosticFactory) {
|
if (value instanceof AbstractDiagnosticFactory) {
|
||||||
AbstractDiagnosticFactory factory = (AbstractDiagnosticFactory) value;
|
AbstractDiagnosticFactory factory = (AbstractDiagnosticFactory)value;
|
||||||
factory.setName(field.getName());
|
factory.setName(field.getName());
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException e) {
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.psi.*;
|
|||||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -135,4 +136,12 @@ public class PositioningStrategies {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static PositioningStrategy<JetTypeProjection> PROJECTION_MODIFIER = new PositioningStrategy<JetTypeProjection>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<TextRange> mark(@NotNull JetTypeProjection element) {
|
||||||
|
return markNode(element.getProjectionNode());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
-126
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.lang.diagnostics;
|
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange;
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author abreslav
|
|
||||||
*/
|
|
||||||
public interface RedeclarationDiagnostic extends Diagnostic {
|
|
||||||
class SimpleRedeclarationDiagnostic extends AbstractDiagnostic<PsiElement> implements RedeclarationDiagnostic {
|
|
||||||
|
|
||||||
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement, @NotNull String name, RedeclarationDiagnosticFactory factory) {
|
|
||||||
super(psiElement, factory, factory.severity, factory.makeMessage(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<TextRange> getTextRanges() {
|
|
||||||
return POSITION_REDECLARATION.mark(getPsiElement());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RedeclarationDiagnosticWithDeferredResolution implements RedeclarationDiagnostic {
|
|
||||||
|
|
||||||
private final DeclarationDescriptor duplicatingDescriptor;
|
|
||||||
private final BindingContext contextToResolveToDeclaration;
|
|
||||||
private final RedeclarationDiagnosticFactory factory;
|
|
||||||
private PsiElement element;
|
|
||||||
|
|
||||||
public RedeclarationDiagnosticWithDeferredResolution(@NotNull DeclarationDescriptor duplicatingDescriptor, @NotNull BindingContext contextToResolveToDeclaration, RedeclarationDiagnosticFactory factory) {
|
|
||||||
this.duplicatingDescriptor = duplicatingDescriptor;
|
|
||||||
this.contextToResolveToDeclaration = contextToResolveToDeclaration;
|
|
||||||
this.factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PsiElement resolve() {
|
|
||||||
if (element == null) {
|
|
||||||
element = BindingContextUtils.descriptorToDeclaration(contextToResolveToDeclaration, duplicatingDescriptor);
|
|
||||||
assert element != null : "No element for descriptor: " + duplicatingDescriptor;
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public PsiElement getPsiElement() {
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<TextRange> getTextRanges() {
|
|
||||||
return POSITION_REDECLARATION.mark(getPsiElement());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public PsiFile getPsiFile() {
|
|
||||||
return resolve().getContainingFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public AbstractDiagnosticFactory getFactory() {
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return factory.makeMessage(duplicatingDescriptor.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Severity getSeverity() {
|
|
||||||
return factory.severity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PositioningStrategy<PsiElement> POSITION_REDECLARATION = new PositioningStrategy<PsiElement>() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<TextRange> mark(@NotNull PsiElement element) {
|
|
||||||
if (element instanceof JetNamedDeclaration) {
|
|
||||||
PsiElement nameIdentifier = ((JetNamedDeclaration) element).getNameIdentifier();
|
|
||||||
if (nameIdentifier != null) {
|
|
||||||
return markElement(nameIdentifier);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (element instanceof JetFile) {
|
|
||||||
JetFile file = (JetFile) element;
|
|
||||||
PsiElement nameIdentifier = file.getNamespaceHeader().getNameIdentifier();
|
|
||||||
if (nameIdentifier != null) {
|
|
||||||
return markElement(nameIdentifier);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return markElement(element);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
+28
-33
@@ -16,45 +16,40 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class RedeclarationDiagnosticFactory extends AbstractDiagnosticFactory {
|
public class RedeclarationDiagnosticFactory extends DiagnosticFactory1<PsiElement, String> {
|
||||||
|
private static final PositioningStrategy<PsiElement> POSITION_REDECLARATION = new PositioningStrategy<PsiElement>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<TextRange> mark(@NotNull PsiElement element) {
|
||||||
|
if (element instanceof JetNamedDeclaration) {
|
||||||
|
PsiElement nameIdentifier = ((JetNamedDeclaration) element).getNameIdentifier();
|
||||||
|
if (nameIdentifier != null) {
|
||||||
|
return markElement(nameIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (element instanceof JetFile) {
|
||||||
|
JetFile file = (JetFile) element;
|
||||||
|
PsiElement nameIdentifier = file.getNamespaceHeader().getNameIdentifier();
|
||||||
|
if (nameIdentifier != null) {
|
||||||
|
return markElement(nameIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return markElement(element);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final String name;
|
public RedeclarationDiagnosticFactory(Severity severity) {
|
||||||
final Severity severity;
|
super(severity, POSITION_REDECLARATION);
|
||||||
private final String messagePrefix;
|
|
||||||
|
|
||||||
public static final RedeclarationDiagnosticFactory REDECLARATION = new RedeclarationDiagnosticFactory(
|
|
||||||
"REDECLARATION", Severity.ERROR, "Redeclaration: ");
|
|
||||||
public static final RedeclarationDiagnosticFactory NAME_SHADOWING = new RedeclarationDiagnosticFactory(
|
|
||||||
"NAME_SHADOWING", Severity.WARNING, "Name shadowed: ");
|
|
||||||
|
|
||||||
public RedeclarationDiagnosticFactory(String name, Severity severity, String messagePrefix) {
|
|
||||||
this.name = name;
|
|
||||||
this.severity = severity;
|
|
||||||
this.messagePrefix = messagePrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RedeclarationDiagnostic on(@NotNull PsiElement duplicatingElement, @NotNull String name) {
|
|
||||||
return new RedeclarationDiagnostic.SimpleRedeclarationDiagnostic(duplicatingElement, name, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String makeMessage(String identifier) {
|
|
||||||
return messagePrefix + identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-5
@@ -25,17 +25,20 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class DiagnosticWithPsiElement<E extends PsiElement> extends AbstractDiagnostic<E> {
|
public class SimpleDiagnostic<E extends PsiElement> extends AbstractDiagnostic<E> {
|
||||||
public DiagnosticWithPsiElement(@NotNull E psiElement, @NotNull DiagnosticFactoryWithPsiElement<E> factory, @NotNull Severity severity, @NotNull String message) {
|
public SimpleDiagnostic(@NotNull E psiElement,
|
||||||
super(psiElement, factory, severity, message);
|
@NotNull SimpleDiagnosticFactory<E> factory,
|
||||||
|
@NotNull Severity severity) {
|
||||||
|
super(psiElement, factory, severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public DiagnosticFactoryWithPsiElement<E> getFactory() {
|
public SimpleDiagnosticFactory<E> getFactory() {
|
||||||
return (DiagnosticFactoryWithPsiElement<E>)super.getFactory();
|
return (SimpleDiagnosticFactory<E>)super.getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<TextRange> getTextRanges() {
|
public List<TextRange> getTextRanges() {
|
||||||
return getFactory().getTextRanges(this);
|
return getFactory().getTextRanges(this);
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author svtk
|
||||||
|
*/
|
||||||
|
public class SimpleDiagnosticFactory<E extends PsiElement> extends DiagnosticFactoryWithPsiElement<E> {
|
||||||
|
|
||||||
|
protected SimpleDiagnosticFactory(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
|
||||||
|
super(severity, positioningStrategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends PsiElement> SimpleDiagnosticFactory<T> create(Severity severity) {
|
||||||
|
return create(severity, PositioningStrategies.DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends PsiElement> SimpleDiagnosticFactory<T> create(Severity severity, PositioningStrategy<? super T> positioningStrategy) {
|
||||||
|
return new SimpleDiagnosticFactory<T>(severity, positioningStrategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public SimpleDiagnostic<E> on(@NotNull E element) {
|
||||||
|
return new SimpleDiagnostic<E>(element, this, severity);
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
-12
@@ -17,30 +17,35 @@
|
|||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
|
import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class UnresolvedReferenceDiagnosticFactory extends AbstractDiagnosticFactory {
|
public class UnresolvedReferenceDiagnosticFactory extends DiagnosticFactory1<JetReferenceExpression, String> {
|
||||||
|
public UnresolvedReferenceDiagnosticFactory() {
|
||||||
private final String message;
|
super(Severity.ERROR, new PositioningStrategy<JetReferenceExpression>() {
|
||||||
|
@NotNull
|
||||||
private UnresolvedReferenceDiagnosticFactory(String message) {
|
@Override
|
||||||
this.message = message;
|
public List<TextRange> mark(@NotNull JetReferenceExpression element) {
|
||||||
|
if (element instanceof JetArrayAccessExpression) {
|
||||||
|
return ((JetArrayAccessExpression) element).getBracketRanges();
|
||||||
|
}
|
||||||
|
return Collections.singletonList(element.getTextRange());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnresolvedReferenceDiagnostic on(@NotNull JetReferenceExpression reference) {
|
public DiagnosticWithParameters1<JetReferenceExpression, String> on(@NotNull JetReferenceExpression reference) {
|
||||||
return new UnresolvedReferenceDiagnostic(reference, message);
|
return new DiagnosticWithParameters1<JetReferenceExpression, String>(reference, reference.getText(), this, severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnresolvedReferenceDiagnosticFactory create(String message) {
|
public static UnresolvedReferenceDiagnosticFactory create() {
|
||||||
return new UnresolvedReferenceDiagnosticFactory(message);
|
return new UnresolvedReferenceDiagnosticFactory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-14
@@ -17,27 +17,20 @@
|
|||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class UnusedElementDiagnosticFactory<T extends PsiElement, A> extends DiagnosticFactory1<T, A> {
|
public class UnusedElementDiagnosticFactory<T extends PsiElement, A> extends DiagnosticFactory1<T, A> {
|
||||||
private UnusedElementDiagnosticFactory(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> renderer) {
|
private UnusedElementDiagnosticFactory(Severity severity, PositioningStrategy<? super T> positioningStrategy) {
|
||||||
super(severity, message, positioningStrategy, renderer);
|
super(severity, positioningStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> renderer) {
|
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, PositioningStrategy<? super T> positioningStrategy) {
|
||||||
return new UnusedElementDiagnosticFactory<T, A>(severity, message, positioningStrategy, renderer);
|
return new UnusedElementDiagnosticFactory<T, A>(severity, positioningStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy) {
|
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity) {
|
||||||
return create(severity, message, positioningStrategy, Renderers.TO_STRING);
|
return create(severity, PositioningStrategies.DEFAULT);
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message, Renderer<? super A> renderer) {
|
|
||||||
return create(severity, message, PositioningStrategies.DEFAULT, renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message) {
|
|
||||||
return create(severity, message, PositioningStrategies.DEFAULT, Renderers.TO_STRING);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+393
@@ -0,0 +1,393 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetTypeConstraint;
|
||||||
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||||
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.*;
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.RENDER_TYPE;
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.TO_STRING;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/13/12
|
||||||
|
*/
|
||||||
|
public class DefaultErrorMessages {
|
||||||
|
public static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap();
|
||||||
|
public static final DiagnosticRenderer<Diagnostic> RENDERER = new DispatchingDiagnosticRenderer(MAP);
|
||||||
|
|
||||||
|
static {
|
||||||
|
MAP.put(EXCEPTION_WHILE_ANALYZING, "{0}", new Renderer<Throwable>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull Throwable e) {
|
||||||
|
return e.getClass().getSimpleName() + ": " + e.getMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MAP.put(UNRESOLVED_REFERENCE, "Unresolved reference: {0}", TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'' in ''{1}''", NAME, NAME);
|
||||||
|
MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'' in ''{1}''", NAME, NAME);
|
||||||
|
|
||||||
|
MAP.put(REDECLARATION, "Redeclaration: {0}", NAME);
|
||||||
|
MAP.put(NAME_SHADOWING, "Name shadowed: {0}", NAME);
|
||||||
|
|
||||||
|
MAP.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(INCOMPATIBLE_MODIFIERS, "Incompatible modifiers: ''{0}''", new Renderer<Collection<JetKeywordToken>>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull Collection<JetKeywordToken> tokens) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (JetKeywordToken token : tokens) {
|
||||||
|
if (sb.length() != 0) {
|
||||||
|
sb.append(" ");
|
||||||
|
}
|
||||||
|
sb.append(token.getValue());
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
MAP.put(ILLEGAL_MODIFIER, "Illegal modifier ''{0}''", TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING);
|
||||||
|
MAP.put(ABSTRACT_MODIFIER_IN_TRAIT, "Modifier ''abstract'' is redundant in trait");
|
||||||
|
MAP.put(OPEN_MODIFIER_IN_TRAIT, "Modifier ''open'' is redundant in trait");
|
||||||
|
MAP.put(REDUNDANT_MODIFIER_IN_GETTER, "Visibility modifiers are redundant in getter");
|
||||||
|
MAP.put(TRAIT_CAN_NOT_BE_FINAL, "Trait cannot be final");
|
||||||
|
MAP.put(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM,
|
||||||
|
"Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message
|
||||||
|
MAP.put(RETURN_NOT_ALLOWED, "'return' is not allowed here");
|
||||||
|
MAP.put(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE, "Projections are not allowed for immediate arguments of a supertype");
|
||||||
|
MAP.put(LABEL_NAME_CLASH, "There is more than one label with such a name in this scope");
|
||||||
|
MAP.put(EXPRESSION_EXPECTED_NAMESPACE_FOUND, "Expression expected, but a namespace name found");
|
||||||
|
|
||||||
|
MAP.put(CANNOT_IMPORT_FROM_ELEMENT, "Cannot import from ''{0}''", NAME);
|
||||||
|
MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
|
||||||
|
MAP.put(USELESS_HIDDEN_IMPORT, "Useless import, it is hidden further");
|
||||||
|
MAP.put(USELESS_SIMPLE_IMPORT, "Useless import, does nothing");
|
||||||
|
|
||||||
|
MAP.put(CANNOT_INFER_PARAMETER_TYPE,
|
||||||
|
"Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
|
||||||
|
|
||||||
|
MAP.put(NO_BACKING_FIELD_ABSTRACT_PROPERTY, "This property doesn't have a backing field, because it's abstract");
|
||||||
|
MAP.put(NO_BACKING_FIELD_CUSTOM_ACCESSORS,
|
||||||
|
"This property doesn't have a backing field, because it has custom accessors without reference to the backing field");
|
||||||
|
MAP.put(INACCESSIBLE_BACKING_FIELD, "The backing field is not accessible here");
|
||||||
|
MAP.put(NOT_PROPERTY_BACKING_FIELD, "The referenced variable is not a property and doesn't have backing field");
|
||||||
|
|
||||||
|
MAP.put(MIXING_NAMED_AND_POSITIONED_ARGUMENTS, "Mixing named and positioned arguments in not allowed");
|
||||||
|
MAP.put(ARGUMENT_PASSED_TWICE, "An argument is already passed for this parameter");
|
||||||
|
MAP.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", TO_STRING);
|
||||||
|
MAP.put(VARARG_OUTSIDE_PARENTHESES, "Passing value as a vararg is only allowed inside a parenthesized argument list");
|
||||||
|
MAP.put(NON_VARARG_SPREAD, "The spread operator (*foo) may only be applied in a vararg position");
|
||||||
|
|
||||||
|
MAP.put(MANY_FUNCTION_LITERAL_ARGUMENTS, "Only one function literal is allowed outside a parenthesized argument list");
|
||||||
|
MAP.put(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER, "This property must either have a type annotation or be initialized");
|
||||||
|
|
||||||
|
MAP.put(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, "This property cannot be declared abstract");
|
||||||
|
MAP.put(ABSTRACT_PROPERTY_NOT_IN_CLASS, "A property may be abstract only when defined in a class or trait");
|
||||||
|
MAP.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, "Property with initializer cannot be abstract");
|
||||||
|
MAP.put(ABSTRACT_PROPERTY_WITH_GETTER, "Property with getter implementation cannot be abstract");
|
||||||
|
MAP.put(ABSTRACT_PROPERTY_WITH_SETTER, "Property with setter implementation cannot be abstract");
|
||||||
|
|
||||||
|
MAP.put(PACKAGE_MEMBER_CANNOT_BE_PROTECTED, "Package member cannot be protected");
|
||||||
|
|
||||||
|
MAP.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility");
|
||||||
|
MAP.put(BACKING_FIELD_IN_TRAIT, "Property in a trait cannot have a backing field");
|
||||||
|
MAP.put(MUST_BE_INITIALIZED, "Property must be initialized");
|
||||||
|
MAP.put(MUST_BE_INITIALIZED_OR_BE_ABSTRACT, "Property must be initialized or be abstract");
|
||||||
|
MAP.put(PROPERTY_INITIALIZER_IN_TRAIT, "Property initializers are not allowed in traits");
|
||||||
|
MAP.put(PROPERTY_INITIALIZER_NO_BACKING_FIELD, "Initializer is not allowed here because this property has no backing field");
|
||||||
|
MAP.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, "Abstract property ''{0}'' in non-abstract class ''{1}''", NAME, NAME);
|
||||||
|
MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", NAME, NAME);
|
||||||
|
MAP.put(ABSTRACT_FUNCTION_WITH_BODY, "A function ''{0}'' with body cannot be abstract", NAME);
|
||||||
|
MAP.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without a body must be abstract", NAME);
|
||||||
|
MAP.put(NON_MEMBER_ABSTRACT_FUNCTION, "Function ''{0}'' is not a class or trait member and cannot be abstract", NAME);
|
||||||
|
|
||||||
|
MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME);
|
||||||
|
MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "Non-final member in a final class");
|
||||||
|
|
||||||
|
MAP.put(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, "Public or protected member should have specified type");
|
||||||
|
|
||||||
|
MAP.put(PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT, "Projections are not allowed on type arguments of functions and properties");
|
||||||
|
MAP.put(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here");
|
||||||
|
MAP.put(SUPERTYPE_NOT_INITIALIZED_DEFAULT, "Constructor invocation should be explicitly specified");
|
||||||
|
MAP.put(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY, "A secondary constructor may appear only in a class that has a primary constructor");
|
||||||
|
MAP.put(SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST, "Secondary constructors must have an initializer list");
|
||||||
|
MAP.put(BY_IN_SECONDARY_CONSTRUCTOR, "'by'-clause is only supported for primary constructors");
|
||||||
|
MAP.put(INITIALIZER_WITH_NO_ARGUMENTS, "Constructor arguments required");
|
||||||
|
MAP.put(MANY_CALLS_TO_THIS, "Only one call to 'this(...)' is allowed");
|
||||||
|
MAP.put(NOTHING_TO_OVERRIDE, "''{0}'' overrides nothing", NAME);
|
||||||
|
MAP.put(VIRTUAL_MEMBER_HIDDEN, "''{0}'' hides member of supertype ''{2}'' and needs ''override'' modifier", NAME, NAME, NAME);
|
||||||
|
|
||||||
|
MAP.put(CANNOT_OVERRIDE_INVISIBLE_MEMBER, "''{0}'' cannot has no access to ''{1}'' in class {2}, so it cannot override it",
|
||||||
|
DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
|
||||||
|
MAP.put(CANNOT_INFER_VISIBILITY, "Cannot infer visibility. Please specify it explicitly");
|
||||||
|
|
||||||
|
MAP.put(ENUM_ENTRY_SHOULD_BE_INITIALIZED, "Missing delegation specifier ''{0}''", NAME);
|
||||||
|
MAP.put(ENUM_ENTRY_ILLEGAL_TYPE, "The type constructor of enum entry should be ''{0}''", NAME);
|
||||||
|
|
||||||
|
MAP.put(UNINITIALIZED_VARIABLE, "Variable ''{0}'' must be initialized", NAME);
|
||||||
|
MAP.put(UNINITIALIZED_PARAMETER, "Parameter ''{0}'' is uninitialized here", NAME);
|
||||||
|
MAP.put(UNUSED_VARIABLE, "Variable ''{0}'' is never used", NAME);
|
||||||
|
MAP.put(UNUSED_PARAMETER, "Parameter ''{0}'' is never used", NAME);
|
||||||
|
MAP.put(ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, "Variable ''{0}'' is assigned but never accessed", NAME);
|
||||||
|
MAP.put(VARIABLE_WITH_REDUNDANT_INITIALIZER, "Variable ''{0}'' initializer is redundant", NAME);
|
||||||
|
MAP.put(UNUSED_VALUE, "The value ''{0}'' assigned to ''{1}'' is never used", ELEMENT_TEXT, TO_STRING);
|
||||||
|
MAP.put(UNUSED_CHANGED_VALUE, "The value changed at ''{0}'' is never used", ELEMENT_TEXT);
|
||||||
|
MAP.put(UNUSED_EXPRESSION, "The expression is unused");
|
||||||
|
MAP.put(UNUSED_FUNCTION_LITERAL, "The function literal is unused. If you mean block, you can use 'run { ... }'");
|
||||||
|
|
||||||
|
MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME);
|
||||||
|
MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME);
|
||||||
|
MAP.put(VARIABLE_EXPECTED, "Variable expected");
|
||||||
|
|
||||||
|
MAP.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER,
|
||||||
|
"This property has a custom setter, so initialization using backing field required", NAME);
|
||||||
|
MAP.put(INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER,
|
||||||
|
"Setter of this property can be overridden, so initialization using backing field required", NAME);
|
||||||
|
|
||||||
|
MAP.put(FUNCTION_PARAMETERS_OF_INLINE_FUNCTION, "Function parameters of inline function can only be invoked", NAME);
|
||||||
|
|
||||||
|
MAP.put(UNREACHABLE_CODE, "Unreachable code");
|
||||||
|
|
||||||
|
MAP.put(MANY_CLASS_OBJECTS, "Only one class object is allowed per class");
|
||||||
|
MAP.put(CLASS_OBJECT_NOT_ALLOWED, "A class object is not allowed here");
|
||||||
|
MAP.put(DELEGATION_IN_TRAIT, "Traits cannot use delegation");
|
||||||
|
MAP.put(DELEGATION_NOT_TO_TRAIT, "Only traits can be delegated to");
|
||||||
|
MAP.put(NO_CONSTRUCTOR, "This class does not have a constructor");
|
||||||
|
MAP.put(NOT_A_CLASS, "Not a class");
|
||||||
|
MAP.put(ILLEGAL_ESCAPE_SEQUENCE, "Illegal escape sequence");
|
||||||
|
|
||||||
|
MAP.put(LOCAL_EXTENSION_PROPERTY, "Local extension properties are not allowed");
|
||||||
|
MAP.put(LOCAL_VARIABLE_WITH_GETTER, "Local variables are not allowed to have getters");
|
||||||
|
MAP.put(LOCAL_VARIABLE_WITH_SETTER, "Local variables are not allowed to have setters");
|
||||||
|
MAP.put(VAL_WITH_SETTER, "A 'val'-property cannot have a setter");
|
||||||
|
|
||||||
|
MAP.put(NO_GET_METHOD, "No get method providing array access");
|
||||||
|
MAP.put(NO_SET_METHOD, "No set method providing array access");
|
||||||
|
|
||||||
|
MAP.put(INC_DEC_SHOULD_NOT_RETURN_UNIT, "Functions inc(), dec() shouldn't return Unit to be used by operators ++, --");
|
||||||
|
MAP.put(ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT, "Function ''{0}'' should return Unit to be used by corresponding operator ''{1}''",
|
||||||
|
NAME, ELEMENT_TEXT);
|
||||||
|
MAP.put(ASSIGN_OPERATOR_AMBIGUITY, "Assignment operators ambiguity: {0}", AMBIGUOUS_CALLS);
|
||||||
|
|
||||||
|
MAP.put(EQUALS_MISSING, "No method 'equals(jet.Any?) : jet.Boolean' available");
|
||||||
|
MAP.put(ASSIGNMENT_IN_EXPRESSION_CONTEXT, "Assignments are not expressions, and only expressions are allowed in this context");
|
||||||
|
MAP.put(NAMESPACE_IS_NOT_AN_EXPRESSION, "'namespace' is not an expression, it can only be used on the left-hand side of a dot ('.')");
|
||||||
|
MAP.put(SUPER_IS_NOT_AN_EXPRESSION, "''{0}'' is not an expression, it can only be used on the left-hand side of a dot ('.')", TO_STRING);
|
||||||
|
MAP.put(DECLARATION_IN_ILLEGAL_CONTEXT, "Declarations are not allowed in this position");
|
||||||
|
MAP.put(SETTER_PARAMETER_WITH_DEFAULT_VALUE, "Setter parameters cannot have default values");
|
||||||
|
MAP.put(NO_THIS, "'this' is not defined in this context");
|
||||||
|
MAP.put(SUPER_NOT_AVAILABLE, "No supertypes are accessible in this context");
|
||||||
|
MAP.put(AMBIGUOUS_SUPER, "Many supertypes available, please specify the one you mean in angle brackets, e.g. 'super<Foo>'");
|
||||||
|
MAP.put(ABSTRACT_SUPER_CALL, "Abstract member cannot be accessed directly");
|
||||||
|
MAP.put(NOT_A_SUPERTYPE, "Not a supertype");
|
||||||
|
MAP.put(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, "Type arguments do not need to be specified in a 'super' qualifier");
|
||||||
|
MAP.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, "No cast needed, use ':' instead");
|
||||||
|
MAP.put(USELESS_CAST, "No cast needed");
|
||||||
|
MAP.put(CAST_NEVER_SUCCEEDS, "This cast can never succeed");
|
||||||
|
MAP.put(WRONG_SETTER_PARAMETER_TYPE, "Setter parameter type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(WRONG_GETTER_RETURN_TYPE, "Getter return type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(NO_CLASS_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a class object", NAME);
|
||||||
|
MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified");
|
||||||
|
|
||||||
|
MAP.put(HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY,
|
||||||
|
"An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property");
|
||||||
|
MAP.put(HAS_NEXT_MISSING, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
|
||||||
|
MAP.put(HAS_NEXT_FUNCTION_AMBIGUITY, "Function 'iterator().hasNext()' is ambiguous for this expression");
|
||||||
|
MAP.put(HAS_NEXT_MUST_BE_READABLE, "The 'iterator().hasNext' property of the loop range must be readable");
|
||||||
|
MAP.put(HAS_NEXT_PROPERTY_TYPE_MISMATCH, "The type of ''iterator().hasNext'' property of the loop range must be jet.Boolean, but is {0}",
|
||||||
|
RENDER_TYPE);
|
||||||
|
MAP.put(HAS_NEXT_FUNCTION_TYPE_MISMATCH, "The ''iterator().hasNext()'' function of the loop range must return jet.Boolean, but returns {0}",
|
||||||
|
RENDER_TYPE);
|
||||||
|
MAP.put(NEXT_AMBIGUITY, "Function 'iterator().next()' is ambiguous for this expression");
|
||||||
|
MAP.put(NEXT_MISSING, "Loop range must have an 'iterator().next()' function");
|
||||||
|
MAP.put(ITERATOR_MISSING, "For-loop range must have an iterator() method");
|
||||||
|
MAP.put(ITERATOR_AMBIGUITY, "Method ''iterator()'' is ambiguous for this expression: {0}", AMBIGUOUS_CALLS);
|
||||||
|
|
||||||
|
MAP.put(COMPARE_TO_TYPE_MISMATCH, "''compareTo()'' must return jet.Int, but returns {0}", RENDER_TYPE);
|
||||||
|
MAP.put(CALLEE_NOT_A_FUNCTION, "Expecting a function type, but found {0}", RENDER_TYPE);
|
||||||
|
|
||||||
|
MAP.put(RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY,
|
||||||
|
"Returns are not allowed for functions with expression body. Use block body in '{...}'");
|
||||||
|
MAP.put(NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, "A 'return' expression required in a function with a block body ('{...}')");
|
||||||
|
MAP.put(RETURN_TYPE_MISMATCH, "This function must return a value of type {0}", RENDER_TYPE);
|
||||||
|
MAP.put(EXPECTED_TYPE_MISMATCH, "Expected a value of type {0}", RENDER_TYPE);
|
||||||
|
MAP.put(ASSIGNMENT_TYPE_MISMATCH,
|
||||||
|
"Expected a value of type {0}. Assignment operation is not an expression, so it does not return any value", RENDER_TYPE);
|
||||||
|
MAP.put(IMPLICIT_CAST_TO_UNIT_OR_ANY, "Type was casted to ''{0}''. Please specify ''{0}'' as expected type, if you mean such cast",
|
||||||
|
RENDER_TYPE);
|
||||||
|
MAP.put(EXPRESSION_EXPECTED, "{0} is not an expression, and only expression are allowed here", new Renderer<JetExpression>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull JetExpression expression) {
|
||||||
|
String expressionType = expression.toString();
|
||||||
|
return expressionType.substring(0, 1) +
|
||||||
|
expressionType.substring(1).toLowerCase();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MAP.put(UPPER_BOUND_VIOLATED, "Type argument is not within its bounds: should be subtype of ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(FINAL_CLASS_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a class object cannot extend it", RENDER_TYPE);
|
||||||
|
MAP.put(FINAL_UPPER_BOUND, "''{0}'' is a final type, and thus a value of the type parameter is predetermined", RENDER_TYPE);
|
||||||
|
MAP.put(USELESS_ELVIS, "Elvis operator (?:) always returns the left operand of non-nullable type {0}", RENDER_TYPE);
|
||||||
|
MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME);
|
||||||
|
MAP.put(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS, "Class object upper bounds of {0} have empty intersection", NAME);
|
||||||
|
|
||||||
|
MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", DescriptorRenderer.TEXT);
|
||||||
|
MAP.put(ERROR_COMPILE_TIME_VALUE, "{0}", TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(ELSE_MISPLACED_IN_WHEN, "'else' entry must be the last one in a when-expression");
|
||||||
|
|
||||||
|
MAP.put(NO_ELSE_IN_WHEN, "'when' expression must contain 'else' branch");
|
||||||
|
MAP.put(TYPE_MISMATCH_IN_RANGE, "Type mismatch: incompatible types of range and element checked in it");
|
||||||
|
MAP.put(CYCLIC_INHERITANCE_HIERARCHY, "There's a cycle in the inheritance hierarchy for this type");
|
||||||
|
|
||||||
|
MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list");
|
||||||
|
MAP.put(SUPERTYPE_NOT_A_CLASS_OR_TRAIT, "Only classes and traits may serve as supertypes");
|
||||||
|
MAP.put(SUPERTYPE_INITIALIZED_IN_TRAIT, "Traits cannot initialize supertypes");
|
||||||
|
MAP.put(CONSTRUCTOR_IN_TRAIT, "A trait may not have a constructor");
|
||||||
|
MAP.put(SECONDARY_CONSTRUCTORS_ARE_NOT_SUPPORTED, "Secondary constructors are not supported");
|
||||||
|
MAP.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice");
|
||||||
|
MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from");
|
||||||
|
|
||||||
|
MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter");
|
||||||
|
MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop");
|
||||||
|
MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", TO_STRING);
|
||||||
|
MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR, "Anonymous initializers are only allowed in the presence of a primary constructor");
|
||||||
|
MAP.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable");
|
||||||
|
MAP.put(UNSAFE_CALL, "Only safe calls (?.) are allowed on a nullable receiver of type {0}", RENDER_TYPE);
|
||||||
|
MAP.put(AMBIGUOUS_LABEL, "Ambiguous label");
|
||||||
|
MAP.put(UNSUPPORTED, "Unsupported [{0}]", TO_STRING);
|
||||||
|
MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE);
|
||||||
|
MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE);
|
||||||
|
MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", new Renderer<JetTypeConstraint>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull JetTypeConstraint typeConstraint) {
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
|
||||||
|
}
|
||||||
|
}, NAME);
|
||||||
|
MAP.put(AUTOCAST_IMPOSSIBLE, "Automatic cast to ''{0}'' is impossible, because ''{1}'' could have changed since the is-check", RENDER_TYPE,
|
||||||
|
NAME);
|
||||||
|
|
||||||
|
MAP.put(TYPE_MISMATCH_IN_FOR_LOOP, "The loop iterates over values of type {0} but the parameter is declared to be {1}", RENDER_TYPE,
|
||||||
|
RENDER_TYPE);
|
||||||
|
MAP.put(TYPE_MISMATCH_IN_CONDITION, "Condition must be of type jet.Boolean, but is of type {0}", RENDER_TYPE);
|
||||||
|
MAP.put(TYPE_MISMATCH_IN_TUPLE_PATTERN, "Type mismatch: subject is of type {0} but the pattern is a {1}-tuple", RENDER_TYPE, TO_STRING);
|
||||||
|
MAP.put(TYPE_MISMATCH_IN_BINDING_PATTERN, "{0} is not a supertype of {1}. Use ''is'' to match against {0}", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(INCOMPATIBLE_TYPES, "Incompatible types: {0} and {1}", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(EXPECTED_CONDITION, "Expected condition of jet.Boolean type");
|
||||||
|
|
||||||
|
MAP.put(CANNOT_CHECK_FOR_ERASED, "Cannot check for instance of erased type: {0}", RENDER_TYPE);
|
||||||
|
MAP.put(UNCHECKED_CAST, "Unchecked cast: {0} to {1}", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
|
||||||
|
MAP.put(INCONSISTENT_TYPE_PARAMETER_VALUES, "Type parameter {0} of ''{1}'' has inconsistent values: {2}", NAME, NAME,
|
||||||
|
new Renderer<Collection<JetType>>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull Collection<JetType> types) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (Iterator<JetType> iterator = types.iterator(); iterator.hasNext(); ) {
|
||||||
|
JetType jetType = iterator.next();
|
||||||
|
builder.append(jetType);
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MAP.put(EQUALITY_NOT_APPLICABLE, "Operator ''{0}'' cannot be applied to ''{1}'' and ''{2}''", new Renderer<JetSimpleNameExpression>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull JetSimpleNameExpression nameExpression) {
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
return nameExpression.getReferencedName();
|
||||||
|
}
|
||||||
|
}, RENDER_TYPE, RENDER_TYPE);
|
||||||
|
|
||||||
|
MAP.put(SENSELESS_COMPARISON, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(OVERRIDING_FINAL_MEMBER, "''{0}'' in ''{1}'' is final and cannot be overridden", NAME, NAME);
|
||||||
|
MAP.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME);
|
||||||
|
MAP.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME);
|
||||||
|
|
||||||
|
MAP.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, "Return type of ''{0}'' is not a subtype of the return type of overridden member {1}",
|
||||||
|
NAME, DescriptorRenderer.TEXT);
|
||||||
|
|
||||||
|
MAP.put(VAR_OVERRIDDEN_BY_VAL, "Var-property {0} cannot be overridden by val-property {1}", DescriptorRenderer.TEXT,
|
||||||
|
DescriptorRenderer.TEXT);
|
||||||
|
|
||||||
|
MAP.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, "{0} must be declared abstract or implement abstract member {1}", RENDER_CLASS_OR_OBJECT,
|
||||||
|
DescriptorRenderer.TEXT);
|
||||||
|
|
||||||
|
MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits many implementations of it",
|
||||||
|
RENDER_CLASS_OR_OBJECT, DescriptorRenderer.TEXT);
|
||||||
|
|
||||||
|
MAP.put(CONFLICTING_OVERLOADS, "{1} is already defined in ''{0}''", DescriptorRenderer.TEXT, TO_STRING);
|
||||||
|
|
||||||
|
|
||||||
|
MAP.put(RESULT_TYPE_MISMATCH, "{0} must return {1} but returns {2}", TO_STRING, RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(UNSAFE_INFIX_CALL,
|
||||||
|
"Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. " +
|
||||||
|
"Use '?.'-qualified call instead",
|
||||||
|
TO_STRING, TO_STRING, TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity: {0}", AMBIGUOUS_CALLS);
|
||||||
|
MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS);
|
||||||
|
MAP.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter {0}", NAME);
|
||||||
|
MAP.put(MISSING_RECEIVER, "A receiver of type {0} is required", RENDER_TYPE);
|
||||||
|
MAP.put(NO_RECEIVER_ADMITTED, "No receiver can be passed to this function or property");
|
||||||
|
|
||||||
|
MAP.put(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS, "Cannot create an instance of an abstract class");
|
||||||
|
MAP.put(TYPE_INFERENCE_FAILED, "Type inference failed: {0}", TO_STRING);
|
||||||
|
MAP.put(WRONG_NUMBER_OF_TYPE_ARGUMENTS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type argument} expected", null);
|
||||||
|
|
||||||
|
MAP.put(UNRESOLVED_IDE_TEMPLATE, "Unresolved IDE template: {0}", TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED,
|
||||||
|
"This expression is treated as an argument to the function call on the previous line. " +
|
||||||
|
"Separate it with a semicolon (;) if it is not intended to be an argument.");
|
||||||
|
|
||||||
|
MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", TO_STRING);
|
||||||
|
|
||||||
|
MAP.setImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefaultErrorMessages() {
|
||||||
|
}
|
||||||
|
}
|
||||||
+77
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/13/12
|
||||||
|
*/
|
||||||
|
public final class DiagnosticFactoryToRendererMap {
|
||||||
|
private final Map<AbstractDiagnosticFactory, DiagnosticRenderer<?>> map =
|
||||||
|
new HashMap<AbstractDiagnosticFactory, DiagnosticRenderer<?>>();
|
||||||
|
private boolean immutable = false;
|
||||||
|
|
||||||
|
private void checkMutability() {
|
||||||
|
if (immutable) {
|
||||||
|
throw new IllegalStateException("factory to renderer map is already immutable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <E extends PsiElement> void put(@NotNull SimpleDiagnosticFactory<E> factory, @NotNull String message) {
|
||||||
|
checkMutability();
|
||||||
|
map.put(factory, new SimpleDiagnosticRenderer(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <E extends PsiElement, A> void put(@NotNull DiagnosticFactory1<E, A> factory, @NotNull String message, @Nullable Renderer<? super A> rendererA) {
|
||||||
|
checkMutability();
|
||||||
|
map.put(factory, new DiagnosticWithParameters1Renderer<A>(message, rendererA));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <E extends PsiElement, A, B> void put(@NotNull DiagnosticFactory2<E, A, B> factory,
|
||||||
|
@NotNull String message,
|
||||||
|
@Nullable Renderer<? super A> rendererA,
|
||||||
|
@Nullable Renderer<? super B> rendererB) {
|
||||||
|
checkMutability();
|
||||||
|
map.put(factory, new DiagnosticWithParameters2Renderer<A, B>(message, rendererA, rendererB));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <E extends PsiElement, A, B, C> void put(@NotNull DiagnosticFactory3<E, A, B, C> factory,
|
||||||
|
@NotNull String message,
|
||||||
|
@Nullable Renderer<? super A> rendererA,
|
||||||
|
@Nullable Renderer<? super B> rendererB,
|
||||||
|
@Nullable Renderer<? super C> rendererC) {
|
||||||
|
checkMutability();
|
||||||
|
map.put(factory, new DiagnosticWithParameters3Renderer<A, B, C>(message, rendererA, rendererB, rendererC));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public DiagnosticRenderer<?> get(@NotNull AbstractDiagnosticFactory factory) {
|
||||||
|
return map.get(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImmutable() {
|
||||||
|
immutable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/12/12
|
||||||
|
*/
|
||||||
|
public interface DiagnosticRenderer<D extends Diagnostic> extends Renderer<D> {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
String render(@NotNull D diagnostic);
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/18/12
|
||||||
|
*/
|
||||||
|
public class DiagnosticRendererUtil {
|
||||||
|
private DiagnosticRendererUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <P> Object renderParameter(@NotNull P parameter, @Nullable Renderer<P> renderer) {
|
||||||
|
return renderer == null ? parameter : renderer.render(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticRendererUtil.renderParameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/12/12
|
||||||
|
*/
|
||||||
|
public class DiagnosticWithParameters1Renderer<A> implements DiagnosticRenderer<DiagnosticWithParameters1<?, A>> {
|
||||||
|
private final MessageFormat messageFormat;
|
||||||
|
private final Renderer<? super A> rendererForA;
|
||||||
|
|
||||||
|
public DiagnosticWithParameters1Renderer(@NotNull String message, @Nullable Renderer<? super A> rendererForA) {
|
||||||
|
this.messageFormat = new MessageFormat(message);
|
||||||
|
this.rendererForA = rendererForA;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull DiagnosticWithParameters1<?, A> diagnostic) {
|
||||||
|
return messageFormat.format(new Object[]{renderParameter(diagnostic.getA(), rendererForA)});
|
||||||
|
}
|
||||||
|
}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticRendererUtil.renderParameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/12/12
|
||||||
|
*/
|
||||||
|
public class DiagnosticWithParameters2Renderer<A, B> implements DiagnosticRenderer<DiagnosticWithParameters2<?, A, B>> {
|
||||||
|
private final MessageFormat messageFormat;
|
||||||
|
private final Renderer<? super A> rendererForA;
|
||||||
|
private final Renderer<? super B> rendererForB;
|
||||||
|
|
||||||
|
public DiagnosticWithParameters2Renderer(@NotNull String message, @Nullable Renderer<? super A> rendererForA, @Nullable Renderer<? super B> rendererForB) {
|
||||||
|
this.messageFormat = new MessageFormat(message);
|
||||||
|
this.rendererForA = rendererForA;
|
||||||
|
this.rendererForB = rendererForB;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull DiagnosticWithParameters2<?, A, B> diagnostic) {
|
||||||
|
return messageFormat.format(new Object[]{
|
||||||
|
renderParameter(diagnostic.getA(), rendererForA),
|
||||||
|
renderParameter(diagnostic.getB(), rendererForB)});
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters3;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticRendererUtil.renderParameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/12/12
|
||||||
|
*/
|
||||||
|
public class DiagnosticWithParameters3Renderer<A, B, C> implements DiagnosticRenderer<DiagnosticWithParameters3<?, A, B, C>> {
|
||||||
|
private final MessageFormat messageFormat;
|
||||||
|
private final Renderer<? super A> rendererForA;
|
||||||
|
private final Renderer<? super B> rendererForB;
|
||||||
|
private final Renderer<? super C> rendererForC;
|
||||||
|
|
||||||
|
public DiagnosticWithParameters3Renderer(@NotNull String message,
|
||||||
|
@Nullable Renderer<? super A> rendererForA,
|
||||||
|
@Nullable Renderer<? super B> rendererForB,
|
||||||
|
@Nullable Renderer<? super C> rendererForC) {
|
||||||
|
this.messageFormat = new MessageFormat(message);
|
||||||
|
this.rendererForA = rendererForA;
|
||||||
|
this.rendererForB = rendererForB;
|
||||||
|
this.rendererForC = rendererForC;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull DiagnosticWithParameters3<?, A, B, C> diagnostic) {
|
||||||
|
return messageFormat.format(new Object[]{
|
||||||
|
renderParameter(diagnostic.getA(), rendererForA),
|
||||||
|
renderParameter(diagnostic.getB(), rendererForB),
|
||||||
|
renderParameter(diagnostic.getC(), rendererForC)});
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/13/12
|
||||||
|
*/
|
||||||
|
public class DispatchingDiagnosticRenderer implements DiagnosticRenderer<Diagnostic> {
|
||||||
|
private final DiagnosticFactoryToRendererMap[] maps;
|
||||||
|
|
||||||
|
public DispatchingDiagnosticRenderer(DiagnosticFactoryToRendererMap... maps) {
|
||||||
|
this.maps = maps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull Diagnostic diagnostic) {
|
||||||
|
for (DiagnosticFactoryToRendererMap map : maps) {
|
||||||
|
DiagnosticRenderer renderer = map.get(diagnostic.getFactory());
|
||||||
|
if (renderer != null) {
|
||||||
|
//noinspection unchecked
|
||||||
|
return renderer.render(diagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Don't know how to render diagnostic of type " + diagnostic.getFactory().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-6
@@ -14,17 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics.rendering;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public interface Renderer<P> {
|
public interface Renderer<O> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
String render(@Nullable P element);
|
String render(@NotNull O object);
|
||||||
}
|
}
|
||||||
+27
-12
@@ -14,17 +14,20 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.lang.diagnostics;
|
package org.jetbrains.jet.lang.diagnostics.rendering;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.Named;
|
import org.jetbrains.jet.lang.descriptors.Named;
|
||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
@@ -32,8 +35,8 @@ public class Renderers {
|
|||||||
public static final Renderer<Object> TO_STRING = new Renderer<Object>() {
|
public static final Renderer<Object> TO_STRING = new Renderer<Object>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(@Nullable Object element) {
|
public String render(@NotNull Object element) {
|
||||||
return element == null ? "null" : element.toString();
|
return element.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,8 +48,7 @@ public class Renderers {
|
|||||||
public static final Renderer<Object> NAME = new Renderer<Object>() {
|
public static final Renderer<Object> NAME = new Renderer<Object>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(@Nullable Object element) {
|
public String render(@NotNull Object element) {
|
||||||
if (element == null) return "null";
|
|
||||||
if (element instanceof Named) {
|
if (element instanceof Named) {
|
||||||
return ((Named) element).getName();
|
return ((Named) element).getName();
|
||||||
}
|
}
|
||||||
@@ -57,8 +59,7 @@ public class Renderers {
|
|||||||
public static final Renderer<PsiElement> ELEMENT_TEXT = new Renderer<PsiElement>() {
|
public static final Renderer<PsiElement> ELEMENT_TEXT = new Renderer<PsiElement>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(@Nullable PsiElement element) {
|
public String render(@NotNull PsiElement element) {
|
||||||
if (element == null) return "null";
|
|
||||||
return element.getText();
|
return element.getText();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -66,8 +67,7 @@ public class Renderers {
|
|||||||
public static final Renderer<JetClassOrObject> RENDER_CLASS_OR_OBJECT = new Renderer<JetClassOrObject>() {
|
public static final Renderer<JetClassOrObject> RENDER_CLASS_OR_OBJECT = new Renderer<JetClassOrObject>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(@Nullable JetClassOrObject classOrObject) {
|
public String render(@NotNull JetClassOrObject classOrObject) {
|
||||||
assert classOrObject != null;
|
|
||||||
String name = classOrObject.getName() != null ? " '" + classOrObject.getName() + "'" : "";
|
String name = classOrObject.getName() != null ? " '" + classOrObject.getName() + "'" : "";
|
||||||
if (classOrObject instanceof JetClass) {
|
if (classOrObject instanceof JetClass) {
|
||||||
return "Class" + name;
|
return "Class" + name;
|
||||||
@@ -80,9 +80,24 @@ public class Renderers {
|
|||||||
public static final Renderer<JetType> RENDER_TYPE = new Renderer<JetType>() {
|
public static final Renderer<JetType> RENDER_TYPE = new Renderer<JetType>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(@Nullable JetType type) {
|
public String render(@NotNull JetType type) {
|
||||||
assert type != null;
|
|
||||||
return DescriptorRenderer.TEXT.renderType(type);
|
return DescriptorRenderer.TEXT.renderType(type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final Renderer<Collection<? extends ResolvedCall<? extends CallableDescriptor>>> AMBIGUOUS_CALLS =
|
||||||
|
new Renderer<Collection<? extends ResolvedCall<? extends CallableDescriptor>>>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull Collection<? extends ResolvedCall<? extends CallableDescriptor>> argument) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder("\n");
|
||||||
|
for (ResolvedCall<? extends CallableDescriptor> call : argument) {
|
||||||
|
stringBuilder.append(DescriptorRenderer.TEXT.render(call.getResultingDescriptor())).append("\n");
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private Renderers() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.diagnostics.rendering;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Evgeny Gerashchenko
|
||||||
|
* @since 4/12/12
|
||||||
|
*/
|
||||||
|
public class SimpleDiagnosticRenderer implements DiagnosticRenderer<Diagnostic> {
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
public SimpleDiagnosticRenderer(@NotNull String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull Diagnostic diagnostic) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -286,7 +286,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (declType == null) {
|
if (declType == null) {
|
||||||
errorAndAdvance("Expecting namespace or top level declaration");
|
errorAndAdvance("Expecting package directive or top level declaration");
|
||||||
decl.drop();
|
decl.drop();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public class DeclarationsChecker {
|
|||||||
if (!(classDescriptor.getModality() == Modality.ABSTRACT) && classDescriptor.getKind() != ClassKind.ENUM_CLASS) {
|
if (!(classDescriptor.getModality() == Modality.ABSTRACT) && classDescriptor.getKind() != ClassKind.ENUM_CLASS) {
|
||||||
JetClass classElement = (JetClass) BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
|
JetClass classElement = (JetClass) BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
|
||||||
String name = property.getName();
|
String name = property.getName();
|
||||||
trace.report(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.on(property, name != null ? name : "", classDescriptor, classElement));
|
trace.report(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.on(property, name != null ? name : "", classDescriptor));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
||||||
@@ -252,7 +252,7 @@ public class DeclarationsChecker {
|
|||||||
boolean inAbstractClass = classDescriptor.getModality() == Modality.ABSTRACT;
|
boolean inAbstractClass = classDescriptor.getModality() == Modality.ABSTRACT;
|
||||||
if (hasAbstractModifier && !inAbstractClass && !inTrait && !inEnum) {
|
if (hasAbstractModifier && !inAbstractClass && !inTrait && !inEnum) {
|
||||||
JetClass classElement = (JetClass) BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
|
JetClass classElement = (JetClass) BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
|
||||||
trace.report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, functionDescriptor.getName(), classDescriptor, classElement));
|
trace.report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, functionDescriptor.getName(), classDescriptor));
|
||||||
}
|
}
|
||||||
if (hasAbstractModifier && inTrait) {
|
if (hasAbstractModifier && inTrait) {
|
||||||
trace.report(ABSTRACT_MODIFIER_IN_TRAIT.on(function));
|
trace.report(ABSTRACT_MODIFIER_IN_TRAIT.on(function));
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class DelegatingBindingTrace implements BindingTrace {
|
|||||||
private final BindingContext bindingContext = new BindingContext() {
|
private final BindingContext bindingContext = new BindingContext() {
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Collection<Diagnostic> getDiagnostics() {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return diagnostics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -57,6 +57,7 @@ public class DelegatingBindingTrace implements BindingTrace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public BindingContext getBindingContext() {
|
public BindingContext getBindingContext() {
|
||||||
return bindingContext;
|
return bindingContext;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ public class DescriptorResolver {
|
|||||||
type = typeResolver.resolveType(parameterScope, typeReference, trace, true);
|
type = typeResolver.resolveType(parameterScope, typeReference, trace, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(functionDescriptor, valueParameter, i, type, trace);
|
ValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(parameterScope, functionDescriptor, valueParameter, i, type, trace);
|
||||||
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
||||||
result.add(valueParameterDescriptor);
|
result.add(valueParameterDescriptor);
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public MutableValueParameterDescriptor resolveValueParameterDescriptor(DeclarationDescriptor declarationDescriptor, JetParameter valueParameter, int index, JetType type, BindingTrace trace) {
|
public MutableValueParameterDescriptor resolveValueParameterDescriptor(JetScope scope, DeclarationDescriptor declarationDescriptor, JetParameter valueParameter, int index, JetType type, BindingTrace trace) {
|
||||||
JetType varargElementType = null;
|
JetType varargElementType = null;
|
||||||
JetType variableType = type;
|
JetType variableType = type;
|
||||||
if (valueParameter.hasModifier(JetTokens.VARARG_KEYWORD)) {
|
if (valueParameter.hasModifier(JetTokens.VARARG_KEYWORD)) {
|
||||||
@@ -282,7 +282,7 @@ public class DescriptorResolver {
|
|||||||
MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
|
MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
|
||||||
declarationDescriptor,
|
declarationDescriptor,
|
||||||
index,
|
index,
|
||||||
annotationResolver.createAnnotationStubs(valueParameter.getModifierList(), trace),
|
annotationResolver.resolveAnnotations(scope, valueParameter.getModifierList(), trace),
|
||||||
JetPsiUtil.safeName(valueParameter.getName()),
|
JetPsiUtil.safeName(valueParameter.getName()),
|
||||||
valueParameter.isMutable(),
|
valueParameter.isMutable(),
|
||||||
variableType,
|
variableType,
|
||||||
@@ -431,6 +431,9 @@ public class DescriptorResolver {
|
|||||||
// Error is reported by the parser
|
// Error is reported by the parser
|
||||||
type = ErrorUtils.createErrorType("Annotation is absent");
|
type = ErrorUtils.createErrorType("Annotation is absent");
|
||||||
}
|
}
|
||||||
|
if (parameter.hasModifier(JetTokens.VARARG_KEYWORD)) {
|
||||||
|
return getVarargParameterType(type);
|
||||||
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -724,7 +727,7 @@ public class DescriptorResolver {
|
|||||||
JetType inType = propertyDescriptor.getType();
|
JetType inType = propertyDescriptor.getType();
|
||||||
if (inType != null) {
|
if (inType != null) {
|
||||||
if (!TypeUtils.equalTypes(type, inType)) {
|
if (!TypeUtils.equalTypes(type, inType)) {
|
||||||
trace.report(WRONG_SETTER_PARAMETER_TYPE.on(typeReference, inType));
|
trace.report(WRONG_SETTER_PARAMETER_TYPE.on(typeReference, inType, type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -732,7 +735,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MutableValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(setterDescriptor, parameter, 0, type, trace);
|
MutableValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(scope, setterDescriptor, parameter, 0, type, trace);
|
||||||
setterDescriptor.initialize(valueParameterDescriptor);
|
setterDescriptor.initialize(valueParameterDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -777,7 +780,7 @@ public class DescriptorResolver {
|
|||||||
if (returnTypeReference != null) {
|
if (returnTypeReference != null) {
|
||||||
returnType = typeResolver.resolveType(scope, returnTypeReference, trace, true);
|
returnType = typeResolver.resolveType(scope, returnTypeReference, trace, true);
|
||||||
if (outType != null && !TypeUtils.equalTypes(returnType, outType)) {
|
if (outType != null && !TypeUtils.equalTypes(returnType, outType)) {
|
||||||
trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType()));
|
trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType(), outType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -920,7 +923,7 @@ public class DescriptorResolver {
|
|||||||
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
|
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
|
||||||
JetType substitutedBound = substitutor.safeSubstitute(bound, Variance.INVARIANT);
|
JetType substitutedBound = substitutor.safeSubstitute(bound, Variance.INVARIANT);
|
||||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(typeArgument, substitutedBound)) {
|
if (!JetTypeChecker.INSTANCE.isSubtypeOf(typeArgument, substitutedBound)) {
|
||||||
trace.report(UPPER_BOUND_VIOLATED.on(argumentTypeReference, substitutedBound));
|
trace.report(UPPER_BOUND_VIOLATED.on(argumentTypeReference, substitutedBound, typeArgument));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-7
@@ -33,9 +33,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMapper.Status.ERROR;
|
import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMapper.Status.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMapper.Status.OK;
|
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMapper.Status.WEAK_ERROR;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -219,10 +217,6 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
|||||||
status = ERROR;
|
status = ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidateCall.getThisObject().exists() != candidateCall.getResultingDescriptor().getExpectedThisObject().exists()) {
|
|
||||||
assert false : "Shouldn't happen because of TaskPrioritizer: " + candidateCall.getCandidateDescriptor();
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -529,6 +529,23 @@ public class TypeUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addAllClassDescriptors(@NotNull JetType type, @NotNull Set<ClassDescriptor> set) {
|
||||||
|
ClassDescriptor cd = getClassDescriptor(type);
|
||||||
|
if (cd != null) {
|
||||||
|
set.add(cd);
|
||||||
|
}
|
||||||
|
for (TypeProjection projection : type.getArguments()) {
|
||||||
|
addAllClassDescriptors(projection.getType(), set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<ClassDescriptor> getAllClassDescriptors(@NotNull JetType type) {
|
||||||
|
Set<ClassDescriptor> classDescriptors = new HashSet<ClassDescriptor>();
|
||||||
|
addAllClassDescriptors(type, classDescriptors);
|
||||||
|
return new ArrayList<ClassDescriptor>(classDescriptors);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasUnsubstitutedTypeParameters(JetType type) {
|
public static boolean hasUnsubstitutedTypeParameters(JetType type) {
|
||||||
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
|
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+2
-1
@@ -195,7 +195,8 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
type = ErrorUtils.createErrorType("Cannot be inferred");
|
type = ErrorUtils.createErrorType("Cannot be inferred");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ValueParameterDescriptor valueParameterDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type, context.trace);
|
ValueParameterDescriptor valueParameterDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveValueParameterDescriptor(
|
||||||
|
context.scope, functionDescriptor, declaredParameter, i, type, context.trace);
|
||||||
valueParameterDescriptors.add(valueParameterDescriptor);
|
valueParameterDescriptors.add(valueParameterDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ package org.jetbrains.jet.resolve;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Renderer;
|
import org.jetbrains.jet.lang.diagnostics.rendering.Renderer;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
|
import org.jetbrains.jet.lang.resolve.FqNameUnsafe;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||||
@@ -28,10 +30,7 @@ import org.jetbrains.jet.lang.types.Variance;
|
|||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -79,7 +78,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visitValueParameterDescriptor(ValueParameterDescriptor descriptor, StringBuilder builder) {
|
public Void visitValueParameterDescriptor(ValueParameterDescriptor descriptor, StringBuilder builder) {
|
||||||
super.visitVariableDescriptor(descriptor, builder);
|
super.visitVariableDescriptor(descriptor, builder, true);
|
||||||
if (descriptor.hasDefaultValue()) {
|
if (descriptor.hasDefaultValue()) {
|
||||||
builder.append(" = ...");
|
builder.append(" = ...");
|
||||||
}
|
}
|
||||||
@@ -120,6 +119,15 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<String> getOuterClassesNames(ClassDescriptor cd) {
|
||||||
|
ArrayList<String> result = new ArrayList<String>();
|
||||||
|
while (cd.getContainingDeclaration() instanceof ClassifierDescriptor) {
|
||||||
|
result.add(cd.getName());
|
||||||
|
cd = (ClassDescriptor)cd.getContainingDeclaration();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private String renderDefaultType(JetType type, boolean shortNamesOnly) {
|
private String renderDefaultType(JetType type, boolean shortNamesOnly) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
ClassifierDescriptor cd = type.getConstructor().getDeclarationDescriptor();
|
ClassifierDescriptor cd = type.getConstructor().getDeclarationDescriptor();
|
||||||
@@ -130,7 +138,18 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
typeNameObject = type.getConstructor();
|
typeNameObject = type.getConstructor();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typeNameObject = shortNamesOnly ? cd.getName() : DescriptorUtils.getFQName(cd);
|
if (shortNamesOnly) {
|
||||||
|
// for nested classes qualified name should be used
|
||||||
|
typeNameObject = cd.getName();
|
||||||
|
DeclarationDescriptor parent = cd.getContainingDeclaration();
|
||||||
|
while (parent instanceof ClassDescriptor) {
|
||||||
|
typeNameObject = parent.getName() + "." + typeNameObject;
|
||||||
|
parent = parent.getContainingDeclaration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
typeNameObject = DescriptorUtils.getFQName(cd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(typeNameObject);
|
sb.append(typeNameObject);
|
||||||
@@ -209,8 +228,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(DeclarationDescriptor declarationDescriptor) {
|
public String render(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||||
if (declarationDescriptor == null) return lt() + "null>";
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
declarationDescriptor.accept(rootVisitor, stringBuilder);
|
declarationDescriptor.accept(rootVisitor, stringBuilder);
|
||||||
if (shouldRenderDefinedIn()) {
|
if (shouldRenderDefinedIn()) {
|
||||||
@@ -228,7 +246,8 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
|
|
||||||
final DeclarationDescriptor containingDeclaration = declarationDescriptor.getContainingDeclaration();
|
final DeclarationDescriptor containingDeclaration = declarationDescriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration != null) {
|
if (containingDeclaration != null) {
|
||||||
renderFullyQualifiedName(containingDeclaration, stringBuilder);
|
FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration);
|
||||||
|
stringBuilder.append(FqName.ROOT.toUnsafe().equals(fqName) ? "root package" : escape(fqName.getFqName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,34 +264,34 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderFullyQualifiedName(DeclarationDescriptor descriptor, StringBuilder stringBuilder) {
|
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
|
||||||
if (containingDeclaration != null) {
|
|
||||||
renderFullyQualifiedName(containingDeclaration, stringBuilder);
|
|
||||||
stringBuilder.append(".");
|
|
||||||
}
|
|
||||||
stringBuilder.append(escape(descriptor.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RenderDeclarationDescriptorVisitor extends DeclarationDescriptorVisitor<Void, StringBuilder> {
|
private class RenderDeclarationDescriptorVisitor extends DeclarationDescriptorVisitor<Void, StringBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visitValueParameterDescriptor(ValueParameterDescriptor descriptor, StringBuilder builder) {
|
public Void visitValueParameterDescriptor(ValueParameterDescriptor descriptor, StringBuilder builder) {
|
||||||
builder.append(renderKeyword("value-parameter")).append(" ");
|
builder.append(renderKeyword("value-parameter")).append(" ");
|
||||||
if (descriptor.getVarargElementType() != null) {
|
|
||||||
builder.append(renderKeyword("vararg")).append(" ");
|
|
||||||
}
|
|
||||||
return super.visitValueParameterDescriptor(descriptor, builder);
|
return super.visitValueParameterDescriptor(descriptor, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visitVariableDescriptor(VariableDescriptor descriptor, StringBuilder builder) {
|
public Void visitVariableDescriptor(VariableDescriptor descriptor, StringBuilder builder) {
|
||||||
|
return visitVariableDescriptor(descriptor, builder, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Void visitVariableDescriptor(VariableDescriptor descriptor, StringBuilder builder, boolean skipValVar) {
|
||||||
|
JetType type = descriptor.getType();
|
||||||
|
if (descriptor instanceof ValueParameterDescriptor) {
|
||||||
|
JetType varargElementType = ((ValueParameterDescriptor)descriptor).getVarargElementType();
|
||||||
|
if (varargElementType != null) {
|
||||||
|
builder.append(renderKeyword("vararg")).append(" ");
|
||||||
|
type = varargElementType;
|
||||||
|
}
|
||||||
|
}
|
||||||
String typeString = renderPropertyPrefixAndComputeTypeString(
|
String typeString = renderPropertyPrefixAndComputeTypeString(
|
||||||
builder,
|
builder,
|
||||||
descriptor.isVar(),
|
skipValVar ? null : descriptor.isVar(),
|
||||||
Collections.<TypeParameterDescriptor>emptyList(),
|
Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
ReceiverDescriptor.NO_RECEIVER,
|
ReceiverDescriptor.NO_RECEIVER,
|
||||||
descriptor.getType());
|
type);
|
||||||
renderName(descriptor, builder);
|
renderName(descriptor, builder);
|
||||||
builder.append(" : ").append(escape(typeString));
|
builder.append(" : ").append(escape(typeString));
|
||||||
return super.visitVariableDescriptor(descriptor, builder);
|
return super.visitVariableDescriptor(descriptor, builder);
|
||||||
@@ -280,13 +299,15 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
|
|
||||||
private String renderPropertyPrefixAndComputeTypeString(
|
private String renderPropertyPrefixAndComputeTypeString(
|
||||||
@NotNull StringBuilder builder,
|
@NotNull StringBuilder builder,
|
||||||
boolean isVar,
|
@Nullable Boolean isVar,
|
||||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||||
@NotNull ReceiverDescriptor receiver,
|
@NotNull ReceiverDescriptor receiver,
|
||||||
@Nullable JetType outType) {
|
@Nullable JetType outType) {
|
||||||
String typeString = lt() + "no type>";
|
String typeString = lt() + "no type>";
|
||||||
if (outType != null) {
|
if (outType != null) {
|
||||||
builder.append(renderKeyword(isVar ? "var" : "val")).append(" ");
|
if (isVar != null) {
|
||||||
|
builder.append(renderKeyword(isVar ? "var" : "val")).append(" ");
|
||||||
|
}
|
||||||
typeString = renderType(outType);
|
typeString = renderType(outType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,22 +336,27 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void renderVisibility(Visibility visibility, StringBuilder builder) {
|
private void renderVisibility(Visibility visibility, StringBuilder builder) {
|
||||||
builder.append(visibility).append(" ");
|
if ("package".equals(visibility.toString())) {
|
||||||
|
builder.append("public/*package*/ ");
|
||||||
|
} else {
|
||||||
|
builder.append(renderKeyword(visibility.toString())).append(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderModality(Modality modality, StringBuilder builder) {
|
private void renderModality(Modality modality, StringBuilder builder) {
|
||||||
|
String keyword = "";
|
||||||
switch (modality) {
|
switch (modality) {
|
||||||
case FINAL:
|
case FINAL:
|
||||||
builder.append("final");
|
keyword = "final";
|
||||||
break;
|
break;
|
||||||
case OPEN:
|
case OPEN:
|
||||||
builder.append("open");
|
keyword = "open";
|
||||||
break;
|
break;
|
||||||
case ABSTRACT:
|
case ABSTRACT:
|
||||||
builder.append("abstract");
|
keyword = "abstract";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
builder.append(" ");
|
builder.append(renderKeyword(keyword)).append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -388,6 +414,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.append(">");
|
builder.append(">");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -475,7 +502,13 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder) {
|
protected void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder) {
|
||||||
if (!descriptor.isReified()) {
|
if (descriptor.isReified()) {
|
||||||
|
String variance = descriptor.getVariance().toString();
|
||||||
|
if (!variance.isEmpty()) {
|
||||||
|
builder.append(renderKeyword(variance)).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
builder.append(renderKeyword("erased")).append(" ");
|
builder.append(renderKeyword("erased")).append(" ");
|
||||||
}
|
}
|
||||||
renderName(descriptor, builder);
|
renderName(descriptor, builder);
|
||||||
|
|||||||
@@ -32,11 +32,12 @@ public class Slices {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <K, V> boolean processRewrite(WritableSlice<K, V> slice, K key, V oldValue, V newValue) {
|
public <K, V> boolean processRewrite(WritableSlice<K, V> slice, K key, V oldValue, V newValue) {
|
||||||
assert (oldValue == null && newValue == null) || (oldValue != null && oldValue.equals(newValue))
|
if (!((oldValue == null && newValue == null) || (oldValue != null && oldValue.equals(newValue)))) {
|
||||||
: "Rewrite at slice " + slice +
|
throw new IllegalStateException("Rewrite at slice " + slice +
|
||||||
" key: " + key +
|
" key: " + key +
|
||||||
" old value: " + oldValue + '@' + System.identityHashCode(oldValue) +
|
" old value: " + oldValue + '@' + System.identityHashCode(oldValue) +
|
||||||
" new value: " + newValue + '@' + System.identityHashCode(newValue);
|
" new value: " + newValue + '@' + System.identityHashCode(newValue));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?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="true" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MODULE_DIR$/../../ideaSDK/lib/junit-4.10.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$MODULE_DIR$/../../ideaSDK/lib/junit-4.10-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Return code: 0
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package Hello
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
System.out?.println("Hello!")
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
OUT Hello!
|
||||||
|
Return code: 0
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
OUT Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||||
|
OUT -output [String] output directory
|
||||||
|
OUT -jar [String] jar file name
|
||||||
|
OUT -src [String] source file or directory
|
||||||
|
OUT -module [String] module to compile
|
||||||
|
OUT -classpath [String] classpath to use when compiling
|
||||||
|
OUT -includeRuntime [flag]
|
||||||
|
OUT -stdlib [String] Path to the stdlib.jar
|
||||||
|
OUT -jdkHeaders [String] Path to the kotlin-jdk-headers.jar
|
||||||
|
OUT -help (-h) [flag]
|
||||||
|
OUT -mode [String] Special compiler modes: stubs or jdkHeaders
|
||||||
|
OUT -tags [flag]
|
||||||
|
OUT -verbose [flag]
|
||||||
|
OUT -version [flag]
|
||||||
|
ERR exec() finished with INTERNAL_ERROR return code
|
||||||
|
Return code: 2
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.kotlin;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.*;
|
||||||
|
|
||||||
|
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||||
|
@Test
|
||||||
|
public void help() throws Exception {
|
||||||
|
runCompiler("help", "--help");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void compileAndRunHelloApp() throws Exception {
|
||||||
|
final String jar = tempDir.getAbsolutePath() + File.separator + "hello.jar";
|
||||||
|
|
||||||
|
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", jar));
|
||||||
|
runJava("hello.run", "-cp", jar, "Hello.namespace");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* 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.kotlin;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
import com.intellij.execution.ExecutionException;
|
||||||
|
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||||
|
import com.intellij.execution.process.OSProcessHandler;
|
||||||
|
import com.intellij.execution.process.ProcessAdapter;
|
||||||
|
import com.intellij.execution.process.ProcessEvent;
|
||||||
|
import com.intellij.execution.process.ProcessOutputTypes;
|
||||||
|
import com.intellij.openapi.application.PathManager;
|
||||||
|
import com.intellij.openapi.util.Key;
|
||||||
|
import com.intellij.openapi.util.SystemInfo;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.util.ArrayUtil;
|
||||||
|
import com.intellij.util.Function;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.rules.TestRule;
|
||||||
|
import org.junit.rules.TestWatcher;
|
||||||
|
import org.junit.runner.Description;
|
||||||
|
import sun.misc.JarFilter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static com.google.common.base.Charsets.UTF_8;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public abstract class KotlinIntegrationTestBase {
|
||||||
|
protected File tempDir;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TestRule watchman = new TestWatcher() {
|
||||||
|
@Override
|
||||||
|
protected void starting(Description description) {
|
||||||
|
tempDir = Files.createTempDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void succeeded(Description description) {
|
||||||
|
try {
|
||||||
|
tempDir.delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.print("Can't delete temp directory " + tempDir + ": " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void failed(Throwable e, Description description) {
|
||||||
|
System.err.println("Temp directory: " + tempDir);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
protected int runCompiler(String logName, String... arguments) throws Exception {
|
||||||
|
final File lib = getCompilerLib();
|
||||||
|
|
||||||
|
final File[] jars = lib.listFiles(new JarFilter());
|
||||||
|
final String classpath = StringUtil.join(jars, new Function<File, String>() {
|
||||||
|
@Override
|
||||||
|
public String fun(File file) {
|
||||||
|
return file.getAbsolutePath();
|
||||||
|
}
|
||||||
|
}, File.pathSeparator);
|
||||||
|
|
||||||
|
Collection<String> javaArgs = new ArrayList<String>();
|
||||||
|
javaArgs.add("-cp");
|
||||||
|
javaArgs.add(classpath);
|
||||||
|
javaArgs.add("org.jetbrains.jet.cli.jvm.K2JVMCompiler");
|
||||||
|
Collections.addAll(javaArgs, arguments);
|
||||||
|
|
||||||
|
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int runJava(String logName, String... arguments) throws Exception {
|
||||||
|
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||||
|
commandLine.setWorkDirectory(getTestDataDirectory());
|
||||||
|
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
|
||||||
|
commandLine.addParameters(arguments);
|
||||||
|
|
||||||
|
StringBuilder executionLog = new StringBuilder();
|
||||||
|
int exitCode = runProcess(commandLine, executionLog);
|
||||||
|
|
||||||
|
if (logName == null) {
|
||||||
|
assertEquals("Non-zero exit code", 0, exitCode);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
check(logName, executionLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
return exitCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void check(String baseName, StringBuilder content) throws IOException {
|
||||||
|
final File tmpFile = new File(getTestDataDirectory(), baseName + ".tmp");
|
||||||
|
final File goldFile = new File(getTestDataDirectory(), baseName + ".gold");
|
||||||
|
|
||||||
|
if (!goldFile.isFile()) {
|
||||||
|
Files.write(content, tmpFile, Charsets.UTF_8);
|
||||||
|
fail("No gold file " + goldFile);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final String goldContent = Files.toString(goldFile, UTF_8);
|
||||||
|
if (!goldContent.equals(content.toString())) {
|
||||||
|
Files.write(content, tmpFile, Charsets.UTF_8);
|
||||||
|
fail("tmp and gold differ, tmp file: " + tmpFile);
|
||||||
|
}
|
||||||
|
tmpFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int runProcess(final GeneralCommandLine commandLine, final StringBuilder executionLog) throws ExecutionException {
|
||||||
|
OSProcessHandler handler =
|
||||||
|
new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
|
||||||
|
|
||||||
|
final StringBuilder outContent = new StringBuilder();
|
||||||
|
final StringBuilder errContent = new StringBuilder();
|
||||||
|
|
||||||
|
handler.addProcessListener(new ProcessAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onTextAvailable(ProcessEvent event, Key outputType) {
|
||||||
|
if (outputType == ProcessOutputTypes.SYSTEM) {
|
||||||
|
System.out.print(event.getText());
|
||||||
|
}
|
||||||
|
else if (outputType == ProcessOutputTypes.STDOUT) {
|
||||||
|
appendToContent(outContent, "OUT ", event.getText());
|
||||||
|
}
|
||||||
|
else if (outputType == ProcessOutputTypes.STDERR) {
|
||||||
|
appendToContent(errContent, "ERR ", event.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendToContent(StringBuilder content, String prefix, String line) {
|
||||||
|
content.append(prefix);
|
||||||
|
content.append(StringUtil.trimTrailing(line));
|
||||||
|
content.append("\n");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
handler.startNotify();
|
||||||
|
handler.waitFor();
|
||||||
|
int exitCode = handler.getProcess().exitValue();
|
||||||
|
|
||||||
|
executionLog.append(outContent);
|
||||||
|
executionLog.append(errContent);
|
||||||
|
executionLog.append("Return code: ").append(exitCode).append("\n");
|
||||||
|
|
||||||
|
return exitCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static File getJavaRuntime() {
|
||||||
|
final File javaHome = new File(System.getProperty("java.home"));
|
||||||
|
final String javaExe = SystemInfo.isWindows ? "java.exe" : "java";
|
||||||
|
|
||||||
|
final File runtime = new File(javaHome, "bin" + File.separator + javaExe);
|
||||||
|
assertTrue("no java runtime at " + runtime, runtime.isFile());
|
||||||
|
|
||||||
|
return runtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static File getCompilerLib() {
|
||||||
|
final File file = new File(getKotlinProjectHome(), "dist" + File.separator + "kotlinc" + File.separator + "lib");
|
||||||
|
assertTrue("no kotlin compiler lib at " + file, file.isDirectory());
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static File getTestDataDirectory() {
|
||||||
|
return new File(getKotlinProjectHome(), "compiler" + File.separator + "integration-tests" + File.separator + "data");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static File getKotlinProjectHome() {
|
||||||
|
return new File(PathManager.getHomePath()).getParentFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,5 +19,5 @@ fun test() {
|
|||||||
bar(1, 1, "")
|
bar(1, 1, "")
|
||||||
bar(1, 1, "")
|
bar(1, 1, "")
|
||||||
bar(1, <!MIXING_NAMED_AND_POSITIONED_ARGUMENTS!>z<!> = "")
|
bar(1, <!MIXING_NAMED_AND_POSITIONED_ARGUMENTS!>z<!> = "")
|
||||||
bar<!NO_VALUE_FOR_PARAMETER!>(1, <!UNRESOLVED_REFERENCE, MIXING_NAMED_AND_POSITIONED_ARGUMENTS!>zz<!> = "", <!MIXING_NAMED_AND_POSITIONED_ARGUMENTS!><!UNRESOLVED_REFERENCE!>zz<!>.foo<!>)<!>
|
bar<!NO_VALUE_FOR_PARAMETER!>(1, <!NAMED_PARAMETER_NOT_FOUND, MIXING_NAMED_AND_POSITIONED_ARGUMENTS!>zz<!> = "", <!MIXING_NAMED_AND_POSITIONED_ARGUMENTS!><!UNRESOLVED_REFERENCE!>zz<!>.foo<!>)<!>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fun test() {
|
fun test() {
|
||||||
fun <T> foo(){}
|
fun <T> foo(){}
|
||||||
foo<<!PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT!>in Int<!>>()
|
foo<<!PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT!>in<!> Int>()
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user