Revert misleading whitespace changes.

This commit is contained in:
Pavel V. Talanov
2012-04-09 15:04:27 +04:00
parent 62efa95211
commit 652be4ed95
7 changed files with 73 additions and 98 deletions
@@ -54,18 +54,12 @@ public class GenerationState {
this(project, builderFactory, Progress.DEAF, analyzeExhaust, files); this(project, builderFactory, Progress.DEAF, analyzeExhaust, files);
} }
public GenerationState(Project project, public GenerationState(Project project, ClassBuilderFactory builderFactory, Progress progress, @NotNull AnalyzeExhaust exhaust, @NotNull List<JetFile> files) {
ClassBuilderFactory builderFactory,
Progress progress,
@NotNull AnalyzeExhaust exhaust,
@NotNull List<JetFile> files) {
this.project = project; this.project = project;
this.progress = progress; this.progress = progress;
this.analyzeExhaust = exhaust; this.analyzeExhaust = exhaust;
this.files = files; this.files = files;
this.injector = this.injector = new InjectorForJvmCodegen(analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), this.files, project, this, builderFactory);
new InjectorForJvmCodegen(analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), this.files, project, this,
builderFactory);
} }
@NotNull @NotNull
@@ -90,13 +84,11 @@ public class GenerationState {
} }
public ClassBuilder forClassImplementation(ClassDescriptor aClass) { public ClassBuilder forClassImplementation(ClassDescriptor aClass) {
return getFactory().newVisitor( return getFactory().newVisitor(getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName() + ".class");
getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName() + ".class");
} }
public ClassBuilder forTraitImplementation(ClassDescriptor aClass) { public ClassBuilder forTraitImplementation(ClassDescriptor aClass) {
return getFactory().newVisitor( return getFactory().newVisitor(getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.TRAIT_IMPL).getInternalName() + ".class");
getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.TRAIT_IMPL).getInternalName() + ".class");
} }
public Pair<String, ClassBuilder> forAnonymousSubclass(JetExpression expression) { public Pair<String, ClassBuilder> forAnonymousSubclass(JetExpression expression) {
@@ -142,17 +134,14 @@ public class GenerationState {
closure.cv = nameAndVisitor.getSecond(); closure.cv = nameAndVisitor.getSecond();
closure.name = nameAndVisitor.getFirst(); closure.name = nameAndVisitor.getFirst();
final CodegenContext objectContext = closure.context.intoAnonymousClass( final CodegenContext objectContext = closure.context.intoAnonymousClass(
closure, analyzeExhaust.getBindingContext().get(BindingContext.CLASS, objectDeclaration), OwnerKind.IMPLEMENTATION, closure, analyzeExhaust.getBindingContext().get(BindingContext.CLASS, objectDeclaration), OwnerKind.IMPLEMENTATION, injector.getJetTypeMapper());
injector.getJetTypeMapper());
new ImplementationBodyCodegen(objectDeclaration, objectContext, nameAndVisitor.getSecond(), this).generate(); new ImplementationBodyCodegen(objectDeclaration, objectContext, nameAndVisitor.getSecond(), this).generate();
ConstructorDescriptor constructorDescriptor = analyzeExhaust.getBindingContext().get(BindingContext.CONSTRUCTOR, objectDeclaration); ConstructorDescriptor constructorDescriptor = analyzeExhaust.getBindingContext().get(BindingContext.CONSTRUCTOR, objectDeclaration);
CallableMethod callableMethod = injector.getJetTypeMapper().mapToCallableMethod( CallableMethod callableMethod = injector.getJetTypeMapper().mapToCallableMethod(
constructorDescriptor, OwnerKind.IMPLEMENTATION, constructorDescriptor, OwnerKind.IMPLEMENTATION, injector.getJetTypeMapper().hasThis0(constructorDescriptor.getContainingDeclaration()));
injector.getJetTypeMapper().hasThis0(constructorDescriptor.getContainingDeclaration())); return new GeneratedAnonymousClassDescriptor(nameAndVisitor.first, callableMethod.getSignature().getAsmMethod(), objectContext.outerWasUsed, null);
return new GeneratedAnonymousClassDescriptor(nameAndVisitor.first, callableMethod.getSignature().getAsmMethod(),
objectContext.outerWasUsed, null);
} }
public String createText() { public String createText() {
@@ -162,8 +151,8 @@ public class GenerationState {
List<String> files = factory.files(); List<String> files = factory.files();
for (String file : files) { for (String file : files) {
// if (!file.startsWith("kotlin/")) { // if (!file.startsWith("kotlin/")) {
answer.append("@").append(file).append('\n'); answer.append("@").append(file).append('\n');
answer.append(factory.asText(file)); answer.append(factory.asText(file));
// } // }
} }
@@ -34,11 +34,11 @@ public class GenerationUtils {
} }
public static GenerationState compileFileGetGenerationState(JetFile psiFile) { public static GenerationState compileFileGetGenerationState(JetFile psiFile) {
final AnalyzeExhaust analyzeExhaust = final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile, JetControlFlowDataTraceFactory.EMPTY);
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile, JetControlFlowDataTraceFactory.EMPTY); GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false),
GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false), analyzeExhaust, analyzeExhaust, Collections.singletonList(psiFile));
Collections.singletonList(psiFile));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
return state; return state;
} }
} }
@@ -37,13 +37,12 @@ import java.util.Collections;
*/ */
public abstract class CodegenTestCase extends JetLiteFixture { public abstract class CodegenTestCase extends JetLiteFixture {
protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args) protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args) throws IllegalAccessException {
throws IllegalAccessException {
boolean caught = false; boolean caught = false;
try { try {
foo.invoke(instance, args); foo.invoke(instance, args);
} }
catch (InvocationTargetException ex) { catch(InvocationTargetException ex) {
caught = exceptionClass.isInstance(ex.getTargetException()); caught = exceptionClass.isInstance(ex.getTargetException());
} }
assertTrue(caught); assertTrue(caught);
@@ -61,17 +60,16 @@ public abstract class CodegenTestCase extends JetLiteFixture {
} }
protected void loadText(final String text) { protected void loadText(final String text) {
myFile = (JetFile)createFile("a.jet", text); myFile = (JetFile) createFile("a.jet", text);
} }
@Override @Override
protected String loadFile(final String name) { protected String loadFile(final String name) {
try { try {
final String content = doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name); final String content = doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
myFile = (JetFile)createFile(name, content); myFile = (JetFile) createFile(name, content);
return content; return content;
} } catch (IOException e) {
catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -89,12 +87,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String actual; String actual;
try { try {
actual = blackBox(); actual = blackBox();
} } catch (NoClassDefFoundError e) {
catch (NoClassDefFoundError e) {
System.out.println(generateToText()); System.out.println(generateToText());
throw e; throw e;
} } catch (Throwable e) {
catch (Throwable e) {
System.out.println(generateToText()); System.out.println(generateToText());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -112,10 +108,9 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", "."); String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", ".");
Class<?> namespaceClass = loader.loadClass(fqName); Class<?> namespaceClass = loader.loadClass(fqName);
Method method = namespaceClass.getMethod("box"); Method method = namespaceClass.getMethod("box");
return (String)method.invoke(null); return (String) method.invoke(null);
} } finally {
finally { loader.dispose();
loader.dispose();
} }
} }
@@ -128,8 +123,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
} }
private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) { private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) {
final AnalyzeExhaust analyzeExhaust = final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY);
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY);
GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile)); GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
return state; return state;
@@ -149,11 +143,9 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", "."); String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", ".");
try { try {
return createClassLoader(state).loadClass(fqName); return createClassLoader(state).loadClass(fqName);
} } catch (ClassNotFoundException e) {
catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} } catch (MalformedURLException e) {
catch (MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
@@ -162,10 +154,8 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected Class loadClass(String fqName, @NotNull ClassFileFactory state) { protected Class loadClass(String fqName, @NotNull ClassFileFactory state) {
try { try {
return createClassLoader(state).loadClass(fqName); return createClassLoader(state).loadClass(fqName);
} } catch (ClassNotFoundException e) {
catch (ClassNotFoundException e) { } catch (MalformedURLException e) {
}
catch (MalformedURLException e) {
} }
fail("No classfile was generated for: " + fqName); fail("No classfile was generated for: " + fqName);
@@ -178,8 +168,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
ClassBuilderFactory classBuilderFactory = ClassBuilderFactories.binaries(false); ClassBuilderFactory classBuilderFactory = ClassBuilderFactories.binaries(false);
return generateCommon(classBuilderFactory).getFactory(); return generateCommon(classBuilderFactory).getFactory();
} } catch (RuntimeException e) {
catch (RuntimeException e) {
System.out.println(generateToText()); System.out.println(generateToText());
throw e; throw e;
} }
@@ -200,12 +189,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
r = method; r = method;
} }
if (r == null) { if (r == null)
throw new AssertionError(); throw new AssertionError();
}
return r; return r;
} } catch (Error e) {
catch (Error e) {
System.out.println(generateToText()); System.out.println(generateToText());
throw e; throw e;
} }
@@ -233,11 +220,11 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected static void assertIsCurrentTime(long returnValue) { protected static void assertIsCurrentTime(long returnValue) {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
long diff = Math.abs(returnValue - currentTime); long diff = Math.abs(returnValue - currentTime);
assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)", assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)", diff <= 1L);
diff <= 1L);
} }
protected Class loadImplementationClass(@NotNull ClassFileFactory codegens, final String name) { protected Class loadImplementationClass(@NotNull ClassFileFactory codegens, final String name) {
return loadClass(name, codegens); return loadClass(name, codegens);
} }
} }
@@ -35,9 +35,9 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode; import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeConstructor; import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -139,13 +139,11 @@ public abstract class ExpectedResolveData {
JetStandardLibrary lib = JetStandardLibrary.getInstance(); JetStandardLibrary lib = JetStandardLibrary.getInstance();
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files,
Predicates.<PsiFile>alwaysTrue(), Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR);
JetControlFlowDataTraceFactory.EMPTY,
CompilerSpecialMode.REGULAR);
BindingContext bindingContext = analyzeExhaust.getBindingContext(); BindingContext bindingContext = analyzeExhaust.getBindingContext();
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) { for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
if (diagnostic instanceof UnresolvedReferenceDiagnostic) { if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic)diagnostic; UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
unresolvedReferences.add(unresolvedReferenceDiagnostic.getPsiElement()); unresolvedReferences.add(unresolvedReferenceDiagnostic.getPsiElement());
} }
} }
@@ -176,35 +174,35 @@ public abstract class ExpectedResolveData {
JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(element, JetReferenceExpression.class); JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(element, JetReferenceExpression.class);
if ("!".equals(name)) { if ("!".equals(name)) {
assertTrue( assertTrue(
"Must have been unresolved: " + "Must have been unresolved: " +
renderReferenceInContext(referenceExpression) + renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
unresolvedReferences.contains(referenceExpression)); unresolvedReferences.contains(referenceExpression));
continue; continue;
} }
if ("!!".equals(name)) { if ("!!".equals(name)) {
assertTrue( assertTrue(
"Must have been resolved to multiple descriptors: " + "Must have been resolved to multiple descriptors: " +
renderReferenceInContext(referenceExpression) + renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null); bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null);
continue; continue;
} }
else if ("!null".equals(name)) { else if ("!null".equals(name)) {
assertTrue( assertTrue(
"Must have been resolved to null: " + "Must have been resolved to null: " +
renderReferenceInContext(referenceExpression) + renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(REFERENCE_TARGET, referenceExpression) == null bindingContext.get(REFERENCE_TARGET, referenceExpression) == null
); );
continue; continue;
} }
else if ("!error".equals(name)) { else if ("!error".equals(name)) {
assertTrue( assertTrue(
"Must have been resolved to error: " + "Must have been resolved to error: " +
renderReferenceInContext(referenceExpression) + renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression)) ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression))
); );
continue; continue;
} }
@@ -252,30 +250,30 @@ public abstract class ExpectedResolveData {
if (expected instanceof JetParameter || actual instanceof JetParameter) { if (expected instanceof JetParameter || actual instanceof JetParameter) {
DeclarationDescriptor expectedDescriptor; DeclarationDescriptor expectedDescriptor;
if (name.startsWith("$")) { if (name.startsWith("$")) {
expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter)expected); expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter) expected);
} }
else { else {
expectedDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expected); expectedDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expected);
if (expectedDescriptor == null) { if (expectedDescriptor == null) {
expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement)expected); expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement) expected);
} }
} }
DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference); DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference);
if (actualDescriptor instanceof VariableAsFunctionDescriptor) { if (actualDescriptor instanceof VariableAsFunctionDescriptor) {
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor)actualDescriptor; VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) actualDescriptor;
actualDescriptor = descriptor.getVariableDescriptor(); actualDescriptor = descriptor.getVariableDescriptor();
} }
assertEquals( assertEquals(
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".", "Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expectedDescriptor, actualDescriptor); expectedDescriptor, actualDescriptor);
} }
else { else {
assertEquals( assertEquals(
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".", "Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expected, actual); expected, actual);
} }
} }
@@ -307,8 +305,7 @@ public abstract class ExpectedResolveData {
expectedTypeConstructor = classDescriptor.getTypeConstructor(); expectedTypeConstructor = classDescriptor.getTypeConstructor();
} }
else if (declaration instanceof JetTypeParameter) { else if (declaration instanceof JetTypeParameter) {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor typeParameterDescriptor = bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter) declaration);
bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter)declaration);
expectedTypeConstructor = typeParameterDescriptor.getTypeConstructor(); expectedTypeConstructor = typeParameterDescriptor.getTypeConstructor();
} }
else { else {
@@ -328,13 +325,14 @@ public abstract class ExpectedResolveData {
PsiElement parent = statement.getParent(); PsiElement parent = statement.getParent();
if (!(parent instanceof JetExpression)) break; if (!(parent instanceof JetExpression)) break;
if (parent instanceof JetBlockExpression) break; if (parent instanceof JetBlockExpression) break;
statement = (JetExpression)parent; statement = (JetExpression) parent;
} }
JetDeclaration declaration = PsiTreeUtil.getParentOfType(referenceExpression, JetDeclaration.class); JetDeclaration declaration = PsiTreeUtil.getParentOfType(referenceExpression, JetDeclaration.class);
return referenceExpression.getText() + " at " + DiagnosticUtils.atLocation(referenceExpression) + return referenceExpression.getText() + " at " + DiagnosticUtils.atLocation(referenceExpression) +
" in " + statement.getText() + (declaration == null ? "" : " in " + declaration.getText()); " in " + statement.getText() + (declaration == null ? "" : " in " + declaration.getText());
} }
private static <T> T getAncestorOfType(Class<T> type, PsiElement element) { private static <T> T getAncestorOfType(Class<T> type, PsiElement element) {
@@ -342,7 +340,7 @@ public abstract class ExpectedResolveData {
element = element.getParent(); element = element.getParent();
} }
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
T result = (T)element; T result = (T) element;
return result; return result;
} }
} }
@@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
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.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
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;
@@ -66,7 +67,7 @@ public class JetSourceNavigationHelper {
} }
final List<JetFile> libraryFiles = findAllSourceFilesWhichContainIdentifier(declaration); final List<JetFile> libraryFiles = findAllSourceFilesWhichContainIdentifier(declaration);
for (JetFile libraryFile : libraryFiles) { for (JetFile libraryFile : libraryFiles) {
BindingContext bindingContext = AnalyzeSingleFileUtil.analyzeSingleFileWithCache(libraryFile).getBindingContext(); BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile(libraryFile);
D descriptor = bindingContext.get(slice, fqName); D descriptor = bindingContext.get(slice, fqName);
if (descriptor != null) { if (descriptor != null) {
return new Tuple2<BindingContext, D>(bindingContext, descriptor); return new Tuple2<BindingContext, D>(bindingContext, descriptor);
@@ -22,6 +22,7 @@ import com.intellij.util.ArrayUtil;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
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.TypeUtils; import org.jetbrains.jet.lang.types.TypeUtils;
@@ -29,13 +30,12 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lexer.JetLexer; import org.jetbrains.jet.lexer.JetLexer;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/** /**
* User: Alefas * User: Alefas
* Date: 31.01.12 * Date: 31.01.12
@@ -68,7 +68,7 @@ public class JetNameSuggester {
public static String[] suggestNames(JetExpression expression, JetNameValidator validator) { public static String[] suggestNames(JetExpression expression, JetNameValidator validator) {
ArrayList<String> result = new ArrayList<String>(); ArrayList<String> result = new ArrayList<String>();
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile()); BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)expression.getContainingFile());
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
if (jetType != null) { if (jetType != null) {
addNamesForType(result, jetType, validator); addNamesForType(result, jetType, validator);
@@ -37,17 +37,17 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.NamespaceType; import org.jetbrains.jet.lang.types.NamespaceType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import org.jetbrains.jet.plugin.refactoring.*; import org.jetbrains.jet.plugin.refactoring.*;
import java.util.*; import java.util.*;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/** /**
* User: Alefas * User: Alefas
* Date: 25.01.12 * Date: 25.01.12
@@ -99,7 +99,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
return; return;
} }
} }
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile()); BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)expression.getContainingFile());
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type
if (expressionType instanceof NamespaceType) { if (expressionType instanceof NamespaceType) {
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.namespace.expression")); showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.namespace.expression"));
@@ -370,7 +370,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
final ArrayList<JetExpression> result = new ArrayList<JetExpression>(); final ArrayList<JetExpression> result = new ArrayList<JetExpression>();
final BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile()); final BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)expression.getContainingFile());
JetVisitorVoid visitor = new JetVisitorVoid() { JetVisitorVoid visitor = new JetVisitorVoid() {
@Override @Override