ErrorHandler introduced
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package org.jetbrains.jet.lang;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ErrorHandler {
|
||||
public static final ErrorHandler DO_NOTHING = new ErrorHandler();
|
||||
public static final ErrorHandler THROW_EXCEPTION = new ErrorHandler();
|
||||
|
||||
}
|
||||
@@ -10,16 +10,23 @@ import org.jetbrains.jet.lang.types.JetTypeInferrer;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetSemanticServices {
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final JetTypeInferrer typeInferrer;
|
||||
|
||||
public JetSemanticServices(JetStandardLibrary standardLibrary) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
this.typeInferrer = new JetTypeInferrer(BindingTrace.DUMMY, this);
|
||||
public static JetSemanticServices createSemanticServices(JetStandardLibrary standardLibrary, ErrorHandler errorHandler) {
|
||||
return new JetSemanticServices(standardLibrary, errorHandler);
|
||||
}
|
||||
|
||||
public JetSemanticServices(Project project) {
|
||||
this(new JetStandardLibrary(project));
|
||||
public static JetSemanticServices createSemanticServices(Project project, ErrorHandler errorHandler) {
|
||||
return new JetSemanticServices(new JetStandardLibrary(project), errorHandler);
|
||||
}
|
||||
|
||||
private final JetTypeInferrer typeInferrer;
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
private JetSemanticServices(JetStandardLibrary standardLibrary, ErrorHandler errorHandler) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
this.errorHandler = errorHandler;
|
||||
this.typeInferrer = new JetTypeInferrer(BindingTrace.DUMMY, this);
|
||||
}
|
||||
|
||||
public JetStandardLibrary getStandardLibrary() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -20,7 +21,9 @@ public class JetPsiChecker implements Annotator {
|
||||
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
|
||||
if (element instanceof JetFile) {
|
||||
JetFile file = (JetFile) element;
|
||||
JetSemanticServices semanticServices = new JetSemanticServices(element.getProject());
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(element.getProject(), new ErrorHandler() {
|
||||
|
||||
});
|
||||
try {
|
||||
final BindingContext bindingContext = new TopDownAnalyzer(semanticServices).process(semanticServices.getStandardLibrary().getLibraryScope(), file.getRootNamespace().getDeclarations());
|
||||
file.getRootNamespace().accept(new JetVisitor() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
|
||||
@@ -66,7 +67,7 @@ public class JetReferenceExpression extends JetExpression {
|
||||
element = element.getParent();
|
||||
}
|
||||
JetFile file = (JetFile) element;
|
||||
JetSemanticServices semanticServices = new JetSemanticServices(element.getProject());
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(element.getProject(), ErrorHandler.DO_NOTHING);
|
||||
BindingContext bindingContext = new TopDownAnalyzer(semanticServices).process(semanticServices.getStandardLibrary().getLibraryScope(), file.getRootNamespace().getDeclarations());
|
||||
return bindingContext.resolveToDeclarationPsiElement(JetReferenceExpression.this);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetFileType;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -50,7 +51,7 @@ public class JetStandardLibrary {
|
||||
JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet",
|
||||
JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));
|
||||
|
||||
JetSemanticServices bootstrappingSemanticServices = new JetSemanticServices(this);
|
||||
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this, ErrorHandler.DO_NOTHING);
|
||||
TopDownAnalyzer bootstrappingTDA = new TopDownAnalyzer(bootstrappingSemanticServices);
|
||||
BindingContext bindingContext = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
||||
this.libraryScope = bindingContext.getTopLevelScope();
|
||||
|
||||
@@ -338,7 +338,9 @@ public class JetTypeInferrer {
|
||||
throw new IllegalArgumentException("Unsupported element: " + elem);
|
||||
}
|
||||
});
|
||||
trace.recordExpressionType(expression, result[0]);
|
||||
if (result[0] != null) {
|
||||
trace.recordExpressionType(expression, result[0]);
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
|
||||
@@ -396,14 +398,18 @@ public class JetTypeInferrer {
|
||||
@Override
|
||||
public FunctionDescriptor getFunctionDescriptorForNamedArguments(@NotNull List<Type> typeArguments, @NotNull Map<String, Type> valueArgumentTypes, @Nullable Type functionLiteralArgumentType) {
|
||||
FunctionDescriptor descriptor = result[0].getFunctionDescriptorForNamedArguments(typeArguments, valueArgumentTypes, functionLiteralArgumentType);
|
||||
trace.recordReferenceResolution(reference[0], descriptor);
|
||||
if (descriptor != null) {
|
||||
trace.recordReferenceResolution(reference[0], descriptor);
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionDescriptor getFunctionDescriptorForPositionedArguments(@NotNull List<Type> typeArguments, @NotNull List<Type> positionedValueArgumentTypes) {
|
||||
FunctionDescriptor descriptor = result[0].getFunctionDescriptorForPositionedArguments(typeArguments, positionedValueArgumentTypes);
|
||||
trace.recordReferenceResolution(reference[0], descriptor);
|
||||
if (descriptor != null) {
|
||||
trace.recordReferenceResolution(reference[0], descriptor);
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.util.TraceClassVisitor;
|
||||
@@ -62,7 +62,7 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
||||
StringWriter writer = new StringWriter();
|
||||
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||
JetNamespace namespace = jetFile.getRootNamespace();
|
||||
codegen.generate(namespace, new TraceClassVisitor(new PrintWriter(writer)), new JetSemanticServices(new JetStandardLibrary(getProject())));
|
||||
codegen.generate(namespace, new TraceClassVisitor(new PrintWriter(writer)), JetSemanticServices.createSemanticServices(getProject(), ErrorHandler.THROW_EXCEPTION));
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
||||
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
final JetNamespace namespace = jetFile.getRootNamespace();
|
||||
codegen.generate(namespace, writer, new JetSemanticServices(new JetStandardLibrary(getProject())));
|
||||
codegen.generate(namespace, writer, JetSemanticServices.createSemanticServices(getProject(), ErrorHandler.THROW_EXCEPTION));
|
||||
final byte[] data = writer.toByteArray();
|
||||
MyClassLoader classLoader = new MyClassLoader(NamespaceGenTest.class.getClassLoader());
|
||||
final Class aClass = classLoader.doDefineClass(NamespaceCodegen.getJVMClassName(namespace).replace("/", "."), data);
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.resolve;
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
@@ -39,7 +40,7 @@ public class JetResolveTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testBasic() throws Exception {
|
||||
JetFile jetFile = JetChangeUtil.createFile(getProject(), FileUtil.loadTextAndClose(new FileReader(getTestDataPath() + "/resolve/Basic.jet")));
|
||||
List<JetDeclaration> declarations = jetFile.getRootNamespace().getDeclarations();
|
||||
BindingContext bindingContext = new TopDownAnalyzer(new JetSemanticServices(library)).process(library.getLibraryScope(), declarations);
|
||||
BindingContext bindingContext = new TopDownAnalyzer(JetSemanticServices.createSemanticServices(library, ErrorHandler.THROW_EXCEPTION)).process(library.getLibraryScope(), declarations);
|
||||
|
||||
JetClass classADecl = (JetClass) declarations.get(0);
|
||||
ClassDescriptor classA = bindingContext.getClassDescriptor(classADecl);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.JetChangeUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
@@ -32,7 +33,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
library = new JetStandardLibrary(getProject());
|
||||
semanticServices = new JetSemanticServices(library);
|
||||
semanticServices = JetSemanticServices.createSemanticServices(library, ErrorHandler.THROW_EXCEPTION);
|
||||
classDefinitions = new ClassDefinitions();
|
||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user