diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java index 03bdc90036e..fdb550c11e7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java @@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.di.InjectorForJvmCodegen; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; @@ -34,7 +35,6 @@ import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetObjectDeclaration; import org.jetbrains.jet.lang.psi.JetObjectLiteralExpression; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.utils.Progress; import java.util.List; @@ -54,12 +54,18 @@ public class GenerationState { this(project, builderFactory, Progress.DEAF, analyzeExhaust, files); } - public GenerationState(Project project, ClassBuilderFactory builderFactory, Progress progress, @NotNull AnalyzeExhaust exhaust, @NotNull List files) { + public GenerationState(Project project, + ClassBuilderFactory builderFactory, + Progress progress, + @NotNull AnalyzeExhaust exhaust, + @NotNull List files) { this.project = project; this.progress = progress; this.analyzeExhaust = exhaust; this.files = files; - this.injector = new InjectorForJvmCodegen(analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), this.files, project, this, builderFactory); + this.injector = + new InjectorForJvmCodegen(analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), this.files, project, this, + builderFactory); } @NotNull @@ -84,11 +90,13 @@ public class GenerationState { } public ClassBuilder forClassImplementation(ClassDescriptor aClass) { - return getFactory().newVisitor(getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName() + ".class"); + return getFactory().newVisitor( + getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName() + ".class"); } public ClassBuilder forTraitImplementation(ClassDescriptor aClass) { - return getFactory().newVisitor(getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.TRAIT_IMPL).getInternalName() + ".class"); + return getFactory().newVisitor( + getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.TRAIT_IMPL).getInternalName() + ".class"); } public Pair forAnonymousSubclass(JetExpression expression) { @@ -134,14 +142,17 @@ public class GenerationState { closure.cv = nameAndVisitor.getSecond(); closure.name = nameAndVisitor.getFirst(); final CodegenContext objectContext = closure.context.intoAnonymousClass( - closure, analyzeExhaust.getBindingContext().get(BindingContext.CLASS, objectDeclaration), OwnerKind.IMPLEMENTATION, injector.getJetTypeMapper()); + closure, analyzeExhaust.getBindingContext().get(BindingContext.CLASS, objectDeclaration), OwnerKind.IMPLEMENTATION, + injector.getJetTypeMapper()); new ImplementationBodyCodegen(objectDeclaration, objectContext, nameAndVisitor.getSecond(), this).generate(); ConstructorDescriptor constructorDescriptor = analyzeExhaust.getBindingContext().get(BindingContext.CONSTRUCTOR, objectDeclaration); CallableMethod callableMethod = injector.getJetTypeMapper().mapToCallableMethod( - constructorDescriptor, OwnerKind.IMPLEMENTATION, injector.getJetTypeMapper().hasThis0(constructorDescriptor.getContainingDeclaration())); - return new GeneratedAnonymousClassDescriptor(nameAndVisitor.first, callableMethod.getSignature().getAsmMethod(), objectContext.outerWasUsed, null); + constructorDescriptor, OwnerKind.IMPLEMENTATION, + injector.getJetTypeMapper().hasThis0(constructorDescriptor.getContainingDeclaration())); + return new GeneratedAnonymousClassDescriptor(nameAndVisitor.first, callableMethod.getSignature().getAsmMethod(), + objectContext.outerWasUsed, null); } public String createText() { @@ -151,8 +162,8 @@ public class GenerationState { List files = factory.files(); for (String file : files) { // if (!file.startsWith("kotlin/")) { - answer.append("@").append(file).append('\n'); - answer.append(factory.asText(file)); + answer.append("@").append(file).append('\n'); + answer.append(factory.asText(file)); // } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationUtils.java b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationUtils.java index 22dd565a94e..b43db7ec503 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationUtils.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationUtils.java @@ -17,9 +17,9 @@ package org.jetbrains.jet.codegen; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import java.util.Collections; @@ -34,10 +34,11 @@ public class GenerationUtils { } public static GenerationState compileFileGetGenerationState(JetFile psiFile) { - final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile, JetControlFlowDataTraceFactory.EMPTY); - GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false), analyzeExhaust, Collections.singletonList(psiFile)); + final AnalyzeExhaust analyzeExhaust = + AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile, JetControlFlowDataTraceFactory.EMPTY); + GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false), analyzeExhaust, + Collections.singletonList(psiFile)); state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); return state; } - } diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java b/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java index cc616bce02e..c5e5c378df8 100644 --- a/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java +++ b/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java @@ -26,6 +26,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.PsiRecursiveElementWalkingVisitor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.codegen.ClassBuilderFactories; import org.jetbrains.jet.codegen.CompilationErrorHandler; import org.jetbrains.jet.codegen.GenerationState; @@ -41,7 +42,6 @@ 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.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; @@ -71,7 +71,11 @@ public class CompileSession { private final CompilerSpecialMode compilerSpecialMode; private AnalyzeExhaust bindingContext; - public CompileSession(JetCoreEnvironment environment, MessageRenderer messageRenderer, PrintStream errorStream, boolean verbose, CompilerSpecialMode mode) { + public CompileSession(JetCoreEnvironment environment, + MessageRenderer messageRenderer, + PrintStream errorStream, + boolean verbose, + CompilerSpecialMode mode) { this.environment = environment; this.messageRenderer = messageRenderer; this.errorStream = errorStream; @@ -90,8 +94,9 @@ public class CompileSession { } public void addSources(String path) { - if(path == null) + if (path == null) { return; + } VirtualFile vFile = environment.getLocalFileSystem().findFileByPath(path); if (vFile == null) { @@ -107,7 +112,7 @@ public class CompileSession { } private void addSources(File file) { - if(file.isDirectory()) { + if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File child : files) { @@ -119,7 +124,7 @@ public class CompileSession { VirtualFile fileByPath = environment.getLocalFileSystem().findFileByPath(file.getAbsolutePath()); if (fileByPath != null) { PsiFile psiFile = PsiManager.getInstance(environment.getProject()).findFile(fileByPath); - if(psiFile instanceof JetFile) { + if (psiFile instanceof JetFile) { sourceFiles.add((JetFile)psiFile); } } @@ -127,7 +132,7 @@ public class CompileSession { } public void addSources(VirtualFile vFile) { - if (vFile.isDirectory()) { + if (vFile.isDirectory()) { for (VirtualFile virtualFile : vFile.getChildren()) { addSources(virtualFile); } @@ -161,22 +166,25 @@ public class CompileSession { /** * @see JetTypeMapper#getFQName(DeclarationDescriptor) - * TODO possibly duplicates DescriptorUtils#getFQName(DeclarationDescriptor) + * TODO possibly duplicates DescriptorUtils#getFQName(DeclarationDescriptor) */ private static String fqName(ClassOrNamespaceDescriptor descriptor) { DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration(); - if (containingDeclaration == null || containingDeclaration instanceof ModuleDescriptor || containingDeclaration.getName().equals(JavaDescriptorResolver.JAVA_ROOT)) { + if (containingDeclaration == null || + containingDeclaration instanceof ModuleDescriptor || + containingDeclaration.getName().equals(JavaDescriptorResolver.JAVA_ROOT)) { return descriptor.getName(); - } else { - return fqName((ClassOrNamespaceDescriptor) containingDeclaration) + "." + descriptor.getName(); + } + else { + return fqName((ClassOrNamespaceDescriptor)containingDeclaration) + "." + descriptor.getName(); } } private void analyzeAndReportSemanticErrors() { Predicate filesToAnalyzeCompletely = - stubs ? Predicates.alwaysFalse() : Predicates.alwaysTrue(); + stubs ? Predicates.alwaysFalse() : Predicates.alwaysTrue(); bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( - environment.getProject(), sourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY, compilerSpecialMode); + environment.getProject(), sourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY, compilerSpecialMode); for (Diagnostic diagnostic : bindingContext.getBindingContext().getDiagnostics()) { reportDiagnostic(messageCollector, diagnostic); @@ -221,7 +229,8 @@ public class CompileSession { public GenerationState generate(boolean module) { Project project = environment.getProject(); GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), - isVerbose ? new BackendProgress() : Progress.DEAF, bindingContext, sourceFiles); + isVerbose ? new BackendProgress() : Progress.DEAF, bindingContext, + sourceFiles); generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); List plugins = environment.getCompilerPlugins(); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java index b3ea52401c4..5419632b5cc 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java @@ -29,6 +29,7 @@ import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; @@ -71,36 +72,38 @@ public class AnalyzerFacadeForJVM { * @param declarationProvider * @return */ - public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file, @NotNull final Function> declarationProvider) { + public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file, + @NotNull final Function> declarationProvider) { // Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously synchronized (lock) { CachedValue bindingContextCachedValue = file.getUserData(BINDING_CONTEXT); if (bindingContextCachedValue == null) { - bindingContextCachedValue = CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider() { - @Override - public Result compute() { - try { - AnalyzeExhaust bindingContext = analyzeFilesWithJavaIntegration( + bindingContextCachedValue = + CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider() { + @Override + public Result compute() { + try { + AnalyzeExhaust bindingContext = analyzeFilesWithJavaIntegration( file.getProject(), declarationProvider.fun(file), Predicates.equalTo(file), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR); - return new Result(bindingContext, PsiModificationTracker.MODIFICATION_COUNT); + return new Result(bindingContext, PsiModificationTracker.MODIFICATION_COUNT); + } + catch (ProcessCanceledException e) { + throw e; + } + catch (Throwable e) { + DiagnosticUtils.throwIfRunningOnServer(e); + LOG.error(e); + BindingTraceContext bindingTraceContext = new BindingTraceContext(); + bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e)); + AnalyzeExhaust analyzeExhaust = new AnalyzeExhaust(bindingTraceContext.getBindingContext(), null); + return new Result(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT); + } } - catch (ProcessCanceledException e) { - throw e; - } - catch (Throwable e) { - DiagnosticUtils.throwIfRunningOnServer(e); - LOG.error(e); - BindingTraceContext bindingTraceContext = new BindingTraceContext(); - bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e)); - AnalyzeExhaust analyzeExhaust = new AnalyzeExhaust(bindingTraceContext.getBindingContext(), null); - return new Result(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT); - } - } - }, false); + }, false); file.putUserData(BINDING_CONTEXT, bindingContextCachedValue); } return bindingContextCachedValue.getValue(); @@ -111,35 +114,36 @@ public class AnalyzerFacadeForJVM { * Analyze project with string cache for the whole project. All given files will be analyzed only for descriptors. */ public static AnalyzeExhaust analyzeProjectWithCache(@NotNull final Project project, - @NotNull final Collection files) { + @NotNull final Collection files) { // Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously synchronized (lock) { CachedValue bindingContextCachedValue = project.getUserData(BINDING_CONTEXT); if (bindingContextCachedValue == null) { - bindingContextCachedValue = CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider() { - @Override - public Result compute() { - try { - AnalyzeExhaust analyzeExhaust = analyzeFilesWithJavaIntegration( + bindingContextCachedValue = + CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider() { + @Override + public Result compute() { + try { + AnalyzeExhaust analyzeExhaust = analyzeFilesWithJavaIntegration( project, files, Predicates.alwaysFalse(), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR); - return new Result(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT); + return new Result(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT); + } + catch (ProcessCanceledException e) { + throw e; + } + catch (Throwable e) { + DiagnosticUtils.throwIfRunningOnServer(e); + LOG.error(e); + BindingTraceContext bindingTraceContext = new BindingTraceContext(); + AnalyzeExhaust analyzeExhaust = new AnalyzeExhaust(bindingTraceContext.getBindingContext(), null); + return new Result(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT); + } } - catch (ProcessCanceledException e) { - throw e; - } - catch (Throwable e) { - DiagnosticUtils.throwIfRunningOnServer(e); - LOG.error(e); - BindingTraceContext bindingTraceContext = new BindingTraceContext(); - AnalyzeExhaust analyzeExhaust = new AnalyzeExhaust(bindingTraceContext.getBindingContext(), null); - return new Result(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT); - } - } - }, false); + }, false); project.putUserData(BINDING_CONTEXT, bindingContextCachedValue); } return bindingContextCachedValue.getValue(); @@ -147,7 +151,7 @@ public class AnalyzerFacadeForJVM { } public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors( - JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory) { + JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory) { AnalyzingUtils.checkForSyntacticErrors(file); AnalyzeExhaust analyzeExhaust = analyzeOneFileWithJavaIntegration(file, flowDataTraceFactory); @@ -159,25 +163,25 @@ public class AnalyzerFacadeForJVM { public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory) { return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file), - Predicates.alwaysTrue(), flowDataTraceFactory, CompilerSpecialMode.REGULAR); + Predicates.alwaysTrue(), flowDataTraceFactory, CompilerSpecialMode.REGULAR); } public static AnalyzeExhaust analyzeFilesWithJavaIntegration( - Project project, Collection files, Predicate filesToAnalyzeCompletely, - JetControlFlowDataTraceFactory flowDataTraceFactory, - CompilerSpecialMode compilerSpecialMode) { + Project project, Collection files, Predicate filesToAnalyzeCompletely, + JetControlFlowDataTraceFactory flowDataTraceFactory, + CompilerSpecialMode compilerSpecialMode) { BindingTraceContext bindingTraceContext = new BindingTraceContext(); final ModuleDescriptor owner = new ModuleDescriptor(""); TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters( - filesToAnalyzeCompletely, false, false); + filesToAnalyzeCompletely, false, false); InjectorForTopDownAnalyzerForJvm injector = new InjectorForTopDownAnalyzerForJvm( - project, topDownAnalysisParameters, - new ObservableBindingTrace(bindingTraceContext), owner, flowDataTraceFactory, - compilerSpecialMode); + project, topDownAnalysisParameters, + new ObservableBindingTrace(bindingTraceContext), owner, flowDataTraceFactory, + compilerSpecialMode); injector.getTopDownAnalyzer().analyzeFiles(files); @@ -190,6 +194,6 @@ public class AnalyzerFacadeForJVM { Project project = files.iterator().next().getProject(); return analyzeFilesWithJavaIntegration(project, files, Predicates.alwaysFalse(), - JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR); + JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR); } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzeExhaust.java b/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java similarity index 93% rename from compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzeExhaust.java rename to compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java index aed2724895c..3a2a9af1ef9 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzeExhaust.java +++ b/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jetbrains.jet.lang.resolve.java; +package org.jetbrains.jet.analyzer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,7 +35,8 @@ public class AnalyzeExhaust { this.standardLibrary = standardLibrary; } - @NotNull public BindingContext getBindingContext() { + @NotNull + public BindingContext getBindingContext() { return bindingContext; } diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java index ed3b3ed3888..9d7a7492f3d 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java @@ -41,6 +41,7 @@ import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.codegen.ClassBuilder; import org.jetbrains.jet.codegen.ClassBuilderFactory; import org.jetbrains.jet.codegen.CompilationErrorHandler; @@ -48,7 +49,6 @@ import org.jetbrains.jet.codegen.GenerationState; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetPsiUtil; import org.jetbrains.jet.lang.resolve.FqName; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; import org.jetbrains.jet.lang.resolve.java.JetJavaMirrorMarker; @@ -100,8 +100,8 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa } private static PsiClass findClass(FqName fqn, StubElement stub) { - if (stub instanceof PsiClassStub && Comparing.equal(fqn.getFqName(), ((PsiClassStub) stub).getQualifiedName())) { - return (PsiClass) stub.getPsi(); + if (stub instanceof PsiClassStub && Comparing.equal(fqn.getFqName(), ((PsiClassStub)stub).getQualifiedName())) { + return (PsiClass)stub.getPsi(); } for (StubElement child : stub.getChildrenStubs()) { @@ -128,14 +128,14 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa }, false); file.putUserData(JAVA_API_STUB, answer); } - + return answer.getValue(); } - + private PsiJavaFileStub calcStub() { final PsiJavaFileStubImpl answer = new PsiJavaFileStubImpl(JetPsiUtil.getFQName(file).getFqName(), true); final Project project = getProject(); - + final Stack stubStack = new Stack(); final ClassBuilderFactory builderFactory = new ClassBuilderFactory() { @@ -168,13 +168,14 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa stubStack.push(answer); answer.setPsiFactory(new ClsWrapperStubPsiFactory()); - final ClsFileImpl fakeFile = new ClsFileImpl((PsiManagerImpl) manager, new ClassFileViewProvider(manager, file.getVirtualFile())) { - @NotNull - @Override - public PsiClassHolderFileStub getStub() { - return answer; - } - }; + final ClsFileImpl fakeFile = + new ClsFileImpl((PsiManagerImpl)manager, new ClassFileViewProvider(manager, file.getVirtualFile())) { + @NotNull + @Override + public PsiClassHolderFileStub getStub() { + return answer; + } + }; fakeFile.setPhysical(false); answer.setPsi(fakeFile); @@ -205,7 +206,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa @Override public boolean isEquivalentTo(PsiElement another) { - return another instanceof PsiClass && Comparing.equal(((PsiClass) another).getQualifiedName(), getQualifiedName()); + return another instanceof PsiClass && Comparing.equal(((PsiClass)another).getQualifiedName(), getQualifiedName()); } @Override @@ -217,7 +218,8 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa public String toString() { try { return JetLightClass.class.getSimpleName() + ":" + getQualifiedName(); - } catch (Throwable e) { + } + catch (Throwable e) { return JetLightClass.class.getSimpleName() + ":" + e.toString(); } } diff --git a/compiler/tests/org/jetbrains/jet/JetTestUtils.java b/compiler/tests/org/jetbrains/jet/JetTestUtils.java index b4a9f37face..95f2aa504ad 100644 --- a/compiler/tests/org/jetbrains/jet/JetTestUtils.java +++ b/compiler/tests/org/jetbrains/jet/JetTestUtils.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.FileUtil; import junit.framework.TestCase; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.compiler.JetCoreEnvironment; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.diagnostics.Diagnostic; @@ -30,7 +31,6 @@ import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.util.slicedmap.ReadOnlySlice; import org.jetbrains.jet.util.slicedmap.SlicedMap; @@ -86,7 +86,7 @@ public class JetTestUtils { @Override public V get(ReadOnlySlice slice, K key) { - if (slice == BindingContext.PROCESSED) return (V) Boolean.FALSE; + if (slice == BindingContext.PROCESSED) return (V)Boolean.FALSE; return SlicedMap.DO_NOTHING.get(slice, key); } @@ -100,61 +100,61 @@ public class JetTestUtils { @Override public void report(@NotNull Diagnostic diagnostic) { if (diagnostic instanceof UnresolvedReferenceDiagnostic) { - UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic; + UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic)diagnostic; throw new IllegalStateException("Unresolved: " + unresolvedReferenceDiagnostic.getPsiElement().getText()); } } }; public static BindingTrace DUMMY_EXCEPTION_ON_ERROR_TRACE = new BindingTrace() { - @Override - public BindingContext getBindingContext() { - return new BindingContext() { - @Override - public Collection getDiagnostics() { - throw new UnsupportedOperationException(); - } + @Override + public BindingContext getBindingContext() { + return new BindingContext() { + @Override + public Collection getDiagnostics() { + throw new UnsupportedOperationException(); + } - @Override - public V get(ReadOnlySlice slice, K key) { - return DUMMY_EXCEPTION_ON_ERROR_TRACE.get(slice, key); - } + @Override + public V get(ReadOnlySlice slice, K key) { + return DUMMY_EXCEPTION_ON_ERROR_TRACE.get(slice, key); + } - @NotNull - @Override - public Collection getKeys(WritableSlice slice) { - return DUMMY_EXCEPTION_ON_ERROR_TRACE.getKeys(slice); - } - }; - } - - @Override - public void record(WritableSlice slice, K key, V value) { - } - - @Override - public void record(WritableSlice slice, K key) { - } - - @Override - public V get(ReadOnlySlice slice, K key) { - return null; - } - - @NotNull - @Override - public Collection getKeys(WritableSlice slice) { - assert slice.isCollective(); - return Collections.emptySet(); - } - - @Override - public void report(@NotNull Diagnostic diagnostic) { - if (diagnostic.getSeverity() == Severity.ERROR) { - throw new IllegalStateException(diagnostic.getMessage()); - } + @NotNull + @Override + public Collection getKeys(WritableSlice slice) { + return DUMMY_EXCEPTION_ON_ERROR_TRACE.getKeys(slice); } }; + } + + @Override + public void record(WritableSlice slice, K key, V value) { + } + + @Override + public void record(WritableSlice slice, K key) { + } + + @Override + public V get(ReadOnlySlice slice, K key) { + return null; + } + + @NotNull + @Override + public Collection getKeys(WritableSlice slice) { + assert slice.isCollective(); + return Collections.emptySet(); + } + + @Override + public void report(@NotNull Diagnostic diagnostic) { + if (diagnostic.getSeverity() == Severity.ERROR) { + throw new IllegalStateException(diagnostic.getMessage()); + } + } + }; public static AnalyzeExhaust analyzeFile(@NotNull JetFile namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { return AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(namespace, flowDataTraceFactory); @@ -202,24 +202,25 @@ public class JetTestUtils { public static void deleteOnShutdown(File file) { if (filesToDelete.isEmpty()) { ShutDownTracker.getInstance().registerShutdownTask(new Runnable() { - @Override - public void run() { + @Override + public void run() { ShutDownTracker.invokeAndWait(true, true, new Runnable() { - @Override - public void run() { - for (File victim : filesToDelete) { - FileUtil.delete(victim); - } - } + @Override + public void run() { + for (File victim : filesToDelete) { + FileUtil.delete(victim); + } + } }); - } - }); + } + }); } filesToDelete.add(file); } public static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE); + public interface TestFileFactory { F create(String fileName, String text); } @@ -254,7 +255,10 @@ public class JetTestUtils { if (!nextFileExists) break; } - assert processedChars == expectedText.length() : "Characters skipped from " + processedChars + " to " + (expectedText.length() - 1); + assert processedChars == expectedText.length() : "Characters skipped from " + + processedChars + + " to " + + (expectedText.length() - 1); } return testFileFiles; } diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index ed18d54693e..d82137e2a2f 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -19,11 +19,10 @@ package org.jetbrains.jet.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetLiteFixture; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetPsiUtil; -import org.jetbrains.jet.lang.resolve.AnalyzingUtils; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.parsing.JetParsingTest; @@ -38,12 +37,13 @@ import java.util.Collections; */ public abstract class CodegenTestCase extends JetLiteFixture { - protected static void assertThrows(Method foo, Class exceptionClass, Object instance, Object... args) throws IllegalAccessException { + protected static void assertThrows(Method foo, Class exceptionClass, Object instance, Object... args) + throws IllegalAccessException { boolean caught = false; try { foo.invoke(instance, args); } - catch(InvocationTargetException ex) { + catch (InvocationTargetException ex) { caught = exceptionClass.isInstance(ex.getTargetException()); } assertTrue(caught); @@ -61,16 +61,17 @@ public abstract class CodegenTestCase extends JetLiteFixture { } protected void loadText(final String text) { - myFile = (JetFile) createFile("a.jet", text); + myFile = (JetFile)createFile("a.jet", text); } @Override protected String loadFile(final String name) { try { final String content = doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name); - myFile = (JetFile) createFile(name, content); + myFile = (JetFile)createFile(name, content); return content; - } catch (IOException e) { + } + catch (IOException e) { throw new RuntimeException(e); } } @@ -88,10 +89,12 @@ public abstract class CodegenTestCase extends JetLiteFixture { String actual; try { actual = blackBox(); - } catch (NoClassDefFoundError e) { + } + catch (NoClassDefFoundError e) { System.out.println(generateToText()); throw e; - } catch (Throwable e) { + } + catch (Throwable e) { System.out.println(generateToText()); throw new RuntimeException(e); } @@ -109,9 +112,10 @@ public abstract class CodegenTestCase extends JetLiteFixture { String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", "."); Class namespaceClass = loader.loadClass(fqName); Method method = namespaceClass.getMethod("box"); - return (String) method.invoke(null); - } finally { - loader.dispose(); + return (String)method.invoke(null); + } + finally { + loader.dispose(); } } @@ -124,7 +128,8 @@ public abstract class CodegenTestCase extends JetLiteFixture { } private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) { - final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY); + final AnalyzeExhaust analyzeExhaust = + AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY); GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile)); state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION); return state; @@ -144,9 +149,11 @@ public abstract class CodegenTestCase extends JetLiteFixture { String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", "."); try { return createClassLoader(state).loadClass(fqName); - } catch (ClassNotFoundException e) { + } + catch (ClassNotFoundException e) { e.printStackTrace(); - } catch (MalformedURLException e) { + } + catch (MalformedURLException e) { e.printStackTrace(); } return null; @@ -155,8 +162,10 @@ public abstract class CodegenTestCase extends JetLiteFixture { protected Class loadClass(String fqName, @NotNull ClassFileFactory state) { try { return createClassLoader(state).loadClass(fqName); - } catch (ClassNotFoundException e) { - } catch (MalformedURLException e) { + } + catch (ClassNotFoundException e) { + } + catch (MalformedURLException e) { } fail("No classfile was generated for: " + fqName); @@ -169,7 +178,8 @@ public abstract class CodegenTestCase extends JetLiteFixture { ClassBuilderFactory classBuilderFactory = ClassBuilderFactories.binaries(false); return generateCommon(classBuilderFactory).getFactory(); - } catch (RuntimeException e) { + } + catch (RuntimeException e) { System.out.println(generateToText()); throw e; } @@ -190,10 +200,12 @@ public abstract class CodegenTestCase extends JetLiteFixture { r = method; } - if (r == null) + if (r == null) { throw new AssertionError(); + } return r; - } catch (Error e) { + } + catch (Error e) { System.out.println(generateToText()); throw e; } @@ -221,11 +233,11 @@ public abstract class CodegenTestCase extends JetLiteFixture { protected static void assertIsCurrentTime(long returnValue) { long currentTime = System.currentTimeMillis(); 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)", diff <= 1L); + assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)", + diff <= 1L); } protected Class loadImplementationClass(@NotNull ClassFileFactory codegens, final String name) { return loadClass(name, codegens); } - } diff --git a/compiler/tests/org/jetbrains/jet/resolve/ExpectedResolveData.java b/compiler/tests/org/jetbrains/jet/resolve/ExpectedResolveData.java index d1653ed6745..9a4acee5571 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/ExpectedResolveData.java +++ b/compiler/tests/org/jetbrains/jet/resolve/ExpectedResolveData.java @@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.diagnostics.Diagnostic; @@ -31,13 +32,12 @@ import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode; 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.TypeConstructor; +import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import java.util.List; import java.util.Map; @@ -139,11 +139,13 @@ public abstract class ExpectedResolveData { JetStandardLibrary lib = JetStandardLibrary.getInstance(); AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, - Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR); + Predicates.alwaysTrue(), + JetControlFlowDataTraceFactory.EMPTY, + CompilerSpecialMode.REGULAR); BindingContext bindingContext = analyzeExhaust.getBindingContext(); for (Diagnostic diagnostic : bindingContext.getDiagnostics()) { if (diagnostic instanceof UnresolvedReferenceDiagnostic) { - UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic; + UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic)diagnostic; unresolvedReferences.add(unresolvedReferenceDiagnostic.getPsiElement()); } } @@ -174,35 +176,35 @@ public abstract class ExpectedResolveData { JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(element, JetReferenceExpression.class); if ("!".equals(name)) { assertTrue( - "Must have been unresolved: " + - renderReferenceInContext(referenceExpression) + - " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), - unresolvedReferences.contains(referenceExpression)); + "Must have been unresolved: " + + renderReferenceInContext(referenceExpression) + + " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), + unresolvedReferences.contains(referenceExpression)); continue; } if ("!!".equals(name)) { assertTrue( - "Must have been resolved to multiple descriptors: " + - renderReferenceInContext(referenceExpression) + - " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), - bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null); + "Must have been resolved to multiple descriptors: " + + renderReferenceInContext(referenceExpression) + + " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), + bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null); continue; } else if ("!null".equals(name)) { assertTrue( - "Must have been resolved to null: " + - renderReferenceInContext(referenceExpression) + - " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), - bindingContext.get(REFERENCE_TARGET, referenceExpression) == null + "Must have been resolved to null: " + + renderReferenceInContext(referenceExpression) + + " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), + bindingContext.get(REFERENCE_TARGET, referenceExpression) == null ); continue; } else if ("!error".equals(name)) { assertTrue( - "Must have been resolved to error: " + - renderReferenceInContext(referenceExpression) + - " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), - ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression)) + "Must have been resolved to error: " + + renderReferenceInContext(referenceExpression) + + " but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)), + ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression)) ); continue; } @@ -250,30 +252,30 @@ public abstract class ExpectedResolveData { if (expected instanceof JetParameter || actual instanceof JetParameter) { DeclarationDescriptor expectedDescriptor; if (name.startsWith("$")) { - expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter) expected); + expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter)expected); } else { expectedDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expected); if (expectedDescriptor == null) { - expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement) expected); + expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement)expected); } } DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference); if (actualDescriptor instanceof VariableAsFunctionDescriptor) { - VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) actualDescriptor; + VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor)actualDescriptor; actualDescriptor = descriptor.getVariableDescriptor(); } assertEquals( - "Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".", - expectedDescriptor, actualDescriptor); + "Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".", + expectedDescriptor, actualDescriptor); } else { assertEquals( - "Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".", - expected, actual); + "Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".", + expected, actual); } } @@ -305,7 +307,8 @@ public abstract class ExpectedResolveData { expectedTypeConstructor = classDescriptor.getTypeConstructor(); } else if (declaration instanceof JetTypeParameter) { - TypeParameterDescriptor typeParameterDescriptor = bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter) declaration); + TypeParameterDescriptor typeParameterDescriptor = + bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter)declaration); expectedTypeConstructor = typeParameterDescriptor.getTypeConstructor(); } else { @@ -325,14 +328,13 @@ public abstract class ExpectedResolveData { PsiElement parent = statement.getParent(); if (!(parent instanceof JetExpression)) break; if (parent instanceof JetBlockExpression) break; - statement = (JetExpression) parent; + statement = (JetExpression)parent; } JetDeclaration declaration = PsiTreeUtil.getParentOfType(referenceExpression, JetDeclaration.class); - 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 getAncestorOfType(Class type, PsiElement element) { @@ -340,7 +342,7 @@ public abstract class ExpectedResolveData { element = element.getParent(); } @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) - T result = (T) element; + T result = (T)element; return result; } } diff --git a/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java b/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java index 3d8a6fe4d30..2cb035ae555 100644 --- a/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java +++ b/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java @@ -18,12 +18,12 @@ package org.jetbrains.jet.types; import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.di.InjectorForTests; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.DescriptorResolver; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler; @@ -45,7 +45,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { tc.setUp(); } - public class JetDefaultModalityModifiersTestCase { + public class JetDefaultModalityModifiersTestCase { private ModuleDescriptor root = new ModuleDescriptor("test_root"); private DescriptorResolver descriptorResolver; private JetScope scope; @@ -62,11 +62,13 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { List declarations = file.getDeclarations(); JetDeclaration aClass = declarations.get(0); assert aClass instanceof JetClass; - AnalyzeExhaust bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeForJVM.SINGLE_DECLARATION_PROVIDER); - DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass); + AnalyzeExhaust bindingContext = + AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeForJVM.SINGLE_DECLARATION_PROVIDER); + DeclarationDescriptor classDescriptor = + bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass); WritableScopeImpl scope = new WritableScopeImpl(libraryScope, root, RedeclarationHandler.DO_NOTHING); assert classDescriptor instanceof ClassifierDescriptor; - scope.addClassifierDescriptor((ClassifierDescriptor) classDescriptor); + scope.addClassifierDescriptor((ClassifierDescriptor)classDescriptor); scope.changeLockLevel(WritableScope.LockLevel.READING); return scope; } @@ -90,8 +92,9 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { MutableClassDescriptor classDescriptor = createClassDescriptor(kind, aClass); List declarations = aClass.getDeclarations(); - JetNamedFunction function = (JetNamedFunction) declarations.get(0); - SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function, JetTestUtils.DUMMY_TRACE); + JetNamedFunction function = (JetNamedFunction)declarations.get(0); + SimpleFunctionDescriptor functionDescriptor = + descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function, JetTestUtils.DUMMY_TRACE); assertEquals(expectedFunctionModality, functionDescriptor.getModality()); } @@ -101,20 +104,25 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { MutableClassDescriptor classDescriptor = createClassDescriptor(kind, aClass); List declarations = aClass.getDeclarations(); - JetProperty property = (JetProperty) declarations.get(0); - PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE); + JetProperty property = (JetProperty)declarations.get(0); + PropertyDescriptor propertyDescriptor = + descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE); assertEquals(expectedPropertyModality, propertyDescriptor.getModality()); } - private void testPropertyAccessorModality(String classWithPropertyWithAccessor, ClassKind kind, Modality expectedPropertyAccessorModality, boolean isGetter) { + private void testPropertyAccessorModality(String classWithPropertyWithAccessor, + ClassKind kind, + Modality expectedPropertyAccessorModality, + boolean isGetter) { JetClass aClass = JetPsiFactory.createClass(getProject(), classWithPropertyWithAccessor); MutableClassDescriptor classDescriptor = createClassDescriptor(kind, aClass); List declarations = aClass.getDeclarations(); - JetProperty property = (JetProperty) declarations.get(0); - PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE); + JetProperty property = (JetProperty)declarations.get(0); + PropertyDescriptor propertyDescriptor = + descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE); PropertyAccessorDescriptor propertyAccessor = isGetter ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter(); @@ -382,13 +390,15 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; open get }", Modality.OPEN); tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final get }", Modality.FINAL); tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; override get() = 2 }", Modality.OPEN); - tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final override get() = 2 }", Modality.FINAL); + tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final override get() = 2 }", + Modality.FINAL); tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0 }", Modality.FINAL); tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; get }", Modality.FINAL); tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final get }", Modality.FINAL); tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; override get() = 2 }", Modality.OPEN); - tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final override get() = 2 }", Modality.FINAL); + tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final override get() = 2 }", + Modality.FINAL); tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int }", Modality.ABSTRACT); tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int get }", Modality.ABSTRACT); @@ -401,10 +411,12 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int }", Modality.ABSTRACT); tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int get }", Modality.ABSTRACT); tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int open get }", Modality.ABSTRACT); - tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int abstract get }", Modality.ABSTRACT); + tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int abstract get }", + Modality.ABSTRACT); tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int override get() = 10 }", Modality.OPEN); tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int open override get() = 10 }", Modality.OPEN); - tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int final override get() = 10 }", Modality.FINAL); + tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int final override get() = 10 }", + Modality.FINAL); tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int }", Modality.ABSTRACT); tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int get }", Modality.ABSTRACT); diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java index c17df603b19..7b53f454aa2 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java +++ b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java @@ -34,13 +34,13 @@ import com.sun.jdi.ReferenceType; import com.sun.jdi.request.ClassPrepareRequest; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.codegen.JetTypeMapper; import org.jetbrains.jet.codegen.NamespaceCodegen; import org.jetbrains.jet.di.InjectorForJetTypeMapper; import org.jetbrains.jet.lang.psi.JetClassOrObject; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetPsiUtil; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade; import java.util.*; @@ -67,7 +67,8 @@ public class JetPositionManager implements PositionManager { int lineNumber; try { lineNumber = location.lineNumber() - 1; - } catch (InternalError e) { + } + catch (InternalError e) { lineNumber = -1; } @@ -86,8 +87,8 @@ public class JetPositionManager implements PositionManager { if (files.length == 1 && files[0] instanceof JetFile) { return files[0]; } - - } catch (AbsentInformationException e) { + } + catch (AbsentInformationException e) { throw new NoDataException(); } @@ -126,7 +127,7 @@ public class JetPositionManager implements PositionManager { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { - final JetFile file = (JetFile) sourcePosition.getFile(); + final JetFile file = (JetFile)sourcePosition.getFile(); JetTypeMapper typeMapper = prepareTypeMapper(file); JetClassOrObject jetClass = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetClassOrObject.class); @@ -155,7 +156,7 @@ public class JetPositionManager implements PositionManager { } final AnalyzeExhaust analyzeExhaust = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file); JetTypeMapper typeMapper = new InjectorForJetTypeMapper( - analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), Collections.singletonList(file)).getJetTypeMapper(); + analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), Collections.singletonList(file)).getJetTypeMapper(); myTypeMappers.put(file, typeMapper); return typeMapper; } @@ -167,15 +168,15 @@ public class JetPositionManager implements PositionManager { throw new NoDataException(); } try { - int line = position.getLine() + 1; - List locations = myDebugProcess.getVirtualMachineProxy().versionHigher("1.4") - ? type.locationsOfLine(DebugProcess.JAVA_STRATUM, null, line) - : type.locationsOfLine(line); - if (locations == null || locations.isEmpty()) throw new NoDataException(); - return locations; + int line = position.getLine() + 1; + List locations = myDebugProcess.getVirtualMachineProxy().versionHigher("1.4") + ? type.locationsOfLine(DebugProcess.JAVA_STRATUM, null, line) + : type.locationsOfLine(line); + if (locations == null || locations.isEmpty()) throw new NoDataException(); + return locations; } catch (AbsentInformationException e) { - throw new NoDataException(); + throw new NoDataException(); } } diff --git a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java index 42a7f9cfadc..b7bfe2551a2 100644 --- a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java +++ b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java @@ -36,12 +36,12 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.util.Alarm; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.codegen.ClassBuilderFactories; import org.jetbrains.jet.codegen.ClassFileFactory; import org.jetbrains.jet.codegen.CompilationErrorHandler; import org.jetbrains.jet.codegen.GenerationState; import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade; import javax.swing.*; @@ -69,7 +69,8 @@ public class BytecodeToolwindow extends JPanel implements Disposable { public BytecodeToolwindow(Project project) { super(new BorderLayout()); myProject = project; - myEditor = EditorFactory.getInstance().createEditor(EditorFactory.getInstance().createDocument(""), project, JavaFileType.INSTANCE, true); + myEditor = + EditorFactory.getInstance().createEditor(EditorFactory.getInstance().createDocument(""), project, JavaFileType.INSTANCE, true); add(myEditor.getComponent()); myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, this); myUpdateAlarm.addRequest(new Runnable() { @@ -92,7 +93,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable { setText(DEFAULT_TEXT); } else { - VirtualFile vFile = ((EditorEx) editor).getVirtualFile(); + VirtualFile vFile = ((EditorEx)editor).getVirtualFile(); if (vFile == null) { setText(DEFAULT_TEXT); return; @@ -104,17 +105,21 @@ public class BytecodeToolwindow extends JPanel implements Disposable { return; } - if (oldLocation == null || !Comparing.equal(oldLocation.editor, location.editor) || oldLocation.modificationStamp != location.modificationStamp) { - setText(generateToText((JetFile) psiFile)); + if (oldLocation == null || + !Comparing.equal(oldLocation.editor, location.editor) || + oldLocation.modificationStamp != location.modificationStamp) { + setText(generateToText((JetFile)psiFile)); } Document document = editor.getDocument(); int startLine = document.getLineNumber(location.startOffset); int endLine = document.getLineNumber(location.endOffset); - if (endLine > startLine && location.endOffset > 0 && document.getCharsSequence().charAt(location.endOffset - 1) == '\n') endLine--; + if (endLine > startLine && location.endOffset > 0 && document.getCharsSequence().charAt(location.endOffset - 1) == '\n') { + endLine--; + } Document byteCodeDocument = myEditor.getDocument(); - + Pair linesRange = mapLines(byteCodeDocument.getText(), startLine, endLine); int endSelectionLineIndex = Math.min(linesRange.second + 1, byteCodeDocument.getLineCount()); @@ -152,7 +157,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable { break; } } - + for (String line : text.split("\n")) { line = line.trim(); @@ -163,7 +168,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable { byteCodeStartLine = byteCodeLine; } - if (byteCodeStartLine > 0&& ktLineNum > endLine) { + if (byteCodeStartLine > 0 && ktLineNum > endLine) { byteCodeEndLine = byteCodeLine - 1; break; } @@ -179,14 +184,12 @@ public class BytecodeToolwindow extends JPanel implements Disposable { } - if (byteCodeStartLine == -1 || byteCodeEndLine == -1) { return new Pair(0, 0); } else { return new Pair(byteCodeStartLine, byteCodeEndLine); } - } private void setText(final String text) { @@ -269,7 +272,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable { if (this == o) return true; if (!(o instanceof Location)) return false; - Location location = (Location) o; + Location location = (Location)o; if (endOffset != location.endOffset) return false; if (modificationStamp != location.modificationStamp) return false; @@ -282,10 +285,10 @@ public class BytecodeToolwindow extends JPanel implements Disposable { @Override public int hashCode() { int result = editor != null ? editor.hashCode() : 0; - result = 31 * result + (int) (modificationStamp ^ (modificationStamp >>> 32)); + result = 31 * result + (int)(modificationStamp ^ (modificationStamp >>> 32)); result = 31 * result + startOffset; result = 31 * result + endOffset; return result; } - } + } } diff --git a/idea/src/org/jetbrains/jet/plugin/project/WholeProjectAnalyzerFacade.java b/idea/src/org/jetbrains/jet/plugin/project/WholeProjectAnalyzerFacade.java index 1fb82439458..88d478585c1 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/WholeProjectAnalyzerFacade.java +++ b/idea/src/org/jetbrains/jet/plugin/project/WholeProjectAnalyzerFacade.java @@ -19,8 +19,8 @@ package org.jetbrains.jet.plugin.project; import com.intellij.openapi.project.Project; import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; @@ -29,8 +29,11 @@ import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; */ public final class WholeProjectAnalyzerFacade { - /** Forbid creating */ - private WholeProjectAnalyzerFacade() {} + /** + * Forbid creating + */ + private WholeProjectAnalyzerFacade() { + } @NotNull