From 7780f853c406b5933b94e5c8fe652bd80a594138 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 20 Oct 2017 14:19:25 +0200 Subject: [PATCH 001/141] fix finding launcher directory in test for SbtRunner additional assertions in test to aid debugging --- .../sbt/project/structure/SbtRunner.scala | 19 +++++++------ .../sbt/shell/SbtProcessManager.scala | 7 +++-- .../jetbrains/sbt/shell/SbtShellRunner.scala | 11 +++++++- .../shell/SbtProjectPlatformTestCase.scala | 28 +++++++++++++------ 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala index 6ef1650d213..afafad75669 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala @@ -207,19 +207,20 @@ object SbtRunner { val file: File = jarWith[this.type] val deep = if (file.getName == "classes") 1 else 2 val playEnabled = Try(getClass.getClassLoader.loadClass("com.intellij.scala.play.Play2Bundle") != null).getOrElse(false) - (file << deep) / "launcher" match { - case res: File if !res.exists() && isInTest => - (for { - scalaVer <- jarWith[this.type].parent - target <- scalaVer.parent - project <- if (playEnabled) Option(target << 3) else target.parent - } yield project / "target" / "plugin" / "Scala" / "launcher").get - case res => res - } + val res = (file << deep) / "launcher" + if (!res.exists() && isInTest) + jarWith[this.type].parent.flatMap(findLauncherDir).get + else res } def getDefaultLauncher: File = getSbtLauncherDir / "sbt-launch.jar" + private def findLauncherDir(from: File): Option[File] = { + val launcherDir = from / "target" / "plugin" / "Scala" / "launcher" + if (launcherDir.exists) Option(launcherDir) + else from.parent.flatMap(findLauncherDir) + } + private val sinceSbtVersion = Version("0.12.4") val sinceSbtVersionShell = Version("0.13.5") diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala index d043b9a8ef6..bbbf19d80a8 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala @@ -182,7 +182,7 @@ class SbtProcessManager(project: Project) extends AbstractProjectComponent(proje val pd = ProcessData(handler, runner) - processData = Option(pd) + processData.synchronized { processData = Option(pd) } pd.runner.initAndRun() pd } @@ -200,7 +200,7 @@ class SbtProcessManager(project: Project) extends AbstractProjectComponent(proje } /** Creates the SbtShellRunner view, or focuses it if it already exists. */ - def openShellRunner(focus: Boolean = false): SbtShellRunner = { + def openShellRunner(focus: Boolean = false): SbtShellRunner = processData.synchronized { val theRunner = processData match { case Some(ProcessData(_, runner)) if runner.getConsoleView.isRunning => @@ -221,7 +221,8 @@ class SbtProcessManager(project: Project) extends AbstractProjectComponent(proje def destroyProcess(): Unit = processData.synchronized { processData match { - case Some(ProcessData(handler, _)) => + case Some(ProcessData(handler, runner)) => + runner.dispose() handler.destroyProcess() processData = None case None => // nothing to do diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala index 8d9f2b0742c..bcb9176b6a0 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala @@ -10,9 +10,11 @@ import com.intellij.execution.process.{OSProcessHandler, ProcessHandler} import com.intellij.execution.runners.AbstractConsoleRunnerWithHistory import com.intellij.execution.ui.layout.PlaceInGrid import com.intellij.execution.ui.{RunContentDescriptor, RunnerLayoutUi} +import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem._ import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Disposer import com.intellij.openapi.wm.{ToolWindow, ToolWindowManager} import com.intellij.ui.content.{Content, ContentFactory} import com.pty4j.{PtyProcess, WinSize} @@ -26,7 +28,9 @@ import scala.collection.JavaConverters._ * Created by jast on 2016-5-29. */ class SbtShellRunner(project: Project, consoleTitle: String, debugConnection: Option[RemoteConnection]) - extends AbstractConsoleRunnerWithHistory[LanguageConsoleImpl](project, consoleTitle, project.getBaseDir.getCanonicalPath) { + extends AbstractConsoleRunnerWithHistory[LanguageConsoleImpl](project, consoleTitle, project.getBaseDir.getCanonicalPath) + with Disposable +{ private val toolWindowTitle = project.getName @@ -162,6 +166,11 @@ class SbtShellRunner(project: Project, consoleTitle: String, debugConnection: Op content } + override def dispose(): Unit = { + myConsoleView.dispose() + Disposer.dispose(myConsoleView) + } + object SbtShellRootType extends ConsoleRootType("sbt.shell", getConsoleTitle) class SbtShellExecuteActionHandler(processHandler: ProcessHandler) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala index 1112ee66b01..b8cb4c79187 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala @@ -6,30 +6,43 @@ import com.intellij.execution.process.{ProcessEvent, ProcessListener} import com.intellij.ide.impl.ProjectUtil import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder +import com.intellij.openapi.externalSystem.model.DataNode +import com.intellij.openapi.externalSystem.model.project.ProjectData +import com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback import com.intellij.openapi.externalSystem.util.ExternalSystemUtil import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.roots.ProjectRootManager -import com.intellij.openapi.util.{Disposer, Key} +import com.intellij.openapi.util.Key import com.intellij.testFramework.{PlatformTestCase, ThreadTracker} import com.intellij.util.ui.UIUtil +import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.util.TestUtils import org.jetbrains.sbt.project.SbtProjectSystem -import org.jetbrains.plugins.scala.extensions._ +import org.junit.Assert /** * Created by Roman.Shein on 27.03.2017. */ abstract class SbtProjectPlatformTestCase extends PlatformTestCase { + override def setUpProject(): Unit = { - //projectFile is the sbt file for the root project - val project = ProjectUtil.openOrImport(getSbtRootFile.getAbsolutePath, null, false) + // projectFile is the sbt file for the root project + val path = getSbtRootFile.getAbsolutePath + val project = ProjectUtil.openOrImport(path, null, false) + assert(project != null, s"project at path $path was null") val sdk = TestUtils.createJdk() inWriteAction { ProjectJdkTable.getInstance.addJdk(sdk) ProjectRootManager.getInstance(project).setProjectSdk(sdk) } - ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(project, SbtProjectSystem.Id)) + val callback = new ExternalProjectRefreshCallback { + override def onFailure(errorMessage: String, errorDetails: String): Unit = + Assert.fail(s"sbt project refresh failed: $errorMessage. Details: $errorDetails") + override def onSuccess(externalProject: DataNode[ProjectData]): Unit = () + } + val importSpec = new ImportSpecBuilder(project, SbtProjectSystem.Id).callback(callback).build() + ExternalSystemUtil.refreshProjects(importSpec) myProject = project } @@ -60,11 +73,10 @@ abstract class SbtProjectPlatformTestCase extends PlatformTestCase { jdkTable.getAllJdks.foreach(jdkTable.removeJdk) } - myRunner.getConsoleView.dispose() - Disposer.dispose(myRunner.getConsoleView) + SbtProcessManager.forProject(getProject).destroyProcess() + UIUtil.dispatchAllInvocationEvents() val handler = myRunner.getProcessHandler - handler.destroyProcess() //give the handler some time to terminate the process while (!handler.isProcessTerminated || handler.isProcessTerminating) { Thread.sleep(100) From ba374bec36649aa0d0fdc1e9511e0163cd71196f Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Fri, 20 Oct 2017 17:41:30 +0300 Subject: [PATCH 002/141] Revert: refactorings for PR: Automatic SBT library import suggestion #393 (9cfa597) fix #SCL-12647 #SCL-12729 --- .../intention/sbt/AddSbtDependencyFix.scala | 20 ++--- .../intention/sbt/AddSbtDependencyUtils.scala | 5 +- .../sbt/ui/SbtPossiblePlacesPanel.scala | 73 +++++++++---------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index 8cc0c3ca5c8..f86eeaa1344 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -19,6 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScPatternDefinition import org.jetbrains.sbt.Sbt import org.jetbrains.sbt.project.SbtProjectSystem import org.jetbrains.sbt.resolvers.SbtResolver +import org.jetbrains.sbt.settings.SbtSystemSettings /** * Created by afonichkin on 7/7/17. @@ -29,7 +30,8 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio file != null && file.isInstanceOf[ScalaFile] && refElement.getManager.isInProject(file) && - ! file.isInstanceOf[ScalaCodeFragment] + ! file.isInstanceOf[ScalaCodeFragment] && + ! SbtSystemSettings.getInstance(project).getLinkedProjectsSettings.isEmpty } override def getText: String = "Add sbt dependency..." @@ -47,17 +49,15 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio val resolver: SbtResolver = SbtResolver.localCacheResolver(None) for { - sbtFile <- sbtFileOpt - module <- refElement.module - if ExternalSystemApiUtil.isExternalSystemAwareModule(SbtProjectSystem.Id, module) - ivyIndex <- resolver.getIndex(project) + sbtFile <- sbtFileOpt + ivyIndex <- resolver.getIndex(project) artifactInfoSet = ivyIndex.searchArtifactInfo(getReferenceText) - psiSbtFile: ScalaFile = PsiManager.getInstance(project).findFile(sbtFile).asInstanceOf[ScalaFile] - depPlaces = getDependencyPlaces(project, psiSbtFile) - wizard = new SbtArtifactSearchWizard(project, artifactInfoSet, depPlaces) + psiSbtFile = PsiManager.getInstance(project).findFile(sbtFile).asInstanceOf[ScalaFile] + depPlaces = getDependencyPlaces(project, psiSbtFile) + wizard = new SbtArtifactSearchWizard(project, artifactInfoSet, depPlaces) (infoOption, fileLineOption) = wizard.search() - artifactInfo <- infoOption - fileLine <- fileLineOption + artifactInfo <- infoOption + fileLine <- fileLineOption } { addDependency(fileLine.element, artifactInfo)(project) refresh(project) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala index 9e8d8b6bf79..beefc1220f2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala @@ -229,12 +229,13 @@ object AddSbtDependencyUtils { private def generateArtifactText(info: ArtifactInfo): String = s""""${info.groupId}" % "${info.artifactId}" % "${info.version}"""" - def getRelativePath(elem: PsiElement)(implicit project: ProjectContext): Option[String] = + def getRelativePath(elem: PsiElement)(implicit project: ProjectContext): Option[String] = { for { path <- Option(elem.getContainingFile.getVirtualFile.getCanonicalPath) - if !path.startsWith(project.getBasePath) + if path.startsWith(project.getBasePath) } yield path.substring(project.getBasePath.length + 1) + } def toDependencyPlaceInfo(elem: PsiElement, affectedProjects: Seq[String])(implicit ctx: ProjectContext): Option[DependencyPlaceInfo] = { val offset = diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index d85e3657dcd..49b996113f4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -25,17 +25,15 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory * Created by afonichkin on 7/19/17. */ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, fileLines: Seq[DependencyPlaceInfo]) extends JPanel { - - private val EDITOR_TOP_MARGIN = 7 - - private val myResultList: Tree = new Tree() - private val myLayout = new BorderLayout() - - private var myCurFileLine: DependencyPlaceInfo = _ - private var myCurEditor: Editor = _ + val myResultList: Tree = new Tree() + var myCurFileLine: DependencyPlaceInfo = _ var canGoNext: Boolean = false + val myLayout = new BorderLayout() + var myCurEditor: Editor = _ + + val EDITOR_TOP_MARGIN = 7 init() @@ -62,24 +60,22 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, myResultList.setCellRenderer(new MyCellRenderer) - myResultList.addTreeSelectionListener(new TreeSelectionListener { - override def valueChanged(treeSelectionEvent: TreeSelectionEvent): Unit = { - val path = treeSelectionEvent.getNewLeadSelectionPath - if (path == null) { - canGoNext = false - myCurFileLine = null - updateEditor() - } else { - path.getLastPathComponent match { - case fileLine: DependencyPlaceInfo if myCurFileLine != fileLine => - canGoNext = true - myCurFileLine = fileLine - updateEditor() - case _ => - } + myResultList.addTreeSelectionListener((treeSelectionEvent: TreeSelectionEvent) => { + val path = treeSelectionEvent.getNewLeadSelectionPath + if (path == null) { + canGoNext = false + myCurFileLine = null + updateEditor() + } else { + path.getLastPathComponent match { + case fileLine: DependencyPlaceInfo if myCurFileLine != fileLine => + canGoNext = true + myCurFileLine = fileLine + updateEditor() + case _ => } - wizard.updateWizardButtons() } + wizard.updateWizardButtons() }) } @@ -87,7 +83,8 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, if (myCurFileLine == null) { remove(myLayout.getLayoutComponent(BorderLayout.SOUTH)) updateUI() - } else for (editor <- createEditor(myCurFileLine.path)) { + } else { + val editor = createEditor(myCurFileLine.path) val editorHighlighter = EditorHighlighterFactory.getInstance.createEditorHighlighter(project, ScalaFileType.INSTANCE) editor.asInstanceOf[EditorEx].setHighlighter(editorHighlighter) editor.getCaretModel.moveToOffset(myCurFileLine.offset) @@ -113,13 +110,14 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, EditorFactory.getInstance.releaseEditor(myCurEditor) } - private def createEditor(path: String): Option[Editor] = { + private def createEditor(path: String): Editor = { val document = FileDocumentManager.getInstance.getDocument(project.getBaseDir.findFileByRelativePath(path)) val tmpFile = ScalaPsiElementFactory.createScalaFileFromText(document.getText)(project) var tmpElement = tmpFile.findElementAt(myCurFileLine.element.getTextOffset) while (tmpElement.getTextRange != myCurFileLine.element.getTextRange) tmpElement = tmpElement.getParent + val dep: PsiElement = AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project).get val viewer = EditorFactory.getInstance.createViewer( EditorFactory.getInstance().createDocument(tmpFile.getText) @@ -128,22 +126,23 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, val scheme = viewer.getColorsScheme val attributes = scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) - for {dep: PsiElement <- AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project)} yield { - - viewer.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, dep.getTextRange.getEndOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE) + viewer.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, dep.getTextRange.getEndOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE) - viewer.getComponent.setPreferredSize(new Dimension(1600, 500)) - viewer.getComponent.updateUI() + viewer.getComponent.setPreferredSize(new Dimension(1600, 500)) + viewer.getComponent.updateUI() - viewer - } + viewer } - def getResult: Option[DependencyPlaceInfo] = - myResultList.getSelectionPaths.collectFirst { - case path if path.getLastPathComponent.isInstanceOf[DependencyPlaceInfo] => - path.getLastPathComponent.asInstanceOf[DependencyPlaceInfo] + def getResult: Option[DependencyPlaceInfo] = { + for (path: TreePath <- myResultList.getSelectionPaths) { + path.getLastPathComponent match { + case info: DependencyPlaceInfo => return Some(info) + case _ => + } } + None + } private class MyTreeModel(elements: Seq[DependencyPlaceInfo]) extends TreeModel { override def getIndexOfChild(parent: scala.Any, child: scala.Any): Int = elements.indexOf(child) From cb982abc94dcbd9897a1aeadd58f0f49eec500bb Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Thu, 19 Oct 2017 19:52:21 +0300 Subject: [PATCH 003/141] TypeResult correct type parameter #SCL-12743 --- .../scala/annotator/FunctionAnnotator.scala | 6 +- .../scala/annotator/ScalaAnnotator.scala | 4 +- .../sbt/SbtDependenciesVisitor.scala | 12 ++- .../ScalaRedundantConversionInspection.scala | 13 ++-- .../codeInspection/collections/package.scala | 21 ++---- .../ScalaEvaluatorBuilderUtil.scala | 22 +++--- .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 3 +- .../api/statements/ScFunctionDefinition.scala | 6 +- .../templates/ScTemplateParents.scala | 74 +++++++------------ .../base/types/ScSelfTypeElementImpl.scala | 3 +- .../impl/expr/ScReferenceExpressionImpl.scala | 26 +++---- .../toplevel/typedef/MonocleInjector.scala | 70 +++++++++++------- .../scala/lang/psi/types/Compatibility.scala | 18 ++--- .../lang/psi/types/ScParameterizedType.scala | 8 +- .../lang/psi/types/ScalaConformance.scala | 25 +++++-- .../lang/psi/types/ScalaPsiTypeBridge.scala | 3 +- .../psi/types/ScalaTypePresentation.scala | 27 ++++--- .../lang/psi/types/result/TypeResult.scala | 26 +++---- .../expression/ScalaTypeSurrounder.scala | 5 +- .../scala/lang/transformation/package.scala | 6 +- .../src/scala/meta/trees/TreeAdapter.scala | 2 +- .../meta/trees/TreeConverterBuilder.scala | 5 +- 22 files changed, 200 insertions(+), 185 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala index 4af5418a131..60a615693b5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala @@ -26,8 +26,10 @@ trait FunctionAnnotator { } } - val tailrecAnnotation = function.annotations.find(_.typeElement.`type`() - .map(_.canonicalText).withFilter(_ == "_root_.scala.annotation.tailrec").isDefined) + val tailrecAnnotation = function.annotations.find { + _.typeElement.`type`().toOption + .map(_.canonicalText).contains("_root_.scala.annotation.tailrec") + } tailrecAnnotation.foreach { it => if (!function.canBeTailRecursive) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index c98afee8b47..a6952851a53 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -572,8 +572,8 @@ abstract class ScalaAnnotator extends Annotator private def checkTypeParamBounds(sTypeParam: ScTypeBoundsOwner, holder: AnnotationHolder) { for { - lower <- sTypeParam.lowerBound - upper <- sTypeParam.upperBound + lower <- sTypeParam.lowerBound.toOption + upper <- sTypeParam.upperBound.toOption if !lower.conforms(upper) annotation = holder.createErrorAnnotation(sTypeParam, ScalaBundle.message("lower.bound.conform.to.upper", upper, lower)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/SbtDependenciesVisitor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/SbtDependenciesVisitor.scala index 41b9ab7f6a1..5357d15cfc3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/SbtDependenciesVisitor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/SbtDependenciesVisitor.scala @@ -60,16 +60,14 @@ object SbtDependenciesVisitor { } def processPatternDefinition(patternDefinition: ScPatternDefinition)(f: PsiElement => Unit): Unit = { - f(patternDefinition) - val processed = patternDefinition.`type`() - .withFilter(_.canonicalText == SBT_PROJECT_TYPE) - .map { _ => - getSettings(patternDefinition).foreach(processMethodCall(_)(f)) - } + val maybeTypeName = patternDefinition.`type`().toOption + .map(_.canonicalText) - processed.getOrElse { + if (maybeTypeName.contains(SBT_PROJECT_TYPE)) { + getSettings(patternDefinition).foreach(processMethodCall(_)(f)) + } else { patternDefinition.expr match { case Some(call: ScMethodCall) => processMethodCall(call)(f) case Some(infix: ScInfixExpr) => processInfix(infix)(f) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantConversionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantConversionInspection.scala index 6b7ab13aa7b..a2c2de7e035 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantConversionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantConversionInspection.scala @@ -29,14 +29,17 @@ class ScalaRedundantConversionInspection extends AbstractInspection("Redundant c target match { case f: ScSyntheticFunction if f.name.startsWith("to") => - for (leftType <- left.`type`(); - conversionType = f.retType if leftType.equiv(conversionType)) - registerProblem(element, left, conversionType.presentableText, offset, holder) + for { + leftType <- left.`type`().toOption + conversionType = f.retType if leftType.equiv(conversionType) + } registerProblem(element, left, conversionType.presentableText, offset, holder) case f: PsiMethod if f.getName == "toString" && f.getParameterList.getParametersCount == 0 && (f.getTypeParameterList == null || f.getTypeParameterList.getTypeParameters.isEmpty) => - for (leftType <- left.`type`() if leftType.canonicalText == "_root_.java.lang.String") - registerProblem(element, left, "java.lang.String", offset, holder) + for { + leftType <- left.`type`().toOption + if leftType.canonicalText == "_root_.java.lang.String" + } registerProblem(element, left, "java.lang.String", offset, holder) case _ => } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala index db923e3dc92..8a5749537ba 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala @@ -367,19 +367,14 @@ package object collections { } } - def isOfClassFrom(expr: ScExpression, patterns: Array[String]): Boolean = Option(expr).flatMap { - _.`type`().toOption - }.flatMap { - _.tryExtractDesignatorSingleton.extractClass - }.exists { - qualifiedNameFitToPatterns(_, patterns) - } - - private def qualifiedNameFitToPatterns(clazz: PsiClass, patterns: Array[String]) = Option(clazz).flatMap { - _.qualifiedName.toOption - }.exists { - ScalaNamesUtil.nameFitToPatterns(_, patterns, strict = false) - } + def isOfClassFrom(expr: ScExpression, patterns: Array[String]): Boolean = + Option(expr).flatMap(_.`type`().toOption) + .flatMap(_.tryExtractDesignatorSingleton.extractClass) + .exists(qualifiedNameFitToPatterns(_, patterns)) + + private def qualifiedNameFitToPatterns(clazz: PsiClass, patterns: Array[String]) = + Option(clazz).flatMap(c => Option(c.qualifiedName)) + .exists(ScalaNamesUtil.nameFitToPatterns(_, patterns, strict = false)) def isOption(expr: ScExpression): Boolean = isOfClassFrom(expr, likeOptionClasses) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala index 480483d0627..682e4ac9464 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala @@ -389,20 +389,18 @@ private[evaluation] trait ScalaEvaluatorBuilderUtil { } def classOfFunctionEvaluator(ref: ScReferenceExpression): Evaluator = { - val clazzJVMName = ref.getContext match { + val maybeClazzJVMName = ref.getContext match { case gen: ScGenericCall => - gen.arguments.head.`type`().map { - val project = ref.getProject - _.extractClass match { - case Some(clazz) => - DebuggerUtil.getClassJVMName(clazz) - case None => null - } - }.getOrElse(null) - case _ => null + gen.arguments.head.`type`().toOption + .flatMap(_.extractClass) + .map(DebuggerUtil.getClassJVMName(_)) + case _ => None + } + + maybeClazzJVMName match { + case Some(clazzName) => new ClassObjectEvaluator(new TypeEvaluator(clazzName)) + case _ => new ScalaLiteralEvaluator(null, Null) } - if (clazzJVMName != null) new ClassObjectEvaluator(new TypeEvaluator(clazzJVMName)) - else new ScalaLiteralEvaluator(null, Null) } def valueClassInstanceEvaluator(value: Evaluator, innerType: ScType, classType: ScType): Evaluator = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index 8d6343a1687..0de80c441f3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -363,9 +363,8 @@ object ScalaPsiUtil { case expression => (expression, tp, Seq.empty) } val invoked = call.getInvokedExpr - val typeParams = invoked.getNonValueType().map { + val typeParams = invoked.getNonValueType().toOption.collect { case ScTypePolymorphicType(_, tps) => tps - case _ => Seq.empty }.getOrElse(Seq.empty) val emptyStringExpression = createExpressionFromText("\"\"") val processor = new MethodResolveProcessor(expr, methodName, if (!isDynamic) args :: Nil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala index deb672b3442..33db21725c2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala @@ -46,8 +46,10 @@ trait ScFunctionDefinition extends ScFunction with ScControlFlowOwner { } def hasTailRecursionAnnotation: Boolean = - annotations.exists(_.typeElement.`type`() - .map(_.canonicalText).exists(_ == "_root_.scala.annotation.tailrec")) + annotations.map(_.typeElement) + .flatMap(_.`type`().toOption) + .map(_.canonicalText) + .contains("_root_.scala.annotation.tailrec") def recursiveReferences: Seq[RecursiveReference] = { val resultExpressions = returnUsages(withBooleanInfix = true) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/templates/ScTemplateParents.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/templates/ScTemplateParents.scala index 444f8c6411f..527a556a01d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/templates/ScTemplateParents.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/templates/ScTemplateParents.scala @@ -11,7 +11,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScParameterizedTypeE import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.SyntheticMembersInjector -import org.jetbrains.plugins.scala.lang.psi.types.result.Success import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} @@ -40,52 +39,35 @@ trait ScTemplateParents extends ScalaPsiElement { } object ScTemplateParents { - def extractSupers(typeElements: Seq[ScTypeElement])(implicit project: ProjectContext): Seq[PsiClass] = { - typeElements.map { - case element: ScTypeElement => - def tail(): PsiClass = { - element.`type`().map { - case tp: ScType => tp.extractClass match { - case Some(clazz) => clazz - case _ => null - } - }.getOrElse(null) - } - def refTail(ref: ScStableCodeReferenceElement): PsiClass = { - val resolve = ref.resolveNoConstructor - if (resolve.length == 1) { - resolve(0) match { - case ScalaResolveResult(c: PsiClass, _) => c - case ScalaResolveResult(ta: ScTypeAliasDefinition, _) => - ta.aliasedType match { - case Success(te, _) => te.extractClass match { - case Some(c) => c - case _ => null - } - case _ => null - } - case _ => tail() - } - } else tail() - } - element match { - case s: ScSimpleTypeElement => - s.reference match { - case Some(ref) => refTail(ref) - case _ => tail() - } - case p: ScParameterizedTypeElement => - p.typeElement match { - case s: ScSimpleTypeElement => - s.reference match { - case Some(ref) => refTail(ref) - case _ => tail() - } - case _ => tail() - } + def extractSupers(typeElements: Seq[ScTypeElement]) + (implicit project: ProjectContext): Seq[PsiClass] = + typeElements.flatMap { element => + def tail(): Option[PsiClass] = + element.`type`().toOption + .flatMap(_.extractClass) + + def refTail(reference: ScStableCodeReferenceElement): Option[PsiClass] = + reference.resolveNoConstructor match { + case Array(head) => head match { + case ScalaResolveResult(c: PsiClass, _) => Some(c) + case ScalaResolveResult(ta: ScTypeAliasDefinition, _) => + ta.aliasedType.toOption + .flatMap(_.extractClass) + case _ => tail() + } case _ => tail() } - }.filter(_ != null) - } + + val maybeReference = element match { + case ScSimpleTypeElement(result) => result + case ScParameterizedTypeElement(ScSimpleTypeElement(result), _) => result + case _ => None + } + + maybeReference match { + case Some(reference) => refTail(reference) + case _ => tail() + } + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala index 9e9d9a51062..1b68839d882 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala @@ -40,8 +40,7 @@ class ScSelfTypeElementImpl private(stub: ScSelfTypeElementStub, node: ASTNode) for { templateType <- parent.`type`() selfType <- ste.`type`() - ct = ScCompoundType(Seq(templateType, selfType), Map.empty, Map.empty) - } yield ct + } yield ScCompoundType(Seq(templateType, selfType)) case None => parent.`type`() } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala index 285549d16b6..4293c0738e5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala @@ -337,6 +337,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case _: ScFunctionExpr => null case f => f } + def isMethodDependent(function: ScFunction): Boolean = { def checkte(te: ScTypeElement): Boolean = { var res = false @@ -348,6 +349,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no }) res } + function.returnTypeElement match { case Some(te) if checkte(te) => return true case _ => @@ -558,22 +560,18 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } def getPrevTypeInfoParams: Seq[TypeParameter] = { - qualifier match { - case Some(_: ScSuperReference) => Seq.empty - case Some(qual) => - qual.getNonValueType().map { - case t: ScTypePolymorphicType => t.typeParameters - case _ => Seq.empty - }.getOrElse(Seq.empty) - case _ => getContext match { - case sugar: ScSugarCallExpr if sugar.operation == this => - sugar.getBaseExpr.getNonValueType().map { - case t: ScTypePolymorphicType => t.typeParameters - case _ => Seq.empty - }.getOrElse(Seq.empty) - case _ => Seq.empty + val maybeExpression = qualifier match { + case Some(_: ScSuperReference) => None + case None => getContext match { + case ScSugarCallExpr(baseExpression, operation, _) if operation == this => Some(baseExpression) + case _ => None } + case result => result } + + maybeExpression.flatMap(_.getNonValueType().toOption).collect { + case ScTypePolymorphicType(_, parameters) => parameters + }.getOrElse(Seq.empty) } private def resolveFailure = Failure("Cannot resolve expression") diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MonocleInjector.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MonocleInjector.scala index 27fe04a7539..4a1c20c0957 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MonocleInjector.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MonocleInjector.scala @@ -1,41 +1,59 @@ -package org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef +package org.jetbrains.plugins.scala.lang.psi.impl +package toplevel +package typedef +import com.intellij.psi.PsiAnnotation import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.base.ScLiteralImpl import org.jetbrains.plugins.scala.lang.psi.impl.statements.params.ScClassParameterImpl -import scala.collection.mutable.ArrayBuffer - class MonocleInjector extends SyntheticMembersInjector { + + import MonocleInjector.mkLens + override def injectFunctions(source: ScTypeDefinition): Seq[String] = { - source match { - // Monocle lenses generation - case obj: ScObject => - obj.fakeCompanionClassOrCompanionClass match { - case clazz: ScClass if clazz.findAnnotationNoAliases("monocle.macros.Lenses") != null => mkLens(obj) - case _ => Seq.empty - } + val companionClass = source match { + case obj: ScObject => obj.fakeCompanionClassOrCompanionClass + case _ => null + } + + companionClass match { + case clazz: ScClass => mkLens(clazz, clazz.findAnnotationNoAliases("monocle.macros.Lenses")) case _ => Seq.empty } } +} + +object MonocleInjector { + + // Monocle lenses generation + private def mkLens(clazz: ScClass, annotation: PsiAnnotation): Seq[String] = annotation match { + case null => Seq.empty + case _ => + val prefix = annotation.findAttributeValue("value") match { + case ScLiteralImpl.string(value) => value + case _ => "" + } + + mkLens(clazz, prefix) + } - private def mkLens(obj: ScObject): ArrayBuffer[String] = { - val buffer = new ArrayBuffer[String] - val clazz = obj.fakeCompanionClassOrCompanionClass.asInstanceOf[ScClass] - val fields = clazz.allVals.collect({ case (f: ScClassParameterImpl, _) => f }).filter(_.isCaseClassVal) - val prefix = Option(clazz.findAnnotationNoAliases("monocle.macros.Lenses").findAttributeValue("value")) match { - case Some(literal: ScLiteralImpl) => literal.getValue.toString - case _ => "" + private[this] def mkLens(clazz: ScClass, prefix: String): Seq[String] = { + val typeParametersText = clazz.typeParameters.map(_.getText) match { + case Seq() => "" + case seq => seq.mkString("[", ",", "]") } - fields.foreach({ i => - val template = if (clazz.typeParameters.isEmpty) - s"def $prefix${i.name}: _root_.monocle.Lens[${clazz.qualifiedName}, ${i.`type`().map(_.canonicalText).getOrElse("Any")}] = ???" - else { - val tparams = s"[${clazz.typeParameters.map(_.getText).mkString(",")}]" - s"def $prefix${i.name}$tparams: _root_.monocle.Lens[${clazz.qualifiedName}$tparams, ${i.typeElement.get.calcType}] = ???" + + clazz.allVals.collect { + case (f: ScClassParameterImpl, _) if f.isCaseClassVal => f + }.map { parameter => + val typeText = if (typeParametersText.isEmpty) { + parameter.`type`().toOption.map(_.canonicalText).getOrElse("Any") + } else { + parameter.typeElement.get.calcType.toString } - buffer += template - }) - buffer + + s"def $prefix${parameter.name}$typeParametersText: _root_.monocle.Lens[${clazz.qualifiedName}$typeParametersText, $typeText] = ???" + } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala index 139ce5860e7..173e677b5cb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala @@ -255,14 +255,13 @@ object Compatibility { val tp = ScParameterizedType(seqType, Seq(param.paramType)) val expectedType = ScParameterizedType(seqType, Seq(param.expectedType)) - for (exprType <- expr.getTypeAfterImplicitConversion(checkWithImplicits, isShapesResolve, Some(expectedType)).tr) yield { - val conforms = exprType.weakConforms(tp) - if (!conforms) { - return ConformanceExtResult(Seq(TypeMismatch(expr, tp)), undefSubst, defaultParameterUsed, matched, matchedTypes) - } else { + for (exprType <- expr.getTypeAfterImplicitConversion(checkWithImplicits, isShapesResolve, Some(expectedType)).tr.toOption) { + if (exprType.weakConforms(tp)) { matched ::= (param, expr) matchedTypes ::= (param, exprType) undefSubst += exprType.conforms(tp, ScUndefinedSubstitutor(), checkWeak = true)._2 + } else { + return ConformanceExtResult(Seq(TypeMismatch(expr, tp)), undefSubst, defaultParameterUsed, matched, matchedTypes) } } case _ => @@ -308,14 +307,13 @@ object Compatibility { (param.paramType, param.expectedType) } - for (exprType <- expr.getTypeAfterImplicitConversion(checkWithImplicits, isShapesResolve, Some(expectedType)).tr) yield { - val conforms = exprType.weakConforms(paramType) - if (!conforms) { - problems ::= TypeMismatch(expr, paramType) - } else { + for (exprType <- expr.getTypeAfterImplicitConversion(checkWithImplicits, isShapesResolve, Some(expectedType)).tr.toOption) { + if (exprType.weakConforms(paramType)) { matched ::= (param, expr) matchedTypes ::= (param, exprType) undefSubst += exprType.conforms(paramType, ScUndefinedSubstitutor(), checkWeak = true)._2 + } else { + problems ::= TypeMismatch(expr, paramType) } } case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala index 4e8e7fd220b..3bc69884895 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala @@ -30,8 +30,8 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq override protected def isAliasTypeInner: Option[AliasType] = { designator match { case ScDesignatorType(ta: ScTypeAlias) => - val existingWildcards = ta.lowerBound.map(ScExistentialType.existingWildcards).getOrElse(Set.empty) ++ - (if (ta.isDefinition) Set.empty else ta.upperBound.map(ScExistentialType.existingWildcards).getOrElse(Set.empty)) + val existingWildcards = ta.lowerBound.toOption.map(ScExistentialType.existingWildcards).getOrElse(Set.empty) ++ + (if (ta.isDefinition) Set.empty else ta.upperBound.toOption.map(ScExistentialType.existingWildcards).getOrElse(Set.empty)) val genericSubst = ScalaPsiUtil. typesCallSubstitutor(ta.typeParameters.map(_.nameAndId), @@ -45,8 +45,8 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq val ta: ScTypeAlias = p.actualElement.asInstanceOf[ScTypeAlias] val subst: ScSubstitutor = p.actualSubst - val existingWildcards = ta.lowerBound.map(subst.subst).map(ScExistentialType.existingWildcards).getOrElse(Set.empty) ++ - (if (ta.isDefinition) Set.empty else ta.upperBound.map(subst.subst).map(ScExistentialType.existingWildcards).getOrElse(Set.empty)) + val existingWildcards = ta.lowerBound.toOption.map(subst.subst).map(ScExistentialType.existingWildcards).getOrElse(Set.empty) ++ + (if (ta.isDefinition) Set.empty else ta.upperBound.toOption.map(subst.subst).map(ScExistentialType.existingWildcards).getOrElse(Set.empty)) val genericSubst = ScalaPsiUtil. typesCallSubstitutor(ta.typeParameters.map(_.nameAndId), diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala index d87482b4c26..4fbb1d4f11e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala @@ -421,7 +421,7 @@ trait ScalaConformance extends api.Conformance { val projected1 = proj1.projected val projected2 = proj2.projected result = conformsInner(projected1, projected2, visited, undefinedSubst) - case param@ParameterizedType(projDes: ScProjectionType, _) => + case ParameterizedType(projDes: ScProjectionType, typeArguments) => //TODO this looks overcomplicated. Improve the code. def cutProj(p: ScType, acc: List[ScProjectionType]): ScType = { if (acc.isEmpty) p else acc.foldLeft(p){ @@ -433,12 +433,25 @@ trait ScalaConformance extends api.Conformance { val t = proj.projected.equiv(projDes.projected, undefinedSubst) if (t._1) { undefinedSubst = t._2 - (projDes.actualElement, proj.actualElement) match { + val (maybeLeft, maybeRight) = (projDes.actualElement, proj.actualElement) match { case (desT: Typeable, projT: Typeable) => - desT.`type`().withFilter(_.isInstanceOf[ScParameterizedType]). - map(_.asInstanceOf[ScParameterizedType]).flatMap(dt => projT.`type`(). - map(c => conformsInner(ScParameterizedType(dt.designator, param.typeArguments), - cutProj(c, acc), visited, undefinedSubst))).map(t => if (t._1) result = t) + val left = desT.`type`().toOption + .collect { + case ParameterizedType(designator, _) => designator + }.map(ScParameterizedType(_, typeArguments)) + + + val right = projT.`type`().toOption + .map(cutProj(_, acc)) + + (left, right) + case _ => (None, None) + } + + maybeLeft.zip(maybeRight).map { + case (left, right) => conformsInner(left, right, visited, undefinedSubst) + }.foreach { + case r@(true, _) => result = r case _ => } } else { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala index 910dcd78656..b0ad5e47b85 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala @@ -183,7 +183,8 @@ trait ScalaPsiTypeBridge extends api.PsiTypeBridge { case _ => createType(clazz, raw = outerClassHasTypeParameters(proj)) } case elem: ScTypeAliasDefinition if !visitedAliases.contains(elem) => - elem.aliasedType.map(toPsiTypeInner(_, noPrimitives, visitedAliases + elem)) + elem.aliasedType.toOption + .map(toPsiTypeInner(_, noPrimitives, visitedAliases + elem)) .getOrElse(javaObject) case _ => javaObject } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaTypePresentation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaTypePresentation.scala index 783b2e187f4..1ffa45a3597 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaTypePresentation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaTypePresentation.scala @@ -147,19 +147,26 @@ trait ScalaTypePresentation extends api.TypePresentation { ta.typeParameters.map(typeParamText(_, ScSubstitutor.empty)).mkString("[", ", ", "]") else "" val decl = s"type ${ta.name}$paramsText" - val defnText = ta match { + val defnText: Iterable[String] = ta match { case tad: ScTypeAliasDefinition => - tad.aliasedType.map { - case tpe if tpe.isNothing => "" - case tpe => s" = ${typeText0(tpe)}" - }.getOrElse("") + tad.aliasedType.toOption + .filterNot(_.isNothing) + .map(typeText0) + .map(" = " + _) case _ => - val (lowerBound, upperBound) = (ta.lowerBound.getOrNothing, ta.upperBound.getOrAny) - val lowerText = if (lowerBound == Nothing) "" else s" >: ${typeText0(lowerBound)}" - val upperText = if (upperBound == Any) "" else s" <: ${typeText0(upperBound)}" - lowerText + upperText + val maybeLowerText = ta.lowerBound.toOption + .filterNot(_.isNothing) + .map(typeText0) + .map(" >: " + _) + + val maybeUpperText = ta.upperBound.toOption + .filterNot(_.isAny) + .map(typeText0) + .map(" <: " + _) + + maybeLowerText ++ maybeUpperText } - Seq(decl + defnText) + Seq(decl + defnText.mkString) case _ => Seq.empty } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala index 71a99999599..ce35a17f82f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala @@ -10,11 +10,11 @@ import org.jetbrains.plugins.scala.project.ProjectContext /** * @author ilyas */ -sealed abstract class TypeResult[+T](implicit val projectContext: ProjectContext) { +sealed abstract class TypeResult[+T <: ScType](implicit val projectContext: ProjectContext) { - def map[U](f: T => U): TypeResult[U] + def map[U <: ScType](f: T => U): TypeResult[U] - def flatMap[U](f: T => TypeResult[U]): TypeResult[U] + def flatMap[U <: ScType](f: T => TypeResult[U]): TypeResult[U] def withFilter(f: T => Boolean): TypeResult[T] @@ -41,12 +41,12 @@ object TypeResult { } } -class Success[T] private(private val result: T) - (implicit context: ProjectContext) extends TypeResult[T] { +class Success[T <: ScType] private(private val result: T) + (implicit context: ProjectContext) extends TypeResult[T] { - def map[U](f: T => U): Success[U] = Success(f(result)) + def map[U <: ScType](f: T => U): Success[U] = Success(f(result)) - def flatMap[U](f: T => TypeResult[U]): TypeResult[U] = f(result) + def flatMap[U <: ScType](f: T => TypeResult[U]): TypeResult[U] = f(result) def withFilter(f: T => Boolean): TypeResult[T] = if (f(result)) this else Failure("Wrong type") @@ -68,10 +68,10 @@ class Success[T] private(private val result: T) object Success { - def apply[T](result: T) - (implicit context: ProjectContext): Success[T] = new Success(result) + def apply[T <: ScType](result: T) + (implicit context: ProjectContext): Success[T] = new Success(result) - def unapply[T](success: Success[T]): Option[(T, Option[PsiElement])] = + def unapply[T <: ScType](success: Success[T]): Option[(T, Option[PsiElement])] = Option(success) .map(_.result) .map((_, None)) @@ -80,11 +80,11 @@ object Success { case class Failure(private val cause: String) (implicit context: ProjectContext) extends TypeResult[Nothing] { - def map[U](f: Nothing => U): Failure = this + def map[U <: ScType](f: Nothing => U): this.type = this - def flatMap[U](f: Nothing => TypeResult[U]): Failure = this + def flatMap[U <: ScType](f: Nothing => TypeResult[U]): this.type = this - def withFilter(f: Nothing => Boolean): Failure = this + def withFilter(f: Nothing => Boolean): this.type = this def foreach[B](f: Nothing => B): Unit = {} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala index a2f3dd45230..414cc088803 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala @@ -13,9 +13,8 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ class ScalaTypeSurrounder extends ScalaExpressionSurrounder { override def getTemplateAsString(elements: Array[PsiElement]): String = { val expression = elements(0).asInstanceOf[ScExpression] - val typeResult = expression.`type`() - val typeText = typeResult.map(_.presentableText).getOrElse("Any") - "(" + super.getTemplateAsString(elements) + ": " + typeText + ")" + val result = expression.`type`().getOrAny + s"(${super.getTemplateAsString(elements)}: ${result.presentableText})" } override def getTemplateDescription: String = "(expr: Type)" diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/package.scala index a5d667e6201..6166cea4aa9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/package.scala @@ -77,7 +77,11 @@ package object transformation { // TODO define PsiMember.qualifiedName def qualifiedNameOf(e: PsiNamedElement): String = e match { // TODO support complex types, how to handle aliases? - case it: ScTypeAliasDefinition => it.aliasedType.map(t => relative(t.canonicalText)).getOrElse(it.name) + case it: ScTypeAliasDefinition => + it.aliasedType.toOption + .map(_.canonicalText) + .map(relative) + .getOrElse(it.name) case it: PsiClass => it.qualifiedName case it: PsiMember => Option(it.containingClass).map(_.qualifiedName + ".").getOrElse("") + it.name case it => it.name diff --git a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala index ec8c1d82202..723e8a8f84b 100644 --- a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala @@ -56,7 +56,7 @@ trait TreeAdapter { convertMods(t), toTermName(t), Seq(t.typeParameters map toTypeParams: _*), Seq(t.paramClauses.clauses.map(convertParamClause): _*), - t.definedReturnType.map(toType(_)).toOption, + t.definedReturnType.toOption.map(toType(_)), expression(t.body).get ) } diff --git a/scala/scala-impl/src/scala/meta/trees/TreeConverterBuilder.scala b/scala/scala-impl/src/scala/meta/trees/TreeConverterBuilder.scala index c853ef76d68..00d769439b9 100644 --- a/scala/scala-impl/src/scala/meta/trees/TreeConverterBuilder.scala +++ b/scala/scala-impl/src/scala/meta/trees/TreeConverterBuilder.scala @@ -16,8 +16,7 @@ import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.{ScDocComment, ScDocInl import scala.collection.immutable.Seq import scala.language.postfixOps -import scala.{meta=>m} -import scala.{Seq => _} +import scala.{meta => m, Seq => _} trait TreeConverterBuilder { self: TreeConverter => @@ -49,7 +48,7 @@ trait TreeConverterBuilder { ret = m.Defn.Def(convertMods(fun), toTermName(fun), Seq(fun.typeParameters map toTypeParams:_*), Seq(fun.paramClauses.clauses.map(convertParamClause):_*), - fun.definedReturnType.map(toType(_)).toOption, + fun.definedReturnType.toOption.map(toType(_)), body ) } From 0a45eefddaded7ebbcbf1741a241a585953588ba Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 20 Oct 2017 17:33:28 +0200 Subject: [PATCH 004/141] can't attach an error reporting callback without breaking things, yay --- .../sbt/project/structure/SbtRunner.scala | 8 +++++--- .../sbt/shell/SbtProjectPlatformTestCase.scala | 14 +++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala index afafad75669..8af039d2f95 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala @@ -206,10 +206,12 @@ object SbtRunner { def getSbtLauncherDir: File = { val file: File = jarWith[this.type] val deep = if (file.getName == "classes") 1 else 2 - val playEnabled = Try(getClass.getClassLoader.loadClass("com.intellij.scala.play.Play2Bundle") != null).getOrElse(false) val res = (file << deep) / "launcher" - if (!res.exists() && isInTest) - jarWith[this.type].parent.flatMap(findLauncherDir).get + if (!res.exists() && isInTest) { + val start = jarWith[this.type].parent + start.flatMap(findLauncherDir) + .getOrElse(throw new RuntimeException(s"could not find sbt launcher dir at or above ${start.get}")) + } else res } diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala index b8cb4c79187..76a00fafd0d 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala @@ -6,9 +6,6 @@ import com.intellij.execution.process.{ProcessEvent, ProcessListener} import com.intellij.ide.impl.ProjectUtil import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder -import com.intellij.openapi.externalSystem.model.DataNode -import com.intellij.openapi.externalSystem.model.project.ProjectData -import com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback import com.intellij.openapi.externalSystem.util.ExternalSystemUtil import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.projectRoots.ProjectJdkTable @@ -19,7 +16,6 @@ import com.intellij.util.ui.UIUtil import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.util.TestUtils import org.jetbrains.sbt.project.SbtProjectSystem -import org.junit.Assert /** * Created by Roman.Shein on 27.03.2017. @@ -36,12 +32,8 @@ abstract class SbtProjectPlatformTestCase extends PlatformTestCase { ProjectJdkTable.getInstance.addJdk(sdk) ProjectRootManager.getInstance(project).setProjectSdk(sdk) } - val callback = new ExternalProjectRefreshCallback { - override def onFailure(errorMessage: String, errorDetails: String): Unit = - Assert.fail(s"sbt project refresh failed: $errorMessage. Details: $errorDetails") - override def onSuccess(externalProject: DataNode[ProjectData]): Unit = () - } - val importSpec = new ImportSpecBuilder(project, SbtProjectSystem.Id).callback(callback).build() + // I would attach a callback here to debug errors, but that overrides the default callback which deos the project updating ... + val importSpec = new ImportSpecBuilder(project, SbtProjectSystem.Id).build() ExternalSystemUtil.refreshProjects(importSpec) myProject = project } @@ -117,4 +109,4 @@ class ProcessLogger extends ProcessListener { synchronized { logBuilder.append(event.getText) } print(event.getText) } -} \ No newline at end of file +} From 68a446defc887dd02d3d2ecfd22c6180f3a32e86 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 20 Oct 2017 17:34:01 +0200 Subject: [PATCH 005/141] ensure correct sbt binaryVersion scheme --- scala/scala-impl/src/org/jetbrains/sbt/SbtUtil.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/SbtUtil.scala b/scala/scala-impl/src/org/jetbrains/sbt/SbtUtil.scala index 426647bba26..e945967c966 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/SbtUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/SbtUtil.scala @@ -48,6 +48,8 @@ object SbtUtil { // 1.0.0 milestones are regarded as not bincompat by sbt if ((sbtVersion ~= Version("1.0.0")) && sbtVersion.presentation.contains("-M")) sbtVersion + // sbt uses binary version x.0 for [x.0,x+1.0[ + else if (sbtVersion.major(1) >= Version("1.0")) Version("1.0") else sbtVersion.major(2) def detectSbtVersion(directory: File, sbtLauncher: => File): String = From 8cc89e08a380c833372ceb9c7265b40880712c8e Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 20 Oct 2017 17:35:48 +0200 Subject: [PATCH 006/141] run tests from root directory since /tests was refactored away --- .idea/runConfigurations/All_Tests.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/runConfigurations/All_Tests.xml b/.idea/runConfigurations/All_Tests.xml index 8b34331c0c4..17a9d3906c0 100644 --- a/.idea/runConfigurations/All_Tests.xml +++ b/.idea/runConfigurations/All_Tests.xml @@ -17,7 +17,7 @@ - + From 88f60a59048ace2c10e2cdb3852cd811a30c625d Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Fri, 20 Oct 2017 18:45:03 +0300 Subject: [PATCH 007/141] fix sizes of add sbt dependency wizard steps fix #SCL-12646 --- .../intention/sbt/ui/SbtArtifactChooseDependencyStep.scala | 2 -- .../annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala | 2 +- .../annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala index 845eb1d7ea7..72e94cd1ff1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala @@ -1,6 +1,5 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt.ui -import java.awt.Dimension import javax.swing.{Icon, JComponent} import com.intellij.ide.wizard.Step @@ -14,7 +13,6 @@ class SbtArtifactChooseDependencyStep(wizard: SbtArtifactSearchWizard, artifactI override def _init(): Unit = { wizard.setTitle("Sbt Artifact Search") - setPreferredSize(new Dimension(1600, 1200)) updateUI() } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index 49b996113f4..f9050f14f52 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -128,7 +128,7 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, viewer.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, dep.getTextRange.getEndOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE) - viewer.getComponent.setPreferredSize(new Dimension(1600, 500)) + viewer.getComponent.updateUI() viewer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala index f213d98e27a..88804b08324 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala @@ -1,10 +1,10 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt.ui -import java.awt.Dimension import javax.swing.{Icon, JComponent} import com.intellij.ide.wizard.Step import com.intellij.openapi.project.Project +import com.intellij.util.ui.JBUI import org.jetbrains.plugins.scala.annotator.intention.sbt.DependencyPlaceInfo /** @@ -15,7 +15,7 @@ class SbtPossiblePlacesStep(wizard: SbtArtifactSearchWizard, project: Project, f override def _init(): Unit = { wizard.setTitle("Place to add dependency") - setPreferredSize(new Dimension(1600, 1200)) + wizard.setSize(JBUI.scale(600), JBUI.scale(750)) updateUI() } From f4227350c16c4b88175e71316d3843479c8fd927 Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Thu, 19 Oct 2017 17:05:12 +0300 Subject: [PATCH 008/141] Ammonite: better run configuration parameters validating #SCL-12775 fixed --- .../ammonite/runconfiguration/AmmoniteRunConfiguration.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala index bd5bcdd824a..6c7cb415166 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala @@ -35,7 +35,7 @@ class AmmoniteRunConfiguration(project: Project, factory: ConfigurationFactory) private var scriptParameters: Option[String] = None def setFilePath(path: String) { - if (path != "") fileName = Option(path) + fileName = Option(path).filter(_ != "") } def setExecPath(path: String) { @@ -43,7 +43,7 @@ class AmmoniteRunConfiguration(project: Project, factory: ConfigurationFactory) } def setScriptParameters(params: String) { - if (params != "") scriptParameters = Option(params) + scriptParameters = Option(params).filter(_ != "") } def getIOFile: Option[File] = fileName.map(new File(_)).filter(_.exists()) From 984b9f7c23c3277ddefac5cfe14b39c5310371e7 Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Thu, 19 Oct 2017 17:15:39 +0300 Subject: [PATCH 009/141] Ammonite: run configuration renamed #SCL-12768 fixed --- .../runconfiguration/AmmoniteRunConfigurationType.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfigurationType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfigurationType.scala index cbb9e28a2c5..c62c966d6dc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfigurationType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfigurationType.scala @@ -19,7 +19,7 @@ class AmmoniteRunConfigurationType extends ConfigurationType with DumbAware { override def getIcon: Icon = Icons.SCALA_CONSOLE - override def getDisplayName: String = "Run Ammonite" + override def getDisplayName: String = "Ammonite" override def getConfigurationTypeDescription: String = "Run Ammonite script" } From 1da8e4eecb65479b9f776f29ee20cdfd5c47355f Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Thu, 19 Oct 2017 17:54:55 +0300 Subject: [PATCH 010/141] Ammonite: file type options in project settings renamed #SCL-12767 fixed --- .../scala/settings/ScalaProjectSettingsPanel.java | 12 ++++++++++++ .../scala/worksheet/ammonite/AmmoniteUtil.scala | 1 + 2 files changed, 13 insertions(+) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/ScalaProjectSettingsPanel.java b/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/ScalaProjectSettingsPanel.java index 42441bd7b62..6ea33a8e0db 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/ScalaProjectSettingsPanel.java +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/ScalaProjectSettingsPanel.java @@ -157,6 +157,18 @@ public void stateChanged(ChangeEvent changeEvent) { if (injectionPrefixTable == null) injectionPrefixTable = new ScalaUiWithDependency.NullComponentWithSettings(); scTypeSelectionCombobox.setModel(new EnumComboBoxModel(ScalaProjectSettings.ScFileMode.class)); + scTypeSelectionCombobox.setRenderer(new ListCellRendererWrapper() { + @Override + public void customize(JList jList, Object o, int i, boolean b, boolean b1) { + if (!(o instanceof ScalaProjectSettings.ScFileMode)) return; + + switch ((ScalaProjectSettings.ScFileMode) o) { + case Auto: setText("Ammonite in test sources, otherwise Worksheet"); break; + case Ammonite: setText("Always Ammonite"); break; + case Worksheet: setText("Always Worksheet"); + } + } + }); autoRunDelaySlider.setMaximum(WorksheetAutoRunner$.MODULE$.RUN_DELAY_MS_MAXIMUM()); autoRunDelaySlider.setMinimum(WorksheetAutoRunner$.MODULE$.RUN_DELAY_MS_MINIMUM()); diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala index 8964315ebfb..b02f5b57d22 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala @@ -50,6 +50,7 @@ object AmmoniteUtil { case ScalaProjectSettings.ScFileMode.Worksheet => false case ScalaProjectSettings.ScFileMode.Auto => ProjectRootManager.getInstance(project).getFileIndex.isUnderSourceRootOfType(virtualFile, ContainerUtilRt.newHashSet(JavaSourceRootType.TEST_SOURCE)) + case _ => false }) } From 5311df9ea5cb0867a9a91b1e482e734f9811e1d7 Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Thu, 19 Oct 2017 19:03:38 +0300 Subject: [PATCH 011/141] Ammonite: correct working dir for run configuration #SCL-12774 fixed --- .../runconfiguration/AmmoniteRunConfiguration.scala | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala index 6c7cb415166..89c0dba8a65 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/runconfiguration/AmmoniteRunConfiguration.scala @@ -58,10 +58,7 @@ class AmmoniteRunConfiguration(project: Project, factory: ConfigurationFactory) execName match { case Some(exec) => val exFile = new File(exec) - if (!exFile.exists()) cmd.setExePath(exec) else { - cmd.setWorkDirectory(exFile.getParentFile) - cmd.setExePath("./" + exFile.getName) - } + if (exFile.exists()) cmd.setExePath(exFile.getAbsolutePath) else cmd.setExePath(exec) case None => cmd.setExePath("amm") } @@ -71,7 +68,12 @@ class AmmoniteRunConfiguration(project: Project, factory: ConfigurationFactory) cmd.addParameter(s"${createPredefFile(getIOFile.map(_.getName).getOrElse("AmmoniteFile.sc"))}") } - fileName.foreach(cmd.addParameter) + fileName.foreach{ + f => + cmd.addParameter(f) + val tf = new File(f) + if (tf.exists()) cmd.setWorkDirectory(tf.getParentFile) + } scriptParameters.foreach(cmd.getParametersList.addParametersString(_)) JavaCommandLineStateUtil.startProcess(cmd) From 8eb400b7d4c8966cd475006a3482a507a22c7452 Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Thu, 19 Oct 2017 20:46:22 +0300 Subject: [PATCH 012/141] Ammonite: process default imports #SCL-12776 fixed --- .../lang/psi/api/FileDeclarationsHolder.scala | 2 ++ .../worksheet/ammonite/AmmoniteUtil.scala | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/FileDeclarationsHolder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/FileDeclarationsHolder.scala index a63e36aab83..4d92a362e88 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/FileDeclarationsHolder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/FileDeclarationsHolder.scala @@ -21,6 +21,7 @@ import org.jetbrains.plugins.scala.lang.psi.{ScDeclarationSequenceHolder, ScImpo import org.jetbrains.plugins.scala.lang.resolve.ResolveUtils import org.jetbrains.plugins.scala.lang.resolve.processor.precedence.{PrecedenceTypes, SubstitutablePrecedenceHelper} import org.jetbrains.plugins.scala.lang.resolve.processor.{BaseProcessor, ResolveProcessor, ResolverEnv} +import org.jetbrains.plugins.scala.worksheet.ammonite.AmmoniteUtil import worksheet.processor.WorksheetCompiler import worksheet.ui.WorksheetIncrementalEditorPrinter @@ -118,6 +119,7 @@ trait FileDeclarationsHolder extends PsiElement with ScDeclarationSequenceHolder if (!re) return false } + AmmoniteUtil.executeImplicitImportsDeclarations(processor, this, state) val checkPredefinedClassesAndPackages = processor match { case r: ResolveProcessor => r.checkPredefinedClassesAndPackages() diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala index b02f5b57d22..958dc5da816 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala @@ -8,15 +8,16 @@ import com.intellij.openapi.roots.libraries.{Library, LibraryTablesRegistrar} import com.intellij.openapi.roots.{OrderRootType, ProjectRootManager} import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile} import com.intellij.psi._ +import com.intellij.psi.scope.PsiScopeProcessor import com.intellij.psi.util.PsiUtilCore import com.intellij.util.containers.ContainerUtilRt import org.jetbrains.jps.model.java.JavaSourceRootType import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement -import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.{ScReferenceElement, ScStableCodeReferenceElement} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject -import org.jetbrains.plugins.scala.lang.psi.impl.ScalaFileImpl +import org.jetbrains.plugins.scala.lang.psi.api.{FileDeclarationsHolder, ScalaFile} +import org.jetbrains.plugins.scala.lang.psi.impl.{ScalaFileImpl, ScalaPsiElementFactory} import org.jetbrains.plugins.scala.project.ModuleExt import org.jetbrains.plugins.scala.settings.ScalaProjectSettings import org.jetbrains.plugins.scala.util.ScalaUtil @@ -36,6 +37,8 @@ object AmmoniteUtil { private val ROOT_EXEC = "$exec" private val ROOT_IVY = "$ivy" private val PARENT_FILE = "^" + + private val DEFAULT_IMPORTS = Seq("ammonite.main.Router._") //todo more default imports ? def isAmmoniteFile(file: ScalaFile): Boolean = { ScalaUtil.findVirtualFile(file) match { @@ -66,6 +69,20 @@ object AmmoniteUtil { case scalaFile: ScalaFile => AmmoniteScriptWrappersHolder.getInstance(file.getProject).findWrapper(scalaFile) case _ => None } + + def executeImplicitImportsDeclarations(processor: PsiScopeProcessor, file: FileDeclarationsHolder, state: ResolveState): Boolean = { + file match { + case ammoniteFile: ScalaFile if isAmmoniteFile(ammoniteFile) => + DEFAULT_IMPORTS.foreach { + imp => + val importStmt = ScalaPsiElementFactory.createImportFromText(s"import $imp")(ammoniteFile.projectContext) + importStmt.processDeclarations(processor, state, null, ammoniteFile) + } + case _ => + } + + true + } /* Resolves $file imports From 480291494d26fe52208870cbed70c8c52215c652 Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Fri, 20 Oct 2017 17:58:16 +0300 Subject: [PATCH 013/141] Ammonite: correct processing of dirs in $file imports #SCL-12772 fixed --- .../plugins/scala/worksheet/ammonite/AmmoniteUtil.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala index 958dc5da816..ac7d0d5e868 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala @@ -107,9 +107,12 @@ object AmmoniteUtil { case Some(d) => refElement.refName match { case PARENT_FILE => Option(d.getParent) - case other if d.isDirectory => - Option(d.asInstanceOf[PsiDirectory].findFile(s"$other.$AMMONITE_EXTENSION")) - case _ => None + case other => + d match { + case dir: PsiDirectory => + Option(dir findFile s"$other.$AMMONITE_EXTENSION").orElse(Option(dir findSubdirectory other)) + case _ => None + } } case a@None => a } From ab0a6c204e41fc6d5ae277f825f9b1e17bd8a0ab Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Fri, 20 Oct 2017 19:01:35 +0300 Subject: [PATCH 014/141] Ammonite: ammonite specific imports considered to be always useful #SCL-12765 fixed --- .../importsTracker/ImportTracker.scala | 3 ++- .../worksheet/ScalaScriptImportsUtil.scala | 22 +++++++++++++++++++ .../worksheet/ammonite/AmmoniteUtil.scala | 7 +++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ScalaScriptImportsUtil.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/importsTracker/ImportTracker.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/importsTracker/ImportTracker.scala index 1eaf38c5e2d..1c1b377c753 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/importsTracker/ImportTracker.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/importsTracker/ImportTracker.scala @@ -9,6 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportExpr import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.{ImportExprUsed, ImportSelectorUsed, ImportUsed} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult +import org.jetbrains.plugins.scala.worksheet.ScalaScriptImportsUtil import scala.collection.mutable import scala.collection.Set @@ -54,6 +55,6 @@ object ImportTracker { } } } - buff.toSeq + ScalaScriptImportsUtil.filterScriptImportsInUnused(file, buff.toSeq) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ScalaScriptImportsUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ScalaScriptImportsUtil.scala new file mode 100644 index 00000000000..0a599db7321 --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ScalaScriptImportsUtil.scala @@ -0,0 +1,22 @@ +package org.jetbrains.plugins.scala.worksheet + +import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.{ImportExprUsed, ImportUsed} +import org.jetbrains.plugins.scala.worksheet.ammonite.AmmoniteUtil + +/** + * User: Dmitry.Naydanov + * Date: 20.10.17. + */ +object ScalaScriptImportsUtil { + def filterScriptImportsInUnused(file: ScalaFile, unused: Seq[ImportUsed]): Seq[ImportUsed] = { + file match { + case ammoniteFile if AmmoniteUtil.isAmmoniteFile(ammoniteFile) => + unused.filterNot { + case ImportExprUsed(ex) => AmmoniteUtil.isAmmoniteSpecificImport(ex) + case _ => false + } + case _ => unused + } + } +} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala index ac7d0d5e868..32a8ab40d53 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala @@ -14,7 +14,7 @@ import com.intellij.util.containers.ContainerUtilRt import org.jetbrains.jps.model.java.JavaSourceRootType import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.{ScReferenceElement, ScStableCodeReferenceElement} -import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.{ScImportExpr, ScImportStmt} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.api.{FileDeclarationsHolder, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.{ScalaFileImpl, ScalaPsiElementFactory} @@ -161,6 +161,11 @@ object AmmoniteUtil { } } + def isAmmoniteSpecificImport(expr: ScImportExpr): Boolean = { + val txt = expr.getText + txt.startsWith(ROOT_EXEC) || txt.startsWith(ROOT_FILE) || txt.startsWith(ROOT_IVY) + } + private def findFileByPattern(pattern: String, predicate: File => Boolean): Option[File] = { abstract class PathPart[T] { protected var current: Option[T] = None From 041b15b27f38a8316e9824e9793fbade2c18077f Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 20 Oct 2017 19:19:39 +0200 Subject: [PATCH 015/141] wait for sbt shell tests to complete before checking for expected output --- .../jetbrains/sbt/shell/UseSbtTestRunTest.scala | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index 665528f3a18..54ebac34dd9 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -9,6 +9,9 @@ import org.jetbrains.plugins.scala.testingSupport.ScalaTestingTestCase import org.jetbrains.plugins.scala.testingSupport.test.{AbstractTestRunConfiguration, TestRunConfigurationForm} import org.junit.experimental.categories.Category +import scala.concurrent.Await +import scala.concurrent.duration._ + /** * Created by Roman.Shein on 13.04.2017. */ @@ -48,7 +51,7 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { runPackage(ScalaTestingTestCase.getSpecs2TemplateConfig(getProject), "test.specs2", "specs2", inSpecsPackage) - //TODO: this test is not taking into aaccount tests in OtherUTest/otherTests because sbt test detection detects only 'test' + //TODO: this test is not taking into account tests in OtherUTest/otherTests because sbt test detection detects only 'test' def testUTestAllInPackage(): Unit = runPackage(ScalaTestingTestCase.getUTestTemplateConfig(getProject), "test.uTest", "uTest", inUTestPackage) @@ -117,7 +120,9 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { config.testKind = TestRunConfigurationForm.TestKind.TEST_NAME config.testName = testName config.setTestClassPath(classFqn) - config.setModule(ModuleManager.getInstance(getProject).findModuleByName(moduleName)) + val module = ModuleManager.getInstance(getProject).findModuleByName(moduleName) + assert(module != null, s"Could not find module '$moduleName' in project '$getProject'") + config.setModule(module) runConfig(config, expectedStrings, unexpectedStrings) } @@ -128,10 +133,13 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { val executionEnvironmentBuilder: ExecutionEnvironmentBuilder = new ExecutionEnvironmentBuilder(config.getProject, executor) executionEnvironmentBuilder.runProfile(config).buildAndExecute() + // we can expect test to be done after additional reload completes, which also resets shell for the next test + val finished = SbtShellCommunication.forProject(config.project).command("reload") + Await.ready(finished, 10.minutes) runner.getConsoleView.flushDeferredText() val log = logger.getLog - expectedStrings.foreach(str => assert(log.contains(str), s"Sbt shell console did not contain $str")) - unexpectedStrings.foreach(str => assert(!log.contains(str), s"Sbt shell console contained $str")) + expectedStrings.foreach(str => assert(log.contains(str), s"Sbt shell console did not contain expected '$str'")) + unexpectedStrings.foreach(str => assert(!log.contains(str), s"Sbt shell console contained unexpected '$str'")) assert(!log.contains(SbtProjectPlatformTestCase.errorPrefix)) } } From 190de8176a4f9b7ff225fca9fe7ce49c8cadd16b Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 20 Oct 2017 19:23:16 +0200 Subject: [PATCH 016/141] make sure sbt shell _latest tests actually use latest configured sbt version (version of sbt runner) --- .../SettingQueryHandlerTest_latest.scala | 2 +- .../{sbt13_latest => sbt_latest}/UseSbtTestRunTest_latest.scala | 2 +- scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/.gitignore | 1 + .../testdata/sbt/shell/sbtTestRunTest/project/build.properties | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) rename scala/scala-impl/test/org/jetbrains/sbt/shell/{sbt13_latest => sbt_latest}/SettingQueryHandlerTest_latest.scala (89%) rename scala/scala-impl/test/org/jetbrains/sbt/shell/{sbt13_latest => sbt_latest}/UseSbtTestRunTest_latest.scala (88%) create mode 100644 scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/.gitignore delete mode 100644 scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/project/build.properties diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt13_latest/SettingQueryHandlerTest_latest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt_latest/SettingQueryHandlerTest_latest.scala similarity index 89% rename from scala/scala-impl/test/org/jetbrains/sbt/shell/sbt13_latest/SettingQueryHandlerTest_latest.scala rename to scala/scala-impl/test/org/jetbrains/sbt/shell/sbt_latest/SettingQueryHandlerTest_latest.scala index de361f9b08e..03a43ea7b6f 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt13_latest/SettingQueryHandlerTest_latest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt_latest/SettingQueryHandlerTest_latest.scala @@ -1,4 +1,4 @@ -package org.jetbrains.sbt.shell.sbt13_latest +package org.jetbrains.sbt.shell.sbt_latest import org.jetbrains.plugins.scala.SlowTests import org.jetbrains.sbt.shell.SettingQueryHandlerTest diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt13_latest/UseSbtTestRunTest_latest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt_latest/UseSbtTestRunTest_latest.scala similarity index 88% rename from scala/scala-impl/test/org/jetbrains/sbt/shell/sbt13_latest/UseSbtTestRunTest_latest.scala rename to scala/scala-impl/test/org/jetbrains/sbt/shell/sbt_latest/UseSbtTestRunTest_latest.scala index 85ed6ec7c5e..e8c40bfe855 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt13_latest/UseSbtTestRunTest_latest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/sbt_latest/UseSbtTestRunTest_latest.scala @@ -1,4 +1,4 @@ -package org.jetbrains.sbt.shell.sbt13_latest +package org.jetbrains.sbt.shell.sbt_latest import org.jetbrains.plugins.scala.SlowTests import org.jetbrains.sbt.shell.UseSbtTestRunTest diff --git a/scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/.gitignore b/scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/.gitignore new file mode 100644 index 00000000000..0e3d7b36f74 --- /dev/null +++ b/scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/.gitignore @@ -0,0 +1 @@ +project/build.properties \ No newline at end of file diff --git a/scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/project/build.properties b/scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/project/build.properties deleted file mode 100644 index 64317fdae59..00000000000 --- a/scala/scala-impl/testdata/sbt/shell/sbtTestRunTest/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=0.13.15 From 81bcaabbefbc8a9f4a4dc5983b16e0b9df6c8492 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Fri, 20 Oct 2017 17:41:30 +0300 Subject: [PATCH 017/141] Revert: refactorings for PR: Automatic SBT library import suggestion #393 (9cfa597) fix #SCL-12647 #SCL-12729 --- .../intention/sbt/AddSbtDependencyFix.scala | 20 ++--- .../intention/sbt/AddSbtDependencyUtils.scala | 5 +- .../sbt/ui/SbtPossiblePlacesPanel.scala | 73 +++++++++---------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index 8cc0c3ca5c8..f86eeaa1344 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -19,6 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScPatternDefinition import org.jetbrains.sbt.Sbt import org.jetbrains.sbt.project.SbtProjectSystem import org.jetbrains.sbt.resolvers.SbtResolver +import org.jetbrains.sbt.settings.SbtSystemSettings /** * Created by afonichkin on 7/7/17. @@ -29,7 +30,8 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio file != null && file.isInstanceOf[ScalaFile] && refElement.getManager.isInProject(file) && - ! file.isInstanceOf[ScalaCodeFragment] + ! file.isInstanceOf[ScalaCodeFragment] && + ! SbtSystemSettings.getInstance(project).getLinkedProjectsSettings.isEmpty } override def getText: String = "Add sbt dependency..." @@ -47,17 +49,15 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio val resolver: SbtResolver = SbtResolver.localCacheResolver(None) for { - sbtFile <- sbtFileOpt - module <- refElement.module - if ExternalSystemApiUtil.isExternalSystemAwareModule(SbtProjectSystem.Id, module) - ivyIndex <- resolver.getIndex(project) + sbtFile <- sbtFileOpt + ivyIndex <- resolver.getIndex(project) artifactInfoSet = ivyIndex.searchArtifactInfo(getReferenceText) - psiSbtFile: ScalaFile = PsiManager.getInstance(project).findFile(sbtFile).asInstanceOf[ScalaFile] - depPlaces = getDependencyPlaces(project, psiSbtFile) - wizard = new SbtArtifactSearchWizard(project, artifactInfoSet, depPlaces) + psiSbtFile = PsiManager.getInstance(project).findFile(sbtFile).asInstanceOf[ScalaFile] + depPlaces = getDependencyPlaces(project, psiSbtFile) + wizard = new SbtArtifactSearchWizard(project, artifactInfoSet, depPlaces) (infoOption, fileLineOption) = wizard.search() - artifactInfo <- infoOption - fileLine <- fileLineOption + artifactInfo <- infoOption + fileLine <- fileLineOption } { addDependency(fileLine.element, artifactInfo)(project) refresh(project) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala index 9e8d8b6bf79..beefc1220f2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala @@ -229,12 +229,13 @@ object AddSbtDependencyUtils { private def generateArtifactText(info: ArtifactInfo): String = s""""${info.groupId}" % "${info.artifactId}" % "${info.version}"""" - def getRelativePath(elem: PsiElement)(implicit project: ProjectContext): Option[String] = + def getRelativePath(elem: PsiElement)(implicit project: ProjectContext): Option[String] = { for { path <- Option(elem.getContainingFile.getVirtualFile.getCanonicalPath) - if !path.startsWith(project.getBasePath) + if path.startsWith(project.getBasePath) } yield path.substring(project.getBasePath.length + 1) + } def toDependencyPlaceInfo(elem: PsiElement, affectedProjects: Seq[String])(implicit ctx: ProjectContext): Option[DependencyPlaceInfo] = { val offset = diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index d85e3657dcd..49b996113f4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -25,17 +25,15 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory * Created by afonichkin on 7/19/17. */ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, fileLines: Seq[DependencyPlaceInfo]) extends JPanel { - - private val EDITOR_TOP_MARGIN = 7 - - private val myResultList: Tree = new Tree() - private val myLayout = new BorderLayout() - - private var myCurFileLine: DependencyPlaceInfo = _ - private var myCurEditor: Editor = _ + val myResultList: Tree = new Tree() + var myCurFileLine: DependencyPlaceInfo = _ var canGoNext: Boolean = false + val myLayout = new BorderLayout() + var myCurEditor: Editor = _ + + val EDITOR_TOP_MARGIN = 7 init() @@ -62,24 +60,22 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, myResultList.setCellRenderer(new MyCellRenderer) - myResultList.addTreeSelectionListener(new TreeSelectionListener { - override def valueChanged(treeSelectionEvent: TreeSelectionEvent): Unit = { - val path = treeSelectionEvent.getNewLeadSelectionPath - if (path == null) { - canGoNext = false - myCurFileLine = null - updateEditor() - } else { - path.getLastPathComponent match { - case fileLine: DependencyPlaceInfo if myCurFileLine != fileLine => - canGoNext = true - myCurFileLine = fileLine - updateEditor() - case _ => - } + myResultList.addTreeSelectionListener((treeSelectionEvent: TreeSelectionEvent) => { + val path = treeSelectionEvent.getNewLeadSelectionPath + if (path == null) { + canGoNext = false + myCurFileLine = null + updateEditor() + } else { + path.getLastPathComponent match { + case fileLine: DependencyPlaceInfo if myCurFileLine != fileLine => + canGoNext = true + myCurFileLine = fileLine + updateEditor() + case _ => } - wizard.updateWizardButtons() } + wizard.updateWizardButtons() }) } @@ -87,7 +83,8 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, if (myCurFileLine == null) { remove(myLayout.getLayoutComponent(BorderLayout.SOUTH)) updateUI() - } else for (editor <- createEditor(myCurFileLine.path)) { + } else { + val editor = createEditor(myCurFileLine.path) val editorHighlighter = EditorHighlighterFactory.getInstance.createEditorHighlighter(project, ScalaFileType.INSTANCE) editor.asInstanceOf[EditorEx].setHighlighter(editorHighlighter) editor.getCaretModel.moveToOffset(myCurFileLine.offset) @@ -113,13 +110,14 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, EditorFactory.getInstance.releaseEditor(myCurEditor) } - private def createEditor(path: String): Option[Editor] = { + private def createEditor(path: String): Editor = { val document = FileDocumentManager.getInstance.getDocument(project.getBaseDir.findFileByRelativePath(path)) val tmpFile = ScalaPsiElementFactory.createScalaFileFromText(document.getText)(project) var tmpElement = tmpFile.findElementAt(myCurFileLine.element.getTextOffset) while (tmpElement.getTextRange != myCurFileLine.element.getTextRange) tmpElement = tmpElement.getParent + val dep: PsiElement = AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project).get val viewer = EditorFactory.getInstance.createViewer( EditorFactory.getInstance().createDocument(tmpFile.getText) @@ -128,22 +126,23 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, val scheme = viewer.getColorsScheme val attributes = scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) - for {dep: PsiElement <- AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project)} yield { - - viewer.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, dep.getTextRange.getEndOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE) + viewer.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, dep.getTextRange.getEndOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE) - viewer.getComponent.setPreferredSize(new Dimension(1600, 500)) - viewer.getComponent.updateUI() + viewer.getComponent.setPreferredSize(new Dimension(1600, 500)) + viewer.getComponent.updateUI() - viewer - } + viewer } - def getResult: Option[DependencyPlaceInfo] = - myResultList.getSelectionPaths.collectFirst { - case path if path.getLastPathComponent.isInstanceOf[DependencyPlaceInfo] => - path.getLastPathComponent.asInstanceOf[DependencyPlaceInfo] + def getResult: Option[DependencyPlaceInfo] = { + for (path: TreePath <- myResultList.getSelectionPaths) { + path.getLastPathComponent match { + case info: DependencyPlaceInfo => return Some(info) + case _ => + } } + None + } private class MyTreeModel(elements: Seq[DependencyPlaceInfo]) extends TreeModel { override def getIndexOfChild(parent: scala.Any, child: scala.Any): Int = elements.indexOf(child) From 025e62625748564334aa0560567869e985ddd7df Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Fri, 20 Oct 2017 18:45:03 +0300 Subject: [PATCH 018/141] fix sizes of add sbt dependency wizard steps fix #SCL-12646 --- .../intention/sbt/ui/SbtArtifactChooseDependencyStep.scala | 2 -- .../annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala | 2 +- .../annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala index 845eb1d7ea7..72e94cd1ff1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala @@ -1,6 +1,5 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt.ui -import java.awt.Dimension import javax.swing.{Icon, JComponent} import com.intellij.ide.wizard.Step @@ -14,7 +13,6 @@ class SbtArtifactChooseDependencyStep(wizard: SbtArtifactSearchWizard, artifactI override def _init(): Unit = { wizard.setTitle("Sbt Artifact Search") - setPreferredSize(new Dimension(1600, 1200)) updateUI() } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index 49b996113f4..f9050f14f52 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -128,7 +128,7 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, viewer.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, dep.getTextRange.getEndOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE) - viewer.getComponent.setPreferredSize(new Dimension(1600, 500)) + viewer.getComponent.updateUI() viewer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala index f213d98e27a..88804b08324 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala @@ -1,10 +1,10 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt.ui -import java.awt.Dimension import javax.swing.{Icon, JComponent} import com.intellij.ide.wizard.Step import com.intellij.openapi.project.Project +import com.intellij.util.ui.JBUI import org.jetbrains.plugins.scala.annotator.intention.sbt.DependencyPlaceInfo /** @@ -15,7 +15,7 @@ class SbtPossiblePlacesStep(wizard: SbtArtifactSearchWizard, project: Project, f override def _init(): Unit = { wizard.setTitle("Place to add dependency") - setPreferredSize(new Dimension(1600, 1200)) + wizard.setSize(JBUI.scale(600), JBUI.scale(750)) updateUI() } From ccfe3b199dc8ed127a890ed0394f28ecf065eda7 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 20 Oct 2017 19:50:08 +0200 Subject: [PATCH 019/141] fix scalameta test failing because the error message was eagerly evaluated... --- .../test/scala/meta/annotations/MetaAnnotationBugsTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala index e5337f227c1..8d06c43b3ff 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala @@ -253,7 +253,7 @@ class MetaAnnotationBugsTest extends MetaAnnotationTestBase { ) createFile(s"@$annotName('abc) class $testClassName") val errors = myFixture.doHighlighting(HighlightSeverity.ERROR) - assertTrue(s"Symbol in annotation causes error: ${errors.get(0)}", errors.isEmpty) + assert(errors.isEmpty, s"Symbol in annotation causes error: ${errors.get(0)}") } // Type parameters resolve to both synthetic and physical elements if target is present in both From ffd564faa69b8bc77f166e7f69d3abf70fb7ffba Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Mon, 23 Oct 2017 15:39:47 +0300 Subject: [PATCH 020/141] getUseScope fixed for private classes and their members: top level private class is visible in the same package, members of private[x] class may be accessed via public inheritors #SCL-11885 fixed #SCL-10610 fixed #SCL-12601 fixed --- .../psi/api/toplevel/typedef/ScMember.scala | 79 +++++++++++++------ .../refactoring/rename3/ScalaRenameTest.scala | 6 ++ .../after/tests/Private.scala | 5 ++ .../after/tests/PrivateTest.scala | 5 ++ .../before/tests/Private.scala | 5 ++ .../before/tests/PrivateTest.scala | 5 ++ .../after/tests/PrivateTest.scala | 6 ++ .../after/tests/test/Private.scala | 7 ++ .../before/tests/PrivateTest.scala | 6 ++ .../before/tests/test/Private.scala | 7 ++ .../after/tests/NameAfterRename.scala | 9 +++ .../after/tests/PrivateTest.scala | 7 ++ .../before/tests/Private.scala | 9 +++ .../before/tests/PrivateTest.scala | 7 ++ 14 files changed, 137 insertions(+), 26 deletions(-) create mode 100644 scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/Private.scala create mode 100644 scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/PrivateTest.scala create mode 100644 scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/Private.scala create mode 100644 scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/PrivateTest.scala create mode 100644 scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/PrivateTest.scala create mode 100644 scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/test/Private.scala create mode 100644 scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/PrivateTest.scala create mode 100644 scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/test/Private.scala create mode 100644 scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/NameAfterRename.scala create mode 100644 scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/PrivateTest.scala create mode 100644 scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/Private.scala create mode 100644 scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/PrivateTest.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScMember.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScMember.scala index 78d741e9b61..7f19f1bec59 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScMember.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScMember.scala @@ -5,6 +5,8 @@ package api package toplevel package typedef +import scala.annotation.tailrec + import com.intellij.openapi.util.Key import com.intellij.psi._ import com.intellij.psi.search.{LocalSearchScope, PackageScope, SearchScope} @@ -19,7 +21,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScMember._ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaFileImpl import org.jetbrains.plugins.scala.lang.psi.stubs.ScMemberOrLocal import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} - import scala.collection.mutable.ArrayBuffer /** @@ -169,44 +170,68 @@ trait ScMember extends ScalaPsiElement with ScModifierListOwner with PsiMember { } abstract override def getUseScope: SearchScope = { - val accessModifier = Option(getModifierList).flatMap(_.accessModifier) + def accessModifier(modifierListOwner: ScModifierListOwner) = Option(getModifierList).flatMap(_.accessModifier) - def withCompanionSearchScope(typeDefinition: ScTypeDefinition): SearchScope = { + def localSearchScope(typeDefinition: ScTypeDefinition, withCompanion: Boolean = true): SearchScope = { val scope = new LocalSearchScope(typeDefinition) - typeDefinition.baseCompanionModule.map { - new LocalSearchScope(_) - }.map { - scope.union - }.getOrElse(scope) + if (withCompanion) { + typeDefinition.baseCompanionModule match { + case Some(td) => scope.union(new LocalSearchScope(td)) + case _ => scope + } + } + else scope } - def fromContainingBlockOrMember(): Option[SearchScope] = { - val blockOrMember = PsiTreeUtil.getContextOfType(this, true, classOf[ScBlock], classOf[ScMember]) + def containingClassScope(withCompanion: Boolean) = containingClass match { + case definition: ScTypeDefinition => Some(localSearchScope(definition, withCompanion)) + case _ => this.containingFile.map(new LocalSearchScope(_)) + } + + def forTopLevelPrivate(modifierListOwner: ScModifierListOwner) = modifierListOwner match { + case td: ScTypeDefinition if td.isTopLevel => + val qName = Option(td.qualifiedName) + val parentPackage = qName.flatMap(ScalaPsiUtil.parentPackage(_, td.getProject)) + parentPackage.map(new PackageScope(_, /*includeSubpackages*/ false, /*includeLibraries*/ true)) + case _ => None + } + + @tailrec + def fromContainingBlockOrMember(elem: PsiElement): Option[SearchScope] = { + val blockOrMember = PsiTreeUtil.getContextOfType(elem, true, classOf[ScBlock], classOf[ScMember]) blockOrMember match { case null => None - case block: ScBlock => Some(new LocalSearchScope(block)) + case b: ScBlock => Some(new LocalSearchScope(b)) + case o: ScObject => Some(o.getUseScope) + case td: ScTypeDefinition => //can't use td.getUseScope because of inheritance + fromUnqualifiedOrThisPrivate(td) match { + case None => fromContainingBlockOrMember(td) + case scope => scope + } case member: ScMember => Some(member.getUseScope) } } + //should be checked only for the member itself + //member of a qualified private class may escape it's package with inheritance def fromQualifiedPrivate(): Option[SearchScope] = { - accessModifier.filter(am => am.isPrivate && am.getReference != null).map(_.scope) collect { - case p: PsiPackage => new PackageScope(p, true, true) - case td: ScTypeDefinition => withCompanionSearchScope(td) + accessModifier(this).filter(am => am.isPrivate && !am.isUnqualifiedPrivateOrThis).map(_.scope) collect { + case p: PsiPackage => new PackageScope(p, /*includeSubpackages*/true, /*includeLibraries*/true) + case td: ScTypeDefinition => localSearchScope(td) } } - val fromModifierOrContext = this match { - case _ if accessModifier.exists(mod => mod.isPrivate && mod.isThis) => - Option(containingClass).orElse(this.containingFile).map { - new LocalSearchScope(_) - } - case _ if accessModifier.exists(_.isUnqualifiedPrivateOrThis) => - Option(containingClass).collect { - case definition: ScTypeDefinition => withCompanionSearchScope(definition) - }.orElse { - this.containingFile.map(new LocalSearchScope(_)) - } + def fromUnqualifiedOrThisPrivate(modifierListOwner: ScModifierListOwner) = { + accessModifier(modifierListOwner) match { + case Some(mod) if mod.isUnqualifiedPrivateOrThis => + forTopLevelPrivate(modifierListOwner).orElse { + containingClassScope(withCompanion = !mod.isThis) + } + case _ => None + } + } + + def fromContext = this match { case cp: ScClassParameter => Option(cp.containingClass).map { _.getUseScope @@ -219,9 +244,11 @@ trait ScMember extends ScalaPsiElement with ScModifierListOwner with PsiMember { } case _ => fromQualifiedPrivate().orElse { - fromContainingBlockOrMember() + fromContainingBlockOrMember(this) } } + val fromModifierOrContext = fromUnqualifiedOrThisPrivate(this).orElse(fromContext) + ScalaPsiUtil.intersectScopes(super.getUseScope, fromModifierOrContext) } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/rename3/ScalaRenameTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/rename3/ScalaRenameTest.scala index a9727344ff8..d7b7e8817e5 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/rename3/ScalaRenameTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/rename3/ScalaRenameTest.scala @@ -59,4 +59,10 @@ class ScalaRenameTest extends ScalaRenameTestBase { def testParamSameAsJavaKeyword(): Unit = doTest() def testObjectImport(): Unit = doTest() + + def testPrivatePackageClassInheritor(): Unit = doTest() + + def testPrivateSamePackage(): Unit = doTest() + + def testPrivateMemberSamePackage(): Unit = doTest() } diff --git a/scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/Private.scala b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/Private.scala new file mode 100644 index 00000000000..f0bec40b20f --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/Private.scala @@ -0,0 +1,5 @@ +package tests + +private object Private { + def NameAfterRename = ??? +} diff --git a/scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/PrivateTest.scala b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/PrivateTest.scala new file mode 100644 index 00000000000..b78f1c73fc1 --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/after/tests/PrivateTest.scala @@ -0,0 +1,5 @@ +package tests + +class PrivateTest { + Private.NameAfterRename +} \ No newline at end of file diff --git a/scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/Private.scala b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/Private.scala new file mode 100644 index 00000000000..d4fd1e99d9e --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/Private.scala @@ -0,0 +1,5 @@ +package tests + +private object Private { + def bar = ??? +} diff --git a/scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/PrivateTest.scala b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/PrivateTest.scala new file mode 100644 index 00000000000..38d31e888ac --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateMemberSamePackage/before/tests/PrivateTest.scala @@ -0,0 +1,5 @@ +package tests + +class PrivateTest { + Private./*caret*/bar +} \ No newline at end of file diff --git a/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/PrivateTest.scala b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/PrivateTest.scala new file mode 100644 index 00000000000..6c29c650669 --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/PrivateTest.scala @@ -0,0 +1,6 @@ +package tests + +class PrivateTest { + val p = new test.Public + p.NameAfterRename +} \ No newline at end of file diff --git a/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/test/Private.scala b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/test/Private.scala new file mode 100644 index 00000000000..be046da11b2 --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/after/tests/test/Private.scala @@ -0,0 +1,7 @@ +package tests.test + +private[test] trait Private { + def NameAfterRename = ??? +} + +class Public extends Private diff --git a/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/PrivateTest.scala b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/PrivateTest.scala new file mode 100644 index 00000000000..13c5d012fb9 --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/PrivateTest.scala @@ -0,0 +1,6 @@ +package tests + +class PrivateTest { + val p = new test.Public + p./*caret*/foo +} \ No newline at end of file diff --git a/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/test/Private.scala b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/test/Private.scala new file mode 100644 index 00000000000..2b1c14d9def --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privatePackageClassInheritor/before/tests/test/Private.scala @@ -0,0 +1,7 @@ +package tests.test + +private[test] trait Private { + def /*caret*/foo = ??? +} + +class Public extends Private diff --git a/scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/NameAfterRename.scala b/scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/NameAfterRename.scala new file mode 100644 index 00000000000..a12e38313fa --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/NameAfterRename.scala @@ -0,0 +1,9 @@ +package tests + +private class NameAfterRename { + def foo = ??? +} + +private object NameAfterRename { + def bar = ??? +} \ No newline at end of file diff --git a/scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/PrivateTest.scala b/scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/PrivateTest.scala new file mode 100644 index 00000000000..8d2681162ed --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateSamePackage/after/tests/PrivateTest.scala @@ -0,0 +1,7 @@ +package tests + +class PrivateTest { + val p = new NameAfterRename + p.foo + NameAfterRename.bar +} \ No newline at end of file diff --git a/scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/Private.scala b/scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/Private.scala new file mode 100644 index 00000000000..196130c2597 --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/Private.scala @@ -0,0 +1,9 @@ +package tests + +private class /*caret*/Private { + def foo = ??? +} + +private object /*caret*/Private { + def bar = ??? +} \ No newline at end of file diff --git a/scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/PrivateTest.scala b/scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/PrivateTest.scala new file mode 100644 index 00000000000..35989033959 --- /dev/null +++ b/scala/scala-impl/testdata/rename3/privateSamePackage/before/tests/PrivateTest.scala @@ -0,0 +1,7 @@ +package tests + +class PrivateTest { + val p = new /*caret*/Private + p.foo + /*caret*/Private.bar +} \ No newline at end of file From 4d8907cbf55f3ebd9201adaba7d39e812a8f78c8 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 14:46:46 +0200 Subject: [PATCH 021/141] lowercase more SBT/Sbt strings --- .../plugins/scala/nailgun/NailgunRunner.java | 2 +- scala/scala-impl/resources/META-INF/SBT.xml | 16 ++++++++-------- .../sbt/ui/SbtArtifactChooseDependencyStep.scala | 2 +- .../sbt/project/modifier/BuildFileModifier.scala | 2 +- .../sbt/shell/SbtShellToolWindowFactory.scala | 2 +- .../sbt/shell/action/SbtShellStartAction.scala | 2 +- .../sbt/shell/action/shellWindowActions.scala | 8 ++++---- .../src/org/jetbrains/sbt/shell/language.scala | 6 +++--- .../sbt/shell/SbtProjectPlatformTestCase.scala | 4 +++- .../jetbrains/sbt/shell/UseSbtTestRunTest.scala | 4 ++-- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java b/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java index 82b761a8b3d..587c77600c8 100644 --- a/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java +++ b/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java @@ -15,7 +15,7 @@ public class NailgunRunner { private static final String SERVER_CLASS_NAME = "org.jetbrains.jps.incremental.scala.remote.Main"; private static final String SBT_WATCHER_ALIAS = "play-sbt-watcher"; - private static final String SBT_WATCHER_DESCRIPTION = "Play framework SBT watcher"; + private static final String SBT_WATCHER_DESCRIPTION = "Play framework sbt watcher"; private static final String SBT_WATCHER_CLASS_NAME = "org.jetbrains.jps.incremental.scala.remote.play.SbtWatcherMain"; private static final String STOP_ALIAS_START = "stop_"; diff --git a/scala/scala-impl/resources/META-INF/SBT.xml b/scala/scala-impl/resources/META-INF/SBT.xml index 2c66c099edf..58c960aa977 100644 --- a/scala/scala-impl/resources/META-INF/SBT.xml +++ b/scala/scala-impl/resources/META-INF/SBT.xml @@ -124,42 +124,42 @@ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala index 72e94cd1ff1..e47c745c241 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala @@ -12,7 +12,7 @@ class SbtArtifactChooseDependencyStep(wizard: SbtArtifactSearchWizard, artifactI extends SbtArtifactSearchPanel(wizard, artifactInfoSet) with Step { override def _init(): Unit = { - wizard.setTitle("Sbt Artifact Search") + wizard.setTitle("sbt artifact search") updateUI() } diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala index f074234b4b2..f74b5e7f150 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala @@ -59,7 +59,7 @@ trait BuildFileModifier { res = false } } - }, "Sbt build file modification", this) + }, "sbt build file modification", this) if (res) ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(project, SbtProjectSystem.Id)) res diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala index d89733c4389..e4cc879c781 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala @@ -53,6 +53,6 @@ class SbtShellToolWindowFactory extends ToolWindowFactory with DumbAware { } object SbtShellToolWindowFactory { - val title = "sbt Shell" + val title = "sbt shell" val ID = "sbt-shell-toolwindow" } diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala index 6205d023341..ec7c742ff02 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala @@ -13,7 +13,7 @@ import org.jetbrains.sbt.shell.SbtProcessManager */ class SbtShellStartAction extends ExternalSystemAction { - setText("Run sbt Shell") + setText("Run sbt shell") override def update(e: AnActionEvent): Unit = { super.update(e) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala index 8867340848b..14c98d3a7ca 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala @@ -34,7 +34,7 @@ class RestartAction(project: Project) extends DumbAwareAction { val templatePresentation: Presentation = getTemplatePresentation templatePresentation.setIcon(AllIcons.Actions.Restart) - templatePresentation.setText("Restart sbt Shell") // TODO i18n / language-bundle + templatePresentation.setText("Restart sbt shell") // TODO i18n / language-bundle def actionPerformed(e: AnActionEvent): Unit = { val twm = ToolWindowManager.getInstance(project) @@ -49,7 +49,7 @@ class StopAction(project: Project) extends DumbAwareAction { copyFrom(ActionManager.getInstance.getAction(IdeActions.ACTION_STOP_PROGRAM)) val templatePresentation: Presentation = getTemplatePresentation templatePresentation.setIcon(AllIcons.Process.Stop) - templatePresentation.setText("Stop sbt Shell") // TODO i18n / language-bundle + templatePresentation.setText("Stop sbt shell") // TODO i18n / language-bundle templatePresentation.setDescription(null) override def actionPerformed(e: AnActionEvent): Unit = { @@ -89,10 +89,10 @@ class DebugShellAction(project: Project, remoteConnection: RemoteConnection) ext private val templatePresentation: Presentation = getTemplatePresentation templatePresentation.setIcon(AllIcons.Actions.StartDebugger) - templatePresentation.setText("Attach debugger to sbt Shell") + templatePresentation.setText("Attach debugger to sbt shell") private val configType = new RemoteConfigurationType - private val configName = "Debug sbt Shell" + private val configName = "Debug sbt shell" private val configFactory = configType.getFactory override def setSelected(e: AnActionEvent, toSet: Boolean): Unit = { diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala index 5e3594e37d0..3df0b29d72d 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala @@ -29,7 +29,7 @@ object SbtShellFileType extends LanguageFileType(SbtShellLanguage) { override def getDefaultExtension: String = "sbts" override def getName: String = "sbtShell" override def getIcon: Icon = Sbt.FileIcon - override def getDescription: String = "Sbt Shell file dummy" + override def getDescription: String = "sbt shell file dummy" } class SbtShellFileTypeFactory extends FileTypeFactory { @@ -40,8 +40,8 @@ class SbtShellFileTypeFactory extends FileTypeFactory { class SbtShellLexerAdapter extends FlexAdapter(new _SbtShellLexer) class SbtShellFile(viewProvider: FileViewProvider) extends PsiFileBase(viewProvider, SbtShellLanguage) { - override def getFileType = SbtShellFileType - override def toString: String = "Sbt Shell File" + override def getFileType: SbtShellFileType.type = SbtShellFileType + override def toString: String = "sbt shell file" } class SbtShellParserDefinition extends ParserDefinition { diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala index 76a00fafd0d..5800e82b3f6 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala @@ -23,7 +23,9 @@ import org.jetbrains.sbt.project.SbtProjectSystem abstract class SbtProjectPlatformTestCase extends PlatformTestCase { override def setUpProject(): Unit = { - // projectFile is the sbt file for the root project + //projectFile is the sbt file for the root project + val sbtRootFile = getSbtRootFile + assert(sbtRootFile.exists, "expected path does not exist: " + sbtRootFile.getAbsolutePath) val path = getSbtRootFile.getAbsolutePath val project = ProjectUtil.openOrImport(path, null, false) assert(project != null, s"project at path $path was null") diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index 54ebac34dd9..0d59181be28 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -138,8 +138,8 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { Await.ready(finished, 10.minutes) runner.getConsoleView.flushDeferredText() val log = logger.getLog - expectedStrings.foreach(str => assert(log.contains(str), s"Sbt shell console did not contain expected '$str'")) - unexpectedStrings.foreach(str => assert(!log.contains(str), s"Sbt shell console contained unexpected '$str'")) + expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'")) + unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'")) assert(!log.contains(SbtProjectPlatformTestCase.errorPrefix)) } } From 522c6d0a4e5aead60604fd43ec9996864f2c3e86 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 16:08:01 +0200 Subject: [PATCH 022/141] more test assertions --- .../sbt/shell/UseSbtTestRunTest.scala | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index 0d59181be28..f41ee5048cc 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -4,6 +4,7 @@ import com.intellij.execution.Executor import com.intellij.execution.executors.DefaultRunExecutor import com.intellij.execution.runners.ExecutionEnvironmentBuilder import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.roots.ProjectRootManager import org.jetbrains.plugins.scala.SlowTests import org.jetbrains.plugins.scala.testingSupport.ScalaTestingTestCase import org.jetbrains.plugins.scala.testingSupport.test.{AbstractTestRunConfiguration, TestRunConfigurationForm} @@ -129,17 +130,25 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { protected def runConfig(config: AbstractTestRunConfiguration, expectedStrings: Seq[String], unexpectedStrings: Seq[String], commandsExpected: Int = 1): Unit = { config.useSbt = true + val project = config.getProject + val sdk = ProjectRootManager.getInstance(project).getProjectSdk + assert(sdk != null, s"project sdk was null in project ${project.getName}") + val executor: Executor = Executor.EXECUTOR_EXTENSION_NAME.findExtension(classOf[DefaultRunExecutor]) val executionEnvironmentBuilder: ExecutionEnvironmentBuilder = - new ExecutionEnvironmentBuilder(config.getProject, executor) + new ExecutionEnvironmentBuilder(project, executor) executionEnvironmentBuilder.runProfile(config).buildAndExecute() // we can expect test to be done after additional reload completes, which also resets shell for the next test - val finished = SbtShellCommunication.forProject(config.project).command("reload") + val finished = SbtShellCommunication.forProject(project).command("reload") Await.ready(finished, 10.minutes) runner.getConsoleView.flushDeferredText() val log = logger.getLog - expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'")) - unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'")) - assert(!log.contains(SbtProjectPlatformTestCase.errorPrefix)) + expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'. Full log:\n$log")) + unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'. Full log:\n$log")) + val logSplitted = logLines(log) + val errorline = logSplitted.find(line => line contains SbtProjectPlatformTestCase.errorPrefix) + assert(errorline.isEmpty, s"log contained errors: $errorline") } + + private def logLines(log: String) = log.split("\n").toVector } From 40653891b9624a74a41d3daa019309b57921faae Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 16:51:24 +0200 Subject: [PATCH 023/141] cbt should use CbtProjectSystem, not sbt --- .../cbt/project/data/service/CbtModuleExtDataService.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala b/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala index 9f9d137573d..efc08cf11f2 100644 --- a/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala +++ b/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala @@ -6,9 +6,9 @@ import com.intellij.openapi.externalSystem.service.notification.{ExternalSystemN import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider import com.intellij.openapi.project.Project import com.intellij.openapi.roots.libraries.Library +import org.jetbrains.plugins.cbt.project.CbtProjectSystem import org.jetbrains.plugins.cbt.structure.CbtModuleExtData import org.jetbrains.plugins.scala.project.{LibraryExt, ModuleExt, Platform, ScalaLanguageLevel} -import org.jetbrains.sbt.project.SbtProjectSystem import org.jetbrains.sbt.project.data.service.{AbstractDataService, AbstractImporter, Importer} class CbtModuleExtDataService extends AbstractDataService[CbtModuleExtData, Library](CbtModuleExtData.Key) { @@ -28,7 +28,7 @@ object CbtModuleExtDataService { NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC) ExternalSystemNotificationManager.getInstance(project) - .showNotification(SbtProjectSystem.Id, notification) + .showNotification(CbtProjectSystem.Id, notification) } private class Importer(toImport: Seq[DataNode[CbtModuleExtData]], From c9a2617dcd3a2d03f8bae5b018ec48d5d0b1b200 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 16:52:24 +0200 Subject: [PATCH 024/141] revert SbtProjectSystemId to SBT since changing it breaks project re-imports. Just changing readable name should cause less issues. External system will include a change to ignore the case in readable name. --- .../src/org/jetbrains/sbt/project/SbtProjectSystem.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala index cac7c6500ea..64f67da40dc 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala @@ -7,5 +7,5 @@ import com.intellij.openapi.externalSystem.model.ProjectSystemId * @author Pavel Fatin */ object SbtProjectSystem { - val Id = new ProjectSystemId("sbt", Sbt.Name) + val Id = new ProjectSystemId("SBT", Sbt.Name) } \ No newline at end of file From e2bfce342f2f50600fbeb992db92cefd31c05281 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Mon, 23 Oct 2017 17:59:19 +0300 Subject: [PATCH 025/141] disable macros2 linemarkers for now fix #EA-107494 --- .../editor/Macros2ExpansionLineMarkerProvider.scala | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scala/scala-impl/src/scala/macros/intellij/editor/Macros2ExpansionLineMarkerProvider.scala b/scala/scala-impl/src/scala/macros/intellij/editor/Macros2ExpansionLineMarkerProvider.scala index 62d26cdd62b..79f8b2a3187 100644 --- a/scala/scala-impl/src/scala/macros/intellij/editor/Macros2ExpansionLineMarkerProvider.scala +++ b/scala/scala-impl/src/scala/macros/intellij/editor/Macros2ExpansionLineMarkerProvider.scala @@ -5,14 +5,6 @@ import org.jetbrains.plugins.scala.lang.macros.expansion.MacroExpansionLineMarke import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder class Macros2ExpansionLineMarkerProvider extends MacroExpansionLineMarkerProvider { - override protected def getExpandMarker(element: PsiElement): Option[Marker] = { - import scala.macros.intellij.psiExt._ - - element.getParent match { - case holder: ScAnnotationsHolder => holder.annotations.find(_.isMacro2).map(a=>newExpandMarker(a.getFirstChild) { _=> }) - case _ => None - } - } - + override protected def getExpandMarker(element: PsiElement): Option[Marker] = None override protected def getUndoMarker(element: PsiElement): Option[Marker] = None } From 86f375b2a0fdfa18a0e83e602271a1b4de7a062b Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 18:06:24 +0200 Subject: [PATCH 026/141] ensure LibraryLoader libraries are disposed --- .../plugins/scala/base/libraryLoaders/LibraryLoader.scala | 7 ++++--- .../scala/base/libraryLoaders/ScalaLibraryLoader.scala | 2 ++ .../base/libraryLoaders/ThirdPartyLibraryLoader.scala | 4 ++-- .../lang/completion3/ScalaCompletionSortingTestCase.scala | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala index 87699e78837..233657d215a 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala @@ -1,17 +1,18 @@ package org.jetbrains.plugins.scala.base.libraryLoaders +import com.intellij.openapi.Disposable import com.intellij.openapi.module.Module -import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl -import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager import org.jetbrains.plugins.scala.debugger.ScalaVersion /** * @author adkozlov */ -trait LibraryLoader { +trait LibraryLoader extends Disposable { implicit val module: Module def init(implicit version: ScalaVersion): Unit def clean(): Unit = {} + + override def dispose(): Unit = clean() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala index 94d7f191517..7b767369e8f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala @@ -5,6 +5,7 @@ import java.io.File import com.intellij.openapi.module.Module import com.intellij.openapi.projectRoots.{ProjectJdkTable, Sdk} import com.intellij.openapi.roots.libraries.Library +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile} import com.intellij.testFramework.PsiTestUtil import org.jetbrains.plugins.scala.ScalaLoader @@ -47,6 +48,7 @@ case class ScalaLibraryLoader(isIncludeReflectLibrary: Boolean = false) val srcRoots = ScalaRuntimeLoader(Sources).rootFiles library = PsiTestUtil.addProjectLibrary(module, "scala-sdk", classRoots.asJava, srcRoots.asJava) + Disposer.register(module, library) inWriteAction { library.convertToScalaSdkWith(languageLevel(files.head), files) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index 57cd1cc9a41..676c6e82e6c 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -6,7 +6,7 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.PsiTestUtil import org.jetbrains.plugins.scala.base.libraryLoaders.IvyLibraryLoader._ -import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_11, Scala_2_12} +import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_11} import org.jetbrains.plugins.scala.project.ModuleExt /** @@ -22,7 +22,7 @@ trait ThirdPartyLibraryLoader extends LibraryLoader { val file = new File(path).getCanonicalFile assert(file.exists(), s"library root for $name does not exist at $file") VfsRootAccess.allowRootAccess(path) - PsiTestUtil.addLibrary(module, path) + PsiTestUtil.addLibrary(this, module, name, path) } protected def path(implicit version: ScalaVersion): String diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala index 27f0df70758..53e78fd705e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala @@ -24,11 +24,12 @@ abstract class ScalaCompletionSortingTestCase extends LightFixtureCompletionTest } } - override def tearDown() { + override def tearDown(): Unit = try { LookupManager.getInstance(getProject).hideActiveLookup() UISettings.getInstance.setSortLookupElementsLexicographically(false) CodeInsightSettings.getInstance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + } finally { super.tearDown() } From 691396e756157025b44f11681dedb393dbe1fbe5 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 24 Oct 2017 01:03:28 +0200 Subject: [PATCH 027/141] fix disposal of paths in libraryloaders --- .../src/org/jetbrains/plugins/scala/ScalaLoader.java | 6 +++--- .../test/utest/UTestConfigurationProducer.scala | 2 +- .../plugins/scala/base/libraryLoaders/LibraryLoader.scala | 5 +++-- .../scala/base/libraryLoaders/ScalaLibraryLoader.scala | 6 ++++-- .../scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala | 3 ++- .../utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java b/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java index 7f368da06f8..37359afca01 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java @@ -56,10 +56,10 @@ public static void loadScala() { ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() { public void projectOpened(Project project) { - CompilerManager compilerManager = CompilerManager.getInstance(project); - compilerManager.addCompilableFileType(ScalaFileType.INSTANCE); + CompilerManager compilerManager = CompilerManager.getInstance(project); + compilerManager.addCompilableFileType(ScalaFileType.INSTANCE); - DebuggerManager.getInstance(project).addClassNameMapper(new ScalaJVMNameMapper()); + DebuggerManager.getInstance(project).addClassNameMapper(new ScalaJVMNameMapper()); } }); } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala index 667b8555fd0..d85851d9762 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala @@ -145,7 +145,7 @@ class UTestConfigurationProducer extends { } //this is checked once we provide a concrete class for test run // if (!containingObject.isInstanceOf[ScObject]) return fail - if (!suitePaths.exists(suitePath => TestConfigurationUtil.isInheritor(containingObject, suitePath))) return (null, null) + if (!suitePaths.exists(suitePath => TestConfigurationUtil.isInheritor(containingObject, suitePath))) return fail val nameContainer = ScalaPsiUtil.getParentWithProperty(element, strict = false, e => TestNodeProvider.isUTestInfixExpr(e) || TestNodeProvider.isUTestSuiteApplyCall(e) || diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala index 233657d215a..fbf26294aa0 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala @@ -2,6 +2,7 @@ package org.jetbrains.plugins.scala.base.libraryLoaders import com.intellij.openapi.Disposable import com.intellij.openapi.module.Module +import com.intellij.openapi.util.Disposer import org.jetbrains.plugins.scala.debugger.ScalaVersion /** @@ -12,7 +13,7 @@ trait LibraryLoader extends Disposable { def init(implicit version: ScalaVersion): Unit - def clean(): Unit = {} + def clean(): Unit = dispose() - override def dispose(): Unit = clean() + override def dispose(): Unit = Disposer.dispose(this) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala index 7b767369e8f..ed74c60da68 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala @@ -4,7 +4,8 @@ import java.io.File import com.intellij.openapi.module.Module import com.intellij.openapi.projectRoots.{ProjectJdkTable, Sdk} -import com.intellij.openapi.roots.libraries.Library +import com.intellij.openapi.roots.OrderRootType +import com.intellij.openapi.roots.libraries.{Library, LibraryTable} import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile} import com.intellij.testFramework.PsiTestUtil @@ -34,6 +35,7 @@ case class ScalaLibraryLoader(isIncludeReflectLibrary: Boolean = false) if (library != null) { inWriteAction { module.detach(library) + library.getTable.removeLibrary(library) } } } @@ -42,7 +44,7 @@ case class ScalaLibraryLoader(isIncludeReflectLibrary: Boolean = false) val loaders = Seq(ScalaCompilerLoader(), ScalaRuntimeLoader()) ++ (if (isIncludeReflectLibrary) Seq(ScalaReflectLoader()) else Seq.empty) - val files = loaders.map(_.path).map(new File(_)) + val files = loaders.map(loader => new File(loader.path)) val classRoots = loaders.flatMap(_.rootFiles) val srcRoots = ScalaRuntimeLoader(Sources).rootFiles diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index 676c6e82e6c..abf15e0b5de 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -3,6 +3,7 @@ package org.jetbrains.plugins.scala.base.libraryLoaders import java.io.File import com.intellij.openapi.module.Module +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.PsiTestUtil import org.jetbrains.plugins.scala.base.libraryLoaders.IvyLibraryLoader._ @@ -22,7 +23,7 @@ trait ThirdPartyLibraryLoader extends LibraryLoader { val file = new File(path).getCanonicalFile assert(file.exists(), s"library root for $name does not exist at $file") VfsRootAccess.allowRootAccess(path) - PsiTestUtil.addLibrary(this, module, name, path) + PsiTestUtil.addLibrary(this, module, file.getName, file.getParent, file.getName) } protected def path(implicit version: ScalaVersion): String diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala index 2808615759e..93997472912 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala @@ -36,7 +36,7 @@ class UTestStaticStringTest_2_11_0_5_4 extends UTestTestBase_2_11_0_5_4 with UTe checkTestsTest(6, 6, "foo") } - protected def checkTestsTest(lineNumber: Int, position: Int, expectedName: String) = { + protected def checkTestsTest(lineNumber: Int, position: Int, expectedName: String): Unit = { assert(checkConfigAndSettings(createTestFromLocation(lineNumber, position, testsTestFileName), testsTestName, "tests" + (if (expectedName.isEmpty) "" else "\\" + expectedName))) } From 3e14ecb16d218a3c290326e9a164e66353c5af65 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 24 Oct 2017 01:45:24 +0200 Subject: [PATCH 028/141] move failing perf test to failing tests --- .../plugins/scala/performance/typing/TypedHandlerTest.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/typing/TypedHandlerTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/typing/TypedHandlerTest.scala index 47a2485c051..c8aa5272274 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/typing/TypedHandlerTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/typing/TypedHandlerTest.scala @@ -1,13 +1,13 @@ package org.jetbrains.plugins.scala.performance.typing -import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.PerfCycleTests import org.junit.experimental.categories.Category /** * @author Roman.Shein * Date: 15.12.2015 */ -@Category(Array(classOf[SlowTests])) +@Category(Array(classOf[PerfCycleTests])) class TypedHandlerTest extends TypingTestWithPerformanceTestBase { val typingTimeout = 200 From cd4bd1b2d7c95cf4990ffe2019ef502f3fb6f7f0 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 24 Oct 2017 02:18:48 +0200 Subject: [PATCH 029/141] fix test name in TeamCity reporting --- .../scala/performance/DownloadingAndImportingTestCase.scala | 2 +- .../projectHighlighting/ScalaLibraryHighlightingTest.scala | 2 +- .../projectHighlighting/ScalacTestdataHighlightingTest.scala | 2 +- .../plugins/scala/util/reporter/ProgressReporter.scala | 4 ++-- .../plugins/scala/util/reporter/TeamCityReporter.scala | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/DownloadingAndImportingTestCase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/DownloadingAndImportingTestCase.scala index acfd6a54277..5278cbf1691 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/DownloadingAndImportingTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/DownloadingAndImportingTestCase.scala @@ -44,7 +44,7 @@ abstract class DownloadingAndImportingTestCase extends ExternalSystemImportingTe settings } - protected val reporter = ProgressReporter.newInstance() + protected val reporter = ProgressReporter.newInstance(getClass.getName) override protected def getExternalSystemId: ProjectSystemId = SbtProjectSystem.Id diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala index 26451c24d4d..c4528f55018 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala @@ -18,7 +18,7 @@ import org.junit.experimental.categories.Category abstract class ScalaLibraryHighlightingTest extends ScalaLightCodeInsightFixtureTestAdapter { def testHighlightScalaLibrary(): Unit = { - val reporter = ProgressReporter.newInstance(reportSuccess = false) + val reporter = ProgressReporter.newInstance(getClass.getName, reportSuccess = false) val sources = ScalaLibraryLoader.ScalaRuntimeLoader(Sources).rootFiles.head VfsUtilCore.processFilesRecursively(sources, (vFile: VirtualFile) => { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalacTestdataHighlightingTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalacTestdataHighlightingTest.scala index b0e02ca857f..ea64abe2523 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalacTestdataHighlightingTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalacTestdataHighlightingTest.scala @@ -18,7 +18,7 @@ import org.junit.experimental.categories.Category @Category(Array(classOf[ScalacTests])) class ScalacTestdataHighlightingTest extends ScalacTestdataHighlightingTestBase { - override val reporter = ProgressReporter.newInstance(reportSuccess = false) + override val reporter = ProgressReporter.newInstance(getClass.getName, reportSuccess = false) override def filesToHighlight: Array[File] = { val testDataPath = TestUtils.getTestDataPath + "/scalacTests/pos/" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/ProgressReporter.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/ProgressReporter.scala index 746e74101b0..dbd12f017b4 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/ProgressReporter.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/ProgressReporter.scala @@ -16,7 +16,7 @@ trait ProgressReporter { } object ProgressReporter { - def newInstance(reportSuccess: Boolean = true): ProgressReporter = { - if (sys.env.contains("TEAMCITY_VERSION")) new TeamCityReporter(reportSuccess) else new ConsoleReporter + def newInstance(name: String, reportSuccess: Boolean = true): ProgressReporter = { + if (sys.env.contains("TEAMCITY_VERSION")) new TeamCityReporter(name, reportSuccess) else new ConsoleReporter } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/TeamCityReporter.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/TeamCityReporter.scala index fff5ed464ef..1192aa4bf9f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/TeamCityReporter.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/reporter/TeamCityReporter.scala @@ -7,7 +7,7 @@ import com.intellij.openapi.util.TextRange * @author mutcianm * @since 16.05.17. */ -class TeamCityReporter(reportSuccess: Boolean) extends ConsoleReporter { +class TeamCityReporter(name: String, reportSuccess: Boolean) extends ConsoleReporter { import TeamCityReporter._ protected var totalErrors = 0 @@ -17,7 +17,7 @@ class TeamCityReporter(reportSuccess: Boolean) extends ConsoleReporter { override def reportError(file: String, range: TextRange, message: String): Unit = { totalErrors += 1 val escaped = escapeTC(Option(message).getOrElse("")) - val testName = s"${getClass.getName}.${Option(file).getOrElse("UNKNOWN")}${Option(range).map(_.toString).getOrElse("(UNKNOWN)")}" + val testName = s"$name.${Option(file).getOrElse("UNKNOWN")}${Option(range).map(_.toString).getOrElse("(UNKNOWN)")}" tcPrint(s"testStarted name='$testName'") tcPrint(s"testFailed name='$testName' message='Highlighting error' details='$escaped'") tcPrint(s"testFinished name='$testName'") From ba46f06f60ddc04e76012d2a14f012448693e176 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 14:46:46 +0200 Subject: [PATCH 030/141] lowercase more SBT/Sbt strings --- .../plugins/scala/nailgun/NailgunRunner.java | 2 +- scala/scala-impl/resources/META-INF/SBT.xml | 16 ++++++++-------- .../sbt/ui/SbtArtifactChooseDependencyStep.scala | 2 +- .../sbt/project/modifier/BuildFileModifier.scala | 2 +- .../sbt/shell/SbtShellToolWindowFactory.scala | 2 +- .../sbt/shell/action/SbtShellStartAction.scala | 2 +- .../sbt/shell/action/shellWindowActions.scala | 8 ++++---- .../src/org/jetbrains/sbt/shell/language.scala | 6 +++--- .../sbt/shell/SbtProjectPlatformTestCase.scala | 4 +++- .../jetbrains/sbt/shell/UseSbtTestRunTest.scala | 4 ++-- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java b/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java index 82b761a8b3d..587c77600c8 100644 --- a/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java +++ b/scala/nailgun/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java @@ -15,7 +15,7 @@ public class NailgunRunner { private static final String SERVER_CLASS_NAME = "org.jetbrains.jps.incremental.scala.remote.Main"; private static final String SBT_WATCHER_ALIAS = "play-sbt-watcher"; - private static final String SBT_WATCHER_DESCRIPTION = "Play framework SBT watcher"; + private static final String SBT_WATCHER_DESCRIPTION = "Play framework sbt watcher"; private static final String SBT_WATCHER_CLASS_NAME = "org.jetbrains.jps.incremental.scala.remote.play.SbtWatcherMain"; private static final String STOP_ALIAS_START = "stop_"; diff --git a/scala/scala-impl/resources/META-INF/SBT.xml b/scala/scala-impl/resources/META-INF/SBT.xml index 2c66c099edf..58c960aa977 100644 --- a/scala/scala-impl/resources/META-INF/SBT.xml +++ b/scala/scala-impl/resources/META-INF/SBT.xml @@ -124,42 +124,42 @@ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala index 72e94cd1ff1..e47c745c241 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala @@ -12,7 +12,7 @@ class SbtArtifactChooseDependencyStep(wizard: SbtArtifactSearchWizard, artifactI extends SbtArtifactSearchPanel(wizard, artifactInfoSet) with Step { override def _init(): Unit = { - wizard.setTitle("Sbt Artifact Search") + wizard.setTitle("sbt artifact search") updateUI() } diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala index f074234b4b2..f74b5e7f150 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/modifier/BuildFileModifier.scala @@ -59,7 +59,7 @@ trait BuildFileModifier { res = false } } - }, "Sbt build file modification", this) + }, "sbt build file modification", this) if (res) ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(project, SbtProjectSystem.Id)) res diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala index d89733c4389..e4cc879c781 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala @@ -53,6 +53,6 @@ class SbtShellToolWindowFactory extends ToolWindowFactory with DumbAware { } object SbtShellToolWindowFactory { - val title = "sbt Shell" + val title = "sbt shell" val ID = "sbt-shell-toolwindow" } diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala index 6205d023341..ec7c742ff02 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala @@ -13,7 +13,7 @@ import org.jetbrains.sbt.shell.SbtProcessManager */ class SbtShellStartAction extends ExternalSystemAction { - setText("Run sbt Shell") + setText("Run sbt shell") override def update(e: AnActionEvent): Unit = { super.update(e) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala index 8867340848b..14c98d3a7ca 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/shellWindowActions.scala @@ -34,7 +34,7 @@ class RestartAction(project: Project) extends DumbAwareAction { val templatePresentation: Presentation = getTemplatePresentation templatePresentation.setIcon(AllIcons.Actions.Restart) - templatePresentation.setText("Restart sbt Shell") // TODO i18n / language-bundle + templatePresentation.setText("Restart sbt shell") // TODO i18n / language-bundle def actionPerformed(e: AnActionEvent): Unit = { val twm = ToolWindowManager.getInstance(project) @@ -49,7 +49,7 @@ class StopAction(project: Project) extends DumbAwareAction { copyFrom(ActionManager.getInstance.getAction(IdeActions.ACTION_STOP_PROGRAM)) val templatePresentation: Presentation = getTemplatePresentation templatePresentation.setIcon(AllIcons.Process.Stop) - templatePresentation.setText("Stop sbt Shell") // TODO i18n / language-bundle + templatePresentation.setText("Stop sbt shell") // TODO i18n / language-bundle templatePresentation.setDescription(null) override def actionPerformed(e: AnActionEvent): Unit = { @@ -89,10 +89,10 @@ class DebugShellAction(project: Project, remoteConnection: RemoteConnection) ext private val templatePresentation: Presentation = getTemplatePresentation templatePresentation.setIcon(AllIcons.Actions.StartDebugger) - templatePresentation.setText("Attach debugger to sbt Shell") + templatePresentation.setText("Attach debugger to sbt shell") private val configType = new RemoteConfigurationType - private val configName = "Debug sbt Shell" + private val configName = "Debug sbt shell" private val configFactory = configType.getFactory override def setSelected(e: AnActionEvent, toSet: Boolean): Unit = { diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala index 5e3594e37d0..3df0b29d72d 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/language.scala @@ -29,7 +29,7 @@ object SbtShellFileType extends LanguageFileType(SbtShellLanguage) { override def getDefaultExtension: String = "sbts" override def getName: String = "sbtShell" override def getIcon: Icon = Sbt.FileIcon - override def getDescription: String = "Sbt Shell file dummy" + override def getDescription: String = "sbt shell file dummy" } class SbtShellFileTypeFactory extends FileTypeFactory { @@ -40,8 +40,8 @@ class SbtShellFileTypeFactory extends FileTypeFactory { class SbtShellLexerAdapter extends FlexAdapter(new _SbtShellLexer) class SbtShellFile(viewProvider: FileViewProvider) extends PsiFileBase(viewProvider, SbtShellLanguage) { - override def getFileType = SbtShellFileType - override def toString: String = "Sbt Shell File" + override def getFileType: SbtShellFileType.type = SbtShellFileType + override def toString: String = "sbt shell file" } class SbtShellParserDefinition extends ParserDefinition { diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala index 76a00fafd0d..5800e82b3f6 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala @@ -23,7 +23,9 @@ import org.jetbrains.sbt.project.SbtProjectSystem abstract class SbtProjectPlatformTestCase extends PlatformTestCase { override def setUpProject(): Unit = { - // projectFile is the sbt file for the root project + //projectFile is the sbt file for the root project + val sbtRootFile = getSbtRootFile + assert(sbtRootFile.exists, "expected path does not exist: " + sbtRootFile.getAbsolutePath) val path = getSbtRootFile.getAbsolutePath val project = ProjectUtil.openOrImport(path, null, false) assert(project != null, s"project at path $path was null") diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index 54ebac34dd9..0d59181be28 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -138,8 +138,8 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { Await.ready(finished, 10.minutes) runner.getConsoleView.flushDeferredText() val log = logger.getLog - expectedStrings.foreach(str => assert(log.contains(str), s"Sbt shell console did not contain expected '$str'")) - unexpectedStrings.foreach(str => assert(!log.contains(str), s"Sbt shell console contained unexpected '$str'")) + expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'")) + unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'")) assert(!log.contains(SbtProjectPlatformTestCase.errorPrefix)) } } From 3b7511e710ce3e8a53ca11e9b6279508b70391cf Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 16:08:01 +0200 Subject: [PATCH 031/141] more test assertions --- .../sbt/shell/UseSbtTestRunTest.scala | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index 0d59181be28..f41ee5048cc 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -4,6 +4,7 @@ import com.intellij.execution.Executor import com.intellij.execution.executors.DefaultRunExecutor import com.intellij.execution.runners.ExecutionEnvironmentBuilder import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.roots.ProjectRootManager import org.jetbrains.plugins.scala.SlowTests import org.jetbrains.plugins.scala.testingSupport.ScalaTestingTestCase import org.jetbrains.plugins.scala.testingSupport.test.{AbstractTestRunConfiguration, TestRunConfigurationForm} @@ -129,17 +130,25 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { protected def runConfig(config: AbstractTestRunConfiguration, expectedStrings: Seq[String], unexpectedStrings: Seq[String], commandsExpected: Int = 1): Unit = { config.useSbt = true + val project = config.getProject + val sdk = ProjectRootManager.getInstance(project).getProjectSdk + assert(sdk != null, s"project sdk was null in project ${project.getName}") + val executor: Executor = Executor.EXECUTOR_EXTENSION_NAME.findExtension(classOf[DefaultRunExecutor]) val executionEnvironmentBuilder: ExecutionEnvironmentBuilder = - new ExecutionEnvironmentBuilder(config.getProject, executor) + new ExecutionEnvironmentBuilder(project, executor) executionEnvironmentBuilder.runProfile(config).buildAndExecute() // we can expect test to be done after additional reload completes, which also resets shell for the next test - val finished = SbtShellCommunication.forProject(config.project).command("reload") + val finished = SbtShellCommunication.forProject(project).command("reload") Await.ready(finished, 10.minutes) runner.getConsoleView.flushDeferredText() val log = logger.getLog - expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'")) - unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'")) - assert(!log.contains(SbtProjectPlatformTestCase.errorPrefix)) + expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'. Full log:\n$log")) + unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'. Full log:\n$log")) + val logSplitted = logLines(log) + val errorline = logSplitted.find(line => line contains SbtProjectPlatformTestCase.errorPrefix) + assert(errorline.isEmpty, s"log contained errors: $errorline") } + + private def logLines(log: String) = log.split("\n").toVector } From 9e44206b57b06536f3f993b43b2f1042dc24fb3e Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 16:51:24 +0200 Subject: [PATCH 032/141] cbt should use CbtProjectSystem, not sbt --- .../cbt/project/data/service/CbtModuleExtDataService.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala b/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala index 9f9d137573d..efc08cf11f2 100644 --- a/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala +++ b/cbt/src/org/jetbrains/plugins/cbt/project/data/service/CbtModuleExtDataService.scala @@ -6,9 +6,9 @@ import com.intellij.openapi.externalSystem.service.notification.{ExternalSystemN import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider import com.intellij.openapi.project.Project import com.intellij.openapi.roots.libraries.Library +import org.jetbrains.plugins.cbt.project.CbtProjectSystem import org.jetbrains.plugins.cbt.structure.CbtModuleExtData import org.jetbrains.plugins.scala.project.{LibraryExt, ModuleExt, Platform, ScalaLanguageLevel} -import org.jetbrains.sbt.project.SbtProjectSystem import org.jetbrains.sbt.project.data.service.{AbstractDataService, AbstractImporter, Importer} class CbtModuleExtDataService extends AbstractDataService[CbtModuleExtData, Library](CbtModuleExtData.Key) { @@ -28,7 +28,7 @@ object CbtModuleExtDataService { NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC) ExternalSystemNotificationManager.getInstance(project) - .showNotification(SbtProjectSystem.Id, notification) + .showNotification(CbtProjectSystem.Id, notification) } private class Importer(toImport: Seq[DataNode[CbtModuleExtData]], From 871d9c9666b931b41d87146f0f3e08d5fab62591 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 16:52:24 +0200 Subject: [PATCH 033/141] revert SbtProjectSystemId to SBT since changing it breaks project re-imports. Just changing readable name should cause less issues. External system will include a change to ignore the case in readable name. --- .../src/org/jetbrains/sbt/project/SbtProjectSystem.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala index cac7c6500ea..64f67da40dc 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectSystem.scala @@ -7,5 +7,5 @@ import com.intellij.openapi.externalSystem.model.ProjectSystemId * @author Pavel Fatin */ object SbtProjectSystem { - val Id = new ProjectSystemId("sbt", Sbt.Name) + val Id = new ProjectSystemId("SBT", Sbt.Name) } \ No newline at end of file From 80b6656cd7ea69626585da0830249269f91f27e0 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 23 Oct 2017 18:06:24 +0200 Subject: [PATCH 034/141] ensure LibraryLoader libraries are disposed --- .../plugins/scala/base/libraryLoaders/LibraryLoader.scala | 7 ++++--- .../scala/base/libraryLoaders/ScalaLibraryLoader.scala | 2 ++ .../base/libraryLoaders/ThirdPartyLibraryLoader.scala | 4 ++-- .../lang/completion3/ScalaCompletionSortingTestCase.scala | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala index 87699e78837..233657d215a 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala @@ -1,17 +1,18 @@ package org.jetbrains.plugins.scala.base.libraryLoaders +import com.intellij.openapi.Disposable import com.intellij.openapi.module.Module -import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl -import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager import org.jetbrains.plugins.scala.debugger.ScalaVersion /** * @author adkozlov */ -trait LibraryLoader { +trait LibraryLoader extends Disposable { implicit val module: Module def init(implicit version: ScalaVersion): Unit def clean(): Unit = {} + + override def dispose(): Unit = clean() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala index 94d7f191517..7b767369e8f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala @@ -5,6 +5,7 @@ import java.io.File import com.intellij.openapi.module.Module import com.intellij.openapi.projectRoots.{ProjectJdkTable, Sdk} import com.intellij.openapi.roots.libraries.Library +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile} import com.intellij.testFramework.PsiTestUtil import org.jetbrains.plugins.scala.ScalaLoader @@ -47,6 +48,7 @@ case class ScalaLibraryLoader(isIncludeReflectLibrary: Boolean = false) val srcRoots = ScalaRuntimeLoader(Sources).rootFiles library = PsiTestUtil.addProjectLibrary(module, "scala-sdk", classRoots.asJava, srcRoots.asJava) + Disposer.register(module, library) inWriteAction { library.convertToScalaSdkWith(languageLevel(files.head), files) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index 57cd1cc9a41..676c6e82e6c 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -6,7 +6,7 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.PsiTestUtil import org.jetbrains.plugins.scala.base.libraryLoaders.IvyLibraryLoader._ -import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_11, Scala_2_12} +import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_11} import org.jetbrains.plugins.scala.project.ModuleExt /** @@ -22,7 +22,7 @@ trait ThirdPartyLibraryLoader extends LibraryLoader { val file = new File(path).getCanonicalFile assert(file.exists(), s"library root for $name does not exist at $file") VfsRootAccess.allowRootAccess(path) - PsiTestUtil.addLibrary(module, path) + PsiTestUtil.addLibrary(this, module, name, path) } protected def path(implicit version: ScalaVersion): String diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala index 27f0df70758..53e78fd705e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaCompletionSortingTestCase.scala @@ -24,11 +24,12 @@ abstract class ScalaCompletionSortingTestCase extends LightFixtureCompletionTest } } - override def tearDown() { + override def tearDown(): Unit = try { LookupManager.getInstance(getProject).hideActiveLookup() UISettings.getInstance.setSortLookupElementsLexicographically(false) CodeInsightSettings.getInstance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + } finally { super.tearDown() } From 054f3ab772cbabfd206c95157bb375ead647fc87 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 24 Oct 2017 01:03:28 +0200 Subject: [PATCH 035/141] fix disposal of paths in libraryloaders --- .../src/org/jetbrains/plugins/scala/ScalaLoader.java | 6 +++--- .../test/utest/UTestConfigurationProducer.scala | 2 +- .../plugins/scala/base/libraryLoaders/LibraryLoader.scala | 5 +++-- .../scala/base/libraryLoaders/ScalaLibraryLoader.scala | 6 ++++-- .../scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala | 3 ++- .../utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java b/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java index 7f368da06f8..37359afca01 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/ScalaLoader.java @@ -56,10 +56,10 @@ public static void loadScala() { ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() { public void projectOpened(Project project) { - CompilerManager compilerManager = CompilerManager.getInstance(project); - compilerManager.addCompilableFileType(ScalaFileType.INSTANCE); + CompilerManager compilerManager = CompilerManager.getInstance(project); + compilerManager.addCompilableFileType(ScalaFileType.INSTANCE); - DebuggerManager.getInstance(project).addClassNameMapper(new ScalaJVMNameMapper()); + DebuggerManager.getInstance(project).addClassNameMapper(new ScalaJVMNameMapper()); } }); } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala index 667b8555fd0..d85851d9762 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/utest/UTestConfigurationProducer.scala @@ -145,7 +145,7 @@ class UTestConfigurationProducer extends { } //this is checked once we provide a concrete class for test run // if (!containingObject.isInstanceOf[ScObject]) return fail - if (!suitePaths.exists(suitePath => TestConfigurationUtil.isInheritor(containingObject, suitePath))) return (null, null) + if (!suitePaths.exists(suitePath => TestConfigurationUtil.isInheritor(containingObject, suitePath))) return fail val nameContainer = ScalaPsiUtil.getParentWithProperty(element, strict = false, e => TestNodeProvider.isUTestInfixExpr(e) || TestNodeProvider.isUTestSuiteApplyCall(e) || diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala index 233657d215a..fbf26294aa0 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala @@ -2,6 +2,7 @@ package org.jetbrains.plugins.scala.base.libraryLoaders import com.intellij.openapi.Disposable import com.intellij.openapi.module.Module +import com.intellij.openapi.util.Disposer import org.jetbrains.plugins.scala.debugger.ScalaVersion /** @@ -12,7 +13,7 @@ trait LibraryLoader extends Disposable { def init(implicit version: ScalaVersion): Unit - def clean(): Unit = {} + def clean(): Unit = dispose() - override def dispose(): Unit = clean() + override def dispose(): Unit = Disposer.dispose(this) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala index 7b767369e8f..ed74c60da68 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala @@ -4,7 +4,8 @@ import java.io.File import com.intellij.openapi.module.Module import com.intellij.openapi.projectRoots.{ProjectJdkTable, Sdk} -import com.intellij.openapi.roots.libraries.Library +import com.intellij.openapi.roots.OrderRootType +import com.intellij.openapi.roots.libraries.{Library, LibraryTable} import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile} import com.intellij.testFramework.PsiTestUtil @@ -34,6 +35,7 @@ case class ScalaLibraryLoader(isIncludeReflectLibrary: Boolean = false) if (library != null) { inWriteAction { module.detach(library) + library.getTable.removeLibrary(library) } } } @@ -42,7 +44,7 @@ case class ScalaLibraryLoader(isIncludeReflectLibrary: Boolean = false) val loaders = Seq(ScalaCompilerLoader(), ScalaRuntimeLoader()) ++ (if (isIncludeReflectLibrary) Seq(ScalaReflectLoader()) else Seq.empty) - val files = loaders.map(_.path).map(new File(_)) + val files = loaders.map(loader => new File(loader.path)) val classRoots = loaders.flatMap(_.rootFiles) val srcRoots = ScalaRuntimeLoader(Sources).rootFiles diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index 676c6e82e6c..abf15e0b5de 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -3,6 +3,7 @@ package org.jetbrains.plugins.scala.base.libraryLoaders import java.io.File import com.intellij.openapi.module.Module +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.PsiTestUtil import org.jetbrains.plugins.scala.base.libraryLoaders.IvyLibraryLoader._ @@ -22,7 +23,7 @@ trait ThirdPartyLibraryLoader extends LibraryLoader { val file = new File(path).getCanonicalFile assert(file.exists(), s"library root for $name does not exist at $file") VfsRootAccess.allowRootAccess(path) - PsiTestUtil.addLibrary(this, module, name, path) + PsiTestUtil.addLibrary(this, module, file.getName, file.getParent, file.getName) } protected def path(implicit version: ScalaVersion): String diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala index 2808615759e..93997472912 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala @@ -36,7 +36,7 @@ class UTestStaticStringTest_2_11_0_5_4 extends UTestTestBase_2_11_0_5_4 with UTe checkTestsTest(6, 6, "foo") } - protected def checkTestsTest(lineNumber: Int, position: Int, expectedName: String) = { + protected def checkTestsTest(lineNumber: Int, position: Int, expectedName: String): Unit = { assert(checkConfigAndSettings(createTestFromLocation(lineNumber, position, testsTestFileName), testsTestName, "tests" + (if (expectedName.isEmpty) "" else "\\" + expectedName))) } From f0a5c6f76f8a4b4c274ea7cc4b65f1adb3b911d8 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 24 Oct 2017 02:37:33 +0200 Subject: [PATCH 036/141] maybe prevent projects leaking by registering library loaders for disposal --- .../ScalaLightPlatformCodeInsightTestCaseAdapter.java | 8 +++++--- .../plugins/scala/base/libraryLoaders/LibraryLoader.scala | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java index 3ceb24142b8..697399373bc 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java @@ -120,7 +120,6 @@ protected void setUp() throws Exception { super.setUp(); TestUtils.disableTimerThread(); - //libLoader.clean(); } protected void setUpWithoutScalaLib() throws Exception { @@ -174,7 +173,10 @@ protected void configureFromFileTextAdapter(@NonNls final String fileName, @Override protected void tearDown() throws Exception { - tearDownLibraries(); - super.tearDown(); + try { + tearDownLibraries(); + } finally { + super.tearDown(); + } } } \ No newline at end of file diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala index fbf26294aa0..b7a5b54cf6f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala @@ -10,6 +10,7 @@ import org.jetbrains.plugins.scala.debugger.ScalaVersion */ trait LibraryLoader extends Disposable { implicit val module: Module + Disposer.register(module,this) def init(implicit version: ScalaVersion): Unit From 4734326037f9f44faee4f87d06ed54553e5df756 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 24 Oct 2017 03:22:09 +0200 Subject: [PATCH 037/141] wait for process exit in sbt shell tests. should fix race condition where a command was used to determine test run config completion --- .../jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala | 7 ++++++- .../test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala index 5800e82b3f6..b6b68246af1 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala @@ -17,6 +17,8 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.util.TestUtils import org.jetbrains.sbt.project.SbtProjectSystem +import scala.concurrent.{Future, Promise} + /** * Created by Roman.Shein on 27.03.2017. */ @@ -98,14 +100,17 @@ object SbtProjectPlatformTestCase { class ProcessLogger extends ProcessListener { private val logBuilder: StringBuilder = new StringBuilder() + private val termination = Promise.apply[Int]() def getLog: String = logBuilder.mkString + def terminated: Future[Int] = termination.future override def processWillTerminate(event: ProcessEvent, willBeDestroyed: Boolean): Unit = {} override def startNotified(event: ProcessEvent): Unit = {} - override def processTerminated(event: ProcessEvent): Unit = {} + override def processTerminated(event: ProcessEvent): Unit = + termination.success(event.getExitCode) override def onTextAvailable(event: ProcessEvent, outputType: Key[_]): Unit = { synchronized { logBuilder.append(event.getText) } diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index f41ee5048cc..f5016370cd9 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -138,11 +138,10 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { val executionEnvironmentBuilder: ExecutionEnvironmentBuilder = new ExecutionEnvironmentBuilder(project, executor) executionEnvironmentBuilder.runProfile(config).buildAndExecute() - // we can expect test to be done after additional reload completes, which also resets shell for the next test - val finished = SbtShellCommunication.forProject(project).command("reload") - Await.ready(finished, 10.minutes) runner.getConsoleView.flushDeferredText() + val exitCode = Await.result(logger.terminated, 10.minutes) val log = logger.getLog + assert(exitCode != 0, "sbt shell completed with nonzero exit code. Full log:\n$log") expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'. Full log:\n$log")) unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'. Full log:\n$log")) val logSplitted = logLines(log) From 8860d4621394b9207a0416b0d0f2388d7ae16006 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 24 Oct 2017 04:29:02 +0200 Subject: [PATCH 038/141] concrete tests need librariesLoaders as val --- .../scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala | 4 ---- .../scala/lang/libraryInjector/LibraryInjectorTest.scala | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala index 3f94af671c0..4c02f358b95 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala @@ -30,10 +30,6 @@ abstract class ScalaLightCodeInsightFixtureTestAdapter JdkLoader() ) - override protected def setUp(): Unit = { - super.setUp() - } - override protected def getProjectDescriptor = new DelegatingProjectDescriptor(super.getProjectDescriptor) { override def setUpProject(project: Project, handler: LightProjectDescriptor.SetupHandler) = { super.setUpProject(project, handler) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala index 87fcac2e77b..d24d9e5fdea 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala @@ -29,7 +29,7 @@ class LibraryInjectorTest extends ModuleTestCase with ScalaSdkOwner { override implicit protected def module: Module = getModule - override protected def librariesLoaders: Seq[LibraryLoader] = Seq( + override protected lazy val librariesLoaders: Seq[LibraryLoader] = Seq( ScalaLibraryLoader(isIncludeReflectLibrary = true), JdkLoader(getTestProjectJdk), SourcesLoader(project.getBasePath), From 42f8477f15d02ca662cff2193e220412e04bfc4c Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Wed, 25 Oct 2017 10:49:34 +0300 Subject: [PATCH 039/141] package output of scala-impl and cbt modules only once #SCL-12794 --- build.sbt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 7b7b5fc2262..01a260e6a97 100644 --- a/build.sbt +++ b/build.sbt @@ -253,6 +253,15 @@ lazy val iLoopWrapperPath = settingKey[File]("Path to repl interface sources") iLoopWrapperPath := baseDirectory.in(compilerJps).value / "resources" / "ILoopWrapperImpl.scala" +//packages output of several modules to a single jar +lazy val scalaPluginJarPackager = + newProject("scalaPluginJarPackager", file("target/tools/scalaPluginJarPackager")) + .settings( + products in Compile := + products.in(scalaImpl, Compile).value ++ + products.in(cbt, Compile).value, + ideSkipProject := true + ) lazy val pluginPackagerCommunity = newProject("pluginPackagerCommunity", file("target/tools/packager")) @@ -301,9 +310,7 @@ lazy val pluginPackagerCommunity = "launcher/sbt-launch.jar") ) val lib = Seq( - MergedArtifact(Seq( - pack.in(scalaImpl, Compile).value, - pack.in(cbt, Compile).value), + Artifact(pack.in(scalaPluginJarPackager, Compile).value, "lib/scala-plugin.jar"), Artifact(pack.in(decompiler, Compile).value, "lib/scalap.jar"), From be4e419f53153f6483889ef575eb6bd54d40d807 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Wed, 25 Oct 2017 12:44:56 +0200 Subject: [PATCH 040/141] another attempt at getting tests to dispose libraries completely and only once because why should it be idempotent when we can throw exceptions everywhere --- .../base/DisposableScalaLibraryLoader.scala | 3 --- .../scala/base/ScalaFixtureTestCase.scala | 2 +- ...laLightCodeInsightFixtureTestAdapter.scala | 19 ++++++++++--------- ...ghtPlatformCodeInsightTestCaseAdapter.java | 12 +----------- .../base/libraryLoaders/LibraryLoader.scala | 5 +---- .../libraryLoaders/ScalaLibraryLoader.scala | 9 ++++----- .../base/libraryLoaders/SourcesLoader.scala | 2 +- .../ThirdPartyLibraryLoader.scala | 2 +- .../ScalaInspectionTestBase.scala | 2 -- .../scala/debugger/DebuggerTestUtil.scala | 2 +- .../debugger/ScalaCompilerTestBase.scala | 4 +++- .../debugger/ScalaDebuggerTestBase.scala | 10 +++------- .../plugins/scala/debugger/ScalaVersion.scala | 16 ++++++++++++---- .../libraryInjector/LibraryInjectorTest.scala | 4 +--- .../WorksheetProcessorTestBase.scala | 5 ----- .../scala/memoryLeaks/MemoryLeakTest.scala | 1 - ...ighlightingPerformanceTypingTestBase.scala | 2 +- .../scala/testcases/FileSetTestCase.java | 1 + .../sbt/annotator/SbtAnnotatorTest.scala | 6 ++++++ .../annotations/MetaAnnotationJarTest.scala | 2 +- .../annotations/MetaAnnotationTestBase.scala | 2 +- 21 files changed, 49 insertions(+), 62 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/DisposableScalaLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/DisposableScalaLibraryLoader.scala index 7b7507c8b68..9ce3e14490a 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/DisposableScalaLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/DisposableScalaLibraryLoader.scala @@ -24,7 +24,4 @@ class DisposableScalaLibraryLoader(implicit project: ProjectContext, module: Mod jdkLoader.init } - override def clean(): Unit = {} - - override def dispose(): Unit = clean() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaFixtureTestCase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaFixtureTestCase.scala index ec9771d1bd7..f5b2b2bb17d 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaFixtureTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaFixtureTestCase.scala @@ -28,7 +28,7 @@ abstract class ScalaFixtureTestCase } override def tearDown(): Unit = { - tearDownLibraries() + disposeLibraries() super.tearDown() } } \ No newline at end of file diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala index 4c02f358b95..d86f6ae966a 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestAdapter.scala @@ -30,14 +30,15 @@ abstract class ScalaLightCodeInsightFixtureTestAdapter JdkLoader() ) - override protected def getProjectDescriptor = new DelegatingProjectDescriptor(super.getProjectDescriptor) { - override def setUpProject(project: Project, handler: LightProjectDescriptor.SetupHandler) = { - super.setUpProject(project, handler) - WriteAction.run(() => { - afterSetUpProject() - }) + override protected def getProjectDescriptor = + new DelegatingProjectDescriptor(super.getProjectDescriptor) { + override def setUpProject(project: Project, handler: LightProjectDescriptor.SetupHandler): Unit = { + super.setUpProject(project, handler) + WriteAction.run(() => { + afterSetUpProject() + }) + } } - } protected def afterSetUpProject(): Unit = { if (loadScalaLibrary) { @@ -46,8 +47,8 @@ abstract class ScalaLightCodeInsightFixtureTestAdapter } } - protected override def tearDown() = { - tearDownLibraries() + override def tearDown(): Unit = { + disposeLibraries() super.tearDown() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java index 697399373bc..6235681fea4 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java @@ -108,12 +108,6 @@ protected void afterSetUpProject() { setUpLibraries(); } - @Override - public void tearDownLibraries() { - for (LibraryLoader libraryLoader : librariesLoadersAdapter()) { - libraryLoader.clean(); - } - } @Override protected void setUp() throws Exception { @@ -122,10 +116,6 @@ protected void setUp() throws Exception { TestUtils.disableTimerThread(); } - protected void setUpWithoutScalaLib() throws Exception { - super.setUp(); - } - protected boolean isIncludeReflectLibrary() { return false; } @@ -174,7 +164,7 @@ protected void configureFromFileTextAdapter(@NonNls final String fileName, @Override protected void tearDown() throws Exception { try { - tearDownLibraries(); + disposeLibraries(); } finally { super.tearDown(); } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala index b7a5b54cf6f..1563bfa3ac9 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/LibraryLoader.scala @@ -10,11 +10,8 @@ import org.jetbrains.plugins.scala.debugger.ScalaVersion */ trait LibraryLoader extends Disposable { implicit val module: Module - Disposer.register(module,this) def init(implicit version: ScalaVersion): Unit - def clean(): Unit = dispose() - - override def dispose(): Unit = Disposer.dispose(this) + override def dispose(): Unit = () } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala index ed74c60da68..43285e3b6ae 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ScalaLibraryLoader.scala @@ -4,8 +4,7 @@ import java.io.File import com.intellij.openapi.module.Module import com.intellij.openapi.projectRoots.{ProjectJdkTable, Sdk} -import com.intellij.openapi.roots.OrderRootType -import com.intellij.openapi.roots.libraries.{Library, LibraryTable} +import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile} import com.intellij.testFramework.PsiTestUtil @@ -31,7 +30,7 @@ case class ScalaLibraryLoader(isIncludeReflectLibrary: Boolean = false) addScalaSdk } - override def clean(): Unit = { + override def dispose(): Unit = { if (library != null) { inWriteAction { module.detach(library) @@ -81,7 +80,7 @@ object ScalaLibraryLoader { Option(fileSystem.refreshAndFindFileByPath(s"$path!/")).toSeq } - override def init(implicit version: ScalaVersion): Unit = {} + override def init(implicit version: ScalaVersion): Unit = () override def folder(implicit version: ScalaVersion): String = name @@ -130,7 +129,7 @@ case class JdkLoader(jdk: Sdk = TestUtils.createJdk()) } } - override def clean(): Unit = { + override def dispose(): Unit = { val model = module.modifiableModel model.setSdk(null) inWriteAction { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/SourcesLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/SourcesLoader.scala index 7ca37499547..a2dbf5ebf59 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/SourcesLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/SourcesLoader.scala @@ -19,7 +19,7 @@ case class SourcesLoader(rootPath: String) PsiTestUtil.addSourceRoot(module, rootFile) } - override def clean(): Unit = { + override def dispose(): Unit = { PsiTestUtil.removeSourceRoot(module, rootFile) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index abf15e0b5de..68a9997c23d 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -23,7 +23,7 @@ trait ThirdPartyLibraryLoader extends LibraryLoader { val file = new File(path).getCanonicalFile assert(file.exists(), s"library root for $name does not exist at $file") VfsRootAccess.allowRootAccess(path) - PsiTestUtil.addLibrary(this, module, file.getName, file.getParent, file.getName) + PsiTestUtil.addLibrary(this, module, name, file.getParent, file.getName) } protected def path(implicit version: ScalaVersion): String diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/ScalaInspectionTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/ScalaInspectionTestBase.scala index 8749ed193ae..77b50f16046 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/ScalaInspectionTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/ScalaInspectionTestBase.scala @@ -46,8 +46,6 @@ abstract class ScalaInspectionTestBase extends ScalaLightCodeInsightFixtureTestA fixture.configureByText("dummy.scala", normalizedText) fixture.enableInspections(classOfInspection) - val description = normalize(this.description) - fixture.doHighlighting().asScala .filter(it => descriptionMatches(it.getDescription)) .map(info => (info, highlightedRange(info))) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/DebuggerTestUtil.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/DebuggerTestUtil.scala index dba1b8be7a0..4d6091f8c6f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/DebuggerTestUtil.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/DebuggerTestUtil.scala @@ -71,7 +71,7 @@ object DebuggerTestUtil { Option(new File(path)) .filter(_.exists()) .flatMap(_.listFiles() - .sortBy(_.getName) + .sortBy(_.getName) // TODO somehow sort by release number to get the newest actually .reverse .find(f => f.getName.contains(suffix) && isJDK(new File(f, postfix))) .map(new File(_, s"$postfix/jre").getAbsolutePath) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala index dfe442b3708..d3a65113340 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala @@ -35,6 +35,8 @@ abstract class ScalaCompilerTestBase extends ModuleTestCase with ScalaSdkOwner { override def setUp(): Unit = { super.setUp() + setUpLibraries() + // uncomment to enable debugging of compile server in tests // BuildManager.getInstance().setBuildProcessDebuggingEnabled(true) // com.intellij.openapi.util.registry.Registry.get("compiler.process.debug.port").setValue(5006) @@ -100,7 +102,7 @@ abstract class ScalaCompilerTestBase extends ModuleTestCase with ScalaSdkOwner { CompilerTestUtil.disableExternalCompiler(myProject) CompileServerLauncher.instance.stop() - tearDownLibraries() + disposeLibraries() } finally { ScalaCompilerTestBase.super.tearDown() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestBase.scala index 0d86d6a392f..536025ec904 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestBase.scala @@ -42,13 +42,9 @@ abstract class ScalaDebuggerTestBase extends ScalaCompilerTestBase { if (testDataProjectPath.exists()) FileUtil.delete(testDataProjectPath) } - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable[Throwable] { - - def run() { - ScalaDebuggerTestBase.super.setUp() - checkOrAddAllSourceFiles() - setUpLibraries() - } + EdtTestUtil.runInEdtAndWait(() => { + ScalaDebuggerTestBase.super.setUp() + checkOrAddAllSourceFiles() }) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala index 25c80af41a1..f52337efed8 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala @@ -2,6 +2,7 @@ package org.jetbrains.plugins.scala.debugger import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Disposer import org.jetbrains.plugins.scala.TestFixtureProvider import org.jetbrains.plugins.scala.base.libraryLoaders.LibraryLoader @@ -47,11 +48,18 @@ trait ScalaSdkOwner { protected def librariesLoaders: Seq[LibraryLoader] - protected def setUpLibraries(): Unit = - librariesLoaders.foreach(_.init) + private lazy val myLoaders = librariesLoaders + + protected def setUpLibraries(): Unit = { + myLoaders.foreach { loader => + loader.init + } + } + + protected def disposeLibraries(): Unit = { + myLoaders.foreach(Disposer.dispose) + } - protected def tearDownLibraries(): Unit = - librariesLoaders.foreach(_.clean()) } // Java compatibility diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala index d24d9e5fdea..11d00fb7031 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/libraryInjector/LibraryInjectorTest.scala @@ -45,15 +45,13 @@ class LibraryInjectorTest extends ModuleTestCase with ScalaSdkOwner { CompilerTestUtil.enableExternalCompiler() DebuggerTestUtil.enableCompileServer(true) DebuggerTestUtil.forceJdk8ForBuildProcess() - - setUpLibraries() } protected override def tearDown() { + disposeLibraries() CompilerTestUtil.disableExternalCompiler(getProject) CompileServerLauncher.instance.stop() - tearDownLibraries() super.tearDown() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/worksheet/WorksheetProcessorTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/worksheet/WorksheetProcessorTestBase.scala index 6ab9fb16fab..cdce06fc66e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/worksheet/WorksheetProcessorTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/worksheet/WorksheetProcessorTestBase.scala @@ -21,11 +21,6 @@ import org.junit.Assert.assertNotNull */ abstract class WorksheetProcessorTestBase extends ScalaCompilerTestBase { - override def setUp(): Unit = { - super.setUp() - setUpLibraries() - } - override protected def useCompileServer: Boolean = true import WorksheetProcessorTestBase._ diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/memoryLeaks/MemoryLeakTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/memoryLeaks/MemoryLeakTest.scala index d5445be320a..652fbe8ff56 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/memoryLeaks/MemoryLeakTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/memoryLeaks/MemoryLeakTest.scala @@ -84,7 +84,6 @@ class MemoryLeakTest extends PlatformTestCase { } private def closeAndDispose(implicit project: ProjectContext): Unit = { - librariesLoaders.foreach(_.clean()) ProjectManagerEx.getInstanceEx.closeAndDispose(project) assertFalse(project.isOpen) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/highlighting/projectHighlighting/RehighlightingPerformanceTypingTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/highlighting/projectHighlighting/RehighlightingPerformanceTypingTestBase.scala index 3a5697b9b91..703bb94de88 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/highlighting/projectHighlighting/RehighlightingPerformanceTypingTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/performance/highlighting/projectHighlighting/RehighlightingPerformanceTypingTestBase.scala @@ -56,7 +56,7 @@ abstract class RehighlightingPerformanceTypingTestBase extends DownloadingAndImp myCodeInsightTestFixture.tearDown() myCodeInsightTestFixture = null - tearDownLibraries() + disposeLibraries() super.tearDown() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testcases/FileSetTestCase.java b/scala/scala-impl/test/org/jetbrains/plugins/scala/testcases/FileSetTestCase.java index a0ef653f323..999105c7e52 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testcases/FileSetTestCase.java +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testcases/FileSetTestCase.java @@ -105,6 +105,7 @@ public ActualTest(File testFile) { myTestFile = testFile; } + @Override protected void setUp() throws Exception { super.setUp(); FileSetTestCase.this.setUp(getProject()); diff --git a/scala/scala-impl/test/org/jetbrains/sbt/annotator/SbtAnnotatorTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/annotator/SbtAnnotatorTest.scala index 61065e70be6..40bd88cf657 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/annotator/SbtAnnotatorTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/annotator/SbtAnnotatorTest.scala @@ -51,6 +51,12 @@ abstract class SbtAnnotatorTestBase extends AnnotatorTestBase with MockSbtBase { } } + override def tearDown(): Unit = try { + disposeLibraries() + } finally { + super.tearDown() + } + override def loadTestFile(): SbtFileImpl = { val fileName = "SbtAnnotator.sbt" val filePath = testdataPath + fileName diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest.scala index 182354b3cec..5f0e431c742 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest.scala @@ -40,7 +40,7 @@ class MetaAnnotationJarTest extends JavaCodeInsightFixtureTestCase with ScalaMet } override def tearDown(): Unit = try { - tearDownLibraries() + disposeLibraries() } finally { inWriteAction { val projectJdkTable = ProjectJdkTable.getInstance() diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala index a8e834f5dfa..4b49719b0d4 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala @@ -82,7 +82,7 @@ abstract class MetaAnnotationTestBase extends JavaCodeInsightFixtureTestCase wit } override def tearDown(): Unit = try { - tearDownLibraries() + disposeLibraries() inWriteAction { val jdkTable = ProjectJdkTable.getInstance() From dd167ddf43588ce40241fe165f458b1041d32119 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Wed, 25 Oct 2017 13:25:40 +0200 Subject: [PATCH 041/141] fix test compilation --- .../completeStatement/ScalaCompleteStatementTestBase.scala | 2 +- .../scala/lang/completion3/ScalaClassNameCompletionTest.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completeStatement/ScalaCompleteStatementTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completeStatement/ScalaCompleteStatementTestBase.scala index 98b20dcbaa5..dc6307dfc39 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completeStatement/ScalaCompleteStatementTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completeStatement/ScalaCompleteStatementTestBase.scala @@ -32,7 +32,7 @@ abstract class ScalaCompleteStatementTestBase extends ScalaLightCodeInsightFixtu getCurrentCodeStyleSettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true } - override protected def tearDown(): Unit = { + override def tearDown(): Unit = { getCurrentCodeStyleSettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false super.tearDown() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaClassNameCompletionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaClassNameCompletionTest.scala index 8c148877cc3..2bc61379299 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaClassNameCompletionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaClassNameCompletionTest.scala @@ -197,7 +197,7 @@ class ImportsWithPrefixCompletionTest extends ScalaClassNameCompletionTest { settings.setImportsWithPrefix(Array.empty) } - override protected def tearDown(): Unit = { + override def tearDown(): Unit = { codeStyleSettings.setImportsWithPrefix(importsWithPrefix) super.tearDown() @@ -243,7 +243,7 @@ class FullQualifiedImportsCompletionTest extends ScalaClassNameCompletionTest { settings.setAddFullQualifiedImports(false) } - override protected def tearDown(): Unit = { + override def tearDown(): Unit = { codeStyleSettings.setAddFullQualifiedImports(isAddFullQualifiedImports) super.tearDown() From 19484879e9796c254573734e14251cafdb97e8e3 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Wed, 25 Oct 2017 13:52:06 +0200 Subject: [PATCH 042/141] fix NPE in compiler test setup --- .../plugins/scala/debugger/ScalaCompilerTestBase.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala index d3a65113340..d3dbed056ca 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaCompilerTestBase.scala @@ -35,8 +35,6 @@ abstract class ScalaCompilerTestBase extends ModuleTestCase with ScalaSdkOwner { override def setUp(): Unit = { super.setUp() - setUpLibraries() - // uncomment to enable debugging of compile server in tests // BuildManager.getInstance().setBuildProcessDebuggingEnabled(true) // com.intellij.openapi.util.registry.Registry.get("compiler.process.debug.port").setValue(5006) @@ -53,6 +51,7 @@ abstract class ScalaCompilerTestBase extends ModuleTestCase with ScalaSdkOwner { compilerVmOptions.foreach(setCompilerVmOptions) DebuggerTestUtil.enableCompileServer(useCompileServer) DebuggerTestUtil.forceJdk8ForBuildProcess() + setUpLibraries() } protected def compilerVmOptions: Option[String] = None From a7b37923bc44eca1e19488d5f5a99b42bc6899ce Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 25 Oct 2017 15:35:26 +0300 Subject: [PATCH 043/141] speed up merging jar files by bypassing FS --- project/Packaging.scala | 42 +++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/project/Packaging.scala b/project/Packaging.scala index 461c76d8f83..555558d6061 100644 --- a/project/Packaging.scala +++ b/project/Packaging.scala @@ -1,4 +1,5 @@ -import java.io.File +import java.io._ +import java.util.zip.{ZipInputStream, ZipOutputStream} import sbt.Keys._ import sbt._ @@ -110,12 +111,41 @@ object Packaging { } } - private def mergeIntoTemporaryJar(filesToMerge: File*): File = - IO.withTemporaryDirectory { tmp => - filesToMerge.foreach(IO.unzip(_, tmp)) + private def mergeIntoTemporaryJar(filesToMerge: File*): File = { val zipFile = File.createTempFile("sbt-merge-result",".jar", IO.temporaryDirectory) - zipFile.delete() - IO.zip((tmp ***) pair (relativeTo(tmp), false), zipFile) + fastMerge(filesToMerge, zipFile) zipFile } + + def copyZipContent(input: File, outStream: ZipOutputStream): Unit = { + val inStream = new ZipInputStream(new BufferedInputStream(new FileInputStream(input))) + try { + val buffer = new Array[Byte](64 * 1024) + var entry = inStream.getNextEntry + while (entry != null) { + try { + outStream.putNextEntry(entry) + var numRead = inStream.read(buffer) + while (numRead > 0) { + outStream.write(buffer, 0, numRead) + numRead = inStream.read(buffer) + } + outStream.closeEntry() + } catch { + case e: IOException => println(s"$e") + } + entry = inStream.getNextEntry + } + } finally { if (inStream != null) inStream.close() } + } + + def fastMerge(input: Seq[File], output: File): Unit = { + val outStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(output))) + try { + for (file <- input) { + copyZipContent(file, outStream) + } + } finally { if (outStream != null) outStream.close() } + } + } From 367e1bc767629f8ca4953d1b70c685ec3044fc3d Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 25 Oct 2017 15:40:28 +0300 Subject: [PATCH 044/141] filter artifacts based on current scala version --- .../intention/sbt/AddSbtDependencyFix.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index f86eeaa1344..c6fa4dfac07 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -1,11 +1,13 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt +import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator import com.intellij.codeInsight.intention.{IntentionAction, LowPriorityAction} import com.intellij.openapi.editor.Editor import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder import com.intellij.openapi.externalSystem.util.{ExternalSystemApiUtil, ExternalSystemUtil} import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.module.{ModuleManager, ModuleUtilCore} +import com.intellij.openapi.progress.{ProgressIndicator, ProgressManager, Task} import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.{PsiElement, PsiFile, PsiManager} @@ -16,9 +18,10 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr import org.jetbrains.plugins.scala.lang.psi.api.statements.ScPatternDefinition +import org.jetbrains.plugins.scala.project.ModuleExt import org.jetbrains.sbt.Sbt import org.jetbrains.sbt.project.SbtProjectSystem -import org.jetbrains.sbt.resolvers.SbtResolver +import org.jetbrains.sbt.resolvers.{ArtifactInfo, SbtResolver} import org.jetbrains.sbt.settings.SbtSystemSettings /** @@ -37,6 +40,10 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio override def getText: String = "Add sbt dependency..." override def invoke(project: Project, editor: Editor, file: PsiFile): Unit = { + def filterByScalaVer(artifacts: Set[ArtifactInfo]): Set[ArtifactInfo] = { + val scalaVer = refElement.module.flatMap(_.scalaSdk.map(_.languageLevel.version)) + scalaVer.map(version => artifacts.filter(_.artifactId.endsWith(version))).getOrElse(artifacts) + } val baseDir: VirtualFile = project.getBaseDir val sbtFileOpt: Option[VirtualFile] = { val buildSbt = baseDir.findChild(Sbt.BuildFile) @@ -54,7 +61,8 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio artifactInfoSet = ivyIndex.searchArtifactInfo(getReferenceText) psiSbtFile = PsiManager.getInstance(project).findFile(sbtFile).asInstanceOf[ScalaFile] depPlaces = getDependencyPlaces(project, psiSbtFile) - wizard = new SbtArtifactSearchWizard(project, artifactInfoSet, depPlaces) + matchingScala = filterByScalaVer(artifactInfoSet) + wizard = new SbtArtifactSearchWizard(project, matchingScala, depPlaces) (infoOption, fileLineOption) = wizard.search() artifactInfo <- infoOption fileLine <- fileLineOption From 09ee40d750e13a03890b4e7093c98d4d092615a2 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 25 Oct 2017 15:29:54 +0300 Subject: [PATCH 045/141] unnecessary implicits removed #SCL-12743 --- .../lang/psi/types/result/TypeResult.scala | 33 ++++++++++++------- .../scala/lang/psi/types/result/package.scala | 9 ----- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala index ce35a17f82f..c27a9e34bed 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.project.ProjectContext /** * @author ilyas */ -sealed abstract class TypeResult[+T <: ScType](implicit val projectContext: ProjectContext) { +sealed abstract class TypeResult[+T <: ScType] { def map[U <: ScType](f: T => U): TypeResult[U] @@ -24,6 +24,10 @@ sealed abstract class TypeResult[+T <: ScType](implicit val projectContext: Proj def isEmpty: Boolean + def getOrNothing: ScType + + def getOrAny: ScType + final def isDefined: Boolean = !isEmpty final def exists(f: T => Boolean): Boolean = withFilter(f).isDefined @@ -34,21 +38,21 @@ sealed abstract class TypeResult[+T <: ScType](implicit val projectContext: Proj } object TypeResult { - def fromOption(o: Option[ScType]) - (implicit pc: ProjectContext): TypeResult[ScType] = o match { - case Some(t) => Success(t) + def fromOption(maybeType: Option[ScType]) + (implicit context: ProjectContext): TypeResult[ScType] = maybeType match { + case Some(scType) => Success(scType) case None => Failure("") } } -class Success[T <: ScType] private(private val result: T) - (implicit context: ProjectContext) extends TypeResult[T] { +final class Success[T <: ScType] private(private val result: T) extends TypeResult[T] { def map[U <: ScType](f: T => U): Success[U] = Success(f(result)) def flatMap[U <: ScType](f: T => TypeResult[U]): TypeResult[U] = f(result) - def withFilter(f: T => Boolean): TypeResult[T] = if (f(result)) this else Failure("Wrong type") + def withFilter(f: T => Boolean): TypeResult[T] = + if (f(result)) this else Failure("Wrong type")(result.projectContext) def foreach[B](f: T => B): Unit = f(result) @@ -56,6 +60,10 @@ class Success[T <: ScType] private(private val result: T) def isEmpty: Boolean = false + def getOrNothing: T = result + + def getOrAny: T = result + override def equals(other: Any): Boolean = other match { case Success((otherResult, _)) => result == otherResult case _ => false @@ -68,8 +76,7 @@ class Success[T <: ScType] private(private val result: T) object Success { - def apply[T <: ScType](result: T) - (implicit context: ProjectContext): Success[T] = new Success(result) + def apply[T <: ScType](result: T): Success[T] = new Success(result) def unapply[T <: ScType](success: Success[T]): Option[(T, Option[PsiElement])] = Option(success) @@ -77,8 +84,8 @@ object Success { .map((_, None)) } -case class Failure(private val cause: String) - (implicit context: ProjectContext) extends TypeResult[Nothing] { +final case class Failure(private val cause: String) + (implicit context: ProjectContext) extends TypeResult[Nothing] { def map[U <: ScType](f: Nothing => U): this.type = this @@ -91,4 +98,8 @@ case class Failure(private val cause: String) def get: Nothing = throw new NoSuchElementException("Failure.get") def isEmpty: Boolean = true + + def getOrNothing: ScType = api.Nothing + + def getOrAny: ScType = api.Any } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala index 34a8bd3c2a9..a3e73fb303d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala @@ -6,15 +6,6 @@ import org.jetbrains.plugins.scala.project.ProjectContext package object result { - implicit class TypeResultExt(val typeResult: TypeResult[ScType]) extends AnyVal { - - def getOrNothing: ScType = typeResult.getOrElse(api.Nothing) - - def getOrAny: ScType = typeResult.getOrElse(api.Any) - - private implicit def context: ProjectContext = typeResult.projectContext - } - implicit class TypeableExt(val typeable: ScalaPsiElement with Typeable) extends AnyVal { def flatMap[E <: ScalaPsiElement](maybeElement: Option[E]) From d529eb3bce61dba79ead67469edfff8edc849265 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 25 Oct 2017 15:38:14 +0300 Subject: [PATCH 046/141] Success is a case class #SCL-12743 --- .../lang/psi/types/DottyPsiTypeBridge.scala | 2 +- .../scala/annotator/PatternAnnotator.scala | 4 ++-- .../scala/annotator/ScalaAnnotator.scala | 16 +++++++------- .../quickfix/AddBreakoutQuickFix.scala | 2 +- .../annotator/quickfix/ChangeTypeFix.scala | 2 +- .../SuggestScalaVariableNameMacro.scala | 4 ++-- .../collections/MapGetOrElseInspection.scala | 2 +- .../codeInspection/collections/package.scala | 2 +- .../MatchToPartialFunctionInspection.scala | 2 +- .../ConvertibleToMethodValueInspection.scala | 2 +- .../ComparingUnrelatedTypesInspection.scala | 4 ++-- ...ctorSimplifyTypeProjectionInspection.scala | 2 +- .../ScalaDocumentationProvider.scala | 5 ++--- .../plugins/scala/format/StringPart.scala | 2 +- .../SameSignatureCallParametersProvider.scala | 4 +--- .../ScalaSmartCompletionContributor.scala | 6 ++--- .../completion/lookups/ScalaLookupItem.scala | 2 +- .../weighter/ScalaByExpectedTypeWeigher.scala | 6 ++--- .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 10 ++++----- .../scala/lang/psi/api/InferUtil.scala | 8 +++---- .../psi/api/base/patterns/ScPattern.scala | 8 +++---- .../lang/psi/api/expr/ExpectedTypes.scala | 10 ++++----- .../lang/psi/api/expr/MethodInvocation.scala | 2 +- .../lang/psi/api/expr/ScAnnotations.scala | 2 +- .../lang/psi/api/expr/ScExpression.scala | 4 ++-- .../lang/psi/api/statements/ScFunction.scala | 6 ++--- .../api/statements/params/ScParameter.scala | 2 +- .../base/patterns/ScTypedPatternImpl.scala | 2 +- .../base/types/ScSimpleTypeElementImpl.scala | 2 +- .../impl/expr/ScReferenceExpressionImpl.scala | 16 +++++++------- .../psi/impl/expr/ScThisReferenceImpl.scala | 2 +- .../lang/psi/impl/expr/ScTryStmtImpl.scala | 2 +- .../statements/params/ScTypeParamImpl.scala | 4 ++-- .../impl/toplevel/typedef/MixinNodes.scala | 2 +- .../impl/toplevel/typedef/ScClassImpl.scala | 2 +- .../simulacrum/SimulacrumInjection.scala | 2 +- .../psi/implicits/ImplicitCollector.scala | 4 ++-- .../lang/psi/light/JavaConversionUtil.scala | 2 +- .../scala/lang/psi/light/LightUtil.scala | 2 +- .../lang/psi/light/ScFunctionWrapper.scala | 12 +++++----- .../light/StaticTraitScFunctionWrapper.scala | 2 +- .../lang/psi/stubs/util/ScalaStubsUtil.scala | 2 +- .../scala/lang/psi/types/BaseTypes.scala | 2 +- .../lang/psi/types/ScParameterizedType.scala | 8 +++---- .../lang/psi/types/ScalaConformance.scala | 4 ++-- .../lang/psi/types/ScalaEquivalence.scala | 4 ++-- .../lang/psi/types/ScalaPsiTypeBridge.scala | 4 ++-- .../lang/psi/types/api/FunctionType.scala | 2 +- .../api/designator/ScDesignatorType.scala | 2 +- .../api/designator/ScProjectionType.scala | 14 ++++++------ .../psi/types/api/designator/ScThisType.scala | 4 ++-- .../scala/lang/psi/types/package.scala | 2 +- .../lang/psi/types/result/TypeResult.scala | 22 +------------------ .../ScalaChangeSignatureUsageHandler.scala | 2 +- .../duplicates/DuplicateMatch.scala | 2 +- .../memberPullUp/ScalaPullUpProcessor.scala | 2 +- .../resolve/ReferenceExpressionResolver.scala | 2 +- .../resolve/processor/BaseProcessor.scala | 4 ++-- .../resolve/processor/ResolveProcessor.scala | 2 +- .../ScalaTestConfigurationProducer.scala | 4 ++-- .../completion/SbtCompletionContributor.scala | 2 +- .../src/scala/meta/trees/TypeAdapter.scala | 6 ++--- .../src/scala/meta/trees/Utils.scala | 2 +- .../scala/lang/macros/MonocleLensesTest.scala | 2 +- .../scala/lang/macros/StalactiteTest.scala | 2 +- .../TypeConformanceTestBase.scala | 2 +- .../typeInference/TypeInferenceDoTest.scala | 4 ++-- .../ExistentialSimplificationTestBase.scala | 4 ++-- .../annotations/MetaAnnotationBugsTest.scala | 6 ++--- 69 files changed, 136 insertions(+), 159 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala index 340bd8f0b9f..6e84ecb33ab 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala @@ -42,7 +42,7 @@ trait DottyPsiTypeBridge extends api.PsiTypeBridge { case syntheticClass: ScSyntheticClass => toPsiType(syntheticClass.stdType) case clazz: PsiClass => createType(clazz, raw = true) case definition: ScTypeAliasDefinition => definition.aliasedType match { - case Success(result, _) => createComponent(result) + case Success(result) => createComponent(result) case _ => createJavaObject } case _ => createJavaObject diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala index 3ea34ac1db4..0bdb2990575 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala @@ -130,7 +130,7 @@ object PatternAnnotator { case Some(ref) => ref.bind() match { case Some(ScalaResolveResult(fun: ScFunction, _)) if fun.name == "unapply" => fun.returnType match { - case Success(rt, _) => + case Success(rt) => val expected = ScPattern.expectedNumberOfExtractorArguments(rt, pattern, ScPattern.isOneArgCaseClassMethod(fun)) val tupleCrushingIsPresent = expected > 0 && numPatterns == 1 && !fun.isSynthetic if (expected != numPatterns && !tupleCrushingIsPresent) { //1 always fits if return type is Option[TupleN] @@ -140,7 +140,7 @@ object PatternAnnotator { case _ => } case Some(ScalaResolveResult(fun: ScFunction, _)) if fun.name == "unapplySeq" => fun.returnType match { - case Success(rt, _) => + case Success(rt) => //subtract 1 because last argument (Seq) may be omitted val expected = ScPattern.expectedNumberOfExtractorArguments(rt, pattern, ScPattern.isOneArgCaseClassMethod(fun)) - 1 if (expected > numPatterns) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index a6952851a53..536299346c5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -97,7 +97,7 @@ abstract class ScalaAnnotator extends Annotator if (isAdvancedHighlightingEnabled(element)) { expr.getTypeAfterImplicitConversion() match { - case ExpressionTypeResult(Success(t, _), _, Some(implicitFunction)) => + case ExpressionTypeResult(Success(t), _, Some(implicitFunction)) => highlightImplicitView(expr, implicitFunction.element, t, expr, holder) case _ => } @@ -975,7 +975,7 @@ abstract class ScalaAnnotator extends Annotator case param: ScParameter => if (!param.isDefaultParam) return //performance optimization param.getRealParameterType match { - case Success(paramType, _) if paramType.extractClass.isDefined => + case Success(paramType) if paramType.extractClass.isDefined => //do not check generic types. See SCL-3508 case _ => return } @@ -1084,7 +1084,7 @@ abstract class ScalaAnnotator extends Annotator import org.jetbrains.plugins.scala.lang.psi.types._ val funType = fun.returnType funType match { - case Success(tp: ScType, _) if tp equiv Unit => return //nothing to check + case Success(tp) if tp equiv Unit => return //nothing to check case _ => } @@ -1191,7 +1191,7 @@ abstract class ScalaAnnotator extends Annotator checkBoundsVariance(fun, holder, fun.nameId, fun.getParent) if (!childHasAnnotation(fun.returnTypeElement, "uncheckedVariance")) { fun.returnType match { - case Success(returnType, _) => + case Success(returnType) => checkVariance(ScalaType.expandAliases(returnType).getOrElse(returnType), Covariant, fun.nameId, fun.getParent, holder) case _ => @@ -1213,10 +1213,10 @@ abstract class ScalaAnnotator extends Annotator if (!modifierIsThis(toCheck)) { for (element <- declaredElements) { element.`type`() match { - case Success(tp, _) => + case Success(tp) => ScalaType.expandAliases(tp) match { //so type alias is highlighted - case Success(newTp, _) => checkVariance(newTp, variance, element.nameId, toCheck, holder) + case Success(newTp) => checkVariance(newTp, variance, element.nameId, toCheck, holder) case _ => checkVariance(tp, variance, element.nameId, toCheck, holder) } case _ => @@ -1410,11 +1410,11 @@ abstract class ScalaAnnotator extends Annotator */ def smartCheckConformance(l: TypeResult[ScType], r: TypeResult[ScType]): Boolean = { val leftType = l match { - case Success(res, _) => res + case Success(res) => res case _ => return true } val rightType = r match { - case Success(res, _) => res + case Success(res) => res case _ => return true } rightType.conforms(leftType) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala index f0f89cd1521..a7e5af1d610 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala @@ -62,7 +62,7 @@ object AddBreakoutQuickFix { def isImplicitCanBuildFromParam(p: ScParameter): Boolean = { p.`type`() match { - case Success(tpe, _) if tpe.canonicalText.startsWith("_root_.scala.collection.generic.CanBuildFrom") => true + case Success(tpe) if tpe.canonicalText.startsWith("_root_.scala.collection.generic.CanBuildFrom") => true case _ => false } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala index 685c7c10389..73d9ca34440 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala @@ -19,7 +19,7 @@ class ChangeTypeFix(typeElement: ScTypeElement, newType: ScType) extends Intenti val getText: String = { val (oldTypeDescripton, newTypeDescription) = typeElement.`type`() match { - case Success(oldType, _) => ScTypePresentation.different(oldType, newType) + case Success(oldType) => ScTypePresentation.different(oldType, newType) case _ => (typeElement.getText, newType.presentableText) } s"Change type '$oldTypeDescripton' to '$newTypeDescription'" diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala index 93756071991..a3be68d93a2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala @@ -66,8 +66,8 @@ object SuggestScalaVariableNameMacro { if (items.length == 0) return default items(0) match { case typed: ScTypedDefinition => typed.`type`() match { - case Success(ParameterizedType(_, typeArgs), _) => typeArgs.head - case Success(JavaArrayType(argument), _) => argument + case Success(ParameterizedType(_, typeArgs)) => typeArgs.head + case Success(JavaArrayType(argument)) => argument case _ => return default } case _ => return default diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala index e0cb1ffff11..2aa07e62f66 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala @@ -59,7 +59,7 @@ object MapGetOrElse extends SimplificationType() { case _ => return false } val mapArgRetType = mapArg.`type`() match { - case Success(FunctionType(retType, _), _) => retType + case Success(FunctionType(retType, _)) => retType case _ => return false } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala index 8a5749537ba..69850d376e2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala @@ -156,7 +156,7 @@ package object collections { import expr.projectContext expr.`type`() match { - case Success(result, _) => + case Success(result) => result match { case FunctionType(returnType, _) => returnType.conforms(api.Boolean) case _ => false diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala index 9d5517fccef..312a72c2209 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala @@ -41,7 +41,7 @@ class MatchToPartialFunctionInspection extends AbstractInspection(inspectionId) private def notExpectedType(expr: ScExpression) = { (expr.`type`(), expr.expectedType()) match { - case (Success(tpe: ScType, _), Some(expType: ScType)) => !expType.equiv(tpe) + case (Success(tpe), Some(expType: ScType)) => !expType.equiv(tpe) case _ => true } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala index bd34ee32ae9..e7e07cb2b1f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala @@ -103,7 +103,7 @@ class ConvertibleToMethodValueInspection extends AbstractInspection(inspectionId conformsExpected(oldExpr) && conformsExpected(newExpr) && oldExpr.`type`().getOrAny.conforms(newExpr.`type`().getOrNothing) case None if newExprText endsWith "_" => (oldExpr.`type`(), newExpr.`type`()) match { - case (Success(oldType, _), Success(newType, _)) => oldType.equiv(newType) + case (Success(oldType), Success(newType)) => oldType.equiv(newType) case _ => false } case _ => false diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala index c1574d5c568..92039e49104 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala @@ -72,7 +72,7 @@ object ComparingUnrelatedTypesInspection { @tailrec private def extractActualType(`type`: ScType): ScType = `type`.isAliasType match { - case Some(ScTypeUtil.AliasType(_, Success(rhs, _), _)) => extractActualType(rhs) + case Some(ScTypeUtil.AliasType(_, Success(rhs), _)) => extractActualType(rhs) case _ => `type`.tryExtractDesignatorSingleton } } @@ -90,7 +90,7 @@ class ComparingUnrelatedTypesInspection extends AbstractInspection(inspectionId, //getType() for the reference on the left side returns singleton type, little hack here val leftOnTheRight = ScalaPsiElementFactory.createExpressionWithContextFromText(left.getText, right.getParent, right) Seq(leftOnTheRight, right) map (_.`type`()) match { - case Seq(Success(leftType, _), Success(rightType, _)) if cannotBeCompared(leftType, rightType) => + case Seq(Success(leftType), Success(rightType)) if cannotBeCompared(leftType, rightType) => val message = generateComparingUnrelatedTypesMsg(leftType, rightType) holder.registerProblem(expr, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING) case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala index bd890db1271..ecaa0b6c33c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala @@ -63,7 +63,7 @@ class KindProjectorSimplifyTypeProjectionInspection extends LocalInspectionTool } alias.aliasedType match { - case Success(paramType: ScParameterizedType, _) => + case Success(paramType: ScParameterizedType) => val typeParam: Seq[ScTypeParam] = alias.typeParameters val valid = typeParam.nonEmpty && diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala index 6331f43686a..279ab2b572d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala @@ -29,7 +29,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createSc import org.jetbrains.plugins.scala.lang.psi.light.ScFunctionWrapper import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, ParameterizedType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result.Success import org.jetbrains.plugins.scala.lang.psi.{PresentationUtil, ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.lang.scaladoc.lexer.ScalaDocTokenType @@ -524,7 +524,7 @@ object ScalaDocumentationProvider { annotation.constructor.args.foreach( a => a.exprs.headOption.map { case exprHead => exprHead.`type`() match { - case Success(head, _) => + case Success(head) => head match { case ParameterizedType(_, args) => args.headOption match { @@ -1029,7 +1029,6 @@ object ScalaDocumentationProvider { } def generateTypeAliasInfo(alias: ScTypeAlias, subst: ScSubstitutor): String = { - import alias.projectContext val buffer = new StringBuilder buffer.append(getMemberHeader(alias)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala index ad3429c7129..eaa72c5acf0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala @@ -59,7 +59,7 @@ case class Injection(expression: ScExpression, specifier: Option[Specifier]) ext it => val _type = expressionType.map(ScalaType.expandAliases(_)).getOrElse(new Object()) _type match { - case Success(result, _) => result match { + case Success(result) => result match { case res: ScType => try { val value = Types.valueOf(res) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala index fe7d9f02e6c..b94f2caa770 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala @@ -98,9 +98,7 @@ class SameSignatureCallParametersProvider extends ScalaCompletionContributor { val index = constructor.arguments.indexOf(args) val typeElement = constructor.typeElement typeElement.`type`() match { - case Success(tp, _) => - val project = position.getProject - + case Success(tp) => val signatures = tp.extractClassType match { case Some((clazz: ScClass, subst)) if !clazz.hasTypeParameters || (clazz.hasTypeParameters && typeElement.isInstanceOf[ScParameterizedTypeElement]) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala index 902d26e3b41..d27a9936c23 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala @@ -120,12 +120,12 @@ class ScalaSmartCompletionContributor extends ScalaCompletionContributor { val second = checkForSecondCompletion && fun.paramClauses.clauses.filterNot(_.isImplicit).flatMap(_.parameters).isEmpty val added = fun.returnType match { - case Success(tp, _) => checkType(tp, infer, second) + case Success(tp) => checkType(tp, infer, second) case _ => false } if (!added) { fun.`type`() match { - case Success(tp, _) => checkType(tp, infer, second, etaExpanded = true) + case Success(tp) => checkType(tp, infer, second, etaExpanded = true) case _ => } } @@ -247,7 +247,7 @@ class ScalaSmartCompletionContributor extends ScalaCompletionContributor { case _: ScNewTemplateDefinition if foundClazz => //do nothing, impossible to invoke case t: ScTemplateDefinition => t.getTypeWithProjections(thisProjections = true) match { - case Success(scType, _) => + case Success(scType) => val lookupString = (if (foundClazz) t.name + "." else "") + "this" val el = new ScalaLookupItem(t, lookupString) if (!scType.equiv(Nothing) && typez.exists(scType conforms _)) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala index 12914bfd4de..638f7c15ec0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala @@ -131,7 +131,7 @@ class ScalaLookupItem(val element: PsiNamedElement, _name: String, containingCla presentationString(param.getRealParameterType.getOrAny, substitutor) case t: ScTemplateDefinition if name == "this" || name.endsWith(".this") => t.getTypeWithProjections(thisProjections = true) match { - case Success(tp, _) => + case Success(tp) => tp.presentableText case _ => "" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala index 5aff9b61453..3d2d7aa7311 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala @@ -84,10 +84,10 @@ class ScalaByExpectedTypeWeigher(expectedTypes: Seq[ScType], position: PsiElemen val subst = ScalaPsiUtil.inferMethodTypesArgs(fun, scalaLookupItem.substitutor) fun.returnType match { - case Success(tp, _) => (tp, helper(tp, subst)) + case Success(tp) => (tp, helper(tp, subst)) case _ => fun.`type`() match { - case Success(tp, _) => (tp, helper(tp, subst)) + case Success(tp) => (tp, helper(tp, subst)) case _ => (null, null) } } @@ -98,7 +98,7 @@ class ScalaByExpectedTypeWeigher(expectedTypes: Seq[ScType], position: PsiElemen (tp, helper(tp, subst)) case typed: ScTypedDefinition => typed.`type`() match { - case Success(tp, _) => (tp, helper(tp)) + case Success(tp) => (tp, helper(tp)) case _ => (null, null) } case f: PsiField => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index 0de80c441f3..16c1904f349 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -223,7 +223,7 @@ object ScalaPsiUtil { lastParent match { case _: ScImportStmt => typeResult match { - case Success(t, _) => + case Success(t) => (processor, place) match { case (b: BaseProcessor, p: ScalaPsiElement) => b.processType(subst subst t, p, state) case _ => true @@ -495,7 +495,7 @@ object ScalaPsiUtil { def collectPartsTr(option: TypeResult[ScType]): Unit = { option match { - case Success(t, _) => collectParts(t) + case Success(t) => collectParts(t) case _ => } } @@ -505,7 +505,7 @@ object ScalaPsiUtil { if (visited.contains(tp)) return visited += tp tp.isAliasType match { - case Some(AliasType(_, _, Success(t, _))) => collectParts(t) + case Some(AliasType(_, _, Success(t))) => collectParts(t) case _ => } @@ -1830,11 +1830,11 @@ object ScalaPsiUtil { def selfTypeValid: Boolean = { td.selfType match { case Some(selfParam: ScParameterizedType) => td.`type`() match { - case Success(classParamTp: ScParameterizedType, _) => selfParam.designator.conforms(classParamTp.designator) + case Success(classParamTp: ScParameterizedType) => selfParam.designator.conforms(classParamTp.designator) case _ => false } case Some(selfTp) => td.`type`() match { - case Success(classType, _) => selfTp.conforms(classType) + case Success(classType) => selfTp.conforms(classType) case _ => false } case _ => true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala index 015eecfa524..e1e137be237 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala @@ -246,7 +246,7 @@ object InferUtil { var nonValueType = _nonValueType nonValueType match { - case Success(ScTypePolymorphicType(m@ScMethodType(internal, _, impl), typeParams), _) + case Success(ScTypePolymorphicType(m@ScMethodType(internal, _, impl), typeParams)) if expectedType.isDefined && (!fromImplicitParameters || impl) => def updateRes(expected: ScType) { if (expected.equiv(Unit)) return //do not update according to Unit type @@ -267,7 +267,7 @@ object InferUtil { } updateRes(expectedType.get) //todo: Something should be unified, that's bad to have fromImplicitParameters parameter. - case Success(ScTypePolymorphicType(internal, typeParams), _) if expectedType.isDefined && fromImplicitParameters => + case Success(ScTypePolymorphicType(internal, typeParams)) if expectedType.isDefined && fromImplicitParameters => def updateRes(expected: ScType) { nonValueType = Success(localTypeInference(internal, Seq(Parameter("", None, expected, expected, isDefault = false, isRepeated = false, isByName = false)), @@ -325,9 +325,9 @@ object InferUtil { } nonValueType match { - case Success(tpt@ScTypePolymorphicType(mt: ScMethodType, _), elem) => + case Success(tpt@ScTypePolymorphicType(mt: ScMethodType, _)) => Success(tpt.copy(internalType = applyImplicitViewToResult(mt, expectedType))) - case Success(mt: ScMethodType, elem) => + case Success(mt: ScMethodType) => Success(applyImplicitViewToResult(mt, expectedType)) case tr => tr } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala index f9fad05e190..ecd76dd3e2f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala @@ -311,7 +311,7 @@ object ScPattern { case _ => } val firstParameterType = fun.parameters.head.`type`() match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return None } val funType = undefSubst.subst(firstParameterType) @@ -321,7 +321,7 @@ object ScPattern { } } fun.returnType match { - case Success(rt, _) => + case Success(rt) => def updateRes(tp: ScType): ScType = { val parameters: Seq[ScTypeParam] = fun.typeParameters tp.recursiveVarianceUpdate { @@ -348,7 +348,7 @@ object ScPattern { s.bindT(p.nameAndId, UndefinedType(TypeParameterType(p, Some(substitutor)))) } val firstParameterRetTp = fun.parameters.head.`type`() match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return None } val funType = undefSubst.subst(firstParameterRetTp) @@ -358,7 +358,7 @@ object ScPattern { } } fun.returnType match { - case Success(rt, _) => + case Success(rt) => val args = ScPattern.extractorParameters(subst.subst(rt), pattern, ScPattern.isOneArgCaseClassMethod(fun)) if (args.isEmpty) return None if (argIndex < args.length - 1) return Some(subst.subst(args(argIndex))) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala index 73045c1146c..d0a82bd6fc5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala @@ -271,7 +271,7 @@ private[expr] object ExpectedTypes { fun.returnTypeElement match { case Some(rte: ScTypeElement) => fun.returnType match { - case Success(rt: ScType, _) => Array((rt, Some(rte))) + case Success(rt) => Array((rt, Some(rte))) case _ => Array.empty } case None => Array.empty @@ -407,7 +407,7 @@ private[expr] object ExpectedTypes { } } tp match { - case Success(ScMethodType(_, params, _), _) => + case Success(ScMethodType(_, params, _)) => if (params.length == 1 && !params.head.isRepeated && exprs.length > 1) { params.head.paramType.removeAbstracts match { case TupleType(args) => applyForParams(args.zipWithIndex.map { @@ -416,7 +416,7 @@ private[expr] object ExpectedTypes { case _ => } } else applyForParams(params) - case Success(t@ScTypePolymorphicType(ScMethodType(_, params, _), _), _) => + case Success(t@ScTypePolymorphicType(ScMethodType(_, params, _), _)) => val subst = t.abstractTypeSubstitutor val newParams = params.map(p => p.copy(paramType = subst.subst(p.paramType))) if (newParams.length == 1 && !newParams.head.isRepeated && exprs.length > 1) { @@ -427,7 +427,7 @@ private[expr] object ExpectedTypes { case _ => } } else applyForParams(newParams) - case Success(ScTypePolymorphicType(anotherType, typeParams), _) if !forApply => + case Success(ScTypePolymorphicType(anotherType, typeParams)) if !forApply => val cand = call.getOrElse(expr).applyShapeResolveForExpectedType(anotherType, exprs, call) if (cand.length == 1) { cand(0) match { @@ -447,7 +447,7 @@ private[expr] object ExpectedTypes { case _ => } } - case Success(anotherType, _) if !forApply => + case Success(anotherType) if !forApply => val cand = call.getOrElse(expr).applyShapeResolveForExpectedType(anotherType, exprs, call) if (cand.length == 1) { cand(0) match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala index 4ea7854c1cc..4460a65c7e5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala @@ -383,7 +383,7 @@ object MethodInvocation { r.importsUsed, r.implicitConversion, Some(r)) } call.getInvokedExpr.getNonValueType() match { - case Success(ScTypePolymorphicType(_, typeParams), _) => + case Success(ScTypePolymorphicType(_, typeParams)) => val fixedType = res.processedType match { case ScTypePolymorphicType(internal, typeParams2) => ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala index 9bb82e4f51b..2cac0e3042a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala @@ -45,7 +45,7 @@ trait ScAnnotations extends ScalaPsiElement with PsiReferenceList { constr.args match { case Some(args) if args.exprs.length == 1 => args.exprs(0).`type`() match { - case Success(ParameterizedType(tp, arg), _) if arg.length == 1 => + case Success(ParameterizedType(tp, arg)) if arg.length == 1 => tp.extractClass match { case Some(clazz) if clazz.qualifiedName == "java.lang.Class" => arg.head.extractClass match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala index 111ac087cad..6fa70e4b006 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala @@ -342,7 +342,7 @@ object ScExpression { else { val inner = expr.getNonValueType(ignoreBaseTypes, fromUnderscore) inner match { - case Success(rtp, _) => + case Success(rtp) => var res = rtp val expType = expectedType(fromUnderscore) @@ -353,7 +353,7 @@ object ScExpression { InferUtil.updateAccordingToExpectedType(Success(rtp), fromImplicitParameters = true, filterTypeParams = false, expectedType = expType, expr = expr, canThrowSCE = true) updatedWithExpected match { - case Success(newRes, _) => + case Success(newRes) => updateWithImplicitParameters(newRes, checkExpectedType = true, fromUnderscore) case _ => updateWithImplicitParameters(oldRes, checkExpectedType = true, fromUnderscore) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala index f98287ccad6..fb14713104b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala @@ -484,7 +484,7 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne case Some(annotation) => annotation.constructor.args.map(_.exprs).getOrElse(Seq.empty).flatMap { _.`type`() match { - case Success(ParameterizedType(des, Seq(arg)), _) => des.extractClass match { + case Success(ParameterizedType(des, Seq(arg))) => des.extractClass match { case Some(clazz) if clazz.qualifiedName == "java.lang.Class" => arg.toPsiType match { case c: PsiClassType => Seq(c) @@ -502,12 +502,12 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne def `type`(): TypeResult[ScType] = { this.returnType match { - case Success(tp: ScType, _) => + case Success(tp) => var res: TypeResult[ScType] = Success(tp) var i = paramClauses.clauses.length - 1 while (i >= 0) { res match { - case Success(t: ScType, _) => + case Success(t) => val parameters = paramClauses.clauses.apply(i).parameters val paramTypes = parameters.map(_.`type`().getOrNothing) res = Success(FunctionType(t, paramTypes)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala index ae6784a473f..fe4c504c29b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala @@ -65,7 +65,7 @@ trait ScParameter extends ScTypedDefinition with ScModifierListOwner with def getRealParameterType: TypeResult[ScType] = `type`() match { case result if !isRepeatedParameter => result - case f@Success(tp: ScType, elem) => + case f@Success(tp) => elementScope.getCachedClass("scala.collection.Seq") .map(ScalaType.designator) .map(ScParameterizedType(_, Seq(tp))) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala index 52321e44e6c..e07e76eb38d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala @@ -38,7 +38,7 @@ class ScTypedPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S override def isIrrefutableFor(t: Option[ScType]): Boolean = { t match { case Some(t) => `type`() match { - case Success(tp, _) if t conforms tp => true + case Success(tp) if t conforms tp => true case _ => false } case _ => false diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala index 477e366d150..39f44a14194 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala @@ -406,7 +406,7 @@ object ScSimpleTypeElementImpl { } case _ => calculateReferenceType(qualifier, shapesOnly) match { - case Success(tp, _) => makeProjection(tp) + case Success(tp) => makeProjection(tp) case failure: Failure => return failure } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala index 4293c0738e5..4757aa11760 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala @@ -244,7 +244,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case ScAbstractType(_, lower, _) => lower case _ => tp }).isAliasType match { - case Some(AliasType(_, Success(lower: DesignatorOwner, _), _)) if lower.isStable => + case Some(AliasType(_, Success(lower: DesignatorOwner), _)) if lower.isStable => return true case _ => tp match { @@ -324,7 +324,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } else { val result = refPatt.`type`() result match { - case Success(tp, _) => s.subst(tp) + case Success(tp) => s.subst(tp) case _ => return result } } @@ -375,7 +375,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case _ => val result = param.getRealParameterType s.subst(result match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return result }) } @@ -391,7 +391,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case ScalaResolveResult(param: ScParameter, s) if param.isRepeatedParameter => val result = param.`type`() val computeType = s.subst(result match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return result }) elementScope.getCachedClass("scala.collection.Seq") @@ -436,14 +436,14 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } else { val result = f.`type`() result match { - case Success(tp, _) => s.subst(tp) + case Success(tp) => s.subst(tp) case _ => return result } } case ScalaResolveResult(typed: ScTypedDefinition, s) => val result = typed.`type`() result match { - case Success(tp, _) => s.subst(tp) + case Success(tp) => s.subst(tp) case _ => return result } case ScalaResolveResult(pack: PsiPackage, _) => ScalaType.designator(pack) @@ -519,7 +519,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no getContext match { case sugar: ScSugarCallExpr if sugar.operation == this => sugar.getBaseExpr.getNonValueType() match { - case Success(ScTypePolymorphicType(_, typeParams), _) => + case Success(ScTypePolymorphicType(_, typeParams)) => inner match { case ScTypePolymorphicType(internal, typeParams2) => return Success(ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2 ++ unresolvedTypeParameters))) @@ -539,7 +539,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } case Some(qualifier) => qualifier.getNonValueType() match { - case Success(ScTypePolymorphicType(_, typeParams), _) => + case Success(ScTypePolymorphicType(_, typeParams)) => inner match { case ScTypePolymorphicType(internal, typeParams2) => return Success(ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2 ++ unresolvedTypeParameters))) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala index 83d953b4003..5bedf3de4a5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala @@ -73,7 +73,7 @@ object ScThisReferenceImpl { td.getTypeWithProjections(thisProjections = true).map { case scType => td.selfType.map(scType.glb(_)).getOrElse(scType) } match { - case Success(scType, _) => scType + case Success(scType) => scType case _ => return Failure("No clazz type found") } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala index 03b7112159a..da0fe189d1c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala @@ -38,7 +38,7 @@ class ScTryStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryS cb.expression match { case Some(expr) if !lifted.isEmpty => expr.`type`() match { - case Success(_, _) => + case Success(_) => val tp = expr.`type`().getOrAny val throwable = ScalaPsiManager.instance(expr.getProject).getCachedClass(expr.resolveScope, "java.lang.Throwable") throwable.fold(lifted) { throwable => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala index c8856a8fda2..40deb396cb7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala @@ -61,8 +61,8 @@ class ScTypeParamImpl private (stub: ScTypeParamStub, node: ASTNode) in } case t => t.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(lower, _), _)) if isLower => extractBound(lower, isLower) - case Some(AliasType(_: ScTypeAliasDefinition, _, Success(upper, _))) if !isLower => extractBound(upper, isLower) + case Some(AliasType(_: ScTypeAliasDefinition, Success(lower), _)) if isLower => extractBound(lower, isLower) + case Some(AliasType(_: ScTypeAliasDefinition, _, Success(upper))) if !isLower => extractBound(upper, isLower) case None => t } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala index b35cc710f0b..fc1effb3ba1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala @@ -535,7 +535,7 @@ object MixinNodes { @tailrec def updateTp(tp: ScType, depth: Int = 0): ScType = { tp.isAliasType match { - case Some(AliasType(_, _, Success(upper, _))) => + case Some(AliasType(_, _, Success(upper))) => if (tp != upper && depth < 100) updateTp(upper, depth + 1) else tp case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala index 097315e52f1..17a9268377b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala @@ -269,7 +269,7 @@ class ScClassImpl protected (stub: ScTemplateDefinitionStub, node: ASTNode) val fields = constructor match { case Some(constr) => constr.parameters.map { param => param.`type`() match { - case Success(tp: TypeParameterType, _) if tp.psiTypeParameter.findAnnotation("scala.specialized") != null => + case Success(tp: TypeParameterType) if tp.psiTypeParameter.findAnnotation("scala.specialized") != null => val factory: PsiElementFactory = PsiElementFactory.SERVICE.getInstance(getProject) val psiTypeText: String = tp.toPsiType.getCanonicalText val text = s"public final $psiTypeText ${param.name};" diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala index d44ff7478c5..06bf8a8e859 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala @@ -136,7 +136,7 @@ class SimulacrumInjection extends SyntheticMembersInjector { val AllOpsSupers = clazz.extendsBlock.templateParents.toSeq.flatMap(parents => parents.typeElements.flatMap { te => te.`type`() match { - case Success(ParameterizedType(classType, Seq(tp)), _) if isProperTpt(tp).isDefined => + case Success(ParameterizedType(classType, Seq(tp))) if isProperTpt(tp).isDefined => def fromType: Seq[String] = { val project = clazz.getProject classType.extractClass match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala index 132e7ee8865..8bf272eeb03 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala @@ -351,7 +351,7 @@ class ImplicitCollector(place: PsiElement, case typeable: Typeable => val subst = c.substitutor typeable.`type`() match { - case Success(t: ScType, _) => + case Success(t) => if (!subst.subst(t).conforms(tp)) reportWrong(c, subst, TypeDoesntConformResult) else @@ -448,7 +448,7 @@ class ImplicitCollector(place: PsiElement, val nonValueType: ScType = try updateNonValueType(nonValueType0) match { - case Success(tpe, _) => tpe + case Success(tpe) => tpe case _ => return wrongTypeParam(BadTypeResult) } catch { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala index 76e96d3958d..198379109b8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala @@ -96,7 +96,7 @@ object JavaConversionUtil { if (arguments.length == 1) { val typeResult = arguments.head.`type`() typeResult match { - case Success(tp, _) => + case Success(tp) => tp.extractClass match { case Some(clazz) => clazz.getQualifiedName + ".class" case _ => problem diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala index df841357984..babd7fa817e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala @@ -30,7 +30,7 @@ object LightUtil { val classes = annotation.constructor.args.map(_.exprs).getOrElse(Seq.empty).flatMap { _.`type`() match { - case Success(ParameterizedType(des, Seq(arg)), _) => des.extractClass match { + case Success(ParameterizedType(des, Seq(arg))) => des.extractClass match { case Some(clazz) if clazz.qualifiedName == "java.lang.Class" => arg.toPsiType match { case c: PsiClassType => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala index afb73a1aac0..34eb57e6e2a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala @@ -183,17 +183,17 @@ object ScFunctionWrapper { val classes = new ArrayBuffer[String]() val project = fun.getProject tp.upperBound.map(subst.subst) match { - case Success(tp: ScCompoundType, _) => + case Success(tp: ScCompoundType) => tp.components.foreach { tp: ScType => tp.extractClass match { case Some(clazz) => classes += clazz.getQualifiedName case _ => } } - case Success(_: StdType, _) => - case Success(tpt: TypeParameterType, _) => + case Success(_: StdType) => + case Success(tpt: TypeParameterType) => classes += tpt.canonicalText - case Success(scType, _) => + case Success(scType) => scType.extractClass match { case Some(clazz) => classes += clazz.getQualifiedName case _ => @@ -235,13 +235,13 @@ object ScFunctionWrapper { else param.getRealParameterType val typeText = paramType.map(subst.subst) match { - case Success(tp, _) if param.isCallByNameParameter => + case Success(tp) if param.isCallByNameParameter => val psiType = tp match { case std: StdType => tp.typeSystem.stdToPsiType(std, noPrimitives = true) case _ => tp.toPsiType } s"scala.Function0<${psiType.getCanonicalText}>" - case Success(tp, _) => + case Success(tp) => JavaConversionUtil.typeText(tp) case _ => "java.lang.Object" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala index 02b7ba1c00b..e43087cb492 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala @@ -38,7 +38,7 @@ class StaticTraitScFunctionWrapper(val function: ScFunction, containingClass: Ps private def paramText(param: ScParameter): String = { val paramAnnotations = JavaConversionUtil.annotations(param).mkString("", " ", " ") val typeText = param.getRealParameterType match { - case Success(tp, _) => + case Success(tp) => val simple = JavaConversionUtil.typeText(tp) if (param.isCallByNameParameter) s"scala.Function0<$simple>" else simple diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala index 7a9a8a0cc4d..dccc8b83c23 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala @@ -88,7 +88,7 @@ object ScalaStubsUtil { selfTypeElement.typeElement match { case Some(typeElement) => typeElement.`type`() match { - case Success(tp, _) => + case Success(tp) => if (checkTp(tp)) { val clazz = PsiTreeUtil.getContextOfType(selfTypeElement, classOf[ScTemplateDefinition]) if (clazz != null) inheritors += clazz diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala index 3eb95564767..9d067750280 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala @@ -130,7 +130,7 @@ private class BaseTypesIterator(tp: ScType) extends Iterator[ScType] { if (!visitedAliases.contains(ta)) { visitedAliases += ta ta.aliasedType match { - case Success(aliased, _) => Some(s.subst(aliased)) + case Success(aliased) => Some(s.subst(aliased)) case _ => None } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala index 3bc69884895..9f31937270b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala @@ -144,7 +144,7 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => (lower match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return (false, uSubst) }).equiv(r, uSubst, falseUndef) case _ => (false, uSubst) @@ -153,7 +153,7 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => (lower match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return (false, uSubst) }).equiv(r, uSubst, falseUndef) case _ => (false, uSubst) @@ -203,7 +203,7 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq designator.extractClassType match { case Some((clazz: ScTypeDefinition, sub)) if startsWith(clazz, prefix) => clazz.`type`() match { - case Success(t, _) => + case Success(t) => val substituted = (sub followed substitutor).subst(t) substituted match { case pt: ScParameterizedType => @@ -240,7 +240,7 @@ object ScParameterizedType { def apply(designator: ScType, typeArgs: Seq[ScType]): ValueType = { def createCompoundProjectionParameterized(pt: ScParameterizedType): ValueType = { pt.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, _, Success(upper: ValueType, _))) => upper + case Some(AliasType(_: ScTypeAliasDefinition, _, Success(upper: ValueType))) => upper case _ => pt } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala index 4fbb1d4f11e..dc00a4166c2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala @@ -393,7 +393,7 @@ trait ScalaConformance extends api.Conformance { } result = l.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(comp: ScCompoundType, _), _)) => + case Some(AliasType(_: ScTypeAliasDefinition, Success(comp: ScCompoundType), _)) => conformsInner(comp, c, HashSet.empty, undefinedSubst) case _ => (false, undefinedSubst) } @@ -1620,7 +1620,7 @@ trait ScalaConformance extends api.Conformance { def processHigherKindedTypeParams(undefType: ParameterizedType, defType: ParameterizedType, undefinedSubst: ScUndefinedSubstitutor, falseUndef: Boolean): (Boolean, ScUndefinedSubstitutor) = { val defTypeExpanded = defType.isAliasType.map(_.lower).map { - case Success(p: ScParameterizedType, _) => p + case Success(p: ScParameterizedType) => p case _ => defType }.getOrElse(defType) extractParams(defTypeExpanded.designator) match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala index 21182aaea0d..d78ad192533 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala @@ -51,12 +51,12 @@ trait ScalaEquivalence extends api.Equivalence { } right.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(right, _), _)) => return equivInner(left, right, substitutor, falseUndef) + case Some(AliasType(_: ScTypeAliasDefinition, Success(right), _)) => return equivInner(left, right, substitutor, falseUndef) case _ => } left.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(left, _), _)) => return equivInner(left, right, substitutor, falseUndef) + case Some(AliasType(_: ScTypeAliasDefinition, Success(left), _)) => return equivInner(left, right, substitutor, falseUndef) case _ => } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala index b0ad5e47b85..4b5133ac162 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala @@ -147,7 +147,7 @@ trait ScalaPsiTypeBridge extends api.PsiTypeBridge { toPsiTypeInner(qualNameToType(c.qualifiedName), noPrimitives) case ScDesignatorType(valClass: ScClass) if ValueClassType.isValueClass(valClass) => valClass.parameters.head.getRealParameterType match { - case Success(tp, _) if !(noPrimitives && tp.isPrimitive) => + case Success(tp) if !(noPrimitives && tp.isPrimitive) => toPsiTypeInner(tp, noPrimitives) case _ => createType(valClass) } @@ -169,7 +169,7 @@ trait ScalaPsiTypeBridge extends api.PsiTypeBridge { } case a: ScTypeAliasDefinition if !visitedAliases.contains(a) => a.aliasedType match { - case Success(c: ScParameterizedType, _) => + case Success(c: ScParameterizedType) => toPsiTypeInner(ScParameterizedType(c.designator, args), noPrimitives, visitedAliases + a) case _ => javaObject } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala index ca30e8085d2..de80efc0d5b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala @@ -41,7 +41,7 @@ sealed trait FunctionTypeFactory { case 0 => None //hack for http://youtrack.jetbrains.com/issue/SCL-6880 to avoid infinite loop. case _ => `type`.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(lower, _), _)) => + case Some(AliasType(_: ScTypeAliasDefinition, Success(lower), _)) => extractForPrefix(lower, prefix, depth - 1) case _ => `type` match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala index 0fc1f941188..10b27dd4d03 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala @@ -29,7 +29,7 @@ case class ScDesignatorType(element: PsiNamedElement, isStatic: Boolean = false) ta match { case ta: ScTypeAliasDefinition => //hack for simple cases, it doesn't cover more complicated examples ta.aliasedType match { - case Success(tp, _) => + case Success(tp) => tp match { case ParameterizedType(des, typeArgs) => val taArgs = ta.typeParameters diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala index 8f8a9ed08ff..b79d6e21386 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala @@ -47,7 +47,7 @@ class ScProjectionType private(val projected: ScType, ta match { case ta: ScTypeAliasDefinition => //hack for simple cases, it doesn't cover more complicated examples ta.aliasedType match { - case Success(tp, _) => + case Success(tp) => actualSubst.subst(tp) match { case ParameterizedType(des, typeArgs) => val taArgs = ta.typeParameters @@ -220,7 +220,7 @@ class ScProjectionType private(val projected: ScType, isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => return (lower match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return (false, uSubst) }).equiv(r, uSubst, falseUndef) case _ => @@ -235,7 +235,7 @@ class ScProjectionType private(val projected: ScType, r.isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => this.equiv(lower match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return (false, uSubst) }, uSubst, falseUndef) case _ => (false, uSubst) @@ -256,7 +256,7 @@ class ScProjectionType private(val projected: ScType, r.isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => this.equiv(lower match { - case Success(tp, _) => tp + case Success(tp) => tp case _ => return (false, uSubst) }, uSubst, falseUndef) case _ => @@ -267,7 +267,7 @@ class ScProjectionType private(val projected: ScType, case t: ScTypedDefinition if t.isStable => val s: ScSubstitutor = ScSubstitutor(projected) followed actualSubst t.`type`() match { - case Success(tp: DesignatorOwner, _) if tp.isSingleton => + case Success(tp: DesignatorOwner) if tp.isSingleton => return s.subst(tp).equiv(r, uSubst, falseUndef) case _ => } @@ -279,7 +279,7 @@ class ScProjectionType private(val projected: ScType, val s: ScSubstitutor = ScSubstitutor(p1) followed proj2.actualSubst t.`type`() match { - case Success(tp: DesignatorOwner, _) if tp.isSingleton => + case Success(tp: DesignatorOwner) if tp.isSingleton => return s.subst(tp).equiv(this, uSubst, falseUndef) case _ => } @@ -293,7 +293,7 @@ class ScProjectionType private(val projected: ScType, case _: ScObject => (false, uSubst) case t: ScTypedDefinition if t.isStable => t.`type`() match { - case Success(singleton: DesignatorOwner, _) if singleton.isSingleton => + case Success(singleton: DesignatorOwner) if singleton.isSingleton => val newSubst = actualSubst.followed(ScSubstitutor(projected)) r.equiv(newSubst.subst(singleton), uSubst, falseUndef) case _ => (false, uSubst) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala index 0e6c926d236..e1737dd3f95 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala @@ -43,7 +43,7 @@ case class ScThisType(element: ScTemplateDefinition) extends DesignatorOwner { (false, substitutor) case (_, ScDesignatorType(typed: ScTypedDefinition)) if typed.isStable => typed.`type`() match { - case Success(tp: DesignatorOwner, _) if tp.isSingleton => + case Success(tp: DesignatorOwner) if tp.isSingleton => this.equiv(tp, substitutor, falseUndef) case _ => (false, substitutor) @@ -51,7 +51,7 @@ case class ScThisType(element: ScTemplateDefinition) extends DesignatorOwner { case (_, ScProjectionType(_, _: ScObject, _)) => (false, substitutor) case (_, p@ScProjectionType(tp, elem: ScTypedDefinition, _)) if elem.isStable => elem.`type`() match { - case Success(singleton: DesignatorOwner, _) if singleton.isSingleton => + case Success(singleton: DesignatorOwner) if singleton.isSingleton => val newSubst = p.actualSubst.followed(ScSubstitutor(tp)) this.equiv(newSubst.subst(singleton), substitutor, falseUndef) case _ => (false, substitutor) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala index 68f4f58fde7..5559684d220 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala @@ -147,7 +147,7 @@ package object types { `type` => `type`.isAliasType match { case Some(AliasType(ta: ScTypeAliasDefinition, _, _: Failure)) if needExpand(ta) => ReplaceWith(projectContext.stdTypes.Any) - case Some(AliasType(ta: ScTypeAliasDefinition, _, Success(upper, _))) if needExpand(ta) => + case Some(AliasType(ta: ScTypeAliasDefinition, _, Success(upper))) if needExpand(ta) => if (visited.contains(`type`)) throw RecursionException val updated = try innerUpdate(upper, visited + `type`) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala index c27a9e34bed..314eaa41a6e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala @@ -4,7 +4,6 @@ package psi package types package result -import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.project.ProjectContext /** @@ -45,7 +44,7 @@ object TypeResult { } } -final class Success[T <: ScType] private(private val result: T) extends TypeResult[T] { +final case class Success[T <: ScType](private val result: T) extends TypeResult[T] { def map[U <: ScType](f: T => U): Success[U] = Success(f(result)) @@ -63,25 +62,6 @@ final class Success[T <: ScType] private(private val result: T) extends TypeResu def getOrNothing: T = result def getOrAny: T = result - - override def equals(other: Any): Boolean = other match { - case Success((otherResult, _)) => result == otherResult - case _ => false - } - - override def hashCode(): Int = result.hashCode() - - override def toString = s"Success($result)" -} - -object Success { - - def apply[T <: ScType](result: T): Success[T] = new Success(result) - - def unapply[T <: ScType](success: Success[T]): Option[(T, Option[PsiElement])] = - Option(success) - .map(_.result) - .map((_, None)) } final case class Failure(private val cause: String) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala index 36620b606d5..c59695fe4eb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala @@ -135,7 +135,7 @@ private[changeSignature] trait ScalaChangeSignatureUsageHandler { val expr = usage.expr val paramTypes = expr.`type`() match { - case Success(FunctionType(_, pTypes), _) => pTypes + case Success(FunctionType(_, pTypes)) => pTypes case _ => Seq.empty } val (names, exprText) = expr match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala index ade14676d54..47023f75ce5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala @@ -90,7 +90,7 @@ class DuplicateMatch(pattern: DuplicatePattern, val candidates: Seq[PsiElement]) private def typesEquiv(expr1: ScExpression, expr2: ScExpression) = { (expr1.`type`(), expr2.`type`()) match { - case (Success(t1, _), Success(t2, _)) => + case (Success(t1), Success(t2)) => def extractFromSingletonType(t: ScType) = t match { case designatorOwner: DesignatorOwner if designatorOwner.isSingleton => designatorOwner.extractDesignatorSingleton diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala index 5a8cc7d2093..7a13802bfb1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala @@ -121,7 +121,7 @@ class ScalaPullUpProcessor(project: Project, private def declarationsText(m: ScMember): Seq[String] = { def textForBinding(b: ScBindingPattern) = { val typeText = b.`type`() match { - case Success(t, _) => s": ${t.canonicalText}" + case Success(t) => s": ${t.canonicalText}" case _ => "" } s"${b.name}$typeText" diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala index 8cd9258030d..901ae7d7c0a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala @@ -475,7 +475,7 @@ class ReferenceExpressionResolver(implicit projectContext: ProjectContext) { ProgressManager.checkCanceled() e.getNonValueType() match { - case Success(tpt @ ScTypePolymorphicType(internal, tp), _) if tp.nonEmpty && + case Success(tpt@ScTypePolymorphicType(internal, tp)) if tp.nonEmpty && !internal.isInstanceOf[ScMethodType] && !internal.isInstanceOf[UndefinedType] /* optimization */ => val substed = tpt.abstractTypeSubstitutor.subst(internal) processType(substed, e, processor) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala index fb7a973c8cb..b006aa8e4ee 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala @@ -191,7 +191,7 @@ abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) case _ => e.`type`() } result match { - case Success(tp, _) => processType(tp, place, state, visitedProjections = visitedProjections, visitedTypeParameter = visitedTypeParameter) + case Success(tp) => processType(tp, place, state, visitedProjections = visitedProjections, visitedTypeParameter = visitedTypeParameter) case _ => true } case ScDesignatorType(e) => @@ -285,7 +285,7 @@ abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) case _ => des.`type`() } typeResult match { - case Success(tp, _) => + case Success(tp) => processType(newSubst subst tp, place, state.put(ScSubstitutor.key, ScSubstitutor.empty), updateWithProjectionSubst = false, visitedProjections = visitedProjections, visitedTypeParameter = visitedTypeParameter) case _ => true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala index 554c04c89b8..b0b8c4027bb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala @@ -295,7 +295,7 @@ object ResolveProcessor { case c: PsiClass => "Class:" + c.qualifiedName case t: ScTypeAliasDefinition if t.typeParameters.isEmpty => t.aliasedType match { - case Success(tp, _) => + case Success(tp) => tp.extractClass match { case Some(_: ScObject) => defaultForTypeAlias(t) case Some(td: ScTypeDefinition) if td.typeParameters.isEmpty && ScalaPsiUtil.hasStablePath(td) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala index 80755fe245b..6ae3a6570b1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala @@ -143,8 +143,8 @@ class ScalaTestConfigurationProducer extends { val params = clauses.head.parameters if (params.nonEmpty) { params.head.`type`() match { - case Success(t, _) if t.isUnit => failedToCheck = false - case Success(tp, _) => + case Success(t) if t.isUnit => failedToCheck = false + case Success(tp) => tp.extractClass match { case Some(psiClass) if psiClass.qualifiedName == "java.lang.String" => call.argumentExpressions.head match { diff --git a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala index cd58269c135..8fb69bee1eb 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala @@ -53,7 +53,7 @@ class SbtCompletionContributor extends ScalaCompletionContributor { def extractSeqType: Option[ScType] = { if (operator.getText != "+=") return None operator.`type`() match { - case Success(ParameterizedType(_, typeArgs), _) => + case Success(ParameterizedType(_, typeArgs)) => typeArgs.last match { case ParameterizedType(settingType, Seq(seqFullType)) if qualifiedName(settingType) == "sbt.Init.Setting" => val collectionTypeNames = Seq("scala.collection.Seq", "scala.collection.immutable.Set") diff --git a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala index d8bd86d7120..e9d4fcff894 100644 --- a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala @@ -97,7 +97,7 @@ trait TypeAdapter { def toType(tr: TypeResult[ptype.ScType]): m.Type = { import org.jetbrains.plugins.scala.lang.psi.types.result._ tr match { - case Success(res, _) => toType(res) + case Success(res) => toType(res) case Failure(cause) => throw new ScalaMetaTypeResultFailure(cause) } } @@ -130,7 +130,7 @@ trait TypeAdapter { m.Type.Name(t.name) case t: ScTypedDefinition => t.getTypeWithCachedSubst match { - case Success(res, _) => toType(res) + case Success(res) => toType(res) case Failure(cause) => unresolved(cause) } case t: ScReferenceElement if dumbMode => @@ -261,7 +261,7 @@ trait TypeAdapter { def returnType(tr: ptype.result.TypeResult[ptype.ScType]): m.Type = { import ptype.result._ tr match { - case Success(t, _) => toType(t) + case Success(t) => toType(t) case Failure(cause) => LOG.warn(s"Failed to infer return type($cause)") m.Type.Name("Unit")//.setTypechecked diff --git a/scala/scala-impl/src/scala/meta/trees/Utils.scala b/scala/scala-impl/src/scala/meta/trees/Utils.scala index 746c4f95794..e89a213f0e3 100644 --- a/scala/scala-impl/src/scala/meta/trees/Utils.scala +++ b/scala/scala-impl/src/scala/meta/trees/Utils.scala @@ -161,7 +161,7 @@ trait Utils { } else { val s = ScSubstitutor(ScSubstitutor.cache.toMap) expr.`type`() match { - case Success(res, elem) => Success(s.subst(res)) + case Success(res) => Success(s.subst(res)) case other => other } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala index cadb09fef5b..0f41389908d 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala @@ -34,7 +34,7 @@ class MonocleLensesTest extends ScalaLightPlatformCodeInsightTestCaseAdapter { val exp = PsiTreeUtil.findElementOfClassAtOffset(getFileAdapter, caretPos, classOf[ScalaPsiElement], false).asInstanceOf[ScObject] exp.allMethods.find(_.name == methodName) match { case Some(x) => x.method.asInstanceOf[ScFunctionDefinition].returnType match { - case Success(t, _) => assertEquals(s"${t.toString} != $expectedType", expectedType, t.toString) + case Success(t) => assertEquals(s"${t.toString} != $expectedType", expectedType, t.toString) case Failure(cause) => fail(cause) } case None => fail("method not found") diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala index 7c9f1a367cd..3896e9a601d 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala @@ -55,7 +55,7 @@ class StalactiteTest extends ScalaLightCodeInsightFixtureTestAdapter { } match { case Some(method) => method.returnType match { - case Success(t, _) => assertEquals(s"${t.presentableText} != $expectedType", expectedType, t.presentableText) + case Success(t) => assertEquals(s"${t.presentableText} != $expectedType", expectedType, t.presentableText) case Failure(cause) => fail(cause) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala index 52e9142a587..324131c8131 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala @@ -97,7 +97,7 @@ abstract class TypeConformanceTestBase extends ScalaLightPlatformCodeInsightTest val expr = valueDecl.expr.getOrElse(sys.error("Expression not found")) expr.`type`() match { - case Success(rhsType, _) => (declaredType, rhsType) + case Success(rhsType) => (declaredType, rhsType) case Failure(msg) => sys.error(s"Couldn't compute type of ${expr.getText}: $msg") } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala index 56b197a829b..1d13dba86d6 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala @@ -26,11 +26,11 @@ trait TypeInferenceDoTest { val scalaFile: ScalaFile = configureFromFileText(fileName, fileText) val expr: ScExpression = findExpression(scalaFile) val typez = expr.`type`() match { - case Success(t, _) if t.isUnit => expr.getTypeIgnoreBaseType + case Success(t) if t.isUnit => expr.getTypeIgnoreBaseType case x => x } typez match { - case Success(ttypez, _) => + case Success(ttypez) => val res = ttypez.presentableText val lastPsi = scalaFile.findElementAt(scalaFile.getText.length - 1) val text = lastPsi.getText diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala index 4b3e52bdec9..340a22f394a 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala @@ -43,7 +43,7 @@ abstract class ExistentialSimplificationTestBase extends ScalaLightPlatformCodeI val expr: ScExpression = PsiTreeUtil.findElementOfClassAtRange(scalaFile, startOffset + addOne, endOffset, classOf[ScExpression]) assert(expr != null, "Not specified expression in range to infer type.") expr.`type`() match { - case Success(ttypez: ScExistentialType, _) => + case Success(ttypez: ScExistentialType) => val res = ttypez.simplify().presentableText val lastPsi = scalaFile.findElementAt(scalaFile.getText.length - 1) @@ -55,7 +55,7 @@ abstract class ExistentialSimplificationTestBase extends ScalaLightPlatformCodeI case _ => assertTrue("Test result must be in last comment statement.", false) } assertEquals(output, res) - case Success(_, _) => fail("Expression has not existential type") + case Success(_) => fail("Expression has not existential type") case Failure(msg) => fail(msg) } } diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala index 8d06c43b3ff..710b0b76de9 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala @@ -1,9 +1,9 @@ package scala.meta.annotations import com.intellij.lang.annotation.HighlightSeverity -import org.jetbrains.plugins.scala.{ScalaBundle, SlowTests} import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTypeDefinition} +import org.jetbrains.plugins.scala.{ScalaBundle, SlowTests} import org.junit.Assert import org.junit.Assert.{assertEquals, assertFalse, assertTrue, fail} import org.junit.experimental.categories.Category @@ -126,14 +126,14 @@ class MetaAnnotationBugsTest extends MetaAnnotationTestBase { .find(_.getName == "foo") .map(_.asInstanceOf[ScFunction].returnType) .getOrElse(fail("Method not generated by annotation")) match { - case Success(res, _) => res + case Success(res) => res case Failure(cause) => fail(s"Failed to infer generated method type: $cause") } val fooBarAType = bar.members .find(_.getName == "fooA").get .asInstanceOf[ScFunction].returnType match { - case Success(res, _) => res + case Success(res) => res case Failure(cause) => fail(s"Failed to infer generated method type: $cause") } From ec3a206c2a6de852611bddd38e1a62a08f856c24 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 25 Oct 2017 16:22:48 +0300 Subject: [PATCH 047/141] TypeInferenceError abstraction #SCL-12743 --- .../lang/psi/types/result/TypeResult.scala | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala index 314eaa41a6e..a311b050fa7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala @@ -4,6 +4,7 @@ package psi package types package result +import org.jetbrains.plugins.scala.lang.psi.types.result.Failure.TypeError import org.jetbrains.plugins.scala.project.ProjectContext /** @@ -64,8 +65,7 @@ final case class Success[T <: ScType](private val result: T) extends TypeResult[ def getOrAny: T = result } -final case class Failure(private val cause: String) - (implicit context: ProjectContext) extends TypeResult[Nothing] { +final class Failure private(private val error: TypeError) extends TypeResult[Nothing] { def map[U <: ScType](f: Nothing => U): this.type = this @@ -79,7 +79,30 @@ final case class Failure(private val cause: String) def isEmpty: Boolean = true - def getOrNothing: ScType = api.Nothing + def getOrNothing: ScType = api.Nothing(error.context) + + def getOrAny: ScType = api.Any(error.context) + + override def equals(other: Any): Boolean = other match { + case that: Failure => error == that.error + case _ => false + } + + override def hashCode(): Int = error.hashCode() + + override def toString = s"Failure(${error.cause})" +} + +object Failure { + + case class TypeError(private[result] val cause: String, + private[result] val context: ProjectContext) + + def apply(message: String) + (implicit context: ProjectContext): Failure = + new Failure(TypeError(message, context)) + + def unapply(failure: Failure): Option[String] = + Some(failure.error.cause) - def getOrAny: ScType = api.Any } From 733336c4acc2ac3a7f515be0ae26e5881de41e9b Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 25 Oct 2017 17:34:13 +0300 Subject: [PATCH 048/141] Success/Failure replacement #SCL-12743 --- .../types/DottyAndOrTypeElementImpl.scala | 4 +- .../types/DottyRefinedTypeElementImpl.scala | 2 +- .../lang/psi/types/DottyPsiTypeBridge.scala | 2 +- .../scala/annotator/FunctionAnnotator.scala | 2 +- .../scala/annotator/PatternAnnotator.scala | 2 +- .../createFromUsage/CreateFromUsageUtil.scala | 1 + .../intention/sbt/AddSbtDependencyUtils.scala | 2 +- .../quickfix/AddBreakoutQuickFix.scala | 2 +- .../annotator/quickfix/ChangeTypeFix.scala | 2 +- .../ScalaGeneratePropertyAction.scala | 1 + .../IntroduceExplicitParameterIntention.scala | 1 + .../IntroduceImplicitParameterIntention.scala | 1 + .../types/MakeTypeMoreSpecificIntention.scala | 6 +- .../macros/ScalaMethodReturnTypeMacro.scala | 1 + .../SuggestScalaVariableNameMacro.scala | 2 +- .../codeInspection/InspectionsUtil.scala | 1 + .../ConvertExpressionToSAMInspection.scala | 3 +- .../booleans/SimplifyBooleanInspection.scala | 1 + .../cast/ScalaRedundantCastInspection.scala | 2 +- .../collections/ExistsEqualsInspection.scala | 1 + .../collections/MapGetOrElseInspection.scala | 2 +- ...undantCollectionConversionInspection.scala | 2 +- .../collections/ToSetAndBackInspection.scala | 2 +- .../collections/UnitInMapInspection.scala | 3 +- .../codeInspection/collections/package.scala | 2 +- .../ScalaUselessExpressionInspection.scala | 1 + .../MatchToPartialFunctionInspection.scala | 2 +- ...hodAccessedAsParameterlessInspection.scala | 1 + .../NestedStatefulMonadsInspection.scala | 1 + .../ConvertibleToMethodValueInspection.scala | 2 +- .../ComparingUnrelatedTypesInspection.scala | 6 +- ...dTypeLambdaCanBeSimplifiedInspection.scala | 1 + ...ctorSimplifyTypeProjectionInspection.scala | 2 +- .../ScalaEvaluatorBuilderUtil.scala | 2 +- .../evaluator/ScalaLiteralEvaluator.scala | 1 + .../evaluation/util/DebuggerUtil.scala | 2 +- .../ScalaDocumentationProvider.scala | 2 +- .../plugins/scala/extensions/package.scala | 1 + .../plugins/scala/format/StringPart.scala | 29 ++--- .../SameSignatureCallParametersProvider.scala | 2 +- .../ScalaSmartCompletionContributor.scala | 2 +- .../ScalaUnresolvedNameContributor.scala | 1 + .../completion/lookups/ScalaLookupItem.scala | 2 +- .../ScalaPostfixTemplatePsiInfo.scala | 1 + .../selector/SelectorConditions.scala | 1 + .../statistician/ScalaStatisticManager.scala | 1 + .../weighter/ScalaByExpectedTypeWeigher.scala | 2 +- .../ScalaFunctionParameterInfoHandler.scala | 1 + .../ScalaPatternParameterInfoHandler.scala | 1 + .../scala/lang/psi/PresentationUtil.scala | 1 + .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 2 +- .../scala/lang/psi/api/InferUtil.scala | 2 +- .../api/base/patterns/ScTuplePattern.scala | 2 +- .../lang/psi/api/base/types/package.scala | 1 + .../lang/psi/api/expr/ExpectedTypes.scala | 2 +- .../lang/psi/api/expr/MethodInvocation.scala | 2 +- .../lang/psi/api/expr/ScAnnotations.scala | 2 +- .../scala/lang/psi/api/expr/ScBlock.scala | 2 +- .../api/statements/ScAnnotationsHolder.scala | 1 + .../lang/psi/api/statements/ScFunction.scala | 2 +- .../statements/ScTypeAliasDefinition.scala | 2 +- .../api/statements/params/ScParameter.scala | 2 +- .../statements/params/ScParameterClause.scala | 1 + .../psi/api/toplevel/ScTypedDefinition.scala | 2 +- .../scala/lang/psi/api/toplevel/package.scala | 1 + .../typedef/ScTemplateDefinition.scala | 2 +- .../scala/lang/psi/fake/FakePsiMethod.scala | 1 + .../psi/impl/ScalaPsiElementFactory.scala | 1 + .../psi/impl/base/ScConstructorImpl.scala | 2 +- .../ScInterpolatedStringLiteralImpl.scala | 2 +- .../lang/psi/impl/base/ScLiteralImpl.scala | 2 +- .../ScStableCodeReferenceElementImpl.scala | 4 +- .../psi/impl/base/ScTypeBoundsOwnerImpl.scala | 2 +- .../patterns/ScCompositePatternImpl.scala | 2 +- .../patterns/ScConstructorPatternImpl.scala | 2 +- .../base/patterns/ScInfixPatternImpl.scala | 2 +- .../base/patterns/ScNamingPatternImpl.scala | 2 +- .../patterns/ScReferencePatternImpl.scala | 2 +- .../base/patterns/ScTypedPatternImpl.scala | 2 +- .../base/patterns/ScWildcardPatternImpl.scala | 2 +- .../types/ScCompoundTypeElementImpl.scala | 2 +- .../types/ScExistentialTypeElementImpl.scala | 2 +- .../ScParameterizedTypeElementImpl.scala | 2 +- .../ScParenthesisedTypeElementImpl.scala | 2 +- .../base/types/ScSimpleTypeElementImpl.scala | 4 +- .../base/types/ScTypeProjectionImpl.scala | 2 +- .../types/ScTypeVariableTypeElementImpl.scala | 2 +- .../lang/psi/impl/expr/ScAnnotationImpl.scala | 1 + .../lang/psi/impl/expr/ScAssignStmtImpl.scala | 2 +- .../psi/impl/expr/ScForStatementImpl.scala | 2 +- .../psi/impl/expr/ScFunctionExprImpl.scala | 2 +- .../lang/psi/impl/expr/ScIfStmtImpl.scala | 2 +- .../lang/psi/impl/expr/ScMatchStmtImpl.scala | 2 +- .../expr/ScNewTemplateDefinitionImpl.scala | 2 +- .../impl/expr/ScParenthesisedExprImpl.scala | 2 +- .../impl/expr/ScReferenceExpressionImpl.scala | 2 +- .../lang/psi/impl/expr/ScReturnStmtImpl.scala | 2 +- .../psi/impl/expr/ScSelfInvocationImpl.scala | 2 +- .../psi/impl/expr/ScSuperReferenceImpl.scala | 2 +- .../psi/impl/expr/ScThisReferenceImpl.scala | 4 +- .../lang/psi/impl/expr/ScThrowStmtImpl.scala | 2 +- .../lang/psi/impl/expr/ScTryStmtImpl.scala | 2 +- .../lang/psi/impl/expr/ScTupleImpl.scala | 2 +- .../lang/psi/impl/expr/ScTypedStmtImpl.scala | 2 +- .../impl/expr/ScUnderscoreSectionImpl.scala | 2 +- .../lang/psi/impl/expr/ScUnitExprImpl.scala | 2 +- .../lang/psi/impl/expr/ScWhileStmtImpl.scala | 2 +- .../psi/impl/expr/xml/ScXmlExprImpl.scala | 2 +- .../psi/impl/expr/xml/ScXmlPatternImpl.scala | 2 +- .../ScFunctionDeclarationImpl.scala | 2 +- .../statements/ScFunctionDefinitionImpl.scala | 2 +- .../statements/ScMacroDefinitionImpl.scala | 2 +- .../statements/ScPatternDefinitionImpl.scala | 2 +- .../ScTypeAliasDeclarationImpl.scala | 2 +- .../statements/ScValueDeclarationImpl.scala | 2 +- .../statements/ScVariableDefinitionImpl.scala | 2 +- .../statements/params/ScParameterImpl.scala | 2 +- .../statements/params/ScTypeParamImpl.scala | 2 +- .../toplevel/imports/ScImportStmtImpl.scala | 2 +- .../toplevel/synthetic/ScSyntheticClass.scala | 2 +- .../templates/ScClassParentsImpl.scala | 1 + .../templates/ScExtendsBlockImpl.scala | 3 +- .../templates/ScTraitParentsImpl.scala | 1 + .../impl/toplevel/typedef/MixinNodes.scala | 2 +- .../impl/toplevel/typedef/ScClassImpl.scala | 2 +- .../typedef/ScTypeDefinitionImpl.scala | 4 +- .../typedef/TypeDefinitionMembers.scala | 3 +- .../simulacrum/SimulacrumInjection.scala | 2 +- .../psi/implicits/ImplicitCollector.scala | 2 +- .../implicits/ScImplicitlyConvertible.scala | 3 +- .../lang/psi/light/JavaConversionUtil.scala | 2 +- .../scala/lang/psi/light/LightUtil.scala | 2 +- .../lang/psi/light/ScFunctionWrapper.scala | 2 +- .../light/StaticTraitScFunctionWrapper.scala | 2 +- .../light/scala/ScLightBindingPattern.scala | 2 +- .../lang/psi/light/scala/ScLightFieldId.scala | 2 +- .../scala/ScLightFunctionDeclaration.scala | 2 +- .../scala/ScLightFunctionDefinition.scala | 2 +- .../psi/light/scala/ScLightParameter.scala | 2 +- .../scala/ScLightTypeAliasDeclaration.scala | 2 +- .../scala/ScLightTypeAliasDefinition.scala | 2 +- .../psi/light/scala/ScLightTypeParam.scala | 2 +- .../ScImplicitFunctionListCellRenderer.scala | 4 +- .../lang/psi/stubs/util/ScalaStubsUtil.scala | 2 +- .../scala/lang/psi/types/BaseTypes.scala | 2 +- .../scala/lang/psi/types/Compatibility.scala | 2 +- .../scala/lang/psi/types/ScCompoundType.scala | 1 + .../lang/psi/types/ScParameterizedType.scala | 2 +- .../scala/lang/psi/types/ScSubstitutor.scala | 1 + .../scala/lang/psi/types/ScalaBounds.scala | 1 + .../lang/psi/types/ScalaConformance.scala | 2 +- .../lang/psi/types/ScalaEquivalence.scala | 2 +- .../lang/psi/types/ScalaPsiTypeBridge.scala | 2 +- .../scala/lang/psi/types/ScalaType.scala | 3 +- .../scala/lang/psi/types/Signature.scala | 1 + .../lang/psi/types/api/TypeParameter.scala | 1 + .../psi/types/api/TypeParameterType.scala | 1 + .../api/designator/ScDesignatorType.scala | 2 +- .../api/designator/ScProjectionType.scala | 2 +- .../psi/types/api/designator/ScThisType.scala | 2 +- .../psi/types/nonvalue/ScMethodType.scala | 1 + .../scala/lang/psi/types/package.scala | 4 +- .../lang/psi/types/result/TypeResult.scala | 108 ------------------ .../scala/lang/psi/types/result/package.scala | 49 ++++++++ .../rearranger/ScalaArrangementVisitor.scala | 3 +- .../ScalaChangeSignatureUsageHandler.scala | 2 +- .../ScalaMethodDescriptor.scala | 1 + .../changeSignature/ScalaParameterInfo.scala | 1 + .../ScalaParameterTableModelItem.scala | 1 + .../ScalaExtractMethodHandler.scala | 1 + .../ScalaExtractMethodUtils.scala | 1 + .../duplicates/DuplicateMatch.scala | 4 +- .../inline/ScalaInlineHandler.scala | 1 + .../ScalaIntroduceParameterHandler.scala | 1 + .../memberPullUp/ScalaPullUpProcessor.scala | 2 +- .../util/ScalaRefactoringUtil.scala | 1 + .../resolve/ReferenceExpressionResolver.scala | 2 +- .../resolve/processor/BaseProcessor.scala | 2 +- .../CompoundTypeCheckProcessor.scala | 1 + .../ExpandedExtractorResolveProcessor.scala | 1 + .../processor/ExtractorResolveProcessor.scala | 8 +- .../processor/MethodResolveProcessor.scala | 2 +- .../resolve/processor/MostSpecificUtil.scala | 1 + .../resolve/processor/ResolveProcessor.scala | 2 +- .../ScalaElementPresentation.scala | 2 +- .../structureView/StructureViewUtil.scala | 1 + .../expression/ScalaTypeSurrounder.scala | 1 + .../ScalaWithIfConditionSurrounder.scala | 5 +- .../ScalaWithIfElseConditionSurrounder.scala | 1 + .../ScalaWithUnaryNotSurrounder.scala | 1 + .../AddTypeToFunctionParameter.scala | 1 + .../AddTypeToMethodDefinition.scala | 1 + .../overrideImplement/ScalaNamedMember.scala | 1 + .../ScalaTestConfigurationProducer.scala | 2 +- .../scala/util/ScEquivalenceUtil.scala | 2 +- .../plugins/scala/util/SideEffectsUtil.scala | 1 + .../sbt/annotator/SbtAnnotator.scala | 1 + .../completion/SbtCompletionContributor.scala | 2 +- .../meta/intellij/QuasiquoteInferUtil.scala | 12 +- .../src/scala/meta/trees/TreeAdapter.scala | 1 + .../src/scala/meta/trees/TypeAdapter.scala | 2 +- .../src/scala/meta/trees/Utils.scala | 12 +- .../scala/lang/macros/MonocleLensesTest.scala | 2 +- .../scala/lang/macros/StalactiteTest.scala | 2 +- .../scala/lang/psi/types/ScLiteralTest.scala | 1 + .../TypeConformanceTestBase.scala | 2 +- .../typeInference/TypeInferenceDoTest.scala | 2 +- .../ExistentialSimplificationTestBase.scala | 2 +- .../IntroduceParameterTestBase.scala | 1 + .../annotator/annotatorConformanceTest.scala | 1 + 210 files changed, 302 insertions(+), 297 deletions(-) delete mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala index 6b58825c96a..c2d47c05d99 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala @@ -4,7 +4,7 @@ import com.intellij.lang.ASTNode import org.jetbrains.plugins.dotty.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElementImpl import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScInfixTypeElement -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} /** @@ -23,7 +23,7 @@ abstract class DottyAndOrTypeElementImpl(node: ASTNode) extends ScalaPsiElementI } ).map(_.getOrElse(default)) - override protected def innerType: Success[ScType] = Success(innerTypeValue) + override protected def innerType: TypeResult[ScType] = Success(innerTypeValue) } class DottyAndTypeElementImpl(node: ASTNode) extends DottyAndOrTypeElementImpl(node) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala index 30484b0d57d..16395c41914 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala @@ -5,7 +5,7 @@ import org.jetbrains.plugins.dotty.lang.psi.api.base.types.DottyRefinedTypeEleme import org.jetbrains.plugins.dotty.lang.psi.types.DottyRefinedType import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElementImpl import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author adkozlov diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala index 6e84ecb33ab..068f2253bca 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala @@ -7,7 +7,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticC import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, StdType, arrayType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.JavaConverters._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala index 60a615693b5..2a8d611c38a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala @@ -8,7 +8,7 @@ import org.jetbrains.plugins.scala.annotator.quickfix.{AddReturnTypeFix, RemoveE import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.types.api._ -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScTypeExt, ScTypesExt} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala index 0bdb2990575..2d2abd14143 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.ComparingUtil._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.DesignatorOwner import org.jetbrains.plugins.scala.lang.psi.types.api.{ScTypePresentation, _} import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, ReplaceWith} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScAbstractType, ScParameterizedType, ScType, ScTypeExt, ScalaType} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateFromUsageUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateFromUsageUtil.scala index 5ba4b6a9434..51da51b3e97 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateFromUsageUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateFromUsageUtil.scala @@ -16,6 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, ScTypeParam} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, ExtractClass} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.refactoring.namesSuggester.NameSuggester import org.jetbrains.plugins.scala.util.TypeAnnotationUtil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala index beefc1220f2..cabfb7c3fec 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScPatternDefinition import org.jetbrains.plugins.scala.lang.psi.api.{ScalaElementVisitor, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext import org.jetbrains.sbt.resolvers.ArtifactInfo diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala index a7e5af1d610..f5f101b03ce 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScForStateme import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Nikolay.Tropin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala index 73d9ca34440..9e77c93161a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeElementFromText import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.ScTypePresentation -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ class ChangeTypeFix(typeElement: ScTypeElement, newType: ScType) extends IntentionAction { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/generation/ScalaGeneratePropertyAction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/generation/ScalaGeneratePropertyAction.scala index 0ed886b092e..1a01bb67eb1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/generation/ScalaGeneratePropertyAction.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/generation/ScalaGeneratePropertyAction.scala @@ -8,6 +8,7 @@ import org.jetbrains.plugins.scala.codeInsight.generation.GenerationUtil.element import org.jetbrains.plugins.scala.lang.psi.TypeAdjuster import org.jetbrains.plugins.scala.lang.psi.api.statements.ScVariableDefinition import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createDefinitionWithContext, createNewLine} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * Nikolay.Tropin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceExplicitParameterIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceExplicitParameterIntention.scala index a27bb687512..dc6a31ad737 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceExplicitParameterIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceExplicitParameterIntention.scala @@ -21,6 +21,7 @@ import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createExpressionFromText, createParameterFromText} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.namesSuggester.NameSuggester import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaVariableValidator import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceImplicitParameterIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceImplicitParameterIntention.scala index 9345a7d6365..5c532e76e33 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceImplicitParameterIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/expression/IntroduceImplicitParameterIntention.scala @@ -17,6 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext import scala.annotation.tailrec diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/MakeTypeMoreSpecificIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/MakeTypeMoreSpecificIntention.scala index be3af6d3a50..a872a427ae7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/MakeTypeMoreSpecificIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/MakeTypeMoreSpecificIntention.scala @@ -33,7 +33,7 @@ class MakeTypeMoreSpecificIntention extends AbstractTypeAnnotationIntention { for { declared <- variable.declaredType expr <- variable.expr - tp <- expr.`type`() + tp <- expr.`type`().toOption if computeBaseTypes(declared, tp).nonEmpty } setText(message("make.type.more.specific")) @@ -45,7 +45,7 @@ class MakeTypeMoreSpecificIntention extends AbstractTypeAnnotationIntention { for { declared <- value.declaredType expr <- value.expr - tp <- expr.`type`() + tp <- expr.`type`().toOption if computeBaseTypes(declared, tp).nonEmpty } setText(message("make.type.more.specific")) @@ -57,7 +57,7 @@ class MakeTypeMoreSpecificIntention extends AbstractTypeAnnotationIntention { for { declared <- function.returnType expr <- function.body - tp <- expr.`type`() + tp <- expr.`type`().toOption if computeBaseTypes(declared, tp).nonEmpty } setText(message("make.type.more.specific.fun")) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/ScalaMethodReturnTypeMacro.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/ScalaMethodReturnTypeMacro.scala index 0d2893e5656..573e2a37587 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/ScalaMethodReturnTypeMacro.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/ScalaMethodReturnTypeMacro.scala @@ -6,6 +6,7 @@ import org.jetbrains.plugins.scala.codeInsight.template.impl.ScalaCodeContextTyp import org.jetbrains.plugins.scala.codeInsight.template.util.MacroUtil import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala index a3be68d93a2..a05531032a1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala @@ -8,7 +8,7 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.{JavaArrayType, ParameterizedType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.namesSuggester.NameSuggester /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/InspectionsUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/InspectionsUtil.scala index fac005933e0..0aadb4d295d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/InspectionsUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/InspectionsUtil.scala @@ -8,6 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/SAM/ConvertExpressionToSAMInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/SAM/ConvertExpressionToSAMInspection.scala index e815abb1fc1..068d0e8084b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/SAM/ConvertExpressionToSAMInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/SAM/ConvertExpressionToSAMInspection.scala @@ -13,7 +13,8 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScInfixExpr, import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameterClause import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} +import org.jetbrains.plugins.scala.lang.psi.types.ScType +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * Author: Svyatoslav Ilinskiy diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/booleans/SimplifyBooleanInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/booleans/SimplifyBooleanInspection.scala index 95babf93422..6779a5e85e1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/booleans/SimplifyBooleanInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/booleans/SimplifyBooleanInspection.scala @@ -10,6 +10,7 @@ import org.jetbrains.plugins.scala.lang.completion.ScalaKeyword import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createExpressionFromText, createExpressionWithContextFromText} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScTypeExt, api} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaRefactoringUtil.getShortText diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantCastInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantCastInspection.scala index 0e933554362..4b5661e413a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantCastInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/cast/ScalaRedundantCastInspection.scala @@ -24,7 +24,7 @@ class ScalaRedundantCastInspection extends AbstractInspection("Redundant cast") case List(left: ScExpression, ElementText("."), ElementText("asInstanceOf")) => for (actualType <- left.`type`().toOption; typeArgument <- call.arguments.headOption; - castType <- typeArgument.`type`() if actualType.equiv(castType)) { + castType <- typeArgument.`type`().toOption if actualType.equiv(castType)) { val descriptor = { val range = new TextRange(left.getTextLength, call.getTextLength) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ExistsEqualsInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ExistsEqualsInspection.scala index 39b39796444..d44dc4a0069 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ExistsEqualsInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ExistsEqualsInspection.scala @@ -5,6 +5,7 @@ import org.jetbrains.plugins.scala.codeInspection.InspectionBundle import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScMethodCall, ScReferenceExpression} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * Nikolay.Tropin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala index 2aa07e62f66..5c46ee8dbab 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala @@ -5,7 +5,7 @@ import org.jetbrains.plugins.scala.codeInspection.InspectionBundle import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScMethodCall} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * Nikolay.Tropin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/RedundantCollectionConversionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/RedundantCollectionConversionInspection.scala index 736515a90ec..cd2fb300771 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/RedundantCollectionConversionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/RedundantCollectionConversionInspection.scala @@ -5,7 +5,7 @@ import org.jetbrains.plugins.scala.codeInspection.InspectionBundle import org.jetbrains.plugins.scala.extensions.ChildOf import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScGenericCall} import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Nikolay.Tropin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ToSetAndBackInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ToSetAndBackInspection.scala index 028c3eae746..2c4f6ddbcf3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ToSetAndBackInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/ToSetAndBackInspection.scala @@ -3,7 +3,7 @@ package org.jetbrains.plugins.scala.codeInspection.collections import org.jetbrains.plugins.scala.codeInspection.InspectionBundle import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala index 42e7393f4d6..2926786e39d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala @@ -7,9 +7,8 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScBlock, ScExpression, ScFunctionExpr} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScEarlyDefinitions import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody -import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Nikolay.Tropin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala index 69850d376e2..1c7c56f930a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala @@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.{InferUtil, ScalaRecursiveElemen import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, JavaArrayType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.project.ProjectPsiElementExt diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala index 4333128a316..54697452c78 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala @@ -11,6 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScCaseClause, ScC import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunctionDefinition, ScPatternDefinition, ScVariableDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.util.{IntentionAvailabilityChecker, SideEffectsUtil} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala index 312a72c2209..6b4bdd98351 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala @@ -17,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import scala.collection.JavaConverters._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/JavaMutatorMethodAccessedAsParameterlessInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/JavaMutatorMethodAccessedAsParameterlessInspection.scala index be0a5658c5c..4090153d8af 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/JavaMutatorMethodAccessedAsParameterlessInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/JavaMutatorMethodAccessedAsParameterlessInspection.scala @@ -6,6 +6,7 @@ import org.jetbrains.plugins.scala.codeInspection.methodSignature.quickfix.AddCa import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/monads/NestedStatefulMonadsInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/monads/NestedStatefulMonadsInspection.scala index 1599e47dcfb..2f144b89162 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/monads/NestedStatefulMonadsInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/monads/NestedStatefulMonadsInspection.scala @@ -7,6 +7,7 @@ import org.jetbrains.plugins.scala.codeInspection.monads.NestedStatefulMonadsIns import org.jetbrains.plugins.scala.codeInspection.monads.StatefulMonads._ import org.jetbrains.plugins.scala.lang.psi.api.expr.ScMethodCall import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Sergey Tolmachev (tolsi.ru@gmail.com) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala index e7e07cb2b1f..d547eee6e11 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala @@ -19,7 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createExpressionFromText, createExpressionWithContextFromText} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala index 92039e49104..02c8e5a368d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticF import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.api.{ScTypePresentation, _} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil import org.jetbrains.plugins.scala.project.ProjectExt @@ -98,8 +98,8 @@ class ComparingUnrelatedTypesInspection extends AbstractInspection(inspectionId, } case MethodRepr(_, Some(baseExpr), Some(ResolvesTo(fun: ScFunction)), Seq(arg, _*)) if mayNeedHighlighting(fun) => for { - ParameterizedType(_, Seq(elemType)) <- baseExpr.`type`().map(_.tryExtractDesignatorSingleton) - argType <- arg.`type`() + ParameterizedType(_, Seq(elemType)) <- baseExpr.`type`().toOption.map(_.tryExtractDesignatorSingleton) + argType <- arg.`type`().toOption if cannotBeCompared(elemType, argType) } { val message = generateComparingUnrelatedTypesMsg(elemType, argType) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/AppliedTypeLambdaCanBeSimplifiedInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/AppliedTypeLambdaCanBeSimplifiedInspection.scala index 44e4f14db71..5d4bab82fb0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/AppliedTypeLambdaCanBeSimplifiedInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/AppliedTypeLambdaCanBeSimplifiedInspection.scala @@ -11,6 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.PsiTypeParamet import org.jetbrains.plugins.scala.lang.psi.api.{ScalaElementVisitor, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeElementFromText import org.jetbrains.plugins.scala.lang.psi.types.ScSubstitutor +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala index ecaa0b6c33c..ea723213b1e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala @@ -14,7 +14,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.api.{ScalaElementVisitor, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeElementFromText import org.jetbrains.plugins.scala.lang.psi.types.ScParameterizedType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * Author: Svyatoslav Ilinskiy diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala index 682e4ac9464..7375eccecb5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala @@ -34,7 +34,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import scala.annotation.tailrec diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaLiteralEvaluator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaLiteralEvaluator.scala index 9c8eca17098..9d0fec021a1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaLiteralEvaluator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaLiteralEvaluator.scala @@ -6,6 +6,7 @@ import org.jetbrains.plugins.scala.debugger.evaluation.EvaluationException import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral import org.jetbrains.plugins.scala.lang.psi.types.ScType +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * User: Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala index f6fc819bf2d..bbbb4c9f41e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala @@ -26,7 +26,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScEarlyDefinitions, Sc import org.jetbrains.plugins.scala.lang.psi.api.{ScalaFile, ScalaRecursiveElementVisitor} import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ValueClassType} import scala.annotation.tailrec diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala index 279ab2b572d..ac385738c51 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala @@ -29,7 +29,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createSc import org.jetbrains.plugins.scala.lang.psi.light.ScFunctionWrapper import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, ParameterizedType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{PresentationUtil, ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.lang.scaladoc.lexer.ScalaDocTokenType diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala index b3d167ae6c3..3e0baf9a368 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala @@ -38,6 +38,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticC import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.MixinNodes import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.TypeDefinitionMembers.SignatureNodes import org.jetbrains.plugins.scala.lang.psi.light.{PsiClassWrapper, PsiTypedDefinitionWrapper, StaticPsiMethodWrapper} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.psi.{ElementScope, ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala index eaa72c5acf0..1ca39da6675 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/format/StringPart.scala @@ -7,8 +7,8 @@ import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScBlockExpr, ScExpression} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText -import org.jetbrains.plugins.scala.lang.psi.types.result.Success -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScalaType} +import org.jetbrains.plugins.scala.lang.psi.types.ScType +import org.jetbrains.plugins.scala.lang.psi.types.ScalaType.expandAliases import org.jetbrains.plugins.scala.project.ProjectContext /** @@ -55,21 +55,16 @@ case class Injection(expression: ScExpression, specifier: Option[Specifier]) ext case _ => false } - def problem: Option[InjectionProblem] = specifier.flatMap { - it => - val _type = expressionType.map(ScalaType.expandAliases(_)).getOrElse(new Object()) - _type match { - case Success(result) => result match { - case res: ScType => - try { - val value = Types.valueOf(res) - value.formatted(it.format) - None - } catch { - case _: IllegalFormatConversionException => Some(Inapplicable) - case _: IllegalFormatException => Some(Malformed) - } - case _ => Some(Malformed) + def problem: Option[InjectionProblem] = specifier.flatMap { it => + expressionType.flatMap(expandAliases(_).toOption) match { + case Some(result) => + try { + val value = Types.valueOf(result) + value.formatted(it.format) + None + } catch { + case _: IllegalFormatConversionException => Some(Inapplicable) + case _: IllegalFormatException => Some(Malformed) } case _ => Some(Malformed) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala index b94f2caa770..cc84cdac069 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.{ScConstructor, ScMethodLik import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScArgumentExprList, ScMethodCall, ScReferenceExpression, ScSuperReference} import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTemplateDefinition} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala index d27a9936c23..ef5110dd8e5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala @@ -27,7 +27,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticF import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScProjectionType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.processor.CompletionProcessor import org.jetbrains.plugins.scala.lang.resolve.{ResolveUtils, ScalaResolveResult, StdKinds} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaUnresolvedNameContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaUnresolvedNameContributor.scala index 6732a8c4f4e..3bf2b51e2c2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaUnresolvedNameContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaUnresolvedNameContributor.scala @@ -18,6 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunctionDeclaratio import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScModifierListOwner import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.types.ScType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.namesSuggester.NameSuggester import org.jetbrains.plugins.scala.lang.resolve.ResolveTargets._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala index 638f7c15ec0..47ccf96549a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala @@ -25,7 +25,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeParametersOwner import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.{ScImportSelectors, ScImportStmt} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTemplateDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createExpressionFromText, createReferenceFromText} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil.escapeKeyword import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/ScalaPostfixTemplatePsiInfo.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/ScalaPostfixTemplatePsiInfo.scala index 74119ddb667..f14538f7b14 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/ScalaPostfixTemplatePsiInfo.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/ScalaPostfixTemplatePsiInfo.scala @@ -8,6 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScParenthesisedExpr, ScPrefixExpr, ScReferenceExpression} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText import org.jetbrains.plugins.scala.lang.psi.types.api.Boolean +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.surroundWith.surrounders.expression.ScalaWithUnaryNotSurrounder /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/SelectorConditions.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/SelectorConditions.scala index fb5d49ed9c6..0d0f667eec3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/SelectorConditions.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/SelectorConditions.scala @@ -7,6 +7,7 @@ import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil._ import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.util.ScEquivalenceUtil._ import scala.language.implicitConversions diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/statistician/ScalaStatisticManager.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/statistician/ScalaStatisticManager.scala index a4f4e917e3e..c2bc05f069d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/statistician/ScalaStatisticManager.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/statistician/ScalaStatisticManager.scala @@ -6,6 +6,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScClassParameter, ScParameter} import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScTypeAlias, ScValue, ScVariable} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait} +import org.jetbrains.plugins.scala.lang.psi.types.result._ object ScalaStatisticManager { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala index 3d2d7aa7311..cb8f9403af4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticFunction import org.jetbrains.plugins.scala.lang.psi.types.api.{Nothing, ParameterizedType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScalaType} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala index 71f4bdf10e3..876ab58848b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala @@ -28,6 +28,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScTypeParametersOwner, import org.jetbrains.plugins.scala.lang.psi.fake.FakePsiMethod import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.ImplicitCompletionProcessor import org.jetbrains.plugins.scala.lang.resolve.{ResolveUtils, ScalaResolveResult, StdKinds} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala index 12f46db3fb4..899ec049a46 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala @@ -21,6 +21,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.PsiTypeParamet import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{TypeParameterType, UndefinedType} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/PresentationUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/PresentationUtil.scala index 18758804bca..ebc88a9cb6e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/PresentationUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/PresentationUtil.scala @@ -8,6 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.statements.params._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType} import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil import org.jetbrains.plugins.scala.project.{ProjectContext, ProjectContextOwner} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index 16c1904f349..819df965e6e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -45,7 +45,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.lang.resolve.processor._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala index e1e137be237..877a9673c0c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_10 import org.jetbrains.plugins.scala.project._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala index a7d532ef0e4..dbb7458dd1f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala @@ -7,7 +7,7 @@ package patterns import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.TupleType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/package.scala index 4c15dcea8fc..0e5f3f7f35f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/package.scala @@ -1,6 +1,7 @@ package org.jetbrains.plugins.scala.lang.psi.api.base import org.jetbrains.plugins.scala.lang.psi.types.ScType +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author adkozlov diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala index d0a82bd6fc5..5beb2573450 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala @@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{api, _} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala index 4460a65c7e5..a5b739d7ba2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala @@ -15,7 +15,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.lang.resolve.processor.DynamicResolveProcessor import org.jetbrains.plugins.scala.lang.resolve.{ResolveUtils, ScalaResolveResult} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala index 2cac0e3042a..76d2ded4254 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScSimpleTypeElement import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala index da89070dab1..fc4f668b304 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala @@ -23,7 +23,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.mutable import scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScAnnotationsHolder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScAnnotationsHolder.scala index e2942a17bd5..8e6c8a3d54d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScAnnotationsHolder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScAnnotationsHolder.scala @@ -13,6 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createA import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.macroAnnotations._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala index fb14713104b..05eb32552f4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala @@ -35,7 +35,7 @@ import org.jetbrains.plugins.scala.lang.psi.light.scala.{ScLightFunctionDeclarat import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.nonvalue._ -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.macroAnnotations.{Cached, CachedInsidePsiElement, ModCount} import org.jetbrains.plugins.scala.project.UserDataHolderExt diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala index dd736b57f3b..2918ff67391 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeParametersOwner import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{Invariant, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.macroAnnotations.{CachedInsidePsiElement, ModCount} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala index fe4c504c29b..2ed2115d0f2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala @@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScFunctionEx import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScMember} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScImportableDeclarationsOwner, ScModifierListOwner, ScTypedDefinition} import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, ValueType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScParameterizedType, ScType, ScTypeExt, ScalaType} import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameterClause.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameterClause.scala index f2dfa622c1a..d5722c32072 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameterClause.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameterClause.scala @@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypedDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypedDefinition.scala index 682ebbeb835..30096554eb1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypedDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypedDefinition.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.fake.FakePsiMethod import org.jetbrains.plugins.scala.lang.psi.light.{PsiClassWrapper, PsiTypedDefinitionWrapper, StaticPsiTypedDefinitionWrapper} import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result.{Typeable, _} import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} import org.jetbrains.plugins.scala.macroAnnotations.{Cached, CachedInsidePsiElement, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/package.scala index 418e73d05dc..4f0bd3d499a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/package.scala @@ -2,6 +2,7 @@ package org.jetbrains.plugins.scala.lang.psi.api import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScTypeAliasDeclaration, ScTypeAliasDefinition} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author adkozlov diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala index 16b7ec48282..489c7a5db04 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala @@ -33,7 +33,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.TypeDefinition import org.jetbrains.plugins.scala.lang.psi.light.ScFunctionWrapper import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScThisType -import org.jetbrains.plugins.scala.lang.psi.types.result.{TypeResult, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.processor.BaseProcessor import org.jetbrains.plugins.scala.macroAnnotations.{Cached, CachedInsidePsiElement, ModCount} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/fake/FakePsiMethod.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/fake/FakePsiMethod.scala index cec4ff0cf85..b5f76dc6af0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/fake/FakePsiMethod.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/fake/FakePsiMethod.scala @@ -19,6 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * User: Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiElementFactory.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiElementFactory.scala index 1771b705da3..276ccdb5ca9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiElementFactory.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiElementFactory.scala @@ -47,6 +47,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.expr.ScBlockImpl import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.ScalaNamesValidator.isIdentifier import org.jetbrains.plugins.scala.lang.refactoring.util.{ScTypeUtil, ScalaNamesUtil} import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.{ScDocComment, ScDocResolvableCodeReference, ScDocSyntaxElement} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala index 2ed0beb8f28..0c19e742745 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala @@ -23,7 +23,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.api.{TypeParameter, TypeParameterType, UndefinedType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.{ResolveUtils, ScalaResolveResult} import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala index d42102b537f..918725bc438 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala @@ -5,7 +5,7 @@ import com.intellij.lang.ASTNode import org.jetbrains.plugins.scala.lang.psi.api.base.{InterpolatedStringType, ScInterpolatedStringLiteral} import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScMethodCall, ScReferenceExpression} import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.meta.intellij.QuasiquoteInferUtil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala index 0f191e9e2fc..86742af4153 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala @@ -21,7 +21,7 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.{ScInterpolatedStringLiteral, ScLiteral} import org.jetbrains.plugins.scala.lang.psi.types.api.{Char, Int, Nothing, Null} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{api, _} import org.jetbrains.plugins.scala.macroAnnotations.CachedInsidePsiElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala index 451e93daffb..982cecaa7fe 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala @@ -32,12 +32,12 @@ import org.jetbrains.plugins.scala.lang.psi.impl.expr.ScReferenceElementImpl import org.jetbrains.plugins.scala.lang.psi.types.ScSubstitutor import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.processor.{BaseProcessor, CompletionProcessor, ExtractorResolveProcessor} import org.jetbrains.plugins.scala.lang.resolve.{StableCodeReferenceElementResolver, _} import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocResolvableCodeReference import org.jetbrains.plugins.scala.macroAnnotations.{CachedWithRecursionGuard, ModCount} -import worksheet.ammonite.AmmoniteUtil +import org.jetbrains.plugins.scala.worksheet.ammonite.AmmoniteUtil /** * @author AlexanderPodkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala index 8b286b1b071..f6e838165f5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala @@ -8,7 +8,7 @@ import com.intellij.psi.{PsiElement, PsiWhiteSpace} import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeBoundsOwner -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} trait ScTypeBoundsOwnerImpl extends ScTypeBoundsOwner { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala index 1f80a8daf29..2d68ade0c5a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala @@ -10,7 +10,7 @@ import com.intellij.psi._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala index 32305a6b725..f1ac2527d8f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.PsiTypeParamet import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject} import org.jetbrains.plugins.scala.lang.psi.impl.base.types.ScSimpleTypeElementImpl import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing, TypeParameterType, UndefinedType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala index 8a0ff269183..f0f80c42003 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala @@ -10,7 +10,7 @@ import com.intellij.psi._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala index 9cebbe4d12d..f37011ab291 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala @@ -12,7 +12,7 @@ import org.jetbrains.plugins.scala.extensions.ifReadAllowed import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala index 588a7c89448..8a7cad04d4c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.{ScalaElementVisitor, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createWildcardPattern import org.jetbrains.plugins.scala.lang.psi.stubs.ScReferencePatternStub import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala index e07e76eb38d..cbef761a893 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala @@ -15,7 +15,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing, ParameterizedType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialType, api, _} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala index b895762f66f..957f4501a30 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala @@ -10,7 +10,7 @@ import com.intellij.psi._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala index a4494914920..00496b858cb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala @@ -9,7 +9,7 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.types._ -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScCompoundType, ScType} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala index c80ee74edba..2cf92671c9b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala @@ -12,7 +12,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types._ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScTypeAliasDeclaration, ScValueDeclaration} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{Nothing, Singleton, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import _root_.scala.collection.mutable.ListBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala index 38ae1f5e218..5903130a035 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTy import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticClass import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.Any -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala index 7d1dab32662..566a5ac78b0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.types._ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin, ilyas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala index 39f44a14194..1a2e3bc14a6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala @@ -26,7 +26,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator._ import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, Nothing, TypeParameter, TypeParameterType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.macroAnnotations.{CachedWithRecursionGuard, ModCount} @@ -407,7 +407,7 @@ object ScSimpleTypeElementImpl { case _ => calculateReferenceType(qualifier, shapesOnly) match { case Success(tp) => makeProjection(tp) - case failure: Failure => return failure + case failure@Failure(_) => return failure } } Success(result) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala index 91a535b2c67..8d14934dd33 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala @@ -17,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt import org.jetbrains.plugins.scala.lang.psi.impl.expr.ScReferenceElementImpl import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve._ import org.jetbrains.plugins.scala.lang.resolve.processor.{BaseProcessor, CompletionProcessor, ResolveProcessor} import org.jetbrains.plugins.scala.macroAnnotations.{CachedWithRecursionGuard, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala index 7bf1559352d..f4e0d8cfe33 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala @@ -8,7 +8,7 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElementImpl import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeVariableTypeElement import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScType} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAnnotationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAnnotationImpl.scala index 28302b13323..a7001f15aa5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAnnotationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAnnotationImpl.scala @@ -17,6 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText import org.jetbrains.plugins.scala.lang.psi.stubs.ScAnnotationStub import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala index 2b6bd01dac9..cf10b3f0a1c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScVariab import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.MethodResolveProcessor import org.jetbrains.plugins.scala.lang.resolve.{ScalaResolveResult, StdKinds} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala index 3b5b9bf139f..d23eed518be 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala @@ -14,7 +14,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types._ -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.StdKinds import org.jetbrains.plugins.scala.lang.resolve.processor.ImplicitCompletionProcessor import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala index 2d4d62261fb..e659732a56e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, ScParameters} import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala index cd4abeb21bf..3f579169c15 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api.Unit -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala index 7032fbc27db..b31b013124c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala @@ -9,7 +9,7 @@ import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala index 77323b865df..94737a8ba7c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala @@ -24,7 +24,7 @@ import org.jetbrains.plugins.scala.lang.psi.stubs.ScTemplateDefinitionStub import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.AnyRef import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala index 3332adaf139..4a38bb7f506 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala @@ -9,7 +9,7 @@ import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala index 4757aa11760..b6b9cbdf10a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala @@ -302,7 +302,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case ScalaResolveResult(self: ScSelfTypeElement, _) => val clazz = PsiTreeUtil.getContextOfType(self, true, classOf[ScTemplateDefinition]) ScThisReferenceImpl.getThisTypeForTypeDefinition(clazz, this) match { - case success: Success[ScType] => success.get + case Success(value) => value case failure => return failure } case r@ScalaResolveResult(refPatt: ScBindingPattern, s) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala index 10af6d562b2..5fa957f2d80 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala index 19fe2631b62..c92328bf9ae 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala @@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameter import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.ScTypePolymorphicType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.StdKinds import org.jetbrains.plugins.scala.lang.resolve.processor.MethodResolveProcessor diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala index 17cdb1c8717..64db55ee804 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScExtendsBloc import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTemplateDefinition, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.api.{ScalaElementVisitor, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createIdentifier -import org.jetbrains.plugins.scala.lang.psi.types.result.Failure +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala index 5bedf3de4a5..5144fc4f3c9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBod import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{DesignatorOwner, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin @@ -26,7 +26,7 @@ class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with protected override def innerType: TypeResult[ScType] = { import scala.meta.intellij.psiExt.TemplateDefExt refTemplate match { - case Some(td) if td.isMetaAnnotatationImpl => TypeResult.fromOption(ScalaPsiElementFactory.createTypeFromText("scala.meta.Stat", this, null)) + case Some(td) if td.isMetaAnnotatationImpl => TypeResult(ScalaPsiElementFactory.createTypeFromText("scala.meta.Stat", this, null)) case Some(td) => ScThisReferenceImpl.getThisTypeForTypeDefinition(td, this) case _ => Failure("Cannot infer type") } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala index 48e7823f26c..f71cd3f70b0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin, ilyas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala index da0fe189d1c..5123143b870 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{Compatibility, ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.lang.resolve.processor.MethodResolveProcessor diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala index 85082e3b7fa..0e20c915ee7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{TupleType, Unit} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author ilyas, Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala index 3ff5b9dcaaf..ebbd2515696 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala @@ -9,7 +9,7 @@ import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala index a1ceeb02826..a70fb9357c1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala @@ -15,7 +15,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScValue, import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala index fc803989301..de7f392d87e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala @@ -8,7 +8,7 @@ import com.intellij.lang.ASTNode import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author ilyas, Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala index 2c875d96c07..782398c9546 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander.Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala index ef7703398b2..b600d62e019 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala @@ -10,7 +10,7 @@ import com.intellij.lang.ASTNode import org.jetbrains.plugins.scala.lang.psi.api.expr.xml._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala index 52383aa2dd6..2fad67353cf 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala @@ -12,7 +12,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScPattern, ScPatt import org.jetbrains.plugins.scala.lang.psi.api.expr.xml._ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala index 6b28f04a0f8..fb81d848889 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScFunctionStub import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala index 35dccbdf688..1c009c79906 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala @@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createBlockFromExpr import org.jetbrains.plugins.scala.lang.psi.stubs.ScFunctionStub -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala index 2ba9839ade4..c2e4b3ad315 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala @@ -15,7 +15,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.stubs.ScFunctionStub import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Any -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Jason Zaugg diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala index cfd4f72de95..1bbdedbe26a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScValueStub import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala index b37c3dba48d..15c8dac89b7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala @@ -24,7 +24,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createId import org.jetbrains.plugins.scala.lang.psi.stubs.ScTypeAliasStub import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala index 0a76ebf85a9..880e9e64844 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala @@ -14,7 +14,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScValueStub import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala index d2e7cdec9e8..2aa6b8ad725 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScVariableStub import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala index 4a3101819af..ab923007c95 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.stubs._ import org.jetbrains.plugins.scala.lang.psi.stubs.elements.signatures.ScParamElementType import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala index 40deb396cb7..0317697e546 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala @@ -24,7 +24,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.PsiClassFake import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.JavaIdentifier import org.jetbrains.plugins.scala.lang.psi.stubs.ScTypeParamStub import org.jetbrains.plugins.scala.lang.psi.types.api.{ParameterizedType, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala index 88675840edd..f37db9d1ac8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala @@ -23,7 +23,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.base.types.ScSimpleTypeElementI import org.jetbrains.plugins.scala.lang.psi.stubs.ScImportStmtStub import org.jetbrains.plugins.scala.lang.psi.types.ScSubstitutor import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType -import org.jetbrains.plugins.scala.lang.psi.types.result.Failure +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil.clean import org.jetbrains.plugins.scala.lang.resolve.processor._ import org.jetbrains.plugins.scala.lang.resolve.{ResolveTargets, ScalaResolveResult, StdKinds} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala index b70f848ba16..e7552b82f82 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala @@ -25,7 +25,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.{BaseProcessor, ImplicitProcessor, ResolveProcessor, ResolverEnv} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScClassParentsImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScClassParentsImpl.scala index da37f076fff..bfffee933e3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScClassParentsImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScClassParentsImpl.scala @@ -11,6 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScTemplateParentsStub import org.jetbrains.plugins.scala.lang.psi.types._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScExtendsBlockImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScExtendsBlockImpl.scala index aa65da3bfff..df7c4efdacb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScExtendsBlockImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScExtendsBlockImpl.scala @@ -21,8 +21,9 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticClass import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.SyntheticMembersInjector import org.jetbrains.plugins.scala.lang.psi.stubs.ScExtendsBlockStub +import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType -import org.jetbrains.plugins.scala.lang.psi.types.{ScCompoundType, _} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.macroAnnotations.{Cached, CachedInsidePsiElement, ModCount} import scala.collection.Seq diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScTraitParentsImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScTraitParentsImpl.scala index c35513bb698..2fb4037767f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScTraitParentsImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/templates/ScTraitParentsImpl.scala @@ -11,6 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScTemplateParentsStub import org.jetbrains.plugins.scala.lang.psi.types._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala index fc1effb3ba1..c1437d0aa09 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticC import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.api.{ParameterizedType, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.macroAnnotations.CachedWithRecursionGuard diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala index 17a9268377b..d236c551612 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala @@ -23,7 +23,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScTypeParametersOwner, import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.TypeDefinitionMembers.SignatureNodes import org.jetbrains.plugins.scala.lang.psi.stubs.ScTemplateDefinitionStub import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameterType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{PhysicalSignature, ScSubstitutor, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.processor.BaseProcessor import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala index 3317e7a185b..49b212fe13d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala @@ -37,7 +37,7 @@ import org.jetbrains.plugins.scala.lang.psi.stubs.elements.ScTemplateDefinitionE import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameterType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScProjectionType, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} import org.jetbrains.plugins.scala.projectView.{ClassAndCompanionObject, SingularDefinition, TraitAndCompanionObject} @@ -86,7 +86,7 @@ abstract class ScTypeDefinitionImpl protected (stub: ScTemplateDefinitionStub, .exists(isInheritor(_, deep = true)) } - def `type`(): Success[ScType] = { + def `type`(): TypeResult[ScType] = { val parentClass: ScTemplateDefinition = containingClass if (typeParameters.isEmpty) { if (parentClass != null) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/TypeDefinitionMembers.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/TypeDefinitionMembers.scala index cc38233b71f..b1fdf60cd0f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/TypeDefinitionMembers.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/TypeDefinitionMembers.scala @@ -19,8 +19,9 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScExtendsBloc import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScModifierListOwner, ScNamedElement, ScTypedDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.expr.ScInterpolatedPrefixReference +import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, AnyRef} -import org.jetbrains.plugins.scala.lang.psi.types.{api, _} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor._ import org.jetbrains.plugins.scala.macroAnnotations.CachedInsidePsiElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala index 06bf8a8e859..253a1620026 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTy import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.SyntheticMembersInjector import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{ParameterizedType, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala index 8bf272eeb03..c745b2f0365 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala @@ -25,7 +25,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator._ import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{ScMethodType, ScTypePolymorphicType} import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, ReplaceWith} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve._ import org.jetbrains.plugins.scala.lang.resolve.processor.{BaseProcessor, ImplicitProcessor, MostSpecificUtil} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala index f8848fc5253..288fd1acf39 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, Stop} -import org.jetbrains.plugins.scala.lang.psi.types.result.{TypeResult, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.macroAnnotations.{CachedWithRecursionGuard, ModCount} import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_10 @@ -249,6 +249,7 @@ object ScImplicitlyConvertible { def hasRecursiveTypeParameters(`type`: ScType): Boolean = `type`.hasRecursiveTypeParameters(nameAndIds) def substitute(maybeType: TypeResult[ScType]) = maybeType + .toOption .map(substitutor.subst) .map(unSubst.subst) .withFilter(!hasRecursiveTypeParameters(_)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala index 198379109b8..68e22c6327e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala @@ -8,7 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScModifierListOwner import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScClassParents -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala index babd7fa817e..3366b231240 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala @@ -7,7 +7,7 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import _root_.scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala index 34eb57e6e2a..47d23f82911 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala @@ -9,7 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTr import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.api.{StdType, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import _root_.scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala index e43087cb492..c774cd7a449 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala @@ -5,7 +5,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.AnyRef -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala index b0820d51744..c3412939740 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala @@ -6,7 +6,7 @@ import com.intellij.psi.impl.light.LightElement import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala index 1fef3e35b3e..311245fbb5c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala @@ -6,7 +6,7 @@ import com.intellij.psi.impl.light.LightElement import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.ScFieldId import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala index 4da0238f879..7d78be6f4be 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDeclaration import org.jetbrains.plugins.scala.lang.psi.api.statements.params._ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameter -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala index ba3e346b838..7f289110ab3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.params._ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameter -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala index cb7ce6cae82..263bc5afd1c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala @@ -9,7 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScAnnotation, ScExpression} import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala index 94a7f9ec619..76863230f06 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala @@ -8,7 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.ScModifierList import org.jetbrains.plugins.scala.lang.psi.api.expr.ScAnnotation import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDeclaration import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParamClause -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, TypeAliasSignature} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala index e08d661cee5..aa3e71e97ab 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala @@ -9,7 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScAnnotation import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParamClause -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, TypeAliasSignature} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala index c0e70c1d7d9..ccc2b09c3ae 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala @@ -9,7 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeParametersOwner import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.PsiClassFake import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameter -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/presentation/ScImplicitFunctionListCellRenderer.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/presentation/ScImplicitFunctionListCellRenderer.scala index b8a634c7576..87c33a92646 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/presentation/ScImplicitFunctionListCellRenderer.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/presentation/ScImplicitFunctionListCellRenderer.scala @@ -13,6 +13,7 @@ import org.jetbrains.plugins.scala.highlighter.DefaultHighlighter import org.jetbrains.plugins.scala.lang.psi.PresentationUtil import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.DefaultListCellRendererAdapter import org.jetbrains.plugins.scala.util.JListCompatibility @@ -74,8 +75,7 @@ class ScImplicitFunctionListCellRenderer(actual: PsiNamedElement) extends ScImpl element match { case method: ScFunction => method.name + PresentationUtil.presentationString(method.paramClauses) + ": " + - PresentationUtil.presentationString(method.returnType. - getOrAny) + PresentationUtil.presentationString(method.returnType.getOrAny) case b: ScBindingPattern => b.name + ": " + PresentationUtil.presentationString(b.`type`().getOrAny) case _ => element.name diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala index dccc8b83c23..af85d74f2fc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScExtendsBloc import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition import org.jetbrains.plugins.scala.lang.psi.stubs.index.ScalaIndexKeys import org.jetbrains.plugins.scala.lang.psi.stubs.index.ScalaIndexKeys.SUPER_CLASS_NAME_KEY -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScCompoundType, ScType, ScTypeExt} import org.jetbrains.plugins.scala.macroAnnotations.CachedInsidePsiElement import org.jetbrains.plugins.scala.util.ScEquivalenceUtil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala index 9d067750280..6330864f89d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala @@ -12,7 +12,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScTypeAlias, ScTypeA import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.annotation.tailrec import scala.collection.mutable diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala index 173e677b5cb..e3fbf7e605f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala @@ -94,7 +94,7 @@ object Compatibility { } else { import scala.collection.Set - def default: (Success[ScType], Set[ImportUsed]) = (Success(typez), Set.empty) + def default: (TypeResult[ScType], Set[ImportUsed]) = (Success(typez), Set.empty) if (isShape || !checkImplicits || place == null) default else eval(typez, expectedOption) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScCompoundType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScCompoundType.scala index 8e83b3ec2f5..5163082ed31 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScCompoundType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScCompoundType.scala @@ -13,6 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.api.{AnyRef, TypeParametersArrayExt, TypeVisitor, ValueType, _} import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.Update +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext import scala.collection.mutable diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala index 9f31937270b..42f13144e24 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinitio import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.api.{Contravariant, Covariant, Invariant, ParameterizedType, TypeParameterType, TypeVisitor, UndefinedType, ValueType, Variance} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.ScTypePolymorphicType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import scala.collection.immutable.ListMap diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScSubstitutor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScSubstitutor.scala index 6420c751e89..9650e315b0b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScSubstitutor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScSubstitutor.scala @@ -20,6 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, Stop} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.annotation.tailrec import scala.language.implicitConversions diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaBounds.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaBounds.scala index 1ac42c829b3..2e4f24601e1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaBounds.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaBounds.scala @@ -12,6 +12,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTemplateDefinition} import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.util.ScEquivalenceUtil.smartEquivalence diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala index dc00a4166c2..d9b68d8a6cc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{ScMethodType, ScTypePolymorphicType} import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, ReplaceWith} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, Typeable} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.lang.resolve.processor.{CompoundTypeCheckSignatureProcessor, CompoundTypeCheckTypeAliasProcessor} import org.jetbrains.plugins.scala.util.ScEquivalenceUtil._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala index d78ad192533..4863d1ee416 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala @@ -4,7 +4,7 @@ import com.intellij.openapi.util.Computable import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDefinition import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala index 4b5133ac162..2b1665d98db 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.light.PsiClassWrapper import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.NonValueType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.JavaConverters._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala index 72d73b78cef..59189777227 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala @@ -8,7 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScEarlyDefinitions import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTemplateDefinition} import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType @@ -32,7 +32,6 @@ object ScalaType { // with this as we currently only rely on this method to determine covariant types: the parameter // types of FunctionN, or the elements of TupleN def expandAliases(tp: ScType, visited: Set[ScType] = Set.empty): TypeResult[ScType] = { - import tp.projectContext if (visited contains tp) return Success(tp) tp match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Signature.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Signature.scala index 76081dc5053..4d5b2b4654e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Signature.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Signature.scala @@ -13,6 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameters import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScTypeAlias, ScTypeAliasDefinition} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, PsiTypeParamatersExt, TypeParameter, TypeParameterType, Variance} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.project.{ProjectContext, ProjectContextOwner} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameter.scala index 28037ecbb8d..03e41531312 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameter.scala @@ -5,6 +5,7 @@ import org.jetbrains.plugins.scala.extensions.PsiNamedElementExt import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{PsiTypeParameterExt, ScTypeParam} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager import org.jetbrains.plugins.scala.lang.psi.types.ScType +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * Class representing type parameters in our type system. Can be constructed from psi. diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameterType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameterType.scala index abef89816d5..dbdfa7f5e40 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameterType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/TypeParameterType.scala @@ -3,6 +3,7 @@ package org.jetbrains.plugins.scala.lang.psi.types.api import com.intellij.psi.PsiTypeParameter import org.jetbrains.plugins.scala.extensions.PsiNamedElementExt import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{PsiTypeParameterExt, ScTypeParam} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{NamedType, ScSubstitutor, ScType, ScUndefinedSubstitutor} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala index 10b27dd4d03..9e98f2bd254 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala @@ -7,7 +7,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{PsiTypeParame import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScTypeAlias, ScTypeAliasDefinition} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.types.api._ -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScExistentialType, ScType, ScTypeExt, ScUndefinedSubstitutor} import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.util.ScEquivalenceUtil.smartEquivalence diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala index b79d6e21386..610d931f7fd 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticC import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.Update -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.lang.resolve.processor.ResolveProcessor import org.jetbrains.plugins.scala.lang.resolve.{ResolveTargets, ScalaResolveResult} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala index e1737dd3f95..704294a9f79 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala @@ -3,7 +3,7 @@ package org.jetbrains.plugins.scala.lang.psi.types.api.designator import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTemplateDefinition} import org.jetbrains.plugins.scala.lang.psi.types.api.TypeVisitor -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScTypeExt, ScUndefinedSubstitutor} import org.jetbrains.plugins.scala.util.ScEquivalenceUtil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/nonvalue/ScMethodType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/nonvalue/ScMethodType.scala index 37200ede009..afb57fcdf50 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/nonvalue/ScMethodType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/nonvalue/ScMethodType.scala @@ -9,6 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.Update +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala index 5559684d220..026e122818a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala @@ -7,7 +7,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{DesignatorOwne import org.jetbrains.plugins.scala.lang.psi.types.api.{TypeParameterType, _} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.NonValueType import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, ReplaceWith, Stop} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.project.ProjectContext import org.jetbrains.plugins.scala.util.ScEquivalenceUtil.areClassesEquivalent @@ -145,7 +145,7 @@ package object types { def innerUpdate(tp: ScType, visited: Set[ScType]): ScType = { tp.recursiveUpdate { `type` => `type`.isAliasType match { - case Some(AliasType(ta: ScTypeAliasDefinition, _, _: Failure)) if needExpand(ta) => + case Some(AliasType(ta: ScTypeAliasDefinition, _, Failure(_))) if needExpand(ta) => ReplaceWith(projectContext.stdTypes.Any) case Some(AliasType(ta: ScTypeAliasDefinition, _, Success(upper))) if needExpand(ta) => if (visited.contains(`type`)) throw RecursionException diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala deleted file mode 100644 index a311b050fa7..00000000000 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/TypeResult.scala +++ /dev/null @@ -1,108 +0,0 @@ -package org.jetbrains.plugins.scala -package lang -package psi -package types -package result - -import org.jetbrains.plugins.scala.lang.psi.types.result.Failure.TypeError -import org.jetbrains.plugins.scala.project.ProjectContext - -/** - * @author ilyas - */ -sealed abstract class TypeResult[+T <: ScType] { - - def map[U <: ScType](f: T => U): TypeResult[U] - - def flatMap[U <: ScType](f: T => TypeResult[U]): TypeResult[U] - - def withFilter(f: T => Boolean): TypeResult[T] - - def foreach[B](f: T => B) - - def get: T - - def isEmpty: Boolean - - def getOrNothing: ScType - - def getOrAny: ScType - - final def isDefined: Boolean = !isEmpty - - final def exists(f: T => Boolean): Boolean = withFilter(f).isDefined - - final def getOrElse[U >: T](default: => U): U = if (isEmpty) default else get - - final def toOption: Option[T] = if (isEmpty) None else Some(get) -} - -object TypeResult { - def fromOption(maybeType: Option[ScType]) - (implicit context: ProjectContext): TypeResult[ScType] = maybeType match { - case Some(scType) => Success(scType) - case None => Failure("") - } -} - -final case class Success[T <: ScType](private val result: T) extends TypeResult[T] { - - def map[U <: ScType](f: T => U): Success[U] = Success(f(result)) - - def flatMap[U <: ScType](f: T => TypeResult[U]): TypeResult[U] = f(result) - - def withFilter(f: T => Boolean): TypeResult[T] = - if (f(result)) this else Failure("Wrong type")(result.projectContext) - - def foreach[B](f: T => B): Unit = f(result) - - def get: T = result - - def isEmpty: Boolean = false - - def getOrNothing: T = result - - def getOrAny: T = result -} - -final class Failure private(private val error: TypeError) extends TypeResult[Nothing] { - - def map[U <: ScType](f: Nothing => U): this.type = this - - def flatMap[U <: ScType](f: Nothing => TypeResult[U]): this.type = this - - def withFilter(f: Nothing => Boolean): this.type = this - - def foreach[B](f: Nothing => B): Unit = {} - - def get: Nothing = throw new NoSuchElementException("Failure.get") - - def isEmpty: Boolean = true - - def getOrNothing: ScType = api.Nothing(error.context) - - def getOrAny: ScType = api.Any(error.context) - - override def equals(other: Any): Boolean = other match { - case that: Failure => error == that.error - case _ => false - } - - override def hashCode(): Int = error.hashCode() - - override def toString = s"Failure(${error.cause})" -} - -object Failure { - - case class TypeError(private[result] val cause: String, - private[result] val context: ProjectContext) - - def apply(message: String) - (implicit context: ProjectContext): Failure = - new Failure(TypeError(message, context)) - - def unapply(failure: Failure): Option[String] = - Some(failure.error.cause) - -} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala index a3e73fb303d..23d7697ab8c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala @@ -2,10 +2,59 @@ package org.jetbrains.plugins.scala.lang package psi package types +import org.jetbrains.plugins.scala.lang.psi.types.api.StdTypes import org.jetbrains.plugins.scala.project.ProjectContext package object result { + type TypeError = (String, ProjectContext) + type TypeResult[T <: ScType] = Either[TypeError, ScType] + + object Success { + def apply(result: ScType): TypeResult[ScType] = Right(result) + + def unapply(success: Right[TypeError, ScType]): Option[ScType] = Some(success.value) + } + + object Failure { + def apply(cause: String) + (implicit context: ProjectContext): TypeResult[ScType] = Left(cause, context) + + def unapply(left: Left[TypeError, ScType]): Option[String] = { + val (cause, _) = left.value + Some(cause) + } + } + + object TypeResult { + def apply(maybeType: Option[ScType]) + (implicit context: ProjectContext): TypeResult[ScType] = maybeType match { + case Some(scType) => Success(scType) + case None => Failure("") + } + } + + implicit class TypeResultExt(val result: TypeResult[ScType]) extends AnyVal { + + def get: ScType = result match { + case Right(value) => value + case _ => throw new NoSuchElementException("Failure.get") + } + + def isEmpty: Boolean = result.isLeft + + def isDefined: Boolean = result.isRight + + def getOrAny: ScType = getOrApiType(_.Any) + + def getOrNothing: ScType = getOrApiType(_.Nothing) + + private def getOrApiType(apiType: StdTypes => ScType): ScType = result match { + case Right(value) => value + case Left((_, projectContext)) => apiType(projectContext.stdTypes) + } + } + implicit class TypeableExt(val typeable: ScalaPsiElement with Typeable) extends AnyVal { def flatMap[E <: ScalaPsiElement](maybeElement: Option[E]) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/rearranger/ScalaArrangementVisitor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/rearranger/ScalaArrangementVisitor.scala index e72afac2350..e9a5697cbdf 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/rearranger/ScalaArrangementVisitor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/rearranger/ScalaArrangementVisitor.scala @@ -19,10 +19,11 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBod import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScModifierListOwner, ScPackaging} import org.jetbrains.plugins.scala.lang.psi.api.{ScalaElementVisitor, ScalaFile, ScalaRecursiveElementVisitor} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} -import scala.collection.mutable import scala.collection.JavaConverters._ +import scala.collection.mutable /** * @author Roman.Shein diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala index c59695fe4eb..d5c633dc68f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala @@ -16,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScModifierListOwner, S import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, JavaArrayType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiUtil, TypeAdjuster} import org.jetbrains.plugins.scala.lang.refactoring.changeSignature.changeInfo.ScalaChangeInfo import org.jetbrains.plugins.scala.lang.refactoring.extractMethod.ScalaExtractMethodUtils diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaMethodDescriptor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaMethodDescriptor.scala index 8dd50f0107a..3431fa86b6b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaMethodDescriptor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaMethodDescriptor.scala @@ -8,6 +8,7 @@ import com.intellij.refactoring.changeSignature.MethodDescriptor import com.intellij.refactoring.changeSignature.MethodDescriptor.ReadWriteOption import org.jetbrains.plugins.scala.lang.psi.api.base.{ScMethodLike, ScPrimaryConstructor} import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.JavaConverters._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterInfo.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterInfo.scala index fec0b0e2666..28a8b2a41c0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterInfo.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterInfo.scala @@ -13,6 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, JavaArrayType, Nothing} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.beans.{BeanProperty, BooleanBeanProperty} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala index 99764cdb768..115b5fdafd2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala @@ -5,6 +5,7 @@ import com.intellij.refactoring.changeSignature.ParameterTableModelItemBase import org.jetbrains.plugins.scala.debugger.evaluation.ScalaCodeFragment import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.mutable.ListBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodHandler.scala index 1c9b9544621..8da247fa086 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodHandler.scala @@ -25,6 +25,7 @@ import org.jetbrains.plugins.scala.lang.psi.dataFlow.impl.reachingDefs.ReachingD import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createNewLine, createTemplateDefinitionFromText} import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil, TypeAdjuster} import org.jetbrains.plugins.scala.lang.refactoring.extractMethod.duplicates.DuplicatesUtil import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaRefactoringUtil._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodUtils.scala index 90ab0215db6..261051f54ba 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/ScalaExtractMethodUtils.scala @@ -19,6 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScNamedElement, ScType import org.jetbrains.plugins.scala.lang.psi.dataFlow.impl.reachingDefs.VariableInfo import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType} import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil, TypeAdjuster} import org.jetbrains.plugins.scala.lang.refactoring.extractMethod.duplicates.DuplicateMatch diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala index 47023f75ce5..04d3eb53774 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScReferenceE import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticFunction import org.jetbrains.plugins.scala.lang.psi.types.api.designator.DesignatorOwner -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.refactoring.extractMethod.duplicates.DuplicatesUtil._ import org.jetbrains.plugins.scala.lang.refactoring.extractMethod.{ExtractMethodOutput, ExtractMethodParameter} @@ -100,7 +100,7 @@ class DuplicateMatch(pattern: DuplicatePattern, val candidates: Seq[PsiElement]) newTp1.zip(newTp2).forall { case (tp1, tp2) => tp1.equiv(tp2) } - case (_: Failure, _: Failure) => true + case (Failure(_), Failure(_)) => true case _ => false } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala index f6f9917bcd2..f88c325dfc5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala @@ -31,6 +31,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScNamedElement, ScType import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createExpressionFromText, createTypeElementFromText} import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScProjectionType import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, TypeParameterType} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaRefactoringUtil.highlightOccurrences import scala.collection.JavaConverters.iterableAsScalaIterableConverter diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceParameter/ScalaIntroduceParameterHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceParameter/ScalaIntroduceParameterHandler.scala index e57f3511232..ed824b93491 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceParameter/ScalaIntroduceParameterHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceParameter/ScalaIntroduceParameterHandler.scala @@ -27,6 +27,7 @@ import org.jetbrains.plugins.scala.lang.psi.dataFlow.impl.reachingDefs.{Reaching import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, FunctionType} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.changeSignature.{ScalaMethodDescriptor, ScalaParameterInfo} import org.jetbrains.plugins.scala.lang.refactoring.introduceParameter.ScalaIntroduceParameterHandler._ import org.jetbrains.plugins.scala.lang.refactoring.namesSuggester.NameSuggester diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala index 7a13802bfb1..879c386acb0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala @@ -14,7 +14,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScSimpleTypeElement import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScMember, ScTemplateDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.extractTrait.ScalaExtractMemberInfo import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaChangeContextUtil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala index 685d420990f..210612a83f5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala @@ -43,6 +43,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{DesignatorOwner, ScDesignatorType} import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, TypeParameterType} import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, ReplaceWith} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.lang.refactoring.ScalaNamesValidator.isIdentifier import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala index 901ae7d7c0a..8454cbb1684 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala @@ -27,7 +27,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression._ import org.jetbrains.plugins.scala.lang.psi.types.api.UndefinedType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScalaType} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.DynamicResolveProcessor._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala index b006aa8e4ee..a795db1fd24 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala @@ -21,7 +21,7 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.TypeDefinition import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext import scala.collection.{Set, mutable} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/CompoundTypeCheckProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/CompoundTypeCheckProcessor.scala index aa32349c3db..b07629b6f6d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/CompoundTypeCheckProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/CompoundTypeCheckProcessor.scala @@ -9,6 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScTypeAl import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScTypeParametersOwner, ScTypedDefinition} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{Covariant, TypeParameter, Unit, Variance} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.{ResolveTargets, StdKinds} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExpandedExtractorResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExpandedExtractorResolveProcessor.scala index 3620639012e..002cd9239b4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExpandedExtractorResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExpandedExtractorResolveProcessor.scala @@ -9,6 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScProjectionType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.Set import scala.collection.mutable.ArrayBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala index 1f289435d25..14f93354df0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScProjectionType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectPsiElementExt import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_11 @@ -84,8 +84,8 @@ class ExtractorResolveProcessor(ref: ScReferenceElement, r.element match { case fun: ScFunction => val clauses = fun.paramClauses.clauses - if (clauses.length != 0 && clauses.apply(0).parameters.length == 1) { - for (paramType <- clauses(0).parameters.apply(0).`type`() + if (clauses.nonEmpty && clauses.head.parameters.length == 1) { + for (paramType <- clauses.head.parameters.head.`type`().toOption if tp conforms r.substitutor.subst(paramType)) return true } false @@ -93,7 +93,7 @@ class ExtractorResolveProcessor(ref: ScReferenceElement, } } val filtered = candidates.filter(t => isApplicable(t)) - if (filtered.size == 0) candidates + if (filtered.isEmpty) candidates else if (filtered.size == 1) filtered else { new MostSpecificUtil(ref, 1).mostSpecificForResolveResult(filtered, expandInnerResult = false) match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala index 14649f53f21..4af8e5b46e9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala @@ -21,7 +21,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.{ConformanceExtR import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScProjectionType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MostSpecificUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MostSpecificUtil.scala index 6a3cfc9dc32..ea9c28d90a6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MostSpecificUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MostSpecificUtil.scala @@ -21,6 +21,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing, _} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext import scala.collection.Set diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala index b0b8c4027bb..080565cfbca 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala @@ -17,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBod import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScPackageImpl import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.precedence._ import org.jetbrains.plugins.scala.util.ScEquivalenceUtil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/ScalaElementPresentation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/ScalaElementPresentation.scala index d2bfff2e2d3..d20ff0df54c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/ScalaElementPresentation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/ScalaElementPresentation.scala @@ -14,7 +14,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScClassParamet import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScNamedElement, ScPackaging} import org.jetbrains.plugins.scala.lang.psi.types.ScSubstitutor -import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/StructureViewUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/StructureViewUtil.scala index d05faacc77b..c4dd2175e69 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/StructureViewUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/structureView/StructureViewUtil.scala @@ -4,6 +4,7 @@ package structureView import org.jetbrains.plugins.scala.lang.psi.api.statements.params._ import org.jetbrains.plugins.scala.lang.psi.types.ScSubstitutor +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala index 414cc088803..d480d2a0204 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaTypeSurrounder.scala @@ -9,6 +9,7 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScalaTypeSurrounder extends ScalaExpressionSurrounder { override def getTemplateAsString(elements: Array[PsiElement]): String = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfConditionSurrounder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfConditionSurrounder.scala index 6ef308b81d5..1ac69abab80 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfConditionSurrounder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfConditionSurrounder.scala @@ -8,6 +8,7 @@ import com.intellij.lang.ASTNode import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScIfStmt, ScParenthesisedExpr} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScTypeExt, api} @@ -24,8 +25,8 @@ class ScalaWithIfConditionSurrounder extends ScalaExpressionSurrounder { override def isApplicable(elements: Array[PsiElement]): Boolean = { if (elements.length != 1) return false elements(0) match { - case x: ScExpression if x.getTypeIgnoreBaseType.getOrAny. - conforms(api.Boolean(x.projectContext)) => true + case x: ScExpression if x.getTypeIgnoreBaseType.getOrAny + .conforms(api.Boolean(x.projectContext)) => true case _ => false } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfElseConditionSurrounder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfElseConditionSurrounder.scala index 97c86e5827f..68a39d78568 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfElseConditionSurrounder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithIfElseConditionSurrounder.scala @@ -8,6 +8,7 @@ import com.intellij.lang.ASTNode import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScIfStmt, ScParenthesisedExpr} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScTypeExt, api} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithUnaryNotSurrounder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithUnaryNotSurrounder.scala index 85631779f5c..236fb9229db 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithUnaryNotSurrounder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/surroundWith/surrounders/expression/ScalaWithUnaryNotSurrounder.scala @@ -9,6 +9,7 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScParenthesisedExpr} import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * User: Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToFunctionParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToFunctionParameter.scala index 942aedd05a4..49e4880db0a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToFunctionParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToFunctionParameter.scala @@ -7,6 +7,7 @@ import org.jetbrains.plugins.scala.extensions.{&&, Parent} import org.jetbrains.plugins.scala.lang.psi.api.expr.ScFunctionExpr import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, ScParameterClause} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaCode._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToMethodDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToMethodDefinition.scala index 16f9343a7f3..691b626e1ae 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToMethodDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/annotations/AddTypeToMethodDefinition.scala @@ -4,6 +4,7 @@ package annotations import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectContext /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaNamedMember.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaNamedMember.scala index 4da6b7dcc37..32d14d32973 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaNamedMember.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaNamedMember.scala @@ -9,6 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil.getMethodPresentableTex import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.types._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * User: Alexander Podkhalyuzin diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala index 6ae3a6570b1..4c2ae23d1bd 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala @@ -17,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScFuncti import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScMember, ScTrait, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.testingSupport.test.TestConfigurationUtil.isInheritor import org.jetbrains.plugins.scala.testingSupport.test.TestRunConfigurationForm.TestKind import org.jetbrains.plugins.scala.testingSupport.test.{TestConfigurationProducer, TestConfigurationUtil} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala index baaa7d70c51..b57c74ec570 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala @@ -5,7 +5,7 @@ import com.intellij.psi.{PsiClass, PsiElement, PsiPackage} import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAlias import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject -import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult +import org.jetbrains.plugins.scala.lang.psi.types.result.{TypeResult, _} import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala index 39d46063a87..5993f18cddf 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala @@ -13,6 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticFunction import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil diff --git a/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala b/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala index cf8ac404897..7c76509bacc 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala @@ -9,6 +9,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeFromText import org.jetbrains.plugins.scala.lang.psi.types.api.{Nothing, Null} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.project.{ProjectContext, Version} import org.jetbrains.sbt.language.SbtFileImpl diff --git a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala index 8fb69bee1eb..539547f2a4b 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala @@ -17,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.NonValueType -import org.jetbrains.plugins.scala.lang.psi.types.result.Success +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.{ResolveUtils, ScalaResolveResult} import org.jetbrains.plugins.scala.project.ProjectContext diff --git a/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala b/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala index eb005c7756b..25b85c1d8f7 100644 --- a/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala +++ b/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala @@ -6,12 +6,14 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.{ScInterpolated, ScInterpol import org.jetbrains.plugins.scala.lang.psi.api.expr.ScReferenceExpression import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory +import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeFromText import org.jetbrains.plugins.scala.lang.psi.impl.base.patterns.ScInterpolationPatternImpl import org.jetbrains.plugins.scala.lang.psi.impl.expr.ScMethodCallImpl import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult +import org.jetbrains.plugins.scala.project.ProjectContext import scala.meta.Dialect import scala.meta.inputs.Input @@ -58,8 +60,8 @@ object QuasiquoteInferUtil extends scala.meta.quasiquotes.QuasiquoteParsers { case Parsed.Error(_, cause, exc) => Seq.empty } - val types = typeStrings.map(ScalaPsiElementFactory.createTypeFromText(_, stringContextApplicationRef, null)) - val treeType = ScalaPsiElementFactory.createTypeFromText("scala.meta.Tree", stringContextApplicationRef, null) + val types = typeStrings.map(createTypeFromText(_, stringContextApplicationRef, null)) + val treeType = createTypeFromText("scala.meta.Tree", stringContextApplicationRef, null) types.zipWithIndex.map { case (maybeType, i) => val tp = maybeType.orElse(treeType).get @@ -69,7 +71,7 @@ object QuasiquoteInferUtil extends scala.meta.quasiquotes.QuasiquoteParsers { def getMetaQQExprType(pat: ScInterpolatedStringLiteral): TypeResult[ScType] = { ProgressManager.checkCanceled() - implicit val project = pat.projectContext + implicit val context: ProjectContext = pat.projectContext val patternText = escapeQQ(pat) val qqdialect = if (pat.isMultiLineString) @@ -89,7 +91,7 @@ object QuasiquoteInferUtil extends scala.meta.quasiquotes.QuasiquoteParsers { } } catch { case _: ArrayIndexOutOfBoundsException => // workaround for meta parser failure on malformed quasiquotes - TypeResult.fromOption(ScalaPsiElementFactory.createTypeFromText("scala.meta.Tree", pat, null)) + TypeResult(createTypeFromText("scala.meta.Tree", pat, null)) } } diff --git a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala index 723e8a8f84b..185d64bdc1f 100644 --- a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala @@ -8,6 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, api => p, types => ptype} import scala.collection.immutable.Seq diff --git a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala index e9d4fcff894..97118833667 100644 --- a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel._ import org.jetbrains.plugins.scala.lang.psi.impl.base.types.ScInfixTypeElementImpl import org.jetbrains.plugins.scala.lang.psi.types.ScSubstitutor import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameterType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{api => p, types => ptype} import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType diff --git a/scala/scala-impl/src/scala/meta/trees/Utils.scala b/scala/scala-impl/src/scala/meta/trees/Utils.scala index e89a213f0e3..3f0d7805c7b 100644 --- a/scala/scala-impl/src/scala/meta/trees/Utils.scala +++ b/scala/scala-impl/src/scala/meta/trees/Utils.scala @@ -8,7 +8,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticFunction -import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType} import org.jetbrains.plugins.scala.lang.psi.{api => p, types => ptype} @@ -109,10 +109,12 @@ trait Utils { def withSubstitutionCaching[T](fun: TypeResult[ScType] => T): T = { if (dumbMode) { - expr match { - case ts: ScTypedStmt => fun(TypeResult.fromOption(ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null))) - case _ => fun(TypeResult.fromOption(None)) + val maybeType = expr match { + case ts: ScTypedStmt => ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null) + case _ => None } + + fun(TypeResult(maybeType)) } else { ScSubstitutor.cacheSubstitutions = true val tp = expr.`type`() @@ -155,7 +157,7 @@ trait Utils { def getTypeWithCachedSubst: TypeResult[ScType] = { if (dumbMode) { expr match { - case ts: ScTypedStmt => TypeResult.fromOption(ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null)) + case ts: ScTypedStmt => TypeResult(ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null)) case _ => Success(ptype.api.Any) } } else { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala index 0f41389908d..5e219d2866f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala @@ -9,7 +9,7 @@ import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_12} import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.util.TestUtils import org.junit.Assert._ import org.junit.experimental.categories.Category diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala index 3896e9a601d..0ccddd78be8 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala @@ -10,7 +10,7 @@ import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_11} import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ import org.jetbrains.plugins.scala.lang.psi.types.PhysicalSignature -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.util.TestUtils import org.junit.Assert._ import org.junit.experimental.categories.Category diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/types/ScLiteralTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/types/ScLiteralTest.scala index dc70d292e8e..3fe65738d33 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/types/ScLiteralTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/types/ScLiteralTest.scala @@ -3,6 +3,7 @@ package org.jetbrains.plugins.scala.lang.psi.types import org.jetbrains.plugins.scala.base.SimpleTestCase import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.types.api._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.junit.Assert /** diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala index 324131c8131..ca9679108f8 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala @@ -15,7 +15,7 @@ import org.jetbrains.plugins.scala.lang.parser.ScalaElementTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.expr.ScMethodCall import org.jetbrains.plugins.scala.lang.psi.api.statements.ScPatternDefinition -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.junit.Assert.fail diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala index 1d13dba86d6..28ca1dc7980 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala @@ -5,7 +5,7 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.types.api.ScTypePresentation -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.junit.Assert._ /** diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala index 340a22f394a..298dc63805c 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala @@ -12,7 +12,7 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.types.ScExistentialType -import org.jetbrains.plugins.scala.lang.psi.types.result.{Failure, Success} +import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceParameter/IntroduceParameterTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceParameter/IntroduceParameterTestBase.scala index ab2667f9621..f08e9007faa 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceParameter/IntroduceParameterTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceParameter/IntroduceParameterTestBase.scala @@ -17,6 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.ScMethodLike import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass import org.jetbrains.plugins.scala.lang.psi.types.api._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.changeSignature.changeInfo.ScalaChangeInfo import org.jetbrains.plugins.scala.lang.refactoring.changeSignature.{ScalaChangeSignatureProcessor, ScalaMethodDescriptor, ScalaParameterInfo} import org.jetbrains.plugins.scala.lang.refactoring.introduceParameter.ScalaIntroduceParameterHandler diff --git a/scala/scala-impl/test/org/jetbrains/sbt/annotator/annotatorConformanceTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/annotator/annotatorConformanceTest.scala index 18cf9acdf0e..79c164436b6 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/annotator/annotatorConformanceTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/annotator/annotatorConformanceTest.scala @@ -3,6 +3,7 @@ package org.jetbrains.sbt.annotator import org.jetbrains.plugins.scala.SlowTests import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.impl.ScalaCode._ +import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.sbt.annotator.SbtAnnotator.isTypeAllowed import org.jetbrains.sbt.language.SbtFileImpl import org.jetbrains.sbt.{MockSbt_0_12, MockSbt_0_13, MockSbt_1_0, Sbt} From a66cdb2cd28672eaf5f622588ef7ae81d505cefc Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 25 Oct 2017 20:47:51 +0300 Subject: [PATCH 049/141] isEmpty/isDefined methods removed #SCL-12743 --- .../scala/annotator/FunctionAnnotator.scala | 2 +- .../scala/annotator/ScalaAnnotator.scala | 21 ++- .../ComparingUnrelatedTypesInspection.scala | 9 +- .../ScalaPatternParameterInfoHandler.scala | 30 ++-- .../lang/psi/api/statements/ScFunction.scala | 21 ++- .../ScStableCodeReferenceElementImpl.scala | 13 +- .../patterns/ScConstructorPatternImpl.scala | 30 ++-- .../lang/psi/impl/expr/ScTryStmtImpl.scala | 71 +++++----- .../toplevel/imports/ScImportStmtImpl.scala | 15 +- .../scala/lang/psi/light/LightUtil.scala | 18 +-- .../lang/psi/types/ScalaConformance.scala | 131 ++++++++---------- .../scala/lang/psi/types/result/package.scala | 4 - .../ScalaParameterTableModelItem.scala | 15 +- .../scala/util/ScEquivalenceUtil.scala | 9 +- .../src/scala/meta/trees/TreeAdapter.scala | 24 ++-- 15 files changed, 196 insertions(+), 217 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala index 2a8d611c38a..b2bc2b5d91a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala @@ -19,7 +19,7 @@ trait FunctionAnnotator { self: ScalaAnnotator => def annotateFunction(function: ScFunctionDefinition, holder: AnnotationHolder, typeAware: Boolean) { - if (!function.hasExplicitType && !function.returnTypeIsDefined) { + if (!function.hasExplicitType && function.definedReturnType.isLeft) { function.recursiveReferences.foreach { ref => val message = ScalaBundle.message("function.recursive.need.result.type", function.name) holder.createErrorAnnotation(ref.element, message) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index 536299346c5..507df9ee53d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -509,18 +509,16 @@ abstract class ScalaAnnotator extends Annotator val annotation = holder.createErrorAnnotation(expr, error) annotation.setHighlightType(ProblemHighlightType.GENERIC_ERROR) } else if (checkReturnTypeIsBoolean) { - def error() { + val maybeType = candidates(0) match { + case ScalaResolveResult(fun: ScFunction, subst) => fun.returnType.map(subst.subst).toOption + case _ => None + } + + if (!maybeType.exists(_.equiv(Boolean))) { val error = ScalaBundle.message("expected.type.boolean", memberName) val annotation = holder.createErrorAnnotation(expr, error) annotation.setHighlightType(ProblemHighlightType.GENERIC_ERROR) } - candidates(0) match { - case ScalaResolveResult(fun: ScFunction, subst) => - if (fun.returnType.isEmpty || !subst.subst(fun.returnType.get).equiv(Boolean)) { - error() - } - case _ => error() - } } else { block.getContext match { case t: ScTryStmt => @@ -531,11 +529,10 @@ abstract class ScalaAnnotator extends Annotator case ScalaResolveResult(fun: ScFunction, subst) => fun.returnType.map(subst.subst) case _ => return } - val expectedType = Success(tp) - val conformance = smartCheckConformance(expectedType, returnType) + val conformance = smartCheckConformance(Success(tp), returnType) if (!conformance) { if (typeAware) { - val (retTypeText, expectedTypeText) = ScTypePresentation.different(returnType.getOrNothing, expectedType.get) + val (retTypeText, expectedTypeText) = ScTypePresentation.different(returnType.getOrNothing, tp) val error = ScalaBundle.message("expr.type.does.not.conform.expected.type", retTypeText, expectedTypeText) val annotation: Annotation = holder.createErrorAnnotation(expr, error) annotation.setHighlightType(ProblemHighlightType.GENERIC_ERROR_OR_WARNING) @@ -1007,7 +1004,7 @@ abstract class ScalaAnnotator extends Annotator case _ => expr } - val (exprTypeText, expectedTypeText) = ScTypePresentation.different(exprType.getOrNothing, expectedType.get) + val (exprTypeText, expectedTypeText) = ScTypePresentation.different(exprType.getOrNothing, tp) val error = ScalaBundle.message("expr.type.does.not.conform.expected.type", exprTypeText, expectedTypeText) val annotation: Annotation = holder.createErrorAnnotation(markedPsi, error) annotation.setHighlightType(ProblemHighlightType.GENERIC_ERROR_OR_WARNING) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala index 02c8e5a368d..ab14cb2380c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala @@ -17,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.api.{ScTypePresentation, _} import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil +import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.project.ProjectExt import scala.annotation.tailrec @@ -64,15 +64,14 @@ object ComparingUnrelatedTypesInspection { } } - private def undefinedTypeAlias(`type`: ScType) = `type`.isAliasType match { - case Some(ScTypeUtil.AliasType(_, lower, upper)) => - lower.isEmpty || upper.isEmpty || !lower.get.equiv(upper.get) + private def undefinedTypeAlias(`type`: ScType) = `type`.isAliasType.exists { + case AliasType(_, Right(lower), Right(upper)) => !lower.equiv(upper) case _ => false } @tailrec private def extractActualType(`type`: ScType): ScType = `type`.isAliasType match { - case Some(ScTypeUtil.AliasType(_, Success(rhs), _)) => extractActualType(rhs) + case Some(AliasType(_, Success(rhs), _)) => extractActualType(rhs) case _ => `type`.tryExtractDesignatorSingleton } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala index 899ec049a46..8b4d1920db7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaPatternParameterInfoHandler.scala @@ -225,21 +225,21 @@ class ScalaPatternParameterInfoHandler extends ParameterInfoHandlerWithTabAction else { val undefSubst = fun.typeParameters.foldLeft(ScSubstitutor.empty)((s, p) => s.bindT(p.nameAndId, UndefinedType(TypeParameterType(p, Some(substitutor))))) - val result = fun.parameters.head.`type`() - if (result.isEmpty) substitutor - else { - val funType = undefSubst.subst(result.get) - constr.expectedType match { - case Some(tp) => - val conformance = funType.conforms(tp, ScUndefinedSubstitutor()) - if (conformance._1) { - conformance._2.getSubstitutor match { - case Some(newSubst) => newSubst.followed(substitutor) - case _ => substitutor - } - } else substitutor - case _ => substitutor - } + fun.parameters.head.`type`() match { + case Right(result) => + val funType = undefSubst.subst(result) + constr.expectedType match { + case Some(tp) => + val conformance = funType.conforms(tp, ScUndefinedSubstitutor()) + if (conformance._1) { + conformance._2.getSubstitutor match { + case Some(newSubst) => newSubst.followed(substitutor) + case _ => substitutor + } + } else substitutor + case _ => substitutor + } + case Left(_) => substitutor } } res += ((new PhysicalSignature(fun, subst), 0)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala index 05eb32552f4..96a83b96471 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala @@ -216,8 +216,6 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne */ def returnTypeElement: Option[ScTypeElement] - def returnTypeIsDefined: Boolean = !definedReturnType.isEmpty - def hasExplicitType: Boolean = returnTypeElement.isDefined def removeExplicitType() { @@ -568,18 +566,17 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne } private def collectReverseParamTypesNoImplicits: Option[Seq[Seq[ScType]]] = { - var i = paramClauses.clauses.length - 1 - val res: ArrayBuffer[Seq[ScType]] = ArrayBuffer.empty - while (i >= 0) { - val cl = paramClauses.clauses.apply(i) - if (!cl.isImplicit) { - val paramTypes: Seq[TypeResult[ScType]] = cl.parameters.map(_.`type`()) - if (paramTypes.exists(_.isEmpty)) return None - res += paramTypes.map(_.get) + val buffer = ArrayBuffer.empty[Seq[ScType]] + for (cl <- paramClauses.clauses.reverse + if !cl.isImplicit) { + val paramTypes: Seq[TypeResult[ScType]] = cl.parameters.map(_.`type`()) + if (paramTypes.exists(_.isLeft)) return None + + buffer += paramTypes.collect { + case Right(value) => value } - i = i - 1 } - Some(res) + Some(buffer) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala index 982cecaa7fe..4a343b6bd90 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala @@ -345,12 +345,13 @@ class ScStableCodeReferenceElementImpl(node: ASTNode) extends ScReferenceElement case Some(fType) => Success(ScProjectionType(fType, obj, superReference = false)) case _ => td.`type`().map(substitutor.subst) } - var state = ResolveState.initial.put(ScSubstitutor.key, substitutor) - if (fromType.isDefined) { - state = state.put(BaseProcessor.FROM_TYPE_KEY, fromType.get) - processor.processType(fromType.get, this, state) - } else { - td.processDeclarations(processor, state, null, this) + val state = ResolveState.initial.put(ScSubstitutor.key, substitutor) + + fromType match { + case Right(value) => + processor.processType(value, this, state.put(BaseProcessor.FROM_TYPE_KEY, value)) + case _ => + td.processDeclarations(processor, state, null, this) } case _: ScClass | _: ScTrait => td.processDeclarations(processor, ResolveState.initial.put(ScSubstitutor.key, substitutor), null, this) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala index f1ac2527d8f..94265bcf267 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala @@ -107,21 +107,21 @@ class ScConstructorPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) val emptySubst: ScSubstitutor = fun.typeParameters.foldLeft(ScSubstitutor.empty)((s, p) => s.bindT(p.nameAndId, p.upperBound.getOrAny)) val emptyRes = substitutor followed emptySubst - val result = fun.parameters.head.`type`() - if (result.isEmpty) emptyRes - else { - val funType = undefSubst.subst(result.get) - this.expectedType match { - case Some(tp) => - val conformance = funType.conforms(tp, ScUndefinedSubstitutor()) - if (conformance._1) { - conformance._2.getSubstitutor match { - case Some(newSubst) => newSubst followed substitutor followed emptySubst - case _ => emptyRes - } - } else emptyRes - case _ => emptyRes - } + fun.parameters.head.`type`() match { + case Right(result) => + val funType = undefSubst.subst(result) + this.expectedType match { + case Some(tp) => + val conformance = funType.conforms(tp, ScUndefinedSubstitutor()) + if (conformance._1) { + conformance._2.getSubstitutor match { + case Some(newSubst) => newSubst followed substitutor followed emptySubst + case _ => emptyRes + } + } else emptyRes + case _ => emptyRes + } + case Left(_) => emptyRes } } fun.paramClauses.clauses.head.parameters.head.`type`().map(subst.subst) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala index 5123143b870..ec8dcc1adb4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala @@ -6,7 +6,6 @@ package expr import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction @@ -15,10 +14,11 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{Compatibility, ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.lang.resolve.processor.MethodResolveProcessor +import org.jetbrains.plugins.scala.project.ProjectContext /** -* @author Alexander Podkhalyuzin -*/ + * @author Alexander Podkhalyuzin + */ class ScTryStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryStmt { override def accept(visitor: PsiElementVisitor) { @@ -30,37 +30,38 @@ class ScTryStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryS override def toString: String = "TryStatement" - protected override def innerType: TypeResult[ScType] = { - val lifted = tryBlock.`type`() - lifted flatMap { _ => catchBlock match { - case None => lifted - case Some(cb) => - cb.expression match { - case Some(expr) if !lifted.isEmpty => - expr.`type`() match { - case Success(_) => - val tp = expr.`type`().getOrAny - val throwable = ScalaPsiManager.instance(expr.getProject).getCachedClass(expr.resolveScope, "java.lang.Throwable") - throwable.fold(lifted) { throwable => - val throwableType = ScDesignatorType(throwable) - val processor = new MethodResolveProcessor(expr, "apply", List(Seq(new Compatibility.Expression(throwableType))), - Seq.empty, Seq.empty) - processor.processType(tp, expr) - val candidates = processor.candidates - if (candidates.length != 1) lifted - else { - candidates(0) match { - case ScalaResolveResult(fun: ScFunction, subst) => - fun.returnType.map(tp => lifted.get.lub(subst.subst(tp), checkWeak = true)) - case _ => lifted - } - } - } - case _ => lifted - } - case _ => lifted - } - } + import ScTryStmtImpl._ + + protected override def innerType: TypeResult[ScType] = + tryBlock.`type`().flatMap { tryBlockType => + val maybeExpression = catchBlock.flatMap(_.expression) + + val candidates = maybeExpression.toSeq.flatMap { expr => + expr.`type`().toOption.zip(createProcessor(expr)).flatMap { + case (tp, processor) => + processor.processType(tp, expr) + processor.candidates + } + } + + candidates match { + case Seq(ScalaResolveResult(function: ScFunction, substitutor)) => + function.returnType + .map(substitutor.subst) + .map(tryBlockType.lub(_)) + case _ => Success(tryBlockType) + } } - } +} + +object ScTryStmtImpl { + + private def createProcessor(expression: ScExpression) + (implicit projectContext: ProjectContext): Option[MethodResolveProcessor] = + expression.elementScope.getCachedClass("java.lang.Throwable") + .map(ScDesignatorType(_)) + .map(new Compatibility.Expression(_)) + .map { compatibilityExpression => + new MethodResolveProcessor(expression, "apply", List(Seq(compatibilityExpression)), Seq.empty, Seq.empty) + } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala index f37db9d1ac8..f39ad159ff0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/imports/ScImportStmtImpl.scala @@ -205,14 +205,15 @@ class ScImportStmtImpl private (stub: ScImportStmtStub, node: ASTNode) } if (importExpr.isSingleWildcard) { if (!checkWildcardImports) return true - (elem, processor) match { - case (cl: PsiClass, processor: BaseProcessor) if !cl.isInstanceOf[ScTemplateDefinition] => - if (!processor.processType(new ScDesignatorType(cl, true), place, - newState)) return false - case (_, processor: BaseProcessor) if refType.isDefined => - if (!processor.processType(refType.get, place, newState)) return false - case _ => if (!elem.processDeclarations(processor, newState, this, place)) return false + val processed = (elem, refType, processor) match { + case (cl: PsiClass, _, processor: BaseProcessor) if !cl.isInstanceOf[ScTemplateDefinition] => + processor.processType(new ScDesignatorType(cl, true), place, newState) + case (_, Right(value), processor: BaseProcessor) => + processor.processType(value, place, newState) + case _ => + elem.processDeclarations(processor, newState, this, place) } + if (!processed) return false } else if (!processor.execute(elem, newState)) return false case Some(set) => val shadowed: mutable.HashSet[(ScImportSelector, PsiElement)] = mutable.HashSet.empty diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala index 3366b231240..6e23e1c55ff 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala @@ -48,15 +48,15 @@ object LightUtil { if (classes.isEmpty) { annotation.constructor.typeArgList match { case Some(args) => - val classes = args.typeArgs.map(_.`type`()).filter(_.isDefined).map(_.get).flatMap { - _.toPsiType match { - case c: PsiClassType => - c.resolve() match { - case clazz: PsiClass => Seq(clazz.getQualifiedName) - case _ => Seq.empty - } - case _ => Seq.empty - } + val classes = args.typeArgs + .flatMap(_.`type`().toOption) + .flatMap { + _.toPsiType match { + case c: PsiClassType => Option(c.resolve()) + case _ => None + } + }.collect { + case c: PsiClass => c.getQualifiedName } if (classes.nonEmpty) accumulator :+ classes.mkString(sep = ", ") else accumulator diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala index d9b68d8a6cc..cd84706e7f9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala @@ -309,43 +309,38 @@ trait ScalaConformance extends api.Conformance { } trait ThisVisitor extends ScalaTypeVisitor { - override def visitThisType(t: ScThisType) { - val clazz = t.element - val res = clazz.getTypeWithProjections() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(l, res.get, visited, subst, checkWeak) + override def visitThisType(t: ScThisType): Unit = { + result = t.element.getTypeWithProjections() match { + case Right(value) => conformsInner(l, value, visited, subst, checkWeak) + case _ => (false, undefinedSubst) + } } } trait DesignatorVisitor extends ScalaTypeVisitor { - override def visitDesignatorType(d: ScDesignatorType) { - d.element match { - case v: ScBindingPattern => - val res = v.`type`() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(l, res.get, visited, undefinedSubst) - case v: ScParameter => - val res = v.`type`() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(l, res.get, visited, undefinedSubst) - case v: ScFieldId => - val res = v.`type`() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(l, res.get, visited, undefinedSubst) - case _ => + override def visitDesignatorType(d: ScDesignatorType): Unit = { + val maybeType = d.element match { + case v: ScBindingPattern => v.`type`() + case v: ScParameter => v.`type`() + case v: ScFieldId => v.`type`() + case _ => return + } + + result = maybeType match { + case Right(value) => conformsInner(l, value, visited, undefinedSubst) + case _ => (false, undefinedSubst) } } } trait ParameterizedAliasVisitor extends ScalaTypeVisitor { - override def visitParameterizedType(p: ParameterizedType) { + override def visitParameterizedType(p: ParameterizedType): Unit = { p.isAliasType match { case Some(AliasType(_, _, upper)) => - if (upper.isEmpty) { - result = (false, undefinedSubst) - return + result = upper match { + case Right(value) => conformsInner(l, value, visited, undefinedSubst) + case _ => (false, undefinedSubst) } - result = conformsInner(l, upper.get, visited, undefinedSubst) case _ => } } @@ -356,9 +351,8 @@ trait ScalaConformance extends api.Conformance { override def visitDesignatorType(des: ScDesignatorType) { des.isAliasType match { - case Some(AliasType(_, _, upper)) => - if (upper.isEmpty) return - val res = conformsInner(l, upper.get, visited, undefinedSubst) + case Some(AliasType(_, _, Right(value))) => + val res = conformsInner(l, value, visited, undefinedSubst) if (stopDesignatorAliasOnFailure || res._1) result = res case _ => } @@ -409,11 +403,11 @@ trait ScalaConformance extends api.Conformance { trait ProjectionVisitor extends ScalaTypeVisitor { def stopProjectionAliasOnFailure: Boolean = false - override def visitProjectionType(proj2: ScProjectionType) { + override def visitProjectionType(proj2: ScProjectionType): Unit = { proj2.isAliasType match { - case Some(AliasType(_, _, upper)) => - if (upper.isEmpty) return - val res = conformsInner(l, upper.get, visited, undefinedSubst) + case Some(AliasType(_, _, Left(_))) => + case Some(AliasType(_, _, Right(value))) => + val res = conformsInner(l, value, visited, undefinedSubst) if (stopProjectionAliasOnFailure || res._1) result = res case _ => l match { @@ -463,22 +457,19 @@ trait ScalaConformance extends api.Conformance { } findProjectionBase(proj2) case _ => - proj2.actualElement match { + val res = proj2.actualElement match { case syntheticClass: ScSyntheticClass => result = conformsInner(l, syntheticClass.stdType, HashSet.empty, undefinedSubst) - case v: ScBindingPattern => - val res = v.`type`() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(l, proj2.actualSubst.subst(res.get), visited, undefinedSubst) - case v: ScParameter => - val res = v.`type`() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(l, proj2.actualSubst.subst(res.get), visited, undefinedSubst) - case v: ScFieldId => - val res = v.`type`() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(l, proj2.actualSubst.subst(res.get), visited, undefinedSubst) - case _ => + return + case v: ScBindingPattern => v.`type`() + case v: ScParameter => v.`type`() + case v: ScFieldId => v.`type`() + case _ => return + } + + result = res match { + case Right(value) => conformsInner(l, proj2.actualSubst.subst(value), visited, undefinedSubst) + case _ => (false, undefinedSubst) } } } @@ -693,18 +684,15 @@ trait ScalaConformance extends api.Conformance { proj.isAliasType match { case Some(AliasType(_, lower, _)) => - if (lower.isEmpty) { - result = (false, undefinedSubst) - return + result = lower match { + case Right(value) => conformsInner(value, r, visited, undefinedSubst) + case _ => (false, undefinedSubst) } - result = conformsInner(lower.get, r, visited, undefinedSubst) - return case _ => + rightVisitor = new ExistentialVisitor {} + r.visitType(rightVisitor) + if (result != null) return } - - rightVisitor = new ExistentialVisitor {} - r.visitType(rightVisitor) - if (result != null) return } override def visitJavaArrayType(a1: JavaArrayType) { @@ -959,11 +947,11 @@ trait ScalaConformance extends api.Conformance { return case _ => } - if (lower.isEmpty) { - result = (false, undefinedSubst) - return + + result = lower match { + case Right(value) => conformsInner(value, r, visited, undefinedSubst) + case _ => (false, undefinedSubst) } - result = conformsInner(lower.get, r, visited, undefinedSubst) return case _ => } @@ -1249,7 +1237,7 @@ trait ScalaConformance extends api.Conformance { } } - override def visitThisType(t: ScThisType) { + override def visitThisType(t: ScThisType): Unit = { var rightVisitor: ScalaTypeVisitor = new ValDesignatorSimplification with UndefinedSubstVisitor with AbstractVisitor with ParameterizedAbstractVisitor {} @@ -1265,10 +1253,10 @@ trait ScalaConformance extends api.Conformance { r.visitType(rightVisitor) if (result != null) return - val clazz = t.element - val res = clazz.getTypeWithProjections() - if (res.isEmpty) result = (false, undefinedSubst) - else result = conformsInner(res.get, r, visited, subst, checkWeak) + result = t.element.getTypeWithProjections() match { + case Right(value) => conformsInner(value, r, visited, subst, checkWeak) + case _ => (false, undefinedSubst) + } } override def visitDesignatorType(des: ScDesignatorType) { @@ -1305,18 +1293,15 @@ trait ScalaConformance extends api.Conformance { des.isAliasType match { case Some(AliasType(_, lower, _)) => - if (lower.isEmpty) { - result = (false, undefinedSubst) - return + result = lower match { + case Right(value) => conformsInner(value, r, visited, undefinedSubst) + case _ => (false, undefinedSubst) } - result = conformsInner(lower.get, r, visited, undefinedSubst) - return case _ => + rightVisitor = new CompoundTypeVisitor with ExistentialVisitor {} + r.visitType(rightVisitor) + if (result != null) return } - - rightVisitor = new CompoundTypeVisitor with ExistentialVisitor {} - r.visitType(rightVisitor) - if (result != null) return } override def visitTypeParameterType(tpt1: TypeParameterType) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala index 23d7697ab8c..32f5700d7bc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala @@ -41,10 +41,6 @@ package object result { case _ => throw new NoSuchElementException("Failure.get") } - def isEmpty: Boolean = result.isLeft - - def isDefined: Boolean = result.isRight - def getOrAny: ScType = getOrApiType(_.Any) def getOrNothing: ScType = getOrApiType(_.Nothing) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala index 115b5fdafd2..88a7982bfb8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaParameterTableModelItem.scala @@ -5,7 +5,7 @@ import com.intellij.refactoring.changeSignature.ParameterTableModelItemBase import org.jetbrains.plugins.scala.debugger.evaluation.ScalaCodeFragment import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory -import org.jetbrains.plugins.scala.lang.psi.types.result._ +import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable import scala.collection.mutable.ListBuffer @@ -53,13 +53,14 @@ class ScalaParameterTableModelItem(parameter: ScalaParameterInfo, if (parameter.isByName && parameter.isRepeatedParameter) { problems += "Parameter could not be repeated and by-name in the same time" } - val typeElem = ScalaPsiElementFactory.createTypeElementFromText(trimmed, typeCodeFragment, typeCodeFragment) - if (typeElem == null || typeElem.`type`().isEmpty) { - problems += s"Could not understand type $trimmed" - parameter.scType = null + + parameter.scType = ScalaPsiElementFactory.createTypeElementFromText(trimmed, typeCodeFragment, typeCodeFragment) match { + case Typeable(scType) => scType + case _ => null } - else { - parameter.scType = typeElem.`type`().getOrAny + + if (parameter.scType == null) { + problems += s"Could not understand type $trimmed" } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala index b57c74ec570..554d1a5f0e4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala @@ -5,7 +5,7 @@ import com.intellij.psi.{PsiClass, PsiElement, PsiPackage} import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAlias import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject -import org.jetbrains.plugins.scala.lang.psi.types.result.{TypeResult, _} +import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** @@ -43,9 +43,10 @@ object ScEquivalenceUtil { } private def areTypeAliasesEquivalent(ta1: ScTypeAlias, ta2: ScTypeAlias): Boolean = { - def equiv(tr1: TypeResult[ScType], tr2: TypeResult[ScType]): Boolean = { - if (tr1.isEmpty || tr2.isEmpty) false - else tr1.get.equiv(tr2.get) + def equiv(tr1: TypeResult[ScType], tr2: TypeResult[ScType]): Boolean = + (tr1, tr2) match { + case (Right(left), Right(right)) => left.equiv(right) + case _ => false } if (ta1.isExistentialTypeAlias && ta2.isExistentialTypeAlias) { diff --git a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala index 185d64bdc1f..cf097004241 100644 --- a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala @@ -8,7 +8,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, api => p, types => ptype} import scala.collection.immutable.Seq @@ -50,17 +49,18 @@ trait TreeAdapter { m.Term.New(m.Template(Nil, Seq(toCtor(annot.constructor)), m.Term.Param(Nil, m.Name.Anonymous(), None, None), None)) } - def toMacroDefn(t: ScMacroDefinition): m.Defn.Macro = { - if (t.definedReturnType.isEmpty) - unreachable("Macro definition must have return type defined") - m.Defn.Macro( - convertMods(t), toTermName(t), - Seq(t.typeParameters map toTypeParams: _*), - Seq(t.paramClauses.clauses.map(convertParamClause): _*), - t.definedReturnType.toOption.map(toType(_)), - expression(t.body).get - ) - } + def toMacroDefn(t: ScMacroDefinition): m.Defn.Macro = + t.definedReturnType match { + case Right(value) => + m.Defn.Macro( + convertMods(t), toTermName(t), + Seq(t.typeParameters map toTypeParams: _*), + Seq(t.paramClauses.clauses.map(convertParamClause): _*), + Option(toType(value)), + expression(t.body).get + ) + case _ => unreachable("Macro definition must have return type defined") + } def toFunDefn(t: ScFunctionDefinition): m.Defn.Def = { m.Defn.Def(convertMods(t), toTermName(t), From 10fedfa86cfb93addcb117f3d691e5966a055dbd Mon Sep 17 00:00:00 2001 From: "evgeny.nacu" Date: Thu, 26 Oct 2017 13:12:25 +0300 Subject: [PATCH 050/141] scala plugin didn't take in account context bounds for class constructor (when was searching for implicits) #SCL-12609 fixed (cherry picked from commit addbdfc6529ec4fd516d4872ed5c121404642efa) --- .../base/types/ScSimpleTypeElementImpl.scala | 10 ++++--- .../OptimizeImportsImplicitsTest.scala | 2 ++ .../optimize/implicits/SCL12609.scala | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 scala/scala-impl/testdata/optimize/implicits/SCL12609.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala index 1a2e3bc14a6..e7741cbea79 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala @@ -75,19 +75,21 @@ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w def getConstructorParams(constr: PsiMethod, subst: ScSubstitutor): (Seq[Seq[Parameter]], Boolean) = { constr match { case fun: ScFunction => - (fun.effectiveParameterClauses.map(_.effectiveParameters.map { p => + val clauses = fun.effectiveParameterClauses + (clauses.map(_.effectiveParameters.map { p => val paramType: ScType = subst.subst(p.`type`().getOrAny) new Parameter(p.name, p.deprecatedName, paramType, paramType, p.isDefaultParam,p.isRepeatedParameter, p.isCallByNameParameter, p.index, Some(p), p.getDefaultExpression.flatMap(_.`type`().toOption)) }), - fun.parameterList.clauses.lastOption.exists(_.isImplicit)) + clauses.lastOption.exists(_.isImplicit)) case f: ScPrimaryConstructor => - (f.effectiveParameterClauses.map(_.effectiveParameters.map { p => + val clauses = f.effectiveParameterClauses + (clauses.map(_.effectiveParameters.map { p => val paramType: ScType = subst.subst(p.`type`().getOrAny) new Parameter(p.name, p.deprecatedName, paramType, paramType, p.isDefaultParam, p.isRepeatedParameter, p.isCallByNameParameter, p.index, Some(p), p.getDefaultExpression.flatMap(_.`type`().toOption)) }), - f.parameterList.clauses.lastOption.exists(_.isImplicit)) + clauses.lastOption.exists(_.isImplicit)) case m: PsiMethod => (Seq(m.parameters.map { p => Parameter(p.paramType(), isRepeated = p.isVarArgs, index = p.index) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/optimize/generated/OptimizeImportsImplicitsTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/optimize/generated/OptimizeImportsImplicitsTest.scala index bc2d6898823..d1d3236ea3f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/optimize/generated/OptimizeImportsImplicitsTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/optimize/generated/OptimizeImportsImplicitsTest.scala @@ -52,6 +52,8 @@ class OptimizeImportsImplicitsTest extends OptimizeImportsTestBase { def testSCL12332(): Unit = doTest() + def testSCL12609(): Unit = doTest() + //one of the examples from SCL-9326 def testFromUnderscore(): Unit = doTest() } \ No newline at end of file diff --git a/scala/scala-impl/testdata/optimize/implicits/SCL12609.scala b/scala/scala-impl/testdata/optimize/implicits/SCL12609.scala new file mode 100644 index 00000000000..fa171ab154f --- /dev/null +++ b/scala/scala-impl/testdata/optimize/implicits/SCL12609.scala @@ -0,0 +1,28 @@ +trait TypeClass[T] + +class MyImplicitUser[T: TypeClass] + +object SCL12609 { + object Implicits { + implicit object MyImplicityInt extends TypeClass[Int] + } + + import Implicits._ + + new MyImplicitUser[Int] {} +} +/* +trait TypeClass[T] + +class MyImplicitUser[T: TypeClass] + +object SCL12609 { + object Implicits { + implicit object MyImplicityInt extends TypeClass[Int] + } + + import Implicits._ + + new MyImplicitUser[Int] {} +} +*/ \ No newline at end of file From 6c7bb257b9a3882f91420c3bb77fac5231d9f90d Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Thu, 26 Oct 2017 13:19:25 +0300 Subject: [PATCH 051/141] Success class removed #SCL-12743 --- .../types/DottyAndOrTypeElementImpl.scala | 4 +- .../types/DottyRefinedTypeElementImpl.scala | 2 +- .../lang/psi/types/DottyPsiTypeBridge.scala | 3 +- .../scala/annotator/FunctionAnnotator.scala | 2 +- .../scala/annotator/PatternAnnotator.scala | 5 +-- .../scala/annotator/ScalaAnnotator.scala | 20 +++++----- .../quickfix/AddBreakoutQuickFix.scala | 3 +- .../annotator/quickfix/ChangeTypeFix.scala | 3 +- .../SuggestScalaVariableNameMacro.scala | 5 +-- .../collections/MapGetOrElseInspection.scala | 2 +- .../codeInspection/collections/package.scala | 2 +- .../MatchToPartialFunctionInspection.scala | 3 +- .../ConvertibleToMethodValueInspection.scala | 2 +- .../ComparingUnrelatedTypesInspection.scala | 5 +-- ...ctorSimplifyTypeProjectionInspection.scala | 2 +- .../ScalaDocumentationProvider.scala | 2 +- .../SameSignatureCallParametersProvider.scala | 2 +- .../ScalaSmartCompletionContributor.scala | 6 +-- .../completion/lookups/ScalaLookupItem.scala | 2 +- .../weighter/ScalaByExpectedTypeWeigher.scala | 7 ++-- .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 10 ++--- .../scala/lang/psi/api/InferUtil.scala | 16 ++++---- .../psi/api/base/patterns/ScPattern.scala | 8 ++-- .../api/base/patterns/ScTuplePattern.scala | 2 +- .../lang/psi/api/expr/ExpectedTypes.scala | 15 +++---- .../lang/psi/api/expr/MethodInvocation.scala | 6 +-- .../lang/psi/api/expr/ScAnnotations.scala | 3 +- .../scala/lang/psi/api/expr/ScBlock.scala | 8 ++-- .../lang/psi/api/expr/ScExpression.scala | 40 +++++++++---------- .../lang/psi/api/statements/ScFunction.scala | 14 +++---- .../api/statements/params/ScParameter.scala | 4 +- .../psi/impl/base/ScConstructorImpl.scala | 10 ++--- .../lang/psi/impl/base/ScLiteralImpl.scala | 2 +- .../ScStableCodeReferenceElementImpl.scala | 3 +- .../psi/impl/base/ScTypeBoundsOwnerImpl.scala | 2 +- .../patterns/ScCompositePatternImpl.scala | 2 +- .../patterns/ScConstructorPatternImpl.scala | 8 ++-- .../base/patterns/ScInfixPatternImpl.scala | 2 +- .../base/patterns/ScNamingPatternImpl.scala | 2 +- .../patterns/ScReferencePatternImpl.scala | 2 +- .../base/patterns/ScTypedPatternImpl.scala | 2 +- .../base/patterns/ScWildcardPatternImpl.scala | 2 +- .../types/ScCompoundTypeElementImpl.scala | 2 +- .../types/ScExistentialTypeElementImpl.scala | 2 +- .../ScParameterizedTypeElementImpl.scala | 2 +- .../ScParenthesisedTypeElementImpl.scala | 2 +- .../base/types/ScSimpleTypeElementImpl.scala | 22 +++++----- .../types/ScTypeVariableTypeElementImpl.scala | 2 +- .../lang/psi/impl/expr/ScAssignStmtImpl.scala | 4 +- .../psi/impl/expr/ScFunctionExprImpl.scala | 2 +- .../psi/impl/expr/ScGenericCallImpl.scala | 8 ++-- .../lang/psi/impl/expr/ScMatchStmtImpl.scala | 2 +- .../expr/ScNewTemplateDefinitionImpl.scala | 6 +-- .../impl/expr/ScReferenceExpressionImpl.scala | 36 ++++++++--------- .../lang/psi/impl/expr/ScReturnStmtImpl.scala | 2 +- .../psi/impl/expr/ScSelfInvocationImpl.scala | 4 +- .../psi/impl/expr/ScThisReferenceImpl.scala | 4 +- .../lang/psi/impl/expr/ScThrowStmtImpl.scala | 2 +- .../lang/psi/impl/expr/ScTryStmtImpl.scala | 2 +- .../lang/psi/impl/expr/ScTupleImpl.scala | 2 +- .../impl/expr/ScUnderscoreSectionImpl.scala | 2 +- .../lang/psi/impl/expr/ScUnitExprImpl.scala | 2 +- .../lang/psi/impl/expr/ScWhileStmtImpl.scala | 3 +- .../psi/impl/expr/xml/ScXmlExprImpl.scala | 3 +- .../psi/impl/expr/xml/ScXmlPatternImpl.scala | 2 +- .../ScFunctionDeclarationImpl.scala | 2 +- .../statements/ScFunctionDefinitionImpl.scala | 4 +- .../statements/ScMacroDefinitionImpl.scala | 2 +- .../ScTypeAliasDeclarationImpl.scala | 4 +- .../statements/params/ScParameterImpl.scala | 2 +- .../statements/params/ScTypeParamImpl.scala | 5 +-- .../toplevel/synthetic/ScSyntheticClass.scala | 5 +-- .../impl/toplevel/typedef/MixinNodes.scala | 3 +- .../impl/toplevel/typedef/ScClassImpl.scala | 3 +- .../typedef/ScTypeDefinitionImpl.scala | 12 +++--- .../simulacrum/SimulacrumInjection.scala | 2 +- .../psi/implicits/ImplicitCollector.scala | 6 +-- .../lang/psi/light/JavaConversionUtil.scala | 3 +- .../scala/lang/psi/light/LightUtil.scala | 3 +- .../lang/psi/light/ScFunctionWrapper.scala | 12 +++--- .../light/StaticTraitScFunctionWrapper.scala | 3 +- .../light/scala/ScLightBindingPattern.scala | 2 +- .../lang/psi/light/scala/ScLightFieldId.scala | 2 +- .../scala/ScLightFunctionDeclaration.scala | 6 +-- .../scala/ScLightFunctionDefinition.scala | 6 +-- .../psi/light/scala/ScLightParameter.scala | 2 +- .../scala/ScLightTypeAliasDeclaration.scala | 4 +- .../scala/ScLightTypeAliasDefinition.scala | 6 +-- .../psi/light/scala/ScLightTypeParam.scala | 8 ++-- .../lang/psi/stubs/util/ScalaStubsUtil.scala | 3 +- .../scala/lang/psi/types/BaseTypes.scala | 3 +- .../scala/lang/psi/types/Compatibility.scala | 12 +++--- .../lang/psi/types/ScParameterizedType.scala | 9 ++--- .../lang/psi/types/ScalaConformance.scala | 4 +- .../lang/psi/types/ScalaEquivalence.scala | 5 +-- .../lang/psi/types/ScalaPsiTypeBridge.scala | 5 +-- .../scala/lang/psi/types/ScalaType.scala | 6 +-- .../lang/psi/types/api/FunctionType.scala | 3 +- .../api/designator/ScDesignatorType.scala | 5 +-- .../api/designator/ScProjectionType.scala | 16 ++++---- .../psi/types/api/designator/ScThisType.scala | 5 +-- .../scala/lang/psi/types/package.scala | 2 +- .../scala/lang/psi/types/result/package.scala | 16 +++----- .../ScalaChangeSignatureUsageHandler.scala | 3 +- .../duplicates/DuplicateMatch.scala | 2 +- .../memberPullUp/ScalaPullUpProcessor.scala | 3 +- .../resolve/ReferenceExpressionResolver.scala | 3 +- .../resolve/processor/BaseProcessor.scala | 4 +- .../processor/ExtractorResolveProcessor.scala | 3 +- .../processor/MethodResolveProcessor.scala | 2 +- .../resolve/processor/ResolveProcessor.scala | 3 +- .../ScalaTestConfigurationProducer.scala | 5 +-- .../completion/SbtCompletionContributor.scala | 2 +- .../src/scala/meta/trees/TypeAdapter.scala | 6 +-- .../src/scala/meta/trees/Utils.scala | 4 +- .../scala/lang/macros/MonocleLensesTest.scala | 2 +- .../scala/lang/macros/StalactiteTest.scala | 2 +- .../TypeConformanceTestBase.scala | 2 +- .../typeInference/TypeInferenceDoTest.scala | 4 +- .../ExistentialSimplificationTestBase.scala | 4 +- .../annotations/MetaAnnotationBugsTest.scala | 4 +- 121 files changed, 293 insertions(+), 329 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala index c2d47c05d99..eb1579a4ede 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala @@ -19,11 +19,11 @@ abstract class DottyAndOrTypeElementImpl(node: ASTNode) extends ScalaPsiElementI leftTypeElement.`type`(), rightTypeElement match { case Some(typeElement) => typeElement.`type`() - case _ => Success(api.Nothing) + case _ => Right(api.Nothing) } ).map(_.getOrElse(default)) - override protected def innerType: TypeResult[ScType] = Success(innerTypeValue) + override protected def innerType: TypeResult[ScType] = Right(innerTypeValue) } class DottyAndTypeElementImpl(node: ASTNode) extends DottyAndOrTypeElementImpl(node) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala index 16395c41914..231e8494852 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala @@ -12,5 +12,5 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ */ class DottyRefinedTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with DottyRefinedTypeElement { override protected def innerType: TypeResult[ScType] = - Success(DottyRefinedType(typeElement.`type`().getOrAny, refinement)) + Right(DottyRefinedType(typeElement.`type`().getOrAny, refinement)) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala index 068f2253bca..cc9357ac846 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/types/DottyPsiTypeBridge.scala @@ -7,7 +7,6 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticC import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, StdType, arrayType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.JavaConverters._ @@ -42,7 +41,7 @@ trait DottyPsiTypeBridge extends api.PsiTypeBridge { case syntheticClass: ScSyntheticClass => toPsiType(syntheticClass.stdType) case clazz: PsiClass => createType(clazz, raw = true) case definition: ScTypeAliasDefinition => definition.aliasedType match { - case Success(result) => createComponent(result) + case Right(result) => createComponent(result) case _ => createJavaObject } case _ => createJavaObject diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala index b2bc2b5d91a..0f78d21d32a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala @@ -132,6 +132,6 @@ trait FunctionAnnotator { case _ => (Some(element), Any) }) match { case (Some(expression: ScExpression), _) => expression.getTypeAfterImplicitConversion().tr - case (_, default) => Success(default) + case (_, default) => Right(default) } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala index 2d2abd14143..3f45e2af545 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/PatternAnnotator.scala @@ -13,7 +13,6 @@ import org.jetbrains.plugins.scala.lang.psi.types.ComparingUtil._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.DesignatorOwner import org.jetbrains.plugins.scala.lang.psi.types.api.{ScTypePresentation, _} import org.jetbrains.plugins.scala.lang.psi.types.recursiveUpdate.AfterUpdate.{ProcessSubtypes, ReplaceWith} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScAbstractType, ScParameterizedType, ScType, ScTypeExt, ScalaType} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.project.ProjectContext @@ -130,7 +129,7 @@ object PatternAnnotator { case Some(ref) => ref.bind() match { case Some(ScalaResolveResult(fun: ScFunction, _)) if fun.name == "unapply" => fun.returnType match { - case Success(rt) => + case Right(rt) => val expected = ScPattern.expectedNumberOfExtractorArguments(rt, pattern, ScPattern.isOneArgCaseClassMethod(fun)) val tupleCrushingIsPresent = expected > 0 && numPatterns == 1 && !fun.isSynthetic if (expected != numPatterns && !tupleCrushingIsPresent) { //1 always fits if return type is Option[TupleN] @@ -140,7 +139,7 @@ object PatternAnnotator { case _ => } case Some(ScalaResolveResult(fun: ScFunction, _)) if fun.name == "unapplySeq" => fun.returnType match { - case Success(rt) => + case Right(rt) => //subtract 1 because last argument (Seq) may be omitted val expected = ScPattern.expectedNumberOfExtractorArguments(rt, pattern, ScPattern.isOneArgCaseClassMethod(fun)) - 1 if (expected > numPatterns) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index 507df9ee53d..9e67a98fab4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -97,7 +97,7 @@ abstract class ScalaAnnotator extends Annotator if (isAdvancedHighlightingEnabled(element)) { expr.getTypeAfterImplicitConversion() match { - case ExpressionTypeResult(Success(t), _, Some(implicitFunction)) => + case ExpressionTypeResult(Right(t), _, Some(implicitFunction)) => highlightImplicitView(expr, implicitFunction.element, t, expr, holder) case _ => } @@ -529,7 +529,7 @@ abstract class ScalaAnnotator extends Annotator case ScalaResolveResult(fun: ScFunction, subst) => fun.returnType.map(subst.subst) case _ => return } - val conformance = smartCheckConformance(Success(tp), returnType) + val conformance = smartCheckConformance(Right(tp), returnType) if (!conformance) { if (typeAware) { val (retTypeText, expectedTypeText) = ScTypePresentation.different(returnType.getOrNothing, tp) @@ -972,7 +972,7 @@ abstract class ScalaAnnotator extends Annotator case param: ScParameter => if (!param.isDefaultParam) return //performance optimization param.getRealParameterType match { - case Success(paramType) if paramType.extractClass.isDefined => + case Right(paramType) if paramType.extractClass.isDefined => //do not check generic types. See SCL-3508 case _ => return } @@ -983,7 +983,7 @@ abstract class ScalaAnnotator extends Annotator expr.expectedTypeEx(fromUnderscore) match { case Some((tp: ScType, _)) if tp equiv Unit => //do nothing case Some((tp: ScType, typeElement)) => - val expectedType = Success(tp) + val expectedType = Right(tp) implicitFunction match { case Some(_) => //todo: @@ -1081,7 +1081,7 @@ abstract class ScalaAnnotator extends Annotator import org.jetbrains.plugins.scala.lang.psi.types._ val funType = fun.returnType funType match { - case Success(tp) if tp equiv Unit => return //nothing to check + case Right(tp) if tp equiv Unit => return //nothing to check case _ => } @@ -1188,7 +1188,7 @@ abstract class ScalaAnnotator extends Annotator checkBoundsVariance(fun, holder, fun.nameId, fun.getParent) if (!childHasAnnotation(fun.returnTypeElement, "uncheckedVariance")) { fun.returnType match { - case Success(returnType) => + case Right(returnType) => checkVariance(ScalaType.expandAliases(returnType).getOrElse(returnType), Covariant, fun.nameId, fun.getParent, holder) case _ => @@ -1210,10 +1210,10 @@ abstract class ScalaAnnotator extends Annotator if (!modifierIsThis(toCheck)) { for (element <- declaredElements) { element.`type`() match { - case Success(tp) => + case Right(tp) => ScalaType.expandAliases(tp) match { //so type alias is highlighted - case Success(newTp) => checkVariance(newTp, variance, element.nameId, toCheck, holder) + case Right(newTp) => checkVariance(newTp, variance, element.nameId, toCheck, holder) case _ => checkVariance(tp, variance, element.nameId, toCheck, holder) } case _ => @@ -1407,11 +1407,11 @@ abstract class ScalaAnnotator extends Annotator */ def smartCheckConformance(l: TypeResult[ScType], r: TypeResult[ScType]): Boolean = { val leftType = l match { - case Success(res) => res + case Right(res) => res case _ => return true } val rightType = r match { - case Success(res) => res + case Right(res) => res case _ => return true } rightType.conforms(leftType) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala index f5f101b03ce..7b0fc8d37b0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/AddBreakoutQuickFix.scala @@ -10,7 +10,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScForStateme import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory -import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Nikolay.Tropin @@ -62,7 +61,7 @@ object AddBreakoutQuickFix { def isImplicitCanBuildFromParam(p: ScParameter): Boolean = { p.`type`() match { - case Success(tpe) if tpe.canonicalText.startsWith("_root_.scala.collection.generic.CanBuildFrom") => true + case Right(tpe) if tpe.canonicalText.startsWith("_root_.scala.collection.generic.CanBuildFrom") => true case _ => false } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala index 9e77c93161a..076ee52d9da 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/ChangeTypeFix.scala @@ -13,13 +13,12 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeElementFromText import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.ScTypePresentation -import org.jetbrains.plugins.scala.lang.psi.types.result._ class ChangeTypeFix(typeElement: ScTypeElement, newType: ScType) extends IntentionAction { val getText: String = { val (oldTypeDescripton, newTypeDescription) = typeElement.`type`() match { - case Success(oldType) => ScTypePresentation.different(oldType, newType) + case Right(oldType) => ScTypePresentation.different(oldType, newType) case _ => (typeElement.getText, newType.presentableText) } s"Change type '$oldTypeDescripton' to '$newTypeDescription'" diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala index a05531032a1..500996fd20e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/macros/SuggestScalaVariableNameMacro.scala @@ -8,7 +8,6 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.{JavaArrayType, ParameterizedType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.namesSuggester.NameSuggester /** @@ -66,8 +65,8 @@ object SuggestScalaVariableNameMacro { if (items.length == 0) return default items(0) match { case typed: ScTypedDefinition => typed.`type`() match { - case Success(ParameterizedType(_, typeArgs)) => typeArgs.head - case Success(JavaArrayType(argument)) => argument + case Right(ParameterizedType(_, typeArgs)) => typeArgs.head + case Right(JavaArrayType(argument)) => argument case _ => return default } case _ => return default diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala index 5c46ee8dbab..786b782d19b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapGetOrElseInspection.scala @@ -59,7 +59,7 @@ object MapGetOrElse extends SimplificationType() { case _ => return false } val mapArgRetType = mapArg.`type`() match { - case Success(FunctionType(retType, _)) => retType + case Right(FunctionType(retType, _)) => retType case _ => return false } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala index 1c7c56f930a..b5188899a2f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala @@ -156,7 +156,7 @@ package object collections { import expr.projectContext expr.`type`() match { - case Success(result) => + case Right(result) => result match { case FunctionType(returnType, _) => returnType.conforms(api.Boolean) case _ => false diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala index 6b4bdd98351..98bfa7ef7a8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/functionExpressions/MatchToPartialFunctionInspection.scala @@ -17,7 +17,6 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import scala.collection.JavaConverters._ @@ -41,7 +40,7 @@ class MatchToPartialFunctionInspection extends AbstractInspection(inspectionId) private def notExpectedType(expr: ScExpression) = { (expr.`type`(), expr.expectedType()) match { - case (Success(tpe), Some(expType: ScType)) => !expType.equiv(tpe) + case (Right(tpe), Some(expType: ScType)) => !expType.equiv(tpe) case _ => true } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala index d547eee6e11..d1b9f1a0f2b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala @@ -103,7 +103,7 @@ class ConvertibleToMethodValueInspection extends AbstractInspection(inspectionId conformsExpected(oldExpr) && conformsExpected(newExpr) && oldExpr.`type`().getOrAny.conforms(newExpr.`type`().getOrNothing) case None if newExprText endsWith "_" => (oldExpr.`type`(), newExpr.`type`()) match { - case (Success(oldType), Success(newType)) => oldType.equiv(newType) + case (Right(oldType), Right(newType)) => oldType.equiv(newType) case _ => false } case _ => false diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala index ab14cb2380c..43d6dc2e28c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeChecking/ComparingUnrelatedTypesInspection.scala @@ -16,7 +16,6 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticF import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.api.{ScTypePresentation, _} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.project.ProjectExt @@ -71,7 +70,7 @@ object ComparingUnrelatedTypesInspection { @tailrec private def extractActualType(`type`: ScType): ScType = `type`.isAliasType match { - case Some(AliasType(_, Success(rhs), _)) => extractActualType(rhs) + case Some(AliasType(_, Right(rhs), _)) => extractActualType(rhs) case _ => `type`.tryExtractDesignatorSingleton } } @@ -89,7 +88,7 @@ class ComparingUnrelatedTypesInspection extends AbstractInspection(inspectionId, //getType() for the reference on the left side returns singleton type, little hack here val leftOnTheRight = ScalaPsiElementFactory.createExpressionWithContextFromText(left.getText, right.getParent, right) Seq(leftOnTheRight, right) map (_.`type`()) match { - case Seq(Success(leftType), Success(rightType)) if cannotBeCompared(leftType, rightType) => + case Seq(Right(leftType), Right(rightType)) if cannotBeCompared(leftType, rightType) => val message = generateComparingUnrelatedTypesMsg(leftType, rightType) holder.registerProblem(expr, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING) case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala index ea723213b1e..94181a53731 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/typeLambdaSimplify/KindProjectorSimplifyTypeProjectionInspection.scala @@ -63,7 +63,7 @@ class KindProjectorSimplifyTypeProjectionInspection extends LocalInspectionTool } alias.aliasedType match { - case Success(paramType: ScParameterizedType) => + case Right(paramType: ScParameterizedType) => val typeParam: Seq[ScTypeParam] = alias.typeParameters val valid = typeParam.nonEmpty && diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala index ac385738c51..374ec5384bb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/documentationProvider/ScalaDocumentationProvider.scala @@ -524,7 +524,7 @@ object ScalaDocumentationProvider { annotation.constructor.args.foreach( a => a.exprs.headOption.map { case exprHead => exprHead.`type`() match { - case Success(head) => + case Right(head) => head match { case ParameterizedType(_, args) => args.headOption match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala index cc84cdac069..c87f5bb6b35 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/SameSignatureCallParametersProvider.scala @@ -98,7 +98,7 @@ class SameSignatureCallParametersProvider extends ScalaCompletionContributor { val index = constructor.arguments.indexOf(args) val typeElement = constructor.typeElement typeElement.`type`() match { - case Success(tp) => + case Right(tp) => val signatures = tp.extractClassType match { case Some((clazz: ScClass, subst)) if !clazz.hasTypeParameters || (clazz.hasTypeParameters && typeElement.isInstanceOf[ScParameterizedTypeElement]) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala index ef5110dd8e5..dd0a8ed7437 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaSmartCompletionContributor.scala @@ -120,12 +120,12 @@ class ScalaSmartCompletionContributor extends ScalaCompletionContributor { val second = checkForSecondCompletion && fun.paramClauses.clauses.filterNot(_.isImplicit).flatMap(_.parameters).isEmpty val added = fun.returnType match { - case Success(tp) => checkType(tp, infer, second) + case Right(tp) => checkType(tp, infer, second) case _ => false } if (!added) { fun.`type`() match { - case Success(tp) => checkType(tp, infer, second, etaExpanded = true) + case Right(tp) => checkType(tp, infer, second, etaExpanded = true) case _ => } } @@ -247,7 +247,7 @@ class ScalaSmartCompletionContributor extends ScalaCompletionContributor { case _: ScNewTemplateDefinition if foundClazz => //do nothing, impossible to invoke case t: ScTemplateDefinition => t.getTypeWithProjections(thisProjections = true) match { - case Success(scType) => + case Right(scType) => val lookupString = (if (foundClazz) t.name + "." else "") + "this" val el = new ScalaLookupItem(t, lookupString) if (!scType.equiv(Nothing) && typez.exists(scType conforms _)) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala index 47ccf96549a..bcc97e0279d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/lookups/ScalaLookupItem.scala @@ -131,7 +131,7 @@ class ScalaLookupItem(val element: PsiNamedElement, _name: String, containingCla presentationString(param.getRealParameterType.getOrAny, substitutor) case t: ScTemplateDefinition if name == "this" || name.endsWith(".this") => t.getTypeWithProjections(thisProjections = true) match { - case Success(tp) => + case Right(tp) => tp.presentableText case _ => "" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala index cb8f9403af4..c3b1691375c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/weighter/ScalaByExpectedTypeWeigher.scala @@ -10,7 +10,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticFunction import org.jetbrains.plugins.scala.lang.psi.types.api.{Nothing, ParameterizedType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScalaType} /** @@ -84,10 +83,10 @@ class ScalaByExpectedTypeWeigher(expectedTypes: Seq[ScType], position: PsiElemen val subst = ScalaPsiUtil.inferMethodTypesArgs(fun, scalaLookupItem.substitutor) fun.returnType match { - case Success(tp) => (tp, helper(tp, subst)) + case Right(tp) => (tp, helper(tp, subst)) case _ => fun.`type`() match { - case Success(tp) => (tp, helper(tp, subst)) + case Right(tp) => (tp, helper(tp, subst)) case _ => (null, null) } } @@ -98,7 +97,7 @@ class ScalaByExpectedTypeWeigher(expectedTypes: Seq[ScType], position: PsiElemen (tp, helper(tp, subst)) case typed: ScTypedDefinition => typed.`type`() match { - case Success(tp) => (tp, helper(tp)) + case Right(tp) => (tp, helper(tp)) case _ => (null, null) } case f: PsiField => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index 819df965e6e..31b18a3b368 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -223,7 +223,7 @@ object ScalaPsiUtil { lastParent match { case _: ScImportStmt => typeResult match { - case Success(t) => + case Right(t) => (processor, place) match { case (b: BaseProcessor, p: ScalaPsiElement) => b.processType(subst subst t, p, state) case _ => true @@ -495,7 +495,7 @@ object ScalaPsiUtil { def collectPartsTr(option: TypeResult[ScType]): Unit = { option match { - case Success(t) => collectParts(t) + case Right(t) => collectParts(t) case _ => } } @@ -505,7 +505,7 @@ object ScalaPsiUtil { if (visited.contains(tp)) return visited += tp tp.isAliasType match { - case Some(AliasType(_, _, Success(t))) => collectParts(t) + case Some(AliasType(_, _, Right(t))) => collectParts(t) case _ => } @@ -1830,11 +1830,11 @@ object ScalaPsiUtil { def selfTypeValid: Boolean = { td.selfType match { case Some(selfParam: ScParameterizedType) => td.`type`() match { - case Success(classParamTp: ScParameterizedType) => selfParam.designator.conforms(classParamTp.designator) + case Right(classParamTp: ScParameterizedType) => selfParam.designator.conforms(classParamTp.designator) case _ => false } case Some(selfTp) => td.`type`() match { - case Success(classType) => selfTp.conforms(classType) + case Right(classType) => selfTp.conforms(classType) case _ => false } case _ => true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala index 877a9673c0c..cd80be78676 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala @@ -246,7 +246,7 @@ object InferUtil { var nonValueType = _nonValueType nonValueType match { - case Success(ScTypePolymorphicType(m@ScMethodType(internal, _, impl), typeParams)) + case Right(ScTypePolymorphicType(m@ScMethodType(internal, _, impl), typeParams)) if expectedType.isDefined && (!fromImplicitParameters || impl) => def updateRes(expected: ScType) { if (expected.equiv(Unit)) return //do not update according to Unit type @@ -263,13 +263,13 @@ object InferUtil { Seq(Parameter("", None, expected, expected, isDefault = false, isRepeated = false, isByName = false)), Seq(new Expression(undefineSubstitutor(typeParams).subst(valueType))), typeParams, shouldUndefineParameters = false, canThrowSCE = canThrowSCE, filterTypeParams = filterTypeParams) - nonValueType = Success(update) //here should work in different way: + nonValueType = Right(update) //here should work in different way: } updateRes(expectedType.get) //todo: Something should be unified, that's bad to have fromImplicitParameters parameter. - case Success(ScTypePolymorphicType(internal, typeParams)) if expectedType.isDefined && fromImplicitParameters => + case Right(ScTypePolymorphicType(internal, typeParams)) if expectedType.isDefined && fromImplicitParameters => def updateRes(expected: ScType) { - nonValueType = Success(localTypeInference(internal, + nonValueType = Right(localTypeInference(internal, Seq(Parameter("", None, expected, expected, isDefault = false, isRepeated = false, isByName = false)), Seq(new Expression(undefineSubstitutor(typeParams).subst(internal.inferValueType))), typeParams, shouldUndefineParameters = false, canThrowSCE = canThrowSCE, @@ -325,10 +325,10 @@ object InferUtil { } nonValueType match { - case Success(tpt@ScTypePolymorphicType(mt: ScMethodType, _)) => - Success(tpt.copy(internalType = applyImplicitViewToResult(mt, expectedType))) - case Success(mt: ScMethodType) => - Success(applyImplicitViewToResult(mt, expectedType)) + case Right(tpt@ScTypePolymorphicType(mt: ScMethodType, _)) => + Right(tpt.copy(internalType = applyImplicitViewToResult(mt, expectedType))) + case Right(mt: ScMethodType) => + Right(applyImplicitViewToResult(mt, expectedType)) case tr => tr } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala index ecd76dd3e2f..f99339d9d8b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala @@ -311,7 +311,7 @@ object ScPattern { case _ => } val firstParameterType = fun.parameters.head.`type`() match { - case Success(tp) => tp + case Right(tp) => tp case _ => return None } val funType = undefSubst.subst(firstParameterType) @@ -321,7 +321,7 @@ object ScPattern { } } fun.returnType match { - case Success(rt) => + case Right(rt) => def updateRes(tp: ScType): ScType = { val parameters: Seq[ScTypeParam] = fun.typeParameters tp.recursiveVarianceUpdate { @@ -348,7 +348,7 @@ object ScPattern { s.bindT(p.nameAndId, UndefinedType(TypeParameterType(p, Some(substitutor)))) } val firstParameterRetTp = fun.parameters.head.`type`() match { - case Success(tp) => tp + case Right(tp) => tp case _ => return None } val funType = undefSubst.subst(firstParameterRetTp) @@ -358,7 +358,7 @@ object ScPattern { } } fun.returnType match { - case Success(rt) => + case Right(rt) => val args = ScPattern.extractorParameters(subst.subst(rt), pattern, ScPattern.isOneArgCaseClassMethod(fun)) if (args.isEmpty) return None if (argIndex < args.length - 1) return Some(subst.subst(args(argIndex))) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala index dbb7458dd1f..002d2c1d3e3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala @@ -19,6 +19,6 @@ trait ScTuplePattern extends ScPattern { override def `type`(): TypeResult[ScType] = this.flatMap(patternList) { list => val types = list.patterns.map(_.`type`().getOrAny) - Success(TupleType(types)) + Right(TupleType(types)) } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala index 5beb2573450..5af4e5b6d90 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala @@ -271,7 +271,7 @@ private[expr] object ExpectedTypes { fun.returnTypeElement match { case Some(rte: ScTypeElement) => fun.returnType match { - case Success(rt) => Array((rt, Some(rte))) + case Right(rt) => Array((rt, Some(rte))) case _ => Array.empty } case None => Array.empty @@ -407,7 +407,7 @@ private[expr] object ExpectedTypes { } } tp match { - case Success(ScMethodType(_, params, _)) => + case Right(ScMethodType(_, params, _)) => if (params.length == 1 && !params.head.isRepeated && exprs.length > 1) { params.head.paramType.removeAbstracts match { case TupleType(args) => applyForParams(args.zipWithIndex.map { @@ -416,7 +416,7 @@ private[expr] object ExpectedTypes { case _ => } } else applyForParams(params) - case Success(t@ScTypePolymorphicType(ScMethodType(_, params, _), _)) => + case Right(t@ScTypePolymorphicType(ScMethodType(_, params, _), _)) => val subst = t.abstractTypeSubstitutor val newParams = params.map(p => p.copy(paramType = subst.subst(p.paramType))) if (newParams.length == 1 && !newParams.head.isRepeated && exprs.length > 1) { @@ -427,7 +427,7 @@ private[expr] object ExpectedTypes { case _ => } } else applyForParams(newParams) - case Success(ScTypePolymorphicType(anotherType, typeParams)) if !forApply => + case Right(ScTypePolymorphicType(anotherType, typeParams)) if !forApply => val cand = call.getOrElse(expr).applyShapeResolveForExpectedType(anotherType, exprs, call) if (cand.length == 1) { cand(0) match { @@ -437,7 +437,8 @@ private[expr] object ExpectedTypes { if (r.isDynamic) getDynamicReturn(tp) else tp } - var polyType: TypeResult[ScType] = Success(s.subst(fun.polymorphicType()) match { + + var polyType: TypeResult[ScType] = Right(s.subst(fun.polymorphicType()) match { case ScTypePolymorphicType(internal, params) => update(ScTypePolymorphicType(internal, params ++ typeParams)) case tp => update(ScTypePolymorphicType(tp, typeParams)) @@ -447,7 +448,7 @@ private[expr] object ExpectedTypes { case _ => } } - case Success(anotherType) if !forApply => + case Right(anotherType) if !forApply => val cand = call.getOrElse(expr).applyShapeResolveForExpectedType(anotherType, exprs, call) if (cand.length == 1) { cand(0) match { @@ -458,7 +459,7 @@ private[expr] object ExpectedTypes { else tp } - var polyType: TypeResult[ScType] = Success(update(subst.subst(fun.polymorphicType()))) + var polyType: TypeResult[ScType] = Right(update(subst.subst(fun.polymorphicType()))) call.foreach(call => polyType = call.updateAccordingToExpectedType(polyType)) processArgsExpected(res, expr, i, polyType, exprs, forApply = true, isDynamicNamed = isDynamicNamed) case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala index a5b739d7ba2..3a4ea5f8e1c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala @@ -298,7 +298,7 @@ trait MethodInvocation extends ScExpression with ScalaPsiElement { UpdateApplyData(Nothing, Set.empty[ImportUsed], None, this.applyOrUpdateElement) } if (useExpectedType) { - this.updateAccordingToExpectedType(Success(processedType)).foreach(x => processedType = x) + this.updateAccordingToExpectedType(Right(processedType)).foreach(x => processedType = x) } applyOrUpdateElemLocal = applyOrUpdateResult importsUsedLocal = importsUsed @@ -319,7 +319,7 @@ trait MethodInvocation extends ScExpression with ScalaPsiElement { updateCacheFields() - Success(newType) + Right(newType) } @volatile private var problemsVar: Seq[ApplicabilityProblem] = Seq.empty @@ -383,7 +383,7 @@ object MethodInvocation { r.importsUsed, r.implicitConversion, Some(r)) } call.getInvokedExpr.getNonValueType() match { - case Success(ScTypePolymorphicType(_, typeParams)) => + case Right(ScTypePolymorphicType(_, typeParams)) => val fixedType = res.processedType match { case ScTypePolymorphicType(internal, typeParams2) => ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala index 76d2ded4254..d8b0bdf187c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAnnotations.scala @@ -11,7 +11,6 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScSimpleTypeElement import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType -import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander Podkhalyuzin @@ -45,7 +44,7 @@ trait ScAnnotations extends ScalaPsiElement with PsiReferenceList { constr.args match { case Some(args) if args.exprs.length == 1 => args.exprs(0).`type`() match { - case Success(ParameterizedType(tp, arg)) if arg.length == 1 => + case Right(ParameterizedType(tp, arg)) if arg.length == 1 => tp.extractClass match { case Some(clazz) if clazz.qualifiedName == "java.lang.Class" => arg.head.extractClass match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala index fc4f668b304..441676edfcc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala @@ -60,7 +60,7 @@ trait ScBlock extends ScExpression with ScDeclarationSequenceHolder with ScImpor val fun = funs.find(_.isInstanceOf[ScTrait]).getOrElse(return Failure("Cannot find PartialFunction class")) val throwable = manager.getCachedClass(resolveScope, "java.lang.Throwable").orNull if (throwable == null) return Failure("Cannot find Throwable class") - return Success(ScParameterizedType(ScDesignatorType(fun), Seq(ScDesignatorType(throwable), clausesLubType))) + return Right(ScParameterizedType(ScDesignatorType(fun), Seq(ScDesignatorType(throwable), clausesLubType))) case _ => val et = this.expectedType(fromUnderscore = false) .getOrElse(return Failure("Cannot infer type without expected type")) @@ -82,9 +82,9 @@ trait ScBlock extends ScExpression with ScDeclarationSequenceHolder with ScImpor return et match { case FunctionType(_, params) => - Success(FunctionType(clausesLubType, params.map(removeVarianceAbstracts))) + Right(FunctionType(clausesLubType, params.map(removeVarianceAbstracts))) case PartialFunctionType(_, param) => - Success(PartialFunctionType(clausesLubType, removeVarianceAbstracts(param))) + Right(PartialFunctionType(clausesLubType, removeVarianceAbstracts(param))) case _ => Failure("Cannot infer type without expected type of scala.FunctionN or scala.PartialFunction") } @@ -173,7 +173,7 @@ trait ScBlock extends ScExpression with ScDeclarationSequenceHolder with ScImpor val t = existize(e.`type`().getOrAny, Set.empty) if (m.isEmpty) t else new ScExistentialType(t, m.values.toList).simplify() } - Success(inner) + Right(inner) } private def leastClassType(t : ScTemplateDefinition): ScType = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala index 6fa70e4b006..f705ad8fd8b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala @@ -256,7 +256,7 @@ object ScExpression { ScMethodType(expr.getTypeAfterImplicitConversion(ignoreBaseTypes = ignoreBaseType, fromUnderscore = true).tr.getOrAny, params, isImplicit = false) - Success(methType) + Right(methType) } } } @@ -282,7 +282,7 @@ object ScExpression { expectedType(fromUnderscore = fromUnderscore) } - if (isShape) ExpressionTypeResult(Success(shape(expr).getOrElse(Nothing))) + if (isShape) ExpressionTypeResult(Right(shape(expr).getOrElse(Nothing))) else { val tr = getTypeWithoutImplicits(ignoreBaseTypes, fromUnderscore) (expected, tr.toOption) match { @@ -292,7 +292,7 @@ object ScExpression { val samType = tryConvertToSAM(fromUnderscore, expType, tp) if (samType.nonEmpty) samType.get - else if (isJavaReflectPolymorphic) ExpressionTypeResult(Success(expType)) + else if (isJavaReflectPolymorphic) ExpressionTypeResult(Right(expType)) else { val functionType = FunctionType(expType, Seq(tp)) val implicitCollector = new ImplicitCollector(expr, functionType, functionType, None, isImplicitConversion = true) @@ -316,7 +316,7 @@ object ScExpression { } fromImplicit match { case Some((mr, result)) => - ExpressionTypeResult(Success(mr), result.importsUsed, Some(result)) + ExpressionTypeResult(Right(mr), result.importsUsed, Some(result)) case _ => ExpressionTypeResult(tr) } @@ -333,7 +333,7 @@ object ScExpression { val fromNullLiteral = expr match { case lit: ScLiteral => val typeForNull = lit.getTypeForNullWithoutImplicits - if (typeForNull.nonEmpty) Option(Success(typeForNull.get)) + if (typeForNull.nonEmpty) Option(Right(typeForNull.get)) else None case _ => None } @@ -342,7 +342,7 @@ object ScExpression { else { val inner = expr.getNonValueType(ignoreBaseTypes, fromUnderscore) inner match { - case Success(rtp) => + case Right(rtp) => var res = rtp val expType = expectedType(fromUnderscore) @@ -350,10 +350,10 @@ object ScExpression { def updateExpected(oldRes: ScType): ScType = { try { val updatedWithExpected = - InferUtil.updateAccordingToExpectedType(Success(rtp), fromImplicitParameters = true, + InferUtil.updateAccordingToExpectedType(Right(rtp), fromImplicitParameters = true, filterTypeParams = false, expectedType = expType, expr = expr, canThrowSCE = true) updatedWithExpected match { - case Success(newRes) => + case Right(newRes) => updateWithImplicitParameters(newRes, checkExpectedType = true, fromUnderscore) case _ => updateWithImplicitParameters(oldRes, checkExpectedType = true, fromUnderscore) @@ -397,21 +397,21 @@ object ScExpression { val valType = res.inferValueType.unpackedType - if (ignoreBaseTypes) Success(valType) + if (ignoreBaseTypes) Right(valType) else { expType match { case None => - Success(valType) + Right(valType) case Some(expected) if expected.removeAbstracts equiv Unit => //value discarding - Success(Unit) + Right(Unit) case Some(expected) => val narrowing = isNarrowing(expected) if (narrowing.isDefined) narrowing.get else { val widening = isWidening(valType, expected) if (widening.isDefined) widening.get - else Success(valType) + else Right(valType) } } } @@ -466,7 +466,7 @@ object ScExpression { def isChar(v: Long) = v >= scala.Char.MinValue && v <= scala.Char.MaxValue def isShort(v: Long) = v >= scala.Short.MinValue && v <= scala.Short.MaxValue - def success(t: ScType) = Some(Success(t)) + def success(t: ScType) = Some(Right(t)) val intLiteralValue: Int = expr match { case ScIntLiteral(value) => value @@ -497,12 +497,12 @@ object ScExpression { import stdTypes._ (l, r) match { - case (Byte, Short | Int | Long | Float | Double) => Some(Success(expected)) - case (Short, Int | Long | Float | Double) => Some(Success(expected)) - case (Char, Byte | Short | Int | Long | Float | Double) => Some(Success(expected)) - case (Int, Long | Float | Double) => Some(Success(expected)) - case (Long, Float | Double) => Some(Success(expected)) - case (Float, Double) => Some(Success(expected)) + case (Byte, Short | Int | Long | Float | Double) => Some(Right(expected)) + case (Short, Int | Long | Float | Double) => Some(Right(expected)) + case (Char, Byte | Short | Int | Long | Float | Double) => Some(Right(expected)) + case (Int, Long | Float | Double) => Some(Right(expected)) + case (Long, Float | Double) => Some(Right(expected)) + case (Float, Double) => Some(Right(expected)) case _ => None } } @@ -536,7 +536,7 @@ object ScExpression { private def tryConvertToSAM(fromUnderscore: Boolean, expected: ScType, tp: ScType) = { def checkForSAM(etaExpansionHappened: Boolean = false): Option[ExpressionTypeResult] = { - def expectedResult = Some(ExpressionTypeResult(Success(expected))) + def expectedResult = Some(ExpressionTypeResult(Right(expected))) tp match { case FunctionType(_, params) if ScalaPsiUtil.isSAMEnabled(expr) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala index 96a83b96471..010fc048584 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala @@ -173,12 +173,12 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne def definedReturnType: TypeResult[ScType] = { returnTypeElement match { case Some(ret) => ret.`type`() - case _ if !hasAssign => Success(Unit) + case _ if !hasAssign => Right(Unit) case _ => superMethod match { case Some(f: ScFunction) => f.definedReturnType case Some(m: PsiMethod) => - Success(m.getReturnType.toScType()) + Right(m.getReturnType.toScType()) case _ => Failure("No defined return type") } } @@ -482,7 +482,7 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne case Some(annotation) => annotation.constructor.args.map(_.exprs).getOrElse(Seq.empty).flatMap { _.`type`() match { - case Success(ParameterizedType(des, Seq(arg))) => des.extractClass match { + case Right(ParameterizedType(des, Seq(arg))) => des.extractClass match { case Some(clazz) if clazz.qualifiedName == "java.lang.Class" => arg.toPsiType match { case c: PsiClassType => Seq(c) @@ -500,15 +500,15 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne def `type`(): TypeResult[ScType] = { this.returnType match { - case Success(tp) => - var res: TypeResult[ScType] = Success(tp) + case Right(tp) => + var res: TypeResult[ScType] = Right(tp) var i = paramClauses.clauses.length - 1 while (i >= 0) { res match { - case Success(t) => + case Right(t) => val parameters = paramClauses.clauses.apply(i).parameters val paramTypes = parameters.map(_.`type`().getOrNothing) - res = Success(FunctionType(t, paramTypes)) + res = Right(FunctionType(t, paramTypes)) case _ => } i = i - 1 diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala index 2ed2115d0f2..67d3ec1a89b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala @@ -65,11 +65,11 @@ trait ScParameter extends ScTypedDefinition with ScModifierListOwner with def getRealParameterType: TypeResult[ScType] = `type`() match { case result if !isRepeatedParameter => result - case f@Success(tp) => + case f@Right(tp) => elementScope.getCachedClass("scala.collection.Seq") .map(ScalaType.designator) .map(ScParameterizedType(_, Seq(tp))) - .map((result: ValueType) => Success(result)) + .map((result: ValueType) => Right(result)) .getOrElse(f) case f => f } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala index 0c19e742745..ede54f75f1a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala @@ -119,7 +119,7 @@ class ScConstructorImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc tp.typeParameters.map(TypeParameter(_)) case ptp: PsiTypeParameterListOwner if ptp.getTypeParameters.nonEmpty => ptp.getTypeParameters.toSeq.map(TypeParameter(_)) - case _ => return Success(res) + case _ => return Right(res) } s.getParent match { case p: ScParameterizedTypeElement => @@ -128,7 +128,7 @@ class ScConstructorImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc case (arg, typeParam) => (typeParam.nameAndId, arg.`type`().getOrAny) }.toMap) - Success(appSubst.subst(res)) + Right(appSubst.subst(res)) case _ => var nonValueType = ScTypePolymorphicType(res, typeParameters) expectedType match { @@ -153,10 +153,10 @@ class ScConstructorImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc ) val extRes = Compatibility.checkConformanceExt(false, undefParams, paramsByClauses.map(_._1), false, false) val result = extRes.undefSubst.getSubstitutor.map(_.subst(nonValueType)).getOrElse(nonValueType) - return Success(result) + return Right(result) case _ => } - Success(nonValueType) + Right(nonValueType) } } @@ -175,7 +175,7 @@ class ScConstructorImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc Seq(Parameter(p.getName, None, paramType, paramType, p.getDefaultValue != null, isRepeated = false, isByName = false)) case _ => Seq.empty } - buffer += Success(ScMethodType(ScDesignatorType(clazz), params, isImplicit = false)) + buffer += Right(ScMethodType(ScDesignatorType(clazz), params, isImplicit = false)) case _ => } buffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala index 86742af4153..4a769d9c429 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala @@ -61,7 +61,7 @@ class ScLiteralImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScLite case ScalaTokenTypes.kTRUE | ScalaTokenTypes.kFALSE => api.Boolean case _ => return Failure("Wrong Psi to get Literal type") } - Success(inner) + Right(inner) } @CachedInsidePsiElement(this, PsiModificationTracker.MODIFICATION_COUNT) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala index 4a343b6bd90..3a51454532a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala @@ -32,7 +32,6 @@ import org.jetbrains.plugins.scala.lang.psi.impl.expr.ScReferenceElementImpl import org.jetbrains.plugins.scala.lang.psi.types.ScSubstitutor import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.processor.{BaseProcessor, CompletionProcessor, ExtractorResolveProcessor} import org.jetbrains.plugins.scala.lang.resolve.{StableCodeReferenceElementResolver, _} import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocResolvableCodeReference @@ -342,7 +341,7 @@ class ScStableCodeReferenceElementImpl(node: ASTNode) extends ScReferenceElement td match { case obj: ScObject => val fromType = r.fromType match { - case Some(fType) => Success(ScProjectionType(fType, obj, superReference = false)) + case Some(fType) => Right(ScProjectionType(fType, obj, superReference = false)) case _ => td.`type`().map(substitutor.subst) } val state = ResolveState.initial.put(ScSubstitutor.key, substitutor) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala index f6e838165f5..55bb67c5930 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala @@ -75,6 +75,6 @@ trait ScTypeBoundsOwnerImpl extends ScTypeBoundsOwner { private def typeOf(typeElement: Option[ScTypeElement], isLower: Boolean): TypeResult[ScType] = typeElement match { case Some(elem) => elem.`type`().map(extractBound(_, isLower)) - case None => Success(if (isLower) api.Nothing else api.Any) + case None => Right(if (isLower) api.Nothing else api.Any) } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala index 2d68ade0c5a..e41adbd5215 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala @@ -29,7 +29,7 @@ class ScCompositePatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) w override def `type`(): TypeResult[ScType] = { this.expectedType match { - case Some(expected) => Success(expected) + case Some(expected) => Right(expected) case _ => super.`type`() //Failure } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala index 94265bcf267..0cfe56c631a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala @@ -95,9 +95,9 @@ class ScConstructorPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) case _ => emptySubst } } - Success(ScParameterizedType(refType, td.getTypeParameters.map(tp => newSubst.subst(TypeParameterType(tp, None))))) - case td: ScClass => Success(ScalaType.designator(td)) - case obj: ScObject => Success(ScalaType.designator(obj)) + Right(ScParameterizedType(refType, td.getTypeParameters.map(tp => newSubst.subst(TypeParameterType(tp, None))))) + case td: ScClass => Right(ScalaType.designator(td)) + case obj: ScObject => Right(ScalaType.designator(obj)) case fun: ScFunction /*It's unapply method*/ if (fun.name == "unapply" || fun.name == "unapplySeq") && fun.parameters.count(!_.isImplicitParameter) == 1 => val substitutor = r.substitutor @@ -125,7 +125,7 @@ class ScConstructorPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) } } fun.paramClauses.clauses.head.parameters.head.`type`().map(subst.subst) - case _ => Success(Nothing) + case _ => Right(Nothing) } case _ => Failure("Cannot resolve symbol") } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala index f0f80c42003..cbbe4f86892 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala @@ -29,7 +29,7 @@ class ScInfixPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) with override def `type`(): TypeResult[ScType] = { this.expectedType match { - case Some(x) => Success(x) + case Some(x) => Right(x) case _ => Failure("cannot define expected type") } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala index f37011ab291..d075c0872e1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala @@ -36,7 +36,7 @@ class ScNamingPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with override def `type`(): TypeResult[ScType] = { if (getLastChild.isInstanceOf[ScSeqWildcard]) { return this.expectedType match { - case Some(x) => Success(x) + case Some(x) => Right(x) case _ => Failure("No expected type for wildcard naming") } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala index 8a7cad04d4c..185f679559f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala @@ -50,7 +50,7 @@ class ScReferencePatternImpl private(stub: ScReferencePatternStub, node: ASTNode override def `type`(): TypeResult[ScType] = { this.expectedType match { - case Some(x) => Success(x) + case Some(x) => Right(x) case _ => Failure("Cannot define expected type") } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala index cbef761a893..ad49c6edb9c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala @@ -38,7 +38,7 @@ class ScTypedPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S override def isIrrefutableFor(t: Option[ScType]): Boolean = { t match { case Some(t) => `type`() match { - case Success(tp) if t conforms tp => true + case Right(tp) if t conforms tp => true case _ => false } case _ => false diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala index 957f4501a30..96d95f70671 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala @@ -30,7 +30,7 @@ class ScWildcardPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) wi override def toString: String = "WildcardPattern" override def `type`(): TypeResult[ScType] = this.expectedType match { - case Some(x) => Success(x) + case Some(x) => Right(x) case _ => Failure("cannot determine expected type") } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala index 00496b858cb..8e2b2f46b2a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala @@ -23,7 +23,7 @@ class ScCompoundTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) ScCompoundType.fromPsi(componentsTypes, r.holders, r.types) }.getOrElse(new ScCompoundType(componentsTypes)) - Success(compoundType) + Right(compoundType) } override def accept(visitor: ScalaElementVisitor) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala index 2cf92671c9b..8db8da4a74a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala @@ -55,7 +55,7 @@ class ScExistentialTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(no } q.map(ScExistentialType(_, wildcards)) - .flatMap((result: ScExistentialType) => Success(result)) + .flatMap((result: ScExistentialType) => Right(result)) } import com.intellij.psi.scope.PsiScopeProcessor diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala index 5903130a035..f58a83863ca 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala @@ -188,7 +188,7 @@ class ScParameterizedTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl( case Seq() => tr case args => val result = ScParameterizedType(res, args.map(_.`type`().getOrAny)) - Success(result) + Right(result) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala index 566a5ac78b0..d49ab28697e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala @@ -20,7 +20,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScParenthesisedTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScParenthesisedTypeElement { protected def innerType: TypeResult[ScType] = typeElement match { case Some(el) => el.`type`() - case None => Success(Unit) + case None => Right(Unit) } override def accept(visitor: ScalaElementVisitor) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala index e7741cbea79..1076313459f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala @@ -304,18 +304,18 @@ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w ref.resolveNoConstructor match { case Array(ScalaResolveResult(psiTypeParameter: PsiTypeParameter, _)) => - Success(TypeParameterType(psiTypeParameter, None)) + Right(TypeParameterType(psiTypeParameter, None)) case Array(ScalaResolveResult(tvar: ScTypeVariableTypeElement, _)) => - Success(tvar.`type`().getOrAny) + Right(tvar.`type`().getOrAny) case Array(ScalaResolveResult(synth: ScSyntheticClass, _)) => - Success(synth.stdType) + Right(synth.stdType) case Array(ScalaResolveResult(to: ScTypeParametersOwner, subst: ScSubstitutor)) if constrRef && to.isInstanceOf[PsiNamedElement] && (to.typeParameters.isEmpty || getContext.isInstanceOf[ScParameterizedTypeElement]) => val (tp, ss) = getContext match { case p: ScParameterizedTypeElement if !to.isInstanceOf[ScTypeAliasDeclaration] => val (parameterized, ss) = updateForParameterized(subst, to.asInstanceOf[PsiNamedElement], p) - (Success(parameterized), ss) + (Right(parameterized), ss) case _ => (calculateReferenceType(ref), ScSubstitutor.empty) } @@ -326,7 +326,7 @@ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w val (result, ss) = getContext match { case p: ScParameterizedTypeElement if !to.isInstanceOf[ScTypeAliasDeclaration] => val (parameterized, ss) = updateForParameterized(subst, to.asInstanceOf[PsiNamedElement], p) - (Success(parameterized), ss) + (Right(parameterized), ss) case _ => (calculateReferenceType(ref), ScSubstitutor.empty) } @@ -334,9 +334,9 @@ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w case _ => //resolve constructor with local type inference ref.bind() match { case Some(r@ScalaResolveResult(method: PsiMethod, subst: ScSubstitutor)) if !noConstructor => - Success(typeForConstructor(ref, method, subst, r.getActualElement)) + Right(typeForConstructor(ref, method, subst, r.getActualElement)) case Some(ScalaResolveResult(ta: ScTypeAlias, _: ScSubstitutor)) if ta.isExistentialTypeAlias => - Success(ScExistentialArgument(ta.name, ta.typeParameters.map(TypeParameterType(_, None)).toList, + Right(ScExistentialArgument(ta.name, ta.typeParameters.map(TypeParameterType(_, None)).toList, ta.lowerBound.getOrNothing, ta.upperBound.getOrAny)) case _ => calculateReferenceType(ref, shapesOnly = false) } @@ -408,11 +408,11 @@ object ScSimpleTypeElementImpl { } case _ => calculateReferenceType(qualifier, shapesOnly) match { - case Success(tp) => makeProjection(tp) + case Right(tp) => makeProjection(tp) case failure@Failure(_) => return failure } } - Success(result) + Right(result) case _ => ref.pathQualifier match { case Some(thisRef: ScThisReference) => @@ -428,7 +428,7 @@ object ScSimpleTypeElementImpl { case _ => ScalaType.designator(resolvedElement) } } - Success(result) + Right(result) } } } @@ -441,7 +441,7 @@ object ScSimpleTypeElementImpl { val element = Some(path) maybeTemplate match { - case Some(template) => Success(function(template)) + case Some(template) => Right(function(template)) case _ => Failure(message) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala index f4e0d8cfe33..127b1f7e6ca 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala @@ -17,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScType */ class ScTypeVariableTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTypeVariableTypeElement { override protected def innerType: TypeResult[ScType] = - Success(ScExistentialArgument(name, List.empty, Nothing, Any)) + Right(ScExistentialArgument(name, List.empty, Nothing, Any)) override def nameId: PsiElement = findChildByType[PsiElement](ScalaTokenTypes.tIDENTIFIER) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala index cf10b3f0a1c..7597ac843e1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala @@ -34,9 +34,9 @@ class ScAssignStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScA case Some(_) => mirrorMethodCall match { case Some(call) => call.`type`() - case None => Success(Unit) + case None => Right(Unit) } - case _ => Success(Unit) + case _ => Right(Unit) } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala index e659732a56e..a2564b20b3f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala @@ -53,7 +53,7 @@ class ScFunctionExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S val paramTypes = parameters.map(_.`type`().getOrNothing) val maybeResultType = result.map(_.`type`().getOrAny) val functionType = FunctionType(maybeResultType.getOrElse(api.Unit), paramTypes) - Success(functionType) + Right(functionType) } override def controlFlowScope: Option[ScalaPsiElement] = result diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala index eb28dfaadd0..ff1c293bfba 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala @@ -76,8 +76,8 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc refType match { case ScTypePolymorphicType(int, tps) => val subst = ScalaPsiUtil.genericCallSubstitutor(tps.map(_.nameAndId), this) - Success(subst.subst(int)) - case _ => Success(refType) + Right(subst.subst(int)) + case _ => Right(refType) } } @@ -88,8 +88,8 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc refType match { case ScTypePolymorphicType(int, tps) => val subst = ScalaPsiUtil.genericCallSubstitutor(tps.map(_.nameAndId), this) - Success(subst.subst(int)) - case _ => Success(refType) + Right(subst.subst(int)) + case _ => Right(refType) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala index b31b013124c..03d070dd403 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala @@ -30,6 +30,6 @@ class ScMatchStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScMa protected override def innerType: TypeResult[ScType] = { val branchesTypes = getBranches.map(_.`type`().getOrNothing) val branchesLub = branchesTypes.foldLeft(Nothing: ScType)(_.lub(_)) - Success(branchesLub) + Right(branchesLub) } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala index 94737a8ba7c..1a4abead2f3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala @@ -99,15 +99,15 @@ class ScNewTemplateDefinitionImpl private (stub: ScTemplateDefinitionStub, node: if (superTypes.length > 1 || holders.nonEmpty || aliases.nonEmpty) { - Success(ScCompoundType.fromPsi(superTypes, holders.toList, aliases.toList)) + Right(ScCompoundType.fromPsi(superTypes, holders.toList, aliases.toList)) } else { extendsBlock.templateParents match { case Some(tp) if tp.allTypeElements.length == 1 => tp.allTypeElements.head.getNonValueType() case _ => superTypes.headOption match { - case Some(t) => Success(t) - case None => Success(AnyRef) //this is new {} case + case Some(t) => Right(t) + case None => Right(AnyRef) //this is new {} case } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala index b6b9cbdf10a..c5efad2d71f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala @@ -244,7 +244,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case ScAbstractType(_, lower, _) => lower case _ => tp }).isAliasType match { - case Some(AliasType(_, Success(lower: DesignatorOwner), _)) if lower.isStable => + case Some(AliasType(_, Right(lower: DesignatorOwner), _)) if lower.isStable => return true case _ => tp match { @@ -302,7 +302,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case ScalaResolveResult(self: ScSelfTypeElement, _) => val clazz = PsiTreeUtil.getContextOfType(self, true, classOf[ScTemplateDefinition]) ScThisReferenceImpl.getThisTypeForTypeDefinition(clazz, this) match { - case Success(value) => value + case Right(value) => value case failure => return failure } case r@ScalaResolveResult(refPatt: ScBindingPattern, s) => @@ -324,7 +324,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } else { val result = refPatt.`type`() result match { - case Success(tp) => s.subst(tp) + case Right(tp) => s.subst(tp) case _ => return result } } @@ -375,7 +375,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case _ => val result = param.getRealParameterType s.subst(result match { - case Success(tp) => tp + case Right(tp) => tp case _ => return result }) } @@ -391,7 +391,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no case ScalaResolveResult(param: ScParameter, s) if param.isRepeatedParameter => val result = param.`type`() val computeType = s.subst(result match { - case Success(tp) => tp + case Right(tp) => tp case _ => return result }) elementScope.getCachedClass("scala.collection.Seq") @@ -436,14 +436,14 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } else { val result = f.`type`() result match { - case Success(tp) => s.subst(tp) + case Right(tp) => s.subst(tp) case _ => return result } } case ScalaResolveResult(typed: ScTypedDefinition, s) => val result = typed.`type`() result match { - case Success(tp) => s.subst(tp) + case Right(tp) => s.subst(tp) case _ => return result } case ScalaResolveResult(pack: PsiPackage, _) => ScalaType.designator(pack) @@ -519,19 +519,19 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no getContext match { case sugar: ScSugarCallExpr if sugar.operation == this => sugar.getBaseExpr.getNonValueType() match { - case Success(ScTypePolymorphicType(_, typeParams)) => + case Right(ScTypePolymorphicType(_, typeParams)) => inner match { case ScTypePolymorphicType(internal, typeParams2) => - return Success(ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2 ++ unresolvedTypeParameters))) + return Right(ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2 ++ unresolvedTypeParameters))) case _ => - return Success(ScTypePolymorphicType(inner, typeParams ++ unresolvedTypeParameters)) + return Right(ScTypePolymorphicType(inner, typeParams ++ unresolvedTypeParameters)) } case _ if unresolvedTypeParameters.nonEmpty => inner match { case ScTypePolymorphicType(internal, typeParams) => - return Success(ScTypePolymorphicType(internal, unresolvedTypeParameters ++ typeParams)) + return Right(ScTypePolymorphicType(internal, unresolvedTypeParameters ++ typeParams)) case _ => - return Success(ScTypePolymorphicType(inner, unresolvedTypeParameters)) + return Right(ScTypePolymorphicType(inner, unresolvedTypeParameters)) } case _ => } @@ -539,24 +539,24 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } case Some(qualifier) => qualifier.getNonValueType() match { - case Success(ScTypePolymorphicType(_, typeParams)) => + case Right(ScTypePolymorphicType(_, typeParams)) => inner match { case ScTypePolymorphicType(internal, typeParams2) => - return Success(ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2 ++ unresolvedTypeParameters))) + return Right(ScalaPsiUtil.removeBadBounds(ScTypePolymorphicType(internal, typeParams ++ typeParams2 ++ unresolvedTypeParameters))) case _ => - return Success(ScTypePolymorphicType(inner, typeParams ++ unresolvedTypeParameters)) + return Right(ScTypePolymorphicType(inner, typeParams ++ unresolvedTypeParameters)) } case _ if unresolvedTypeParameters.nonEmpty => inner match { case ScTypePolymorphicType(internal, typeParams) => - return Success(ScTypePolymorphicType(internal, unresolvedTypeParameters ++ typeParams)) + return Right(ScTypePolymorphicType(internal, unresolvedTypeParameters ++ typeParams)) case _ => - return Success(ScTypePolymorphicType(inner, unresolvedTypeParameters)) + return Right(ScTypePolymorphicType(inner, unresolvedTypeParameters)) } case _ => } } - Success(inner) + Right(inner) } def getPrevTypeInfoParams: Seq[TypeParameter] = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala index 5fa957f2d80..b6063bb268d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala @@ -29,7 +29,7 @@ class ScReturnStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScR override def toString: String = "ReturnStatement" - protected override def innerType: TypeResult[ScType] = Success(Nothing) + protected override def innerType: TypeResult[ScType] = Right(Nothing) //Failure("Cannot infer type of `return' expression", Some(this)) def returnKeyword: PsiElement = findChildByType[PsiElement](ScalaTokenTypes.kRETURN) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala index c92328bf9ae..39146a46da3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala @@ -73,8 +73,8 @@ class ScSelfInvocationImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with clazz match { case tp: ScTypeParametersOwner if tp.typeParameters.nonEmpty => val params: Seq[TypeParameter] = tp.typeParameters.map(TypeParameter(_)) - Success(ScTypePolymorphicType(res, params)) - case _ => Success(res) + Right(ScTypePolymorphicType(res, params)) + case _ => Right(res) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala index 5144fc4f3c9..56ac28ca2d4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala @@ -73,11 +73,11 @@ object ScThisReferenceImpl { td.getTypeWithProjections(thisProjections = true).map { case scType => td.selfType.map(scType.glb(_)).getOrElse(scType) } match { - case Success(scType) => scType + case Right(scType) => scType case _ => return Failure("No clazz type found") } } } - Success(result) + Right(result) } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala index f71cd3f70b0..45c9345a9fa 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala @@ -26,7 +26,7 @@ class ScThrowStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTh override def toString: String = "ThrowStatement" - protected override def innerType: TypeResult[ScType] = Success(Nothing) + protected override def innerType: TypeResult[ScType] = Right(Nothing) def body: Option[ScExpression] = findChild(classOf[ScExpression]) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala index ec8dcc1adb4..e280b5274a9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala @@ -49,7 +49,7 @@ class ScTryStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryS function.returnType .map(substitutor.subst) .map(tryBlockType.lub(_)) - case _ => Success(tryBlockType) + case _ => Right(tryBlockType) } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala index 0e20c915ee7..eee7fdda40e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala @@ -23,7 +23,7 @@ class ScTupleImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTuple case Seq() => Unit case components => TupleType(components) } - Success(result) + Right(result) } override def accept(visitor: ScalaElementVisitor) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala index a70fb9357c1..09417d23a33 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala @@ -110,7 +110,7 @@ class ScUnderscoreSectionImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w } result match { case None => Failure("No type inferred") - case Some(t) => Success(t) + case Some(t) => Right(t) } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala index de7f392d87e..c8cddf5bfc6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala @@ -17,5 +17,5 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScUnitExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScUnitExpr { override def toString: String = "UnitExpression" - protected override def innerType: TypeResult[ScType] = Success(Unit) + protected override def innerType: TypeResult[ScType] = Right(Unit) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala index 782398c9546..453b416f84c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala @@ -11,7 +11,6 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api -import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alexander.Podkhalyuzin @@ -50,5 +49,5 @@ class ScWhileStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScWh } - protected override def innerType = Success(api.Unit) + protected override def innerType = Right(api.Unit) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala index b600d62e019..736f3843423 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala @@ -26,7 +26,8 @@ class ScXmlExprImpl(node: ASTNode) extends ScalaPsiElementImpl (node) with ScXml if (typez.length != 0) ScalaType.designator(typez(0)) else Nothing } - Success(getElements.length match { + + Right(getElements.length match { case 0 => Any case 1 => getElements.head match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala index 2fad67353cf..e7474452f6a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala @@ -44,6 +44,6 @@ class ScXmlPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) with Sc override def `type`(): TypeResult[ScType] = { val clazz = ScalaPsiManager.instance(getProject).getCachedClass(getResolveScope, "scala.xml.Node").orNull if (clazz == null) return Failure("not found scala.xml.Node") - Success(ScDesignatorType(clazz)) + Right(ScDesignatorType(clazz)) } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala index fb81d848889..a36efe52e07 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala @@ -37,7 +37,7 @@ class ScFunctionDeclarationImpl private (stub: ScFunctionStub, node: ASTNode) override protected def returnTypeInner: TypeResult[ScType] = returnTypeElement match { case Some(t) => t.`type`() - case None => Success(Unit) + case None => Right(Unit) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala index 1c009c79906..2f428682c6b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala @@ -71,10 +71,10 @@ class ScFunctionDefinitionImpl protected (stub: ScFunctionStub, node: ASTNode) override def toString: String = "ScFunctionDefinition: " + ifReadAllowed(name)("") override protected def returnTypeInner: TypeResult[ScType] = returnTypeElement match { - case None if !hasAssign => Success(api.Unit) + case None if !hasAssign => Right(api.Unit) case None => body match { case Some(b) => b.`type`() - case _ => Success(api.Unit) + case _ => Right(api.Unit) } case Some(rte: ScTypeElement) => rte.`type`() } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala index c2e4b3ad315..897af91eb8b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala @@ -66,7 +66,7 @@ class ScMacroDefinitionImpl private (stub: ScFunctionStub, node: ASTNode) override protected def returnTypeInner: TypeResult[ScType] = returnTypeElement match { case Some(rte: ScTypeElement) => rte.`type`() - case None => Success(Any) // TODO look up type from the macro impl. + case None => Right(Any) // TODO look up type from the macro impl. } def body: Option[ScExpression] = byPsiOrStub(findChild(classOf[ScExpression]))(_.bodyExpression) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala index 15c8dac89b7..d57cebabc3a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala @@ -55,12 +55,12 @@ class ScTypeAliasDeclarationImpl private (stub: ScTypeAliasStub, node: ASTNode) def lowerBound: TypeResult[ScType] = lowerTypeElement match { case Some(te) => te.`type`() - case None => Success(Nothing) + case None => Right(Nothing) } def upperBound: TypeResult[ScType] = upperTypeElement match { case Some(te) => te.`type`() - case None => Success(Any) + case None => Right(Any) } override def upperTypeElement: Option[ScTypeElement] = diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala index ab923007c95..a9017bfdac3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala @@ -73,7 +73,7 @@ class ScParameterImpl protected (stub: ScParameterStub, nodeType: ScParamElement def typeElement: Option[ScTypeElement] = byPsiOrStub(paramType.flatMap(_.typeElement.toOption))(_.typeElement) def `type`(): TypeResult[ScType] = { - def success(t: ScType): TypeResult[ScType] = Success(t) + def success(t: ScType): TypeResult[ScType] = Right(t) //todo: this is very error prone way to calc type, when usually we need real parameter type getStub match { case null => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala index 0317697e546..04e2257f632 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScTypeParamImpl.scala @@ -24,7 +24,6 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.PsiClassFake import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.JavaIdentifier import org.jetbrains.plugins.scala.lang.psi.stubs.ScTypeParamStub import org.jetbrains.plugins.scala.lang.psi.types.api.{ParameterizedType, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} @@ -61,8 +60,8 @@ class ScTypeParamImpl private (stub: ScTypeParamStub, node: ASTNode) in } case t => t.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(lower), _)) if isLower => extractBound(lower, isLower) - case Some(AliasType(_: ScTypeAliasDefinition, _, Success(upper))) if !isLower => extractBound(upper, isLower) + case Some(AliasType(_: ScTypeAliasDefinition, Right(lower), _)) if isLower => extractBound(lower, isLower) + case Some(AliasType(_: ScTypeAliasDefinition, _, Right(upper))) if !isLower => extractBound(upper, isLower) case None => t } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala index e7552b82f82..c3530aa1ac1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/synthetic/ScSyntheticClass.scala @@ -25,7 +25,6 @@ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.{BaseProcessor, ImplicitProcessor, ResolveProcessor, ResolverEnv} import org.jetbrains.plugins.scala.project.ProjectContext @@ -66,9 +65,9 @@ class ScSyntheticTypeParameter(override val name: String, val owner: ScFun) def isCovariant = false def isContravariant = false - def lowerBound = Success(Nothing) + def lowerBound = Right(Nothing) - def upperBound = Success(Any) + def upperBound = Right(Any) def getIndex = -1 def getOwner = null diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala index c1437d0aa09..0014ceb7e69 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/MixinNodes.scala @@ -20,7 +20,6 @@ import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticC import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.api.{ParameterizedType, TypeParameterType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.macroAnnotations.CachedWithRecursionGuard @@ -535,7 +534,7 @@ object MixinNodes { @tailrec def updateTp(tp: ScType, depth: Int = 0): ScType = { tp.isAliasType match { - case Some(AliasType(_, _, Success(upper))) => + case Some(AliasType(_, _, Right(upper))) => if (tp != upper && depth < 100) updateTp(upper, depth + 1) else tp case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala index d236c551612..246c5968b1e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScClassImpl.scala @@ -23,7 +23,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScTypeParametersOwner, import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.TypeDefinitionMembers.SignatureNodes import org.jetbrains.plugins.scala.lang.psi.stubs.ScTemplateDefinitionStub import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameterType -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{PhysicalSignature, ScSubstitutor, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.processor.BaseProcessor import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} @@ -269,7 +268,7 @@ class ScClassImpl protected (stub: ScTemplateDefinitionStub, node: ASTNode) val fields = constructor match { case Some(constr) => constr.parameters.map { param => param.`type`() match { - case Success(tp: TypeParameterType) if tp.psiTypeParameter.findAnnotation("scala.specialized") != null => + case Right(tp: TypeParameterType) if tp.psiTypeParameter.findAnnotation("scala.specialized") != null => val factory: PsiElementFactory = PsiElementFactory.SERVICE.getInstance(getProject) val psiTypeText: String = tp.toPsiType.getCanonicalText val text = s"public final $psiTypeText ${param.name};" diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala index 49b212fe13d..c0d9d385c91 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala @@ -90,16 +90,16 @@ abstract class ScTypeDefinitionImpl protected (stub: ScTemplateDefinitionStub, val parentClass: ScTemplateDefinition = containingClass if (typeParameters.isEmpty) { if (parentClass != null) { - Success(ScProjectionType(ScThisType(parentClass), this, superReference = false)) + Right(ScProjectionType(ScThisType(parentClass), this, superReference = false)) } else { - Success(ScalaType.designator(this)) + Right(ScalaType.designator(this)) } } else { if (parentClass != null) { - Success(ScParameterizedType(ScProjectionType(ScThisType(parentClass), this, superReference = false), + Right(ScParameterizedType(ScProjectionType(ScThisType(parentClass), this, superReference = false), typeParameters.map(TypeParameterType(_)))) } else { - Success(ScParameterizedType(ScalaType.designator(this), + Right(ScParameterizedType(ScalaType.designator(this), typeParameters.map(TypeParameterType(_)))) } } @@ -116,9 +116,9 @@ abstract class ScTypeDefinitionImpl protected (stub: ScTemplateDefinitionStub, else ScThisType(parentClazz) val innerProjection = ScProjectionType(tpe, this, superReference = false) - Success(if (typeParameters.isEmpty) innerProjection + Right(if (typeParameters.isEmpty) innerProjection else ScParameterizedType(innerProjection, args)) - } else Success(innerType) + } else Right(innerType) } override def getModifierList: ScModifierList = super[ScTypeDefinition].getModifierList diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala index 253a1620026..4c5f9c32861 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/simulacrum/SimulacrumInjection.scala @@ -136,7 +136,7 @@ class SimulacrumInjection extends SyntheticMembersInjector { val AllOpsSupers = clazz.extendsBlock.templateParents.toSeq.flatMap(parents => parents.typeElements.flatMap { te => te.`type`() match { - case Success(ParameterizedType(classType, Seq(tp))) if isProperTpt(tp).isDefined => + case Right(ParameterizedType(classType, Seq(tp))) if isProperTpt(tp).isDefined => def fromType: Seq[String] = { val project = clazz.getProject classType.extractClass match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala index c745b2f0365..bd735baf6e1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala @@ -351,7 +351,7 @@ class ImplicitCollector(place: PsiElement, case typeable: Typeable => val subst = c.substitutor typeable.`type`() match { - case Success(t) => + case Right(t) => if (!subst.subst(t).conforms(tp)) reportWrong(c, subst, TypeDoesntConformResult) else @@ -385,7 +385,7 @@ class ImplicitCollector(place: PsiElement, private def updateNonValueType(nonValueType0: ScType): TypeResult[ScType] = { InferUtil.updateAccordingToExpectedType( - Success(nonValueType0), + Right(nonValueType0), fromImplicitParameters = true, filterTypeParams = isImplicitConversion, expectedType = Some(tp), @@ -448,7 +448,7 @@ class ImplicitCollector(place: PsiElement, val nonValueType: ScType = try updateNonValueType(nonValueType0) match { - case Success(tpe) => tpe + case Right(tpe) => tpe case _ => return wrongTypeParam(BadTypeResult) } catch { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala index 68e22c6327e..557f32898ca 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/JavaConversionUtil.scala @@ -8,7 +8,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScModifierListOwner import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScClassParents -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** @@ -96,7 +95,7 @@ object JavaConversionUtil { if (arguments.length == 1) { val typeResult = arguments.head.`type`() typeResult match { - case Success(tp) => + case Right(tp) => tp.extractClass match { case Some(clazz) => clazz.getQualifiedName + ".class" case _ => problem diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala index 6e23e1c55ff..af55a6d50ec 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/LightUtil.scala @@ -7,7 +7,6 @@ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType -import org.jetbrains.plugins.scala.lang.psi.types.result._ import _root_.scala.collection.mutable.ArrayBuffer @@ -30,7 +29,7 @@ object LightUtil { val classes = annotation.constructor.args.map(_.exprs).getOrElse(Seq.empty).flatMap { _.`type`() match { - case Success(ParameterizedType(des, Seq(arg))) => des.extractClass match { + case Right(ParameterizedType(des, Seq(arg))) => des.extractClass match { case Some(clazz) if clazz.qualifiedName == "java.lang.Class" => arg.toPsiType match { case c: PsiClassType => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala index 47d23f82911..bc8bc942f75 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/ScFunctionWrapper.scala @@ -183,17 +183,17 @@ object ScFunctionWrapper { val classes = new ArrayBuffer[String]() val project = fun.getProject tp.upperBound.map(subst.subst) match { - case Success(tp: ScCompoundType) => + case Right(tp: ScCompoundType) => tp.components.foreach { tp: ScType => tp.extractClass match { case Some(clazz) => classes += clazz.getQualifiedName case _ => } } - case Success(_: StdType) => - case Success(tpt: TypeParameterType) => + case Right(_: StdType) => + case Right(tpt: TypeParameterType) => classes += tpt.canonicalText - case Success(scType) => + case Right(scType) => scType.extractClass match { case Some(clazz) => classes += clazz.getQualifiedName case _ => @@ -235,13 +235,13 @@ object ScFunctionWrapper { else param.getRealParameterType val typeText = paramType.map(subst.subst) match { - case Success(tp) if param.isCallByNameParameter => + case Right(tp) if param.isCallByNameParameter => val psiType = tp match { case std: StdType => tp.typeSystem.stdToPsiType(std, noPrimitives = true) case _ => tp.toPsiType } s"scala.Function0<${psiType.getCanonicalText}>" - case Success(tp) => + case Right(tp) => JavaConversionUtil.typeText(tp) case _ => "java.lang.Object" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala index c774cd7a449..4b096a54e2a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/StaticTraitScFunctionWrapper.scala @@ -5,7 +5,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.AnyRef -import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author Alefas @@ -38,7 +37,7 @@ class StaticTraitScFunctionWrapper(val function: ScFunction, containingClass: Ps private def paramText(param: ScParameter): String = { val paramAnnotations = JavaConversionUtil.annotations(param).mkString("", " ", " ") val typeText = param.getRealParameterType match { - case Success(tp) => + case Right(tp) => val simple = JavaConversionUtil.typeText(tp) if (param.isCallByNameParameter) s"scala.Function0<$simple>" else simple diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala index c3412939740..1dbd0d23578 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala @@ -22,7 +22,7 @@ class ScLightBindingPattern(rt: ScType, val b: ScBindingPattern) override def getParent: PsiElement = b.getParent - override def `type`(): TypeResult[ScType] = Success(rt) + override def `type`(): TypeResult[ScType] = Right(rt) override def getOriginalElement: PsiElement = super[ScBindingPattern].getOriginalElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala index 311245fbb5c..471ee21c5dd 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala @@ -32,7 +32,7 @@ class ScLightFieldId(rt: ScType, val f: ScFieldId) override protected def findChildByClassScala[T >: Null <: ScalaPsiElement](clazz: Class[T]): T = throw new UnsupportedOperationException("Operation on light element") - override def `type`(): TypeResult[ScType] = Success(rt) + override def `type`(): TypeResult[ScType] = Right(rt) override def getParent: PsiElement = f.getParent //to find right context } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala index 7d78be6f4be..3270969bd2c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala @@ -28,11 +28,11 @@ class ScLightFunctionDeclaration(pTypes: Seq[Seq[ScType]], tParams: Seq[TypePara override def paramClauses: ScParameters = new ScLightParameters(pTypes, fun) - override protected def returnTypeInner: TypeResult[ScType] = Success(rt) + override protected def returnTypeInner: TypeResult[ScType] = Right(rt) - override def definedReturnType: TypeResult[ScType] = Success(rt) + override def definedReturnType: TypeResult[ScType] = Right(rt) - override def declaredType: TypeResult[ScType] = Success(rt) + override def declaredType: TypeResult[ScType] = Right(rt) override def hasExplicitType: Boolean = true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala index 7f289110ab3..09c22e7a714 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala @@ -26,11 +26,11 @@ class ScLightFunctionDefinition(pTypes: Seq[Seq[ScType]], tParams: Seq[TypeParam override def paramClauses: ScParameters = new ScLightParameters(pTypes, fun) - override protected def returnTypeInner: TypeResult[ScType] = Success(rt) + override protected def returnTypeInner: TypeResult[ScType] = Right(rt) - override def definedReturnType: TypeResult[ScType] = Success(rt) + override def definedReturnType: TypeResult[ScType] = Right(rt) - override def declaredType: TypeResult[ScType] = Success(rt) + override def declaredType: TypeResult[ScType] = Right(rt) override def hasExplicitType: Boolean = true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala index 263bc5afd1c..9940ad2ccf7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala @@ -19,7 +19,7 @@ class ScLightParameter(val param: ScParameter, tp: ScType, i: Int) extends LightElement(param.getManager, param.getLanguage) with ScParameter { override def nameId: PsiElement = param.nameId - override def `type`(): TypeResult[ScType] = Success(tp) + override def `type`(): TypeResult[ScType] = Right(tp) override def deprecatedName: Option[String] = param.deprecatedName diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala index 76863230f06..aded82e9150 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala @@ -21,9 +21,9 @@ class ScLightTypeAliasDeclaration(s: TypeAliasSignature, val ta: ScTypeAliasDecl override def nameId: PsiElement = ta.nameId - override def upperBound: TypeResult[ScType] = Success(s.upperBound) + override def upperBound: TypeResult[ScType] = Right(s.upperBound) - override def lowerBound: TypeResult[ScType] = Success(s.lowerBound) + override def lowerBound: TypeResult[ScType] = Right(s.lowerBound) override def getOriginalElement: PsiElement = super[ScTypeAliasDeclaration].getOriginalElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala index aa3e71e97ab..aefe72966b3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala @@ -22,11 +22,11 @@ class ScLightTypeAliasDefinition(s: TypeAliasSignature, val ta: ScTypeAliasDefin override def nameId: PsiElement = ta.nameId - override def upperBound: TypeResult[ScType] = Success(s.upperBound) + override def upperBound: TypeResult[ScType] = Right(s.upperBound) - override def lowerBound: TypeResult[ScType] = Success(s.lowerBound) + override def lowerBound: TypeResult[ScType] = Right(s.lowerBound) - override def aliasedType: TypeResult[ScType] = Success(s.lowerBound) + override def aliasedType: TypeResult[ScType] = Right(s.lowerBound) override def aliasedTypeElement: Option[ScTypeElement] = ta.aliasedTypeElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala index ccc2b09c3ae..61def783037 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala @@ -26,9 +26,9 @@ class ScDelegatingLightTypeParam(t: TypeParameter, val tParam: ScTypeParam) override val typeParamId: Long = tParam.typeParamId - override def upperBound: TypeResult[ScType] = Success(t.upperType) + override def upperBound: TypeResult[ScType] = Right(t.upperType) - override def lowerBound: TypeResult[ScType] = Success(t.lowerType) + override def lowerBound: TypeResult[ScType] = Right(t.lowerType) override def getIndex: Int = tParam.getIndex @@ -93,9 +93,9 @@ class ScExistentialLightTypeParam(override val name: String)(implicit pc: Projec override def isHigherKindedTypeParameter: Boolean = false - override def lowerBound: TypeResult[ScType] = Success(api.Nothing) + override def lowerBound: TypeResult[ScType] = Right(api.Nothing) - override def upperBound: TypeResult[ScType] = Success(api.Any) + override def upperBound: TypeResult[ScType] = Right(api.Any) override def toString: String = name diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala index af85d74f2fc..2180c9bf726 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/stubs/util/ScalaStubsUtil.scala @@ -20,7 +20,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScExtendsBloc import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition import org.jetbrains.plugins.scala.lang.psi.stubs.index.ScalaIndexKeys import org.jetbrains.plugins.scala.lang.psi.stubs.index.ScalaIndexKeys.SUPER_CLASS_NAME_KEY -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScCompoundType, ScType, ScTypeExt} import org.jetbrains.plugins.scala.macroAnnotations.CachedInsidePsiElement import org.jetbrains.plugins.scala.util.ScEquivalenceUtil @@ -88,7 +87,7 @@ object ScalaStubsUtil { selfTypeElement.typeElement match { case Some(typeElement) => typeElement.`type`() match { - case Success(tp) => + case Right(tp) => if (checkTp(tp)) { val clazz = PsiTreeUtil.getContextOfType(selfTypeElement, classOf[ScTemplateDefinition]) if (clazz != null) inheritors += clazz diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala index 6330864f89d..7940dea7a28 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/BaseTypes.scala @@ -12,7 +12,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScTypeAlias, ScTypeA import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.annotation.tailrec import scala.collection.mutable @@ -130,7 +129,7 @@ private class BaseTypesIterator(tp: ScType) extends Iterator[ScType] { if (!visitedAliases.contains(ta)) { visitedAliases += ta ta.aliasedType match { - case Success(aliased) => Some(s.subst(aliased)) + case Right(aliased) => Some(s.subst(aliased)) case _ => None } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala index e3fbf7e605f..56a287bb302 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala @@ -50,12 +50,12 @@ object Compatibility { } - @CachedWithRecursionGuard(place, (Success(typez), Set.empty), ModCount.getBlockModificationCount) + @CachedWithRecursionGuard(place, (Right(typez), Set.empty), ModCount.getBlockModificationCount) private def eval(typez: ScType, expectedOption: Option[ScType]): (TypeResult[ScType], Set[ImportUsed]) = { expectedOption match { - case Some(expected) if typez.conforms(expected) => (Success(typez), Set.empty) + case Some(expected) if typez.conforms(expected) => (Right(typez), Set.empty) case Some(expected) => - val defaultResult: (TypeResult[ScType], Set[ImportUsed]) = (Success(typez), Set.empty) + val defaultResult: (TypeResult[ScType], Set[ImportUsed]) = (Right(typez), Set.empty) implicit val elementScope = place.elementScope val functionType = FunctionType(expected, Seq(typez)) @@ -77,12 +77,12 @@ object Compatibility { } maybeType.map { - (result: ScType) => Success(result) + (result: ScType) => Right(result) }.map { (_, res.importsUsed) }.getOrElse(defaultResult) } else defaultResult - case _ => (Success(typez), Set.empty) + case _ => (Right(typez), Set.empty) } } @@ -94,7 +94,7 @@ object Compatibility { } else { import scala.collection.Set - def default: (TypeResult[ScType], Set[ImportUsed]) = (Success(typez), Set.empty) + def default: (TypeResult[ScType], Set[ImportUsed]) = (Right(typez), Set.empty) if (isShape || !checkImplicits || place == null) default else eval(typez, expectedOption) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala index 42f13144e24..c6d7f9426bc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScParameterizedType.scala @@ -20,7 +20,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinitio import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.api.{Contravariant, Covariant, Invariant, ParameterizedType, TypeParameterType, TypeVisitor, UndefinedType, ValueType, Variance} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.ScTypePolymorphicType -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import scala.collection.immutable.ListMap @@ -144,7 +143,7 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => (lower match { - case Success(tp) => tp + case Right(tp) => tp case _ => return (false, uSubst) }).equiv(r, uSubst, falseUndef) case _ => (false, uSubst) @@ -153,7 +152,7 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => (lower match { - case Success(tp) => tp + case Right(tp) => tp case _ => return (false, uSubst) }).equiv(r, uSubst, falseUndef) case _ => (false, uSubst) @@ -203,7 +202,7 @@ class ScParameterizedType private(val designator: ScType, val typeArguments: Seq designator.extractClassType match { case Some((clazz: ScTypeDefinition, sub)) if startsWith(clazz, prefix) => clazz.`type`() match { - case Success(t) => + case Right(t) => val substituted = (sub followed substitutor).subst(t) substituted match { case pt: ScParameterizedType => @@ -240,7 +239,7 @@ object ScParameterizedType { def apply(designator: ScType, typeArgs: Seq[ScType]): ValueType = { def createCompoundProjectionParameterized(pt: ScParameterizedType): ValueType = { pt.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, _, Success(upper: ValueType))) => upper + case Some(AliasType(_: ScTypeAliasDefinition, _, Right(upper: ValueType))) => upper case _ => pt } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala index cd84706e7f9..b2d5786cba7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaConformance.scala @@ -387,7 +387,7 @@ trait ScalaConformance extends api.Conformance { } result = l.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(comp: ScCompoundType), _)) => + case Some(AliasType(_: ScTypeAliasDefinition, Right(comp: ScCompoundType), _)) => conformsInner(comp, c, HashSet.empty, undefinedSubst) case _ => (false, undefinedSubst) } @@ -1605,7 +1605,7 @@ trait ScalaConformance extends api.Conformance { def processHigherKindedTypeParams(undefType: ParameterizedType, defType: ParameterizedType, undefinedSubst: ScUndefinedSubstitutor, falseUndef: Boolean): (Boolean, ScUndefinedSubstitutor) = { val defTypeExpanded = defType.isAliasType.map(_.lower).map { - case Success(p: ScParameterizedType) => p + case Right(p: ScParameterizedType) => p case _ => defType }.getOrElse(defType) extractParams(defTypeExpanded.designator) match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala index 4863d1ee416..11bbdf6a043 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaEquivalence.scala @@ -4,7 +4,6 @@ import com.intellij.openapi.util.Computable import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDefinition import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType /** @@ -51,12 +50,12 @@ trait ScalaEquivalence extends api.Equivalence { } right.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(right), _)) => return equivInner(left, right, substitutor, falseUndef) + case Some(AliasType(_: ScTypeAliasDefinition, Right(right), _)) => return equivInner(left, right, substitutor, falseUndef) case _ => } left.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(left), _)) => return equivInner(left, right, substitutor, falseUndef) + case Some(AliasType(_: ScTypeAliasDefinition, Right(left), _)) => return equivInner(left, right, substitutor, falseUndef) case _ => } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala index 2b1665d98db..91c7bd35b0d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaPsiTypeBridge.scala @@ -13,7 +13,6 @@ import org.jetbrains.plugins.scala.lang.psi.light.PsiClassWrapper import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.NonValueType -import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.collection.JavaConverters._ @@ -147,7 +146,7 @@ trait ScalaPsiTypeBridge extends api.PsiTypeBridge { toPsiTypeInner(qualNameToType(c.qualifiedName), noPrimitives) case ScDesignatorType(valClass: ScClass) if ValueClassType.isValueClass(valClass) => valClass.parameters.head.getRealParameterType match { - case Success(tp) if !(noPrimitives && tp.isPrimitive) => + case Right(tp) if !(noPrimitives && tp.isPrimitive) => toPsiTypeInner(tp, noPrimitives) case _ => createType(valClass) } @@ -169,7 +168,7 @@ trait ScalaPsiTypeBridge extends api.PsiTypeBridge { } case a: ScTypeAliasDefinition if !visitedAliases.contains(a) => a.aliasedType match { - case Success(c: ScParameterizedType) => + case Right(c: ScParameterizedType) => toPsiTypeInner(ScParameterizedType(c.designator, args), noPrimitives, visitedAliases + a) case _ => javaObject } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala index 59189777227..79624704622 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala @@ -33,14 +33,14 @@ object ScalaType { // types of FunctionN, or the elements of TupleN def expandAliases(tp: ScType, visited: Set[ScType] = Set.empty): TypeResult[ScType] = { - if (visited contains tp) return Success(tp) + if (visited contains tp) return Right(tp) tp match { case proj@ScProjectionType(_, _, _) => proj.actualElement match { case t: ScTypeAliasDefinition if t.typeParameters.isEmpty => t.aliasedType.flatMap(t => expandAliases(proj.actualSubst.subst(t), visited + tp)) case t: ScTypeAliasDeclaration if t.typeParameters.isEmpty => t.upperBound.flatMap(upper => expandAliases(proj.actualSubst.subst(upper), visited + tp)) - case _ => Success(tp) + case _ => Right(tp) } case at: ScAbstractType => expandAliases(at.upper, visited + tp) // ugly hack for SCL-3592 case ScDesignatorType(t: ScType) => expandAliases(t, visited + tp) @@ -52,7 +52,7 @@ object ScalaType { case pt: ScParameterizedType if pt.isAliasType.isDefined => val aliasType: AliasType = pt.isAliasType.get aliasType.upper.flatMap(expandAliases(_, visited + tp)) - case _ => Success(tp) + case _ => Right(tp) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala index de80efc0d5b..b213b985999 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/FunctionType.scala @@ -4,7 +4,6 @@ import org.jetbrains.plugins.scala.lang.psi.ElementScope import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTrait, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScParameterizedType, ScType, ScTypeExt, ScalaType} import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType @@ -41,7 +40,7 @@ sealed trait FunctionTypeFactory { case 0 => None //hack for http://youtrack.jetbrains.com/issue/SCL-6880 to avoid infinite loop. case _ => `type`.isAliasType match { - case Some(AliasType(_: ScTypeAliasDefinition, Success(lower), _)) => + case Some(AliasType(_: ScTypeAliasDefinition, Right(lower), _)) => extractForPrefix(lower, prefix, depth - 1) case _ => `type` match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala index 9e98f2bd254..38f27c41dd6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScDesignatorType.scala @@ -7,7 +7,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{PsiTypeParame import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScTypeAlias, ScTypeAliasDefinition} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.types.api._ -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScExistentialType, ScType, ScTypeExt, ScUndefinedSubstitutor} import org.jetbrains.plugins.scala.lang.refactoring.util.ScTypeUtil.AliasType import org.jetbrains.plugins.scala.util.ScEquivalenceUtil.smartEquivalence @@ -29,14 +28,14 @@ case class ScDesignatorType(element: PsiNamedElement, isStatic: Boolean = false) ta match { case ta: ScTypeAliasDefinition => //hack for simple cases, it doesn't cover more complicated examples ta.aliasedType match { - case Success(tp) => + case Right(tp) => tp match { case ParameterizedType(des, typeArgs) => val taArgs = ta.typeParameters if (taArgs.length == typeArgs.length && taArgs.zip(typeArgs).forall { case (tParam: ScTypeParam, TypeParameterType(_, _, _, param)) if tParam == param => true case _ => false - }) return Some(AliasType(ta, Success(des), Success(des))) + }) return Some(AliasType(ta, Right(des), Right(des))) case _ => } case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala index 610d931f7fd..0c1ef4572e9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScProjectionType.scala @@ -47,14 +47,14 @@ class ScProjectionType private(val projected: ScType, ta match { case ta: ScTypeAliasDefinition => //hack for simple cases, it doesn't cover more complicated examples ta.aliasedType match { - case Success(tp) => + case Right(tp) => actualSubst.subst(tp) match { case ParameterizedType(des, typeArgs) => val taArgs = ta.typeParameters if (taArgs.length == typeArgs.length && taArgs.zip(typeArgs).forall { case (tParam: ScTypeParam, TypeParameterType(_, _, _, param)) if tParam == param => true case _ => false - }) return Some(AliasType(ta, Success(des), Success(des))) + }) return Some(AliasType(ta, Right(des), Right(des))) case _ => } case _ => @@ -220,7 +220,7 @@ class ScProjectionType private(val projected: ScType, isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => return (lower match { - case Success(tp) => tp + case Right(tp) => tp case _ => return (false, uSubst) }).equiv(r, uSubst, falseUndef) case _ => @@ -235,7 +235,7 @@ class ScProjectionType private(val projected: ScType, r.isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => this.equiv(lower match { - case Success(tp) => tp + case Right(tp) => tp case _ => return (false, uSubst) }, uSubst, falseUndef) case _ => (false, uSubst) @@ -256,7 +256,7 @@ class ScProjectionType private(val projected: ScType, r.isAliasType match { case Some(AliasType(_: ScTypeAliasDefinition, lower, _)) => this.equiv(lower match { - case Success(tp) => tp + case Right(tp) => tp case _ => return (false, uSubst) }, uSubst, falseUndef) case _ => @@ -267,7 +267,7 @@ class ScProjectionType private(val projected: ScType, case t: ScTypedDefinition if t.isStable => val s: ScSubstitutor = ScSubstitutor(projected) followed actualSubst t.`type`() match { - case Success(tp: DesignatorOwner) if tp.isSingleton => + case Right(tp: DesignatorOwner) if tp.isSingleton => return s.subst(tp).equiv(r, uSubst, falseUndef) case _ => } @@ -279,7 +279,7 @@ class ScProjectionType private(val projected: ScType, val s: ScSubstitutor = ScSubstitutor(p1) followed proj2.actualSubst t.`type`() match { - case Success(tp: DesignatorOwner) if tp.isSingleton => + case Right(tp: DesignatorOwner) if tp.isSingleton => return s.subst(tp).equiv(this, uSubst, falseUndef) case _ => } @@ -293,7 +293,7 @@ class ScProjectionType private(val projected: ScType, case _: ScObject => (false, uSubst) case t: ScTypedDefinition if t.isStable => t.`type`() match { - case Success(singleton: DesignatorOwner) if singleton.isSingleton => + case Right(singleton: DesignatorOwner) if singleton.isSingleton => val newSubst = actualSubst.followed(ScSubstitutor(projected)) r.equiv(newSubst.subst(singleton), uSubst, falseUndef) case _ => (false, uSubst) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala index 704294a9f79..7d9324f5912 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/api/designator/ScThisType.scala @@ -3,7 +3,6 @@ package org.jetbrains.plugins.scala.lang.psi.types.api.designator import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTemplateDefinition} import org.jetbrains.plugins.scala.lang.psi.types.api.TypeVisitor -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScTypeExt, ScUndefinedSubstitutor} import org.jetbrains.plugins.scala.util.ScEquivalenceUtil @@ -43,7 +42,7 @@ case class ScThisType(element: ScTemplateDefinition) extends DesignatorOwner { (false, substitutor) case (_, ScDesignatorType(typed: ScTypedDefinition)) if typed.isStable => typed.`type`() match { - case Success(tp: DesignatorOwner) if tp.isSingleton => + case Right(tp: DesignatorOwner) if tp.isSingleton => this.equiv(tp, substitutor, falseUndef) case _ => (false, substitutor) @@ -51,7 +50,7 @@ case class ScThisType(element: ScTemplateDefinition) extends DesignatorOwner { case (_, ScProjectionType(_, _: ScObject, _)) => (false, substitutor) case (_, p@ScProjectionType(tp, elem: ScTypedDefinition, _)) if elem.isStable => elem.`type`() match { - case Success(singleton: DesignatorOwner) if singleton.isSingleton => + case Right(singleton: DesignatorOwner) if singleton.isSingleton => val newSubst = p.actualSubst.followed(ScSubstitutor(tp)) this.equiv(newSubst.subst(singleton), substitutor, falseUndef) case _ => (false, substitutor) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala index 026e122818a..642c58fc731 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/package.scala @@ -147,7 +147,7 @@ package object types { `type` => `type`.isAliasType match { case Some(AliasType(ta: ScTypeAliasDefinition, _, Failure(_))) if needExpand(ta) => ReplaceWith(projectContext.stdTypes.Any) - case Some(AliasType(ta: ScTypeAliasDefinition, _, Success(upper))) if needExpand(ta) => + case Some(AliasType(ta: ScTypeAliasDefinition, _, Right(upper))) if needExpand(ta) => if (visited.contains(`type`)) throw RecursionException val updated = try innerUpdate(upper, visited + `type`) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala index 32f5700d7bc..5341abba4ae 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala @@ -7,29 +7,23 @@ import org.jetbrains.plugins.scala.project.ProjectContext package object result { - type TypeError = (String, ProjectContext) + private type TypeError = (String, ProjectContext) type TypeResult[T <: ScType] = Either[TypeError, ScType] - object Success { - def apply(result: ScType): TypeResult[ScType] = Right(result) - - def unapply(success: Right[TypeError, ScType]): Option[ScType] = Some(success.value) - } - object Failure { def apply(cause: String) (implicit context: ProjectContext): TypeResult[ScType] = Left(cause, context) - def unapply(left: Left[TypeError, ScType]): Option[String] = { - val (cause, _) = left.value - Some(cause) + def unapply(result: TypeResult[ScType]): Option[String] = result match { + case Left((cause, _)) => Some(cause) + case _ => None } } object TypeResult { def apply(maybeType: Option[ScType]) (implicit context: ProjectContext): TypeResult[ScType] = maybeType match { - case Some(scType) => Success(scType) + case Some(result) => Right(result) case None => Failure("") } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala index d5c633dc68f..36d0b672556 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/changeSignature/ScalaChangeSignatureUsageHandler.scala @@ -16,7 +16,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScModifierListOwner, S import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{FunctionType, JavaArrayType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiUtil, TypeAdjuster} import org.jetbrains.plugins.scala.lang.refactoring.changeSignature.changeInfo.ScalaChangeInfo import org.jetbrains.plugins.scala.lang.refactoring.extractMethod.ScalaExtractMethodUtils @@ -135,7 +134,7 @@ private[changeSignature] trait ScalaChangeSignatureUsageHandler { val expr = usage.expr val paramTypes = expr.`type`() match { - case Success(FunctionType(_, pTypes)) => pTypes + case Right(FunctionType(_, pTypes)) => pTypes case _ => Seq.empty } val (names, exprText) = expr match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala index 04d3eb53774..73198e67d23 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/extractMethod/duplicates/DuplicateMatch.scala @@ -90,7 +90,7 @@ class DuplicateMatch(pattern: DuplicatePattern, val candidates: Seq[PsiElement]) private def typesEquiv(expr1: ScExpression, expr2: ScExpression) = { (expr1.`type`(), expr2.`type`()) match { - case (Success(t1), Success(t2)) => + case (Right(t1), Right(t2)) => def extractFromSingletonType(t: ScType) = t match { case designatorOwner: DesignatorOwner if designatorOwner.isSingleton => designatorOwner.extractDesignatorSingleton diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala index 879c386acb0..d43f1a7570a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/memberPullUp/ScalaPullUpProcessor.scala @@ -14,7 +14,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScSimpleTypeElement import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScMember, ScTemplateDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.extractTrait.ScalaExtractMemberInfo import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaChangeContextUtil @@ -121,7 +120,7 @@ class ScalaPullUpProcessor(project: Project, private def declarationsText(m: ScMember): Seq[String] = { def textForBinding(b: ScBindingPattern) = { val typeText = b.`type`() match { - case Success(t) => s": ${t.canonicalText}" + case Right(t) => s": ${t.canonicalText}" case _ => "" } s"${b.name}$typeText" diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala index 8454cbb1684..5421476d930 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ReferenceExpressionResolver.scala @@ -27,7 +27,6 @@ import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression._ import org.jetbrains.plugins.scala.lang.psi.types.api.UndefinedType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{ScDesignatorType, ScProjectionType} import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{ScMethodType, ScTypePolymorphicType} -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ScalaType} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.DynamicResolveProcessor._ @@ -475,7 +474,7 @@ class ReferenceExpressionResolver(implicit projectContext: ProjectContext) { ProgressManager.checkCanceled() e.getNonValueType() match { - case Success(tpt@ScTypePolymorphicType(internal, tp)) if tp.nonEmpty && + case Right(tpt@ScTypePolymorphicType(internal, tp)) if tp.nonEmpty && !internal.isInstanceOf[ScMethodType] && !internal.isInstanceOf[UndefinedType] /* optimization */ => val substed = tpt.abstractTypeSubstitutor.subst(internal) processType(substed, e, processor) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala index a795db1fd24..ec92450b3e6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala @@ -191,7 +191,7 @@ abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) case _ => e.`type`() } result match { - case Success(tp) => processType(tp, place, state, visitedProjections = visitedProjections, visitedTypeParameter = visitedTypeParameter) + case Right(tp) => processType(tp, place, state, visitedProjections = visitedProjections, visitedTypeParameter = visitedTypeParameter) case _ => true } case ScDesignatorType(e) => @@ -285,7 +285,7 @@ abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) case _ => des.`type`() } typeResult match { - case Success(tp) => + case Right(tp) => processType(newSubst subst tp, place, state.put(ScSubstitutor.key, ScSubstitutor.empty), updateWithProjectionSubst = false, visitedProjections = visitedProjections, visitedTypeParameter = visitedTypeParameter) case _ => true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala index 14f93354df0..b45f8bbff76 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ExtractorResolveProcessor.scala @@ -11,7 +11,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject} import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScProjectionType -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.project.ProjectPsiElementExt import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_11 @@ -32,7 +31,7 @@ class ExtractorResolveProcessor(ref: ScReferenceElement, def resultsForTypedDef(obj: ScTypedDefinition) { def resultsFor(unapplyName: String) = { val typeResult = getFromType(state) match { - case Some(tp) => Success(ScProjectionType(tp, obj, superReference = false)) + case Some(tp) => Right(ScProjectionType(tp, obj, superReference = false)) case _ => obj.`type`() } val processor = new CollectMethodsProcessor(ref, unapplyName) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala index 4af8e5b46e9..d366b0b5011 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala @@ -89,7 +89,7 @@ class MethodResolveProcessor(override val ref: PsiElement, case obj: ScObject if ref.getParent.isInstanceOf[ScMethodCall] || ref.getParent.isInstanceOf[ScGenericCall] => val functionName = if (isUpdate) "update" else "apply" val typeResult = getFromType(state) match { - case Some(tp) => Success(ScProjectionType(tp, obj, superReference = false)) + case Some(tp) => Right(ScProjectionType(tp, obj, superReference = false)) case _ => obj.`type`() } val processor = new CollectMethodsProcessor(ref, functionName) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala index 080565cfbca..074f4ae21d3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/ResolveProcessor.scala @@ -17,7 +17,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBod import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScPackageImpl import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.lang.resolve.processor.precedence._ import org.jetbrains.plugins.scala.util.ScEquivalenceUtil @@ -295,7 +294,7 @@ object ResolveProcessor { case c: PsiClass => "Class:" + c.qualifiedName case t: ScTypeAliasDefinition if t.typeParameters.isEmpty => t.aliasedType match { - case Success(tp) => + case Right(tp) => tp.extractClass match { case Some(_: ScObject) => defaultForTypeAlias(t) case Some(td: ScTypeDefinition) if td.typeParameters.isEmpty && ScalaPsiUtil.hasStablePath(td) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala index 4c2ae23d1bd..088fbb81b0b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/scalatest/ScalaTestConfigurationProducer.scala @@ -17,7 +17,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScFuncti import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScMember, ScTrait, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt -import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.testingSupport.test.TestConfigurationUtil.isInheritor import org.jetbrains.plugins.scala.testingSupport.test.TestRunConfigurationForm.TestKind import org.jetbrains.plugins.scala.testingSupport.test.{TestConfigurationProducer, TestConfigurationUtil} @@ -143,8 +142,8 @@ class ScalaTestConfigurationProducer extends { val params = clauses.head.parameters if (params.nonEmpty) { params.head.`type`() match { - case Success(t) if t.isUnit => failedToCheck = false - case Success(tp) => + case Right(t) if t.isUnit => failedToCheck = false + case Right(tp) => tp.extractClass match { case Some(psiClass) if psiClass.qualifiedName == "java.lang.String" => call.argumentExpressions.head match { diff --git a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala index 539547f2a4b..81d2dc832ac 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtCompletionContributor.scala @@ -53,7 +53,7 @@ class SbtCompletionContributor extends ScalaCompletionContributor { def extractSeqType: Option[ScType] = { if (operator.getText != "+=") return None operator.`type`() match { - case Success(ParameterizedType(_, typeArgs)) => + case Right(ParameterizedType(_, typeArgs)) => typeArgs.last match { case ParameterizedType(settingType, Seq(seqFullType)) if qualifiedName(settingType) == "sbt.Init.Setting" => val collectionTypeNames = Seq("scala.collection.Seq", "scala.collection.immutable.Set") diff --git a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala index 97118833667..c21b4034250 100644 --- a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala @@ -97,7 +97,7 @@ trait TypeAdapter { def toType(tr: TypeResult[ptype.ScType]): m.Type = { import org.jetbrains.plugins.scala.lang.psi.types.result._ tr match { - case Success(res) => toType(res) + case Right(res) => toType(res) case Failure(cause) => throw new ScalaMetaTypeResultFailure(cause) } } @@ -130,7 +130,7 @@ trait TypeAdapter { m.Type.Name(t.name) case t: ScTypedDefinition => t.getTypeWithCachedSubst match { - case Success(res) => toType(res) + case Right(res) => toType(res) case Failure(cause) => unresolved(cause) } case t: ScReferenceElement if dumbMode => @@ -261,7 +261,7 @@ trait TypeAdapter { def returnType(tr: ptype.result.TypeResult[ptype.ScType]): m.Type = { import ptype.result._ tr match { - case Success(t) => toType(t) + case Right(t) => toType(t) case Failure(cause) => LOG.warn(s"Failed to infer return type($cause)") m.Type.Name("Unit")//.setTypechecked diff --git a/scala/scala-impl/src/scala/meta/trees/Utils.scala b/scala/scala-impl/src/scala/meta/trees/Utils.scala index 3f0d7805c7b..de59064191b 100644 --- a/scala/scala-impl/src/scala/meta/trees/Utils.scala +++ b/scala/scala-impl/src/scala/meta/trees/Utils.scala @@ -158,12 +158,12 @@ trait Utils { if (dumbMode) { expr match { case ts: ScTypedStmt => TypeResult(ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null)) - case _ => Success(ptype.api.Any) + case _ => Right(ptype.api.Any) } } else { val s = ScSubstitutor(ScSubstitutor.cache.toMap) expr.`type`() match { - case Success(res) => Success(s.subst(res)) + case Right(res) => Right(s.subst(res)) case other => other } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala index 5e219d2866f..1b939b751d3 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala @@ -34,7 +34,7 @@ class MonocleLensesTest extends ScalaLightPlatformCodeInsightTestCaseAdapter { val exp = PsiTreeUtil.findElementOfClassAtOffset(getFileAdapter, caretPos, classOf[ScalaPsiElement], false).asInstanceOf[ScObject] exp.allMethods.find(_.name == methodName) match { case Some(x) => x.method.asInstanceOf[ScFunctionDefinition].returnType match { - case Success(t) => assertEquals(s"${t.toString} != $expectedType", expectedType, t.toString) + case Right(t) => assertEquals(s"${t.toString} != $expectedType", expectedType, t.toString) case Failure(cause) => fail(cause) } case None => fail("method not found") diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala index 0ccddd78be8..8d452056d27 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/StalactiteTest.scala @@ -55,7 +55,7 @@ class StalactiteTest extends ScalaLightCodeInsightFixtureTestAdapter { } match { case Some(method) => method.returnType match { - case Success(t) => assertEquals(s"${t.presentableText} != $expectedType", expectedType, t.presentableText) + case Right(t) => assertEquals(s"${t.presentableText} != $expectedType", expectedType, t.presentableText) case Failure(cause) => fail(cause) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala index ca9679108f8..2fed00a20fd 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeConformance/TypeConformanceTestBase.scala @@ -97,7 +97,7 @@ abstract class TypeConformanceTestBase extends ScalaLightPlatformCodeInsightTest val expr = valueDecl.expr.getOrElse(sys.error("Expression not found")) expr.`type`() match { - case Success(rhsType) => (declaredType, rhsType) + case Right(rhsType) => (declaredType, rhsType) case Failure(msg) => sys.error(s"Couldn't compute type of ${expr.getText}: $msg") } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala index 28ca1dc7980..febcebf9939 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/TypeInferenceDoTest.scala @@ -26,11 +26,11 @@ trait TypeInferenceDoTest { val scalaFile: ScalaFile = configureFromFileText(fileName, fileText) val expr: ScExpression = findExpression(scalaFile) val typez = expr.`type`() match { - case Success(t) if t.isUnit => expr.getTypeIgnoreBaseType + case Right(t) if t.isUnit => expr.getTypeIgnoreBaseType case x => x } typez match { - case Success(ttypez) => + case Right(ttypez) => val res = ttypez.presentableText val lastPsi = scalaFile.findElementAt(scalaFile.getText.length - 1) val text = lastPsi.getText diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala index 298dc63805c..d98692bb61e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/types/existentialSimplification/ExistentialSimplificationTestBase.scala @@ -43,7 +43,7 @@ abstract class ExistentialSimplificationTestBase extends ScalaLightPlatformCodeI val expr: ScExpression = PsiTreeUtil.findElementOfClassAtRange(scalaFile, startOffset + addOne, endOffset, classOf[ScExpression]) assert(expr != null, "Not specified expression in range to infer type.") expr.`type`() match { - case Success(ttypez: ScExistentialType) => + case Right(ttypez: ScExistentialType) => val res = ttypez.simplify().presentableText val lastPsi = scalaFile.findElementAt(scalaFile.getText.length - 1) @@ -55,7 +55,7 @@ abstract class ExistentialSimplificationTestBase extends ScalaLightPlatformCodeI case _ => assertTrue("Test result must be in last comment statement.", false) } assertEquals(output, res) - case Success(_) => fail("Expression has not existential type") + case Right(_) => fail("Expression has not existential type") case Failure(msg) => fail(msg) } } diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala index 710b0b76de9..55617200181 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala @@ -126,14 +126,14 @@ class MetaAnnotationBugsTest extends MetaAnnotationTestBase { .find(_.getName == "foo") .map(_.asInstanceOf[ScFunction].returnType) .getOrElse(fail("Method not generated by annotation")) match { - case Success(res) => res + case Right(res) => res case Failure(cause) => fail(s"Failed to infer generated method type: $cause") } val fooBarAType = bar.members .find(_.getName == "fooA").get .asInstanceOf[ScFunction].returnType match { - case Success(res) => res + case Right(res) => res case Failure(cause) => fail(s"Failed to infer generated method type: $cause") } From dfce7a71d51852c3c0d6be56c928583f633cf341 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Thu, 26 Oct 2017 13:23:08 +0300 Subject: [PATCH 052/141] smooth refactoring #SCL-12743 --- .../psi/impl/expr/ScThisReferenceImpl.scala | 3 +- .../scala/lang/psi/types/result/package.scala | 18 +++++------ .../meta/intellij/QuasiquoteInferUtil.scala | 2 +- .../src/scala/meta/trees/Utils.scala | 31 +++++-------------- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala index 56ac28ca2d4..6ed695e8520 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala @@ -11,6 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition} +import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeFromText import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{DesignatorOwner, ScThisType} import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -26,7 +27,7 @@ class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with protected override def innerType: TypeResult[ScType] = { import scala.meta.intellij.psiExt.TemplateDefExt refTemplate match { - case Some(td) if td.isMetaAnnotatationImpl => TypeResult(ScalaPsiElementFactory.createTypeFromText("scala.meta.Stat", this, null)) + case Some(td) if td.isMetaAnnotatationImpl => createTypeFromText("scala.meta.Stat", this, null).asTypeResult case Some(td) => ScThisReferenceImpl.getThisTypeForTypeDefinition(td, this) case _ => Failure("Cannot infer type") } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala index 5341abba4ae..610783c4008 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala @@ -7,8 +7,8 @@ import org.jetbrains.plugins.scala.project.ProjectContext package object result { - private type TypeError = (String, ProjectContext) - type TypeResult[T <: ScType] = Either[TypeError, ScType] + type Failure = (String, ProjectContext) + type TypeResult[T <: ScType] = Either[Failure, ScType] object Failure { def apply(cause: String) @@ -20,9 +20,9 @@ package object result { } } - object TypeResult { - def apply(maybeType: Option[ScType]) - (implicit context: ProjectContext): TypeResult[ScType] = maybeType match { + implicit class OptionTypeExt(val maybeRight: Option[ScType]) extends AnyVal { + + def asTypeResult(implicit context: ProjectContext): TypeResult[ScType] = maybeRight match { case Some(result) => Right(result) case None => Failure("") } @@ -30,10 +30,7 @@ package object result { implicit class TypeResultExt(val result: TypeResult[ScType]) extends AnyVal { - def get: ScType = result match { - case Right(value) => value - case _ => throw new NoSuchElementException("Failure.get") - } + def get: ScType = getOrApiType(null) def getOrAny: ScType = getOrApiType(_.Any) @@ -41,7 +38,8 @@ package object result { private def getOrApiType(apiType: StdTypes => ScType): ScType = result match { case Right(value) => value - case Left((_, projectContext)) => apiType(projectContext.stdTypes) + case Left((_, projectContext)) if apiType != null => apiType(projectContext.stdTypes) + case _ => throw new NoSuchElementException("Failure.get") } } diff --git a/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala b/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala index 25b85c1d8f7..9bbeb60450e 100644 --- a/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala +++ b/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala @@ -91,7 +91,7 @@ object QuasiquoteInferUtil extends scala.meta.quasiquotes.QuasiquoteParsers { } } catch { case _: ArrayIndexOutOfBoundsException => // workaround for meta parser failure on malformed quasiquotes - TypeResult(createTypeFromText("scala.meta.Tree", pat, null)) + createTypeFromText("scala.meta.Tree", pat, null).asTypeResult } } diff --git a/scala/scala-impl/src/scala/meta/trees/Utils.scala b/scala/scala-impl/src/scala/meta/trees/Utils.scala index de59064191b..8abc1fef542 100644 --- a/scala/scala-impl/src/scala/meta/trees/Utils.scala +++ b/scala/scala-impl/src/scala/meta/trees/Utils.scala @@ -6,7 +6,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, ScSugarCallE import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject -import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory +import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeFromText import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.ScSyntheticFunction import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType} @@ -110,11 +110,11 @@ trait Utils { def withSubstitutionCaching[T](fun: TypeResult[ScType] => T): T = { if (dumbMode) { val maybeType = expr match { - case ts: ScTypedStmt => ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null) + case ts: ScTypedStmt => createTypeFromText(ts.getText, expr, null) case _ => None } - fun(TypeResult(maybeType)) + fun(maybeType.asTypeResult) } else { ScSubstitutor.cacheSubstitutions = true val tp = expr.`type`() @@ -124,18 +124,6 @@ trait Utils { res } } - - def getTypeWithCachedSubst: ScType = { - if (dumbMode) { - expr match { - case ts: ScTypedStmt => ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null).getOrElse(ptype.api.Any) - case _ => ptype.api.Any - } - } else { - val s = ScSubstitutor(ScSubstitutor.cache.toMap) - s.subst(expr.`type`().get) - } - } } implicit class RichScFunctionDefinition(expr: ScFunctionDefinition) { @@ -145,8 +133,8 @@ trait Utils { if (dumbMode) { expr.definedReturnType.getOrElse(ptype.api.Any) } else { - val s = ScSubstitutor(ScSubstitutor.cache.toMap) - s.subst(expr.`type`().get) + val substitutor = ScSubstitutor(ScSubstitutor.cache.toMap) + substitutor.subst(expr.`type`().get) } } } @@ -157,15 +145,12 @@ trait Utils { def getTypeWithCachedSubst: TypeResult[ScType] = { if (dumbMode) { expr match { - case ts: ScTypedStmt => TypeResult(ScalaPsiElementFactory.createTypeFromText(ts.getText, expr, null)) + case ts: ScTypedStmt => createTypeFromText(ts.getText, expr, null).asTypeResult case _ => Right(ptype.api.Any) } } else { - val s = ScSubstitutor(ScSubstitutor.cache.toMap) - expr.`type`() match { - case Right(res) => Right(s.subst(res)) - case other => other - } + val substitutor = ScSubstitutor(ScSubstitutor.cache.toMap) + expr.`type`().map(substitutor.subst) } } } From 27cf855f523e624da8b6820fab080317e6616940 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Thu, 26 Oct 2017 14:22:03 +0300 Subject: [PATCH 053/141] TypeResult is not a parameterized type #SCL-12743 --- .../base/types/DottyAndOrTypeElementImpl.scala | 2 +- .../types/DottyRefinedTypeElementImpl.scala | 3 +-- .../scala/annotator/ScalaAnnotator.scala | 2 +- .../quickfix/WrapInOptionQuickFix.scala | 6 +++--- .../types/BaseJavaConvertersIntention.scala | 6 +++--- ...thodAccessedAsParameterlessInspection.scala | 3 +-- .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 4 ++-- .../plugins/scala/lang/psi/api/InferUtil.scala | 4 ++-- .../lang/psi/api/base/ScConstructor.scala | 8 ++++---- .../lang/psi/api/base/patterns/ScPattern.scala | 2 +- .../psi/api/base/patterns/ScTuplePattern.scala | 3 +-- .../api/base/types/ScAnnotTypeElement.scala | 3 +-- .../psi/api/base/types/ScTypeElement.scala | 12 ++++++------ .../lang/psi/api/expr/ExpectedTypes.scala | 10 +++++----- .../lang/psi/api/expr/MethodInvocation.scala | 12 ++++++------ .../scala/lang/psi/api/expr/ScBlock.scala | 2 +- .../scala/lang/psi/api/expr/ScExpression.scala | 16 ++++++++-------- .../lang/psi/api/expr/ScGenericCall.scala | 7 +++---- .../psi/api/expr/ScReferenceExpression.scala | 7 +++---- .../lang/psi/api/expr/ScSelfInvocation.scala | 7 +++---- .../lang/psi/api/statements/ScFunction.scala | 14 +++++++------- .../api/statements/ScTypeAliasDefinition.scala | 6 +++--- .../api/statements/params/ScParameter.scala | 2 +- .../psi/api/toplevel/ScTypeBoundsOwner.scala | 5 +++-- .../typedef/ScTemplateDefinition.scala | 2 +- .../lang/psi/impl/base/ScConstructorImpl.scala | 14 +++++++------- .../lang/psi/impl/base/ScFieldIdImpl.scala | 5 ++--- .../base/ScInterpolatedStringLiteralImpl.scala | 3 +-- .../lang/psi/impl/base/ScLiteralImpl.scala | 2 +- .../psi/impl/base/ScTypeBoundsOwnerImpl.scala | 6 +++--- .../base/patterns/ScCompositePatternImpl.scala | 3 +-- .../patterns/ScConstructorPatternImpl.scala | 2 +- .../base/patterns/ScInfixPatternImpl.scala | 3 +-- .../base/patterns/ScLiteralPatternImpl.scala | 3 +-- .../base/patterns/ScNamingPatternImpl.scala | 4 ++-- .../patterns/ScParenthesisedPatternImpl.scala | 3 +-- .../base/patterns/ScReferencePatternImpl.scala | 2 +- .../ScStableReferenceElementPatternImpl.scala | 3 +-- .../base/patterns/ScTypedPatternImpl.scala | 4 ++-- .../base/patterns/ScWildcardPatternImpl.scala | 2 +- .../base/types/ScCompoundTypeElementImpl.scala | 4 ++-- .../types/ScExistentialTypeElementImpl.scala | 4 ++-- .../types/ScParameterizedTypeElementImpl.scala | 2 +- .../types/ScParenthesisedTypeElementImpl.scala | 3 +-- .../base/types/ScSelfTypeElementImpl.scala | 2 +- .../base/types/ScSimpleTypeElementImpl.scala | 12 ++++++------ .../impl/base/types/ScTypeProjectionImpl.scala | 2 +- .../types/ScTypeVariableTypeElementImpl.scala | 4 ++-- .../base/types/ScWildcardTypeElementImpl.scala | 4 ++-- .../lang/psi/impl/expr/ScAssignStmtImpl.scala | 3 +-- .../psi/impl/expr/ScForStatementImpl.scala | 3 +-- .../psi/impl/expr/ScFunctionExprImpl.scala | 4 ++-- .../lang/psi/impl/expr/ScGenericCallImpl.scala | 18 +++++++++--------- .../lang/psi/impl/expr/ScIfStmtImpl.scala | 4 ++-- .../lang/psi/impl/expr/ScInfixExprImpl.scala | 3 +-- .../lang/psi/impl/expr/ScMatchStmtImpl.scala | 2 +- .../expr/ScNewTemplateDefinitionImpl.scala | 4 ++-- .../impl/expr/ScParenthesisedExprImpl.scala | 3 +-- .../impl/expr/ScReferenceExpressionImpl.scala | 14 +++++++------- .../lang/psi/impl/expr/ScReturnStmtImpl.scala | 3 +-- .../psi/impl/expr/ScSelfInvocationImpl.scala | 8 ++++---- .../psi/impl/expr/ScThisReferenceImpl.scala | 4 ++-- .../lang/psi/impl/expr/ScThrowStmtImpl.scala | 3 +-- .../lang/psi/impl/expr/ScTryStmtImpl.scala | 4 ++-- .../scala/lang/psi/impl/expr/ScTupleImpl.scala | 3 +-- .../lang/psi/impl/expr/ScTypedStmtImpl.scala | 3 +-- .../impl/expr/ScUnderscoreSectionImpl.scala | 4 ++-- .../lang/psi/impl/expr/ScUnitExprImpl.scala | 3 +-- .../lang/psi/impl/expr/xml/ScXmlExprImpl.scala | 2 +- .../psi/impl/expr/xml/ScXmlPatternImpl.scala | 3 +-- .../statements/ScFunctionDeclarationImpl.scala | 3 +-- .../statements/ScFunctionDefinitionImpl.scala | 4 ++-- .../statements/ScMacroDefinitionImpl.scala | 3 +-- .../statements/ScPatternDefinitionImpl.scala | 3 +-- .../ScTypeAliasDeclarationImpl.scala | 5 ++--- .../statements/ScValueDeclarationImpl.scala | 3 +-- .../statements/ScVariableDeclarationImpl.scala | 3 +-- .../statements/ScVariableDefinitionImpl.scala | 3 +-- .../statements/params/ScParameterImpl.scala | 4 ++-- .../typedef/ScTypeDefinitionImpl.scala | 4 ++-- .../lang/psi/implicits/ImplicitCollector.scala | 2 +- .../implicits/ScImplicitlyConvertible.scala | 4 ++-- .../light/scala/ScLightBindingPattern.scala | 2 +- .../lang/psi/light/scala/ScLightFieldId.scala | 2 +- .../scala/ScLightFunctionDeclaration.scala | 6 +++--- .../scala/ScLightFunctionDefinition.scala | 6 +++--- .../psi/light/scala/ScLightParameter.scala | 2 +- .../scala/ScLightTypeAliasDeclaration.scala | 6 +++--- .../scala/ScLightTypeAliasDefinition.scala | 8 ++++---- .../psi/light/scala/ScLightTypeParam.scala | 10 +++++----- .../scala/lang/psi/types/Compatibility.scala | 8 ++++---- .../scala/lang/psi/types/ScalaType.scala | 2 +- .../scala/lang/psi/types/result/Typeable.scala | 2 +- .../scala/lang/psi/types/result/package.scala | 14 +++++++------- .../lang/refactoring/util/ScTypeUtil.scala | 2 +- .../lang/resolve/processor/BaseProcessor.scala | 4 ++-- .../plugins/scala/util/ScEquivalenceUtil.scala | 4 ++-- .../meta/intellij/QuasiquoteInferUtil.scala | 3 +-- .../src/scala/meta/trees/TypeAdapter.scala | 4 ++-- .../src/scala/meta/trees/Utils.scala | 4 ++-- 100 files changed, 220 insertions(+), 252 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala index eb1579a4ede..c3caad1899f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyAndOrTypeElementImpl.scala @@ -23,7 +23,7 @@ abstract class DottyAndOrTypeElementImpl(node: ASTNode) extends ScalaPsiElementI } ).map(_.getOrElse(default)) - override protected def innerType: TypeResult[ScType] = Right(innerTypeValue) + override protected def innerType: TypeResult = Right(innerTypeValue) } class DottyAndTypeElementImpl(node: ASTNode) extends DottyAndOrTypeElementImpl(node) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala index 231e8494852..4910d2ade51 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/dotty/lang/psi/impl/base/types/DottyRefinedTypeElementImpl.scala @@ -4,13 +4,12 @@ import com.intellij.lang.ASTNode import org.jetbrains.plugins.dotty.lang.psi.api.base.types.DottyRefinedTypeElement import org.jetbrains.plugins.dotty.lang.psi.types.DottyRefinedType import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElementImpl -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author adkozlov */ class DottyRefinedTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with DottyRefinedTypeElement { - override protected def innerType: TypeResult[ScType] = + override protected def innerType: TypeResult = Right(DottyRefinedType(typeElement.`type`().getOrAny, refinement)) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index 9e67a98fab4..8b115025261 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -1405,7 +1405,7 @@ abstract class ScalaAnnotator extends Annotator * In other way it will return true to avoid red code. * Check conformance in case l = r. */ - def smartCheckConformance(l: TypeResult[ScType], r: TypeResult[ScType]): Boolean = { + def smartCheckConformance(l: TypeResult, r: TypeResult): Boolean = { val leftType = l match { case Right(res) => res case _ => return true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/WrapInOptionQuickFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/WrapInOptionQuickFix.scala index fbb6d348f41..a3d0ec12690 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/WrapInOptionQuickFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/quickfix/WrapInOptionQuickFix.scala @@ -8,15 +8,15 @@ import com.intellij.psi.PsiFile import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText +import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.ParameterizedType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** * Nikolay.Tropin * 6/27/13 */ -class WrapInOptionQuickFix(expr: ScExpression, expectedType: TypeResult[ScType], exprType: TypeResult[ScType]) extends IntentionAction { +class WrapInOptionQuickFix(expr: ScExpression, expectedType: TypeResult, exprType: TypeResult) extends IntentionAction { override def getText: String = ScalaBundle.message("wrap.in.option.hint") @@ -39,7 +39,7 @@ class WrapInOptionQuickFix(expr: ScExpression, expectedType: TypeResult[ScType], object WrapInOptionQuickFix { - def isAvailable(expr: ScExpression, expectedType: TypeResult[ScType], exprType: TypeResult[ScType]): Boolean = { + def isAvailable(expr: ScExpression, expectedType: TypeResult, exprType: TypeResult): Boolean = { var result = false for { scType <- exprType diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/BaseJavaConvertersIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/BaseJavaConvertersIntention.scala index ba6f7ce3f96..f05d05163d3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/BaseJavaConvertersIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/BaseJavaConvertersIntention.scala @@ -12,8 +12,8 @@ import org.jetbrains.plugins.scala.lang.psi.ScImportsHolder import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScPackaging import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText +import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import scala.annotation.tailrec @@ -39,7 +39,7 @@ abstract class BaseJavaConvertersIntention(methodName: String) extends PsiElemen } } - def isProperTargetCollection(typeResult: TypeResult[ScType], project: Project): Boolean = + def isProperTargetCollection(typeResult: TypeResult, project: Project): Boolean = typeResult.exists { scType => scType.extractClass exists { @@ -49,7 +49,7 @@ abstract class BaseJavaConvertersIntention(methodName: String) extends PsiElemen } } - def isAlreadyConvertedCollection(typeResult: TypeResult[ScType], project: Project): Boolean = + def isAlreadyConvertedCollection(typeResult: TypeResult, project: Project): Boolean = typeResult.exists { scType => scType.extractClass exists { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/EmptyParenMethodAccessedAsParameterlessInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/EmptyParenMethodAccessedAsParameterlessInspection.scala index cd96a56cde1..0087753b570 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/EmptyParenMethodAccessedAsParameterlessInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/methodSignature/EmptyParenMethodAccessedAsParameterlessInspection.scala @@ -6,7 +6,6 @@ import org.jetbrains.plugins.scala.codeInspection.methodSignature.quickfix.AddCa import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult import org.jetbrains.plugins.scala.util.IntentionAvailabilityChecker @@ -47,7 +46,7 @@ class EmptyParenMethodAccessedAsParameterlessInspection extends AbstractMethodSi } } - private def check(e: ScReferenceExpression, holder: ProblemsHolder, callType: TypeResult[ScType]) { + private def check(e: ScReferenceExpression, holder: ProblemsHolder, callType: TypeResult) { e.resolve() match { case (f: ScFunction) if !f.isInCompiledFile && f.isEmptyParen => callType.toOption match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index 31b18a3b368..0ac785de8ec 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -218,7 +218,7 @@ object ScalaPsiUtil { } def processImportLastParent(processor: PsiScopeProcessor, state: ResolveState, place: PsiElement, - lastParent: PsiElement, typeResult: => TypeResult[ScType]): Boolean = { + lastParent: PsiElement, typeResult: => TypeResult): Boolean = { val subst = state.get(ScSubstitutor.key).toOption.getOrElse(ScSubstitutor.empty) lastParent match { case _: ScImportStmt => @@ -493,7 +493,7 @@ object ScalaPsiUtil { } } - def collectPartsTr(option: TypeResult[ScType]): Unit = { + def collectPartsTr(option: TypeResult): Unit = { option match { case Right(t) => collectParts(t) case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala index cd80be78676..c87a6e5ba2d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/InferUtil.scala @@ -236,11 +236,11 @@ object InferUtil { * @param canThrowSCE we fail to get right type then if canThrowSCE throw SafeCheckException * @return updated type */ - def updateAccordingToExpectedType(_nonValueType: TypeResult[ScType], + def updateAccordingToExpectedType(_nonValueType: TypeResult, fromImplicitParameters: Boolean, filterTypeParams: Boolean, expectedType: Option[ScType], expr: PsiElement, - canThrowSCE: Boolean): TypeResult[ScType] = { + canThrowSCE: Boolean): TypeResult = { implicit val ctx: ProjectContext = expr val Unit = ctx.stdTypes.Unit diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/ScConstructor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/ScConstructor.scala index 1d44cae9715..e5696b9159c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/ScConstructor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/ScConstructor.scala @@ -37,11 +37,11 @@ trait ScConstructor extends ScalaPsiElement { def newTemplate: Option[ScNewTemplateDefinition] - def shapeType(i: Int): TypeResult[ScType] + def shapeType(i: Int): TypeResult - def shapeMultiType(i: Int): Seq[TypeResult[ScType]] - - def multiType(i: Int): Seq[TypeResult[ScType]] + def shapeMultiType(i: Int): Seq[TypeResult] + + def multiType(i: Int): Seq[TypeResult] def reference: Option[ScStableCodeReferenceElement] diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala index f99339d9d8b..e063ed3efd9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScPattern.scala @@ -39,7 +39,7 @@ import scala.meta.intellij.QuasiquoteInferUtil trait ScPattern extends ScalaPsiElement with Typeable { def isIrrefutableFor(t: Option[ScType]): Boolean = false - override def `type`(): TypeResult[ScType] = Failure("Cannot type pattern") + override def `type`(): TypeResult = Failure("Cannot type pattern") def bindings: Seq[ScBindingPattern] = { val b = new ArrayBuffer[ScBindingPattern] diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala index 002d2c1d3e3..1608ad1619c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/patterns/ScTuplePattern.scala @@ -5,7 +5,6 @@ package api package base package patterns -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.TupleType import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -17,7 +16,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ trait ScTuplePattern extends ScPattern { def patternList: Option[ScPatterns] = findChild(classOf[ScPatterns]) - override def `type`(): TypeResult[ScType] = this.flatMap(patternList) { list => + override def `type`(): TypeResult = this.flatMap(patternList) { list => val types = list.patterns.map(_.`type`().getOrAny) Right(TupleType(types)) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScAnnotTypeElement.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScAnnotTypeElement.scala index 54b33de6c02..38c82760af3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScAnnotTypeElement.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScAnnotTypeElement.scala @@ -5,7 +5,6 @@ package api package base package types -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult /** @@ -18,5 +17,5 @@ trait ScAnnotTypeElement extends ScTypeElement { def typeElement: ScTypeElement = findChildByClassScala(classOf[ScTypeElement]) - protected def innerType: TypeResult[ScType] = typeElement.`type`() + protected def innerType: TypeResult = typeElement.`type`() } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala index 93c46221906..723744e854c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala @@ -24,17 +24,17 @@ trait ScTypeElement extends ScalaPsiElement with Typeable { s"$typeName: $text" } - def `type`(): TypeResult[ScType] = getType + def `type`(): TypeResult = getType @CachedWithRecursionGuard(this, Failure("Recursive type of type element"), ModCount.getBlockModificationCount) - private[types] def getType: TypeResult[ScType] = innerType + private[types] def getType: TypeResult = innerType - def getTypeNoConstructor: TypeResult[ScType] = getType + def getTypeNoConstructor: TypeResult = getType - def getNonValueType(withUnnecessaryImplicitsUpdate: Boolean = false): TypeResult[ScType] = innerType + def getNonValueType(withUnnecessaryImplicitsUpdate: Boolean = false): TypeResult = innerType - protected def innerType: TypeResult[ScType] + protected def innerType: TypeResult /** Link from a view or context bound to the type element of the corresponding synthetic parameter. */ def analog: Option[ScTypeElement] = { @@ -83,7 +83,7 @@ trait ScDesugarizableTypeElement extends ScTypeElement { def typeElementFromText: String => ScTypeElement = createTypeElementFromText(_, getContext, this) - override protected def innerType: TypeResult[ScType] = computeDesugarizedType match { + override protected def innerType: TypeResult = computeDesugarizedType match { case Some(typeElement) => typeElement.getType case _ => Failure(s"Cannot desugarize $typeName") } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala index 5af4e5b6d90..a50b3c59faa 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ExpectedTypes.scala @@ -89,7 +89,7 @@ private[expr] object ExpectedTypes { } } - def mapResolves(resolves: Array[ResolveResult], types: Array[TypeResult[ScType]]): Array[(TypeResult[ScType], Boolean)] = { + def mapResolves(resolves: Array[ResolveResult], types: Array[TypeResult]): Array[(TypeResult, Boolean)] = { resolves.zip(types).map { case (r: ScalaResolveResult, tp) => val isNamedDynamic = r.isDynamic && r.name == APPLY_DYNAMIC_NAMED @@ -286,7 +286,7 @@ private[expr] object ExpectedTypes { } val callExpression = args.callExpression if (callExpression != null) { - var tps: Array[(TypeResult[ScType], Boolean)] = callExpression match { + var tps: Array[(TypeResult, Boolean)] = callExpression match { case ref: ScReferenceExpression => if (!withResolvedFunction) mapResolves(ref.shapeResolve, ref.shapeMultiType) else mapResolves(ref.multiResolve(false), ref.multiType) @@ -363,7 +363,7 @@ private[expr] object ExpectedTypes { @tailrec private def processArgsExpected(res: ArrayBuffer[(ScType, Option[ScTypeElement])], expr: ScExpression, i: Int, - tp: TypeResult[ScType], exprs: Seq[ScExpression], call: Option[MethodInvocation] = None, + tp: TypeResult, exprs: Seq[ScExpression], call: Option[MethodInvocation] = None, forApply: Boolean = false, isDynamicNamed: Boolean = false) { import expr.projectContext @@ -438,7 +438,7 @@ private[expr] object ExpectedTypes { else tp } - var polyType: TypeResult[ScType] = Right(s.subst(fun.polymorphicType()) match { + var polyType: TypeResult = Right(s.subst(fun.polymorphicType()) match { case ScTypePolymorphicType(internal, params) => update(ScTypePolymorphicType(internal, params ++ typeParams)) case tp => update(ScTypePolymorphicType(tp, typeParams)) @@ -459,7 +459,7 @@ private[expr] object ExpectedTypes { else tp } - var polyType: TypeResult[ScType] = Right(update(subst.subst(fun.polymorphicType()))) + var polyType: TypeResult = Right(update(subst.subst(fun.polymorphicType()))) call.foreach(call => polyType = call.updateAccordingToExpectedType(polyType)) processArgsExpected(res, expr, i, polyType, exprs, forApply = true, isDynamicNamed = isDynamicNamed) case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala index 3a4ea5f8e1c..e762200e087 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/MethodInvocation.scala @@ -129,7 +129,7 @@ trait MethodInvocation extends ScExpression with ScalaPsiElement { */ def isUpdateCall: Boolean = false - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { try { tryToGetInnerType(useExpectedType = true) } catch { @@ -138,7 +138,7 @@ trait MethodInvocation extends ScExpression with ScalaPsiElement { } } - private def tryToGetInnerType(useExpectedType: Boolean): TypeResult[ScType] = { + private def tryToGetInnerType(useExpectedType: Boolean): TypeResult = { var problemsLocal: Seq[ApplicabilityProblem] = Seq.empty var matchedParamsLocal: Seq[(Parameter, ScExpression)] = Seq.empty var importsUsedLocal: collection.Set[ImportUsed] = collection.Set.empty @@ -153,7 +153,7 @@ trait MethodInvocation extends ScExpression with ScalaPsiElement { applyOrUpdateElemVar = applyOrUpdateElemLocal } - var nonValueType: TypeResult[ScType] = getEffectiveInvokedExpr.getNonValueType() + var nonValueType: TypeResult = getEffectiveInvokedExpr.getNonValueType() this match { case _: ScPrefixExpr => return nonValueType //no arg exprs, just reference expression type case _: ScPostfixExpr => return nonValueType //no arg exprs, just reference expression type @@ -264,7 +264,7 @@ trait MethodInvocation extends ScExpression with ScalaPsiElement { } new Expression(actualExpr) { override def getTypeAfterImplicitConversion(checkImplicits: Boolean, isShape: Boolean, - _expectedOption: Option[ScType]): (TypeResult[ScType], collection.Set[ImportUsed]) = { + _expectedOption: Option[ScType]): (TypeResult, collection.Set[ImportUsed]) = { val expectedOption = _expectedOption.map { case TupleType(comps) if comps.length == 2 => comps(1) case t => t @@ -351,8 +351,8 @@ object MethodInvocation { * This method useful in case if you want to update some polymorphic type * according to method call expected type */ - def updateAccordingToExpectedType(nonValueType: TypeResult[ScType], - canThrowSCE: Boolean = false): TypeResult[ScType] = { + def updateAccordingToExpectedType(nonValueType: TypeResult, + canThrowSCE: Boolean = false): TypeResult = { InferUtil.updateAccordingToExpectedType(nonValueType, fromImplicitParameters = false, filterTypeParams = false, expectedType = invocation.expectedType(), expr = invocation, canThrowSCE) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala index 441676edfcc..54b351f66c5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScBlock.scala @@ -34,7 +34,7 @@ import scala.collection.mutable.ArrayBuffer trait ScBlock extends ScExpression with ScDeclarationSequenceHolder with ScImportsHolder { - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { if (hasCaseClauses) { val caseClauses = findChildByClassScala(classOf[ScCaseClauses]) val clauses: Seq[ScCaseClause] = caseClauses.caseClauses diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala index f705ad8fd8b..e1f5d2b6800 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala @@ -38,7 +38,7 @@ trait ScExpression extends ScBlockStatement with PsiAnnotationMemberValue with I import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression._ - override def `type`(): TypeResult[ScType] = + override def `type`(): TypeResult = this.getTypeAfterImplicitConversion().tr @volatile @@ -74,7 +74,7 @@ trait ScExpression extends ScBlockStatement with PsiAnnotationMemberValue with I } } - protected def innerType: TypeResult[ScType] = + protected def innerType: TypeResult = Failure(ScalaBundle.message("no.type.inferred", getText)) /** @@ -206,7 +206,7 @@ trait ScExpression extends ScBlockStatement with PsiAnnotationMemberValue with I object ScExpression { - case class ExpressionTypeResult(tr: TypeResult[ScType], + case class ExpressionTypeResult(tr: TypeResult, importsUsed: scala.collection.Set[ImportUsed] = Set.empty, implicitConversion: Option[ScalaResolveResult] = None) { def implicitFunction: Option[PsiNamedElement] = implicitConversion.map(_.element) @@ -236,11 +236,11 @@ object ScExpression { @CachedWithRecursionGuard(expr, None, ModCount.getBlockModificationCount) def smartExpectedType(fromUnderscore: Boolean = true): Option[ScType] = ExpectedTypes.smartExpectedType(expr, fromUnderscore) - def getTypeIgnoreBaseType: TypeResult[ScType] = getTypeAfterImplicitConversion(ignoreBaseTypes = true).tr + def getTypeIgnoreBaseType: TypeResult = getTypeAfterImplicitConversion(ignoreBaseTypes = true).tr @CachedWithRecursionGuard(expr, Failure("Recursive getNonValueType"), ModCount.getBlockModificationCount) def getNonValueType(ignoreBaseType: Boolean = false, - fromUnderscore: Boolean = false): TypeResult[ScType] = { + fromUnderscore: Boolean = false): TypeResult = { ProgressManager.checkCanceled() if (fromUnderscore) expr.innerType else { @@ -328,7 +328,7 @@ object ScExpression { @CachedWithRecursionGuard(expr, Failure("Recursive getTypeWithoutImplicits"), ModCount.getBlockModificationCount) - def getTypeWithoutImplicits(ignoreBaseTypes: Boolean = false, fromUnderscore: Boolean = false): TypeResult[ScType] = { + def getTypeWithoutImplicits(ignoreBaseTypes: Boolean = false, fromUnderscore: Boolean = false): TypeResult = { ProgressManager.checkCanceled() val fromNullLiteral = expr match { case lit: ScLiteral => @@ -459,7 +459,7 @@ object ScExpression { } //numeric literal narrowing - def isNarrowing(expected: ScType): Option[TypeResult[ScType]] = { + def isNarrowing(expected: ScType): Option[TypeResult] = { import expr.projectContext def isByte(v: Long) = v >= scala.Byte.MinValue && v <= scala.Byte.MaxValue @@ -488,7 +488,7 @@ object ScExpression { } //numeric widening - private def isWidening(valueType: ScType, expected: ScType): Option[TypeResult[ScType]] = { + private def isWidening(valueType: ScType, expected: ScType): Option[TypeResult] = { val (l, r) = (getStdType(valueType), getStdType(expected)) match { case (Some(left), Some(right)) => (left, right) case _ => return None diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala index 0d607169777..4080c2d9520 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala @@ -6,7 +6,6 @@ package expr import com.intellij.psi.ResolveResult import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScTypeArgs, ScTypeElement} -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult /** @@ -25,13 +24,13 @@ trait ScGenericCall extends ScExpression { case _ => Nil } - def shapeType: TypeResult[ScType] + def shapeType: TypeResult - def shapeMultiType: Array[TypeResult[ScType]] + def shapeMultiType: Array[TypeResult] def shapeMultiResolve: Option[Array[ResolveResult]] - def multiType: Array[TypeResult[ScType]] + def multiType: Array[TypeResult] def multiResolve: Option[Array[ResolveResult]] } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReferenceExpression.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReferenceExpression.scala index 0b532b79391..3a6300cb1e4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReferenceExpression.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReferenceExpression.scala @@ -8,7 +8,6 @@ import com.intellij.psi._ import org.jetbrains.plugins.scala.annotator.intention.ScalaImportTypeFix.TypeToImport import org.jetbrains.plugins.scala.lang.psi.api.base._ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameter import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult import org.jetbrains.plugins.scala.lang.resolve.ResolvableReferenceExpression @@ -59,16 +58,16 @@ trait ScReferenceExpression extends ScalaPsiElement with ScExpression with ScRef * Another usecase is when our type inference failed to decide to which method * we should resolve. If all methods has same result type, then we will give valid completion and resolve. */ - def multiType: Array[TypeResult[ScType]] + def multiType: Array[TypeResult] /** * @return types in the same order as shapeResolve */ - def shapeMultiType: Array[TypeResult[ScType]] + def shapeMultiType: Array[TypeResult] def shapeResolve: Array[ResolveResult] - def shapeType: TypeResult[ScType] + def shapeType: TypeResult override def createReplacingElementWithClassName(useFullQualifiedName: Boolean, clazz: TypeToImport): ScReferenceElement = { if (useFullQualifiedName) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala index 340c6998efd..3fed27555e7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala @@ -5,7 +5,6 @@ package api package expr import com.intellij.psi.{PsiElement, PsiReference} -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult /** @@ -20,11 +19,11 @@ trait ScSelfInvocation extends ScalaPsiElement with PsiReference { def bind: Option[PsiElement] - def shapeType(i: Int): TypeResult[ScType] + def shapeType(i: Int): TypeResult - def shapeMultiType(i: Int): Seq[TypeResult[ScType]] + def shapeMultiType(i: Int): Seq[TypeResult] - def multiType(i: Int): Seq[TypeResult[ScType]] + def multiType(i: Int): Seq[TypeResult] def thisElement: PsiElement = getFirstChild } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala index 010fc048584..ad613591f63 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunction.scala @@ -170,7 +170,7 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne false } - def definedReturnType: TypeResult[ScType] = { + def definedReturnType: TypeResult = { returnTypeElement match { case Some(ret) => ret.`type`() case _ if !hasAssign => Right(Unit) @@ -232,9 +232,9 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne def isProcedure: Boolean = paramClauses.clauses.isEmpty - protected def returnTypeInner: TypeResult[ScType] + protected def returnTypeInner: TypeResult - def declaredType: TypeResult[ScType] = this.flatMapType(returnTypeElement) + def declaredType: TypeResult = this.flatMapType(returnTypeElement) def clauses: Option[ScParameters] = Some(paramClauses) @@ -498,10 +498,10 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne } } - def `type`(): TypeResult[ScType] = { + def `type`(): TypeResult = { this.returnType match { case Right(tp) => - var res: TypeResult[ScType] = Right(tp) + var res: TypeResult = Right(tp) var i = paramClauses.clauses.length - 1 while (i >= 0) { res match { @@ -569,7 +569,7 @@ trait ScFunction extends ScalaPsiElement with ScMember with ScTypeParametersOwne val buffer = ArrayBuffer.empty[Seq[ScType]] for (cl <- paramClauses.clauses.reverse if !cl.isImplicit) { - val paramTypes: Seq[TypeResult[ScType]] = cl.parameters.map(_.`type`()) + val paramTypes: Seq[TypeResult] = cl.parameters.map(_.`type`()) if (paramTypes.exists(_.isLeft)) return None buffer += paramTypes.collect { @@ -594,7 +594,7 @@ object ScFunction { /** Is this function sometimes invoked without it's name appearing at the call site? */ def isSpecial: Boolean = Special(function.name) - def returnType: TypeResult[ScType] = { + def returnType: TypeResult = { if (importantOrderFunction(function)) { val parent = function.getParent val isCalculating = isCalculatingFor(parent) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala index 2918ff67391..7757429950e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScTypeAliasDefinition.scala @@ -24,14 +24,14 @@ trait ScTypeAliasDefinition extends ScTypeAlias { def aliasedTypeElement: Option[ScTypeElement] @CachedInsidePsiElement(this, ModCount.getBlockModificationCount) - def aliasedType: TypeResult[ScType] = + def aliasedType: TypeResult = aliasedTypeElement.map { _.`type`() }.getOrElse(Failure("No alias type")) - def lowerBound: TypeResult[ScType] = aliasedType + def lowerBound: TypeResult = aliasedType - def upperBound: TypeResult[ScType] = aliasedType + def upperBound: TypeResult = aliasedType def isExactAliasFor(cls: PsiClass): Boolean = { val isDefinedInObject = containingClass match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala index 67d3ec1a89b..9dcdaea9e2a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/params/ScParameter.scala @@ -62,7 +62,7 @@ trait ScParameter extends ScTypedDefinition with ScModifierListOwner with def getActualDefaultExpression: Option[ScExpression] - def getRealParameterType: TypeResult[ScType] = + def getRealParameterType: TypeResult = `type`() match { case result if !isRepeatedParameter => result case f@Right(tp) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypeBoundsOwner.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypeBoundsOwner.scala index 3f7473e7118..d65b554f39f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypeBoundsOwner.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/ScTypeBoundsOwner.scala @@ -11,8 +11,9 @@ import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult trait ScTypeBoundsOwner extends ScalaPsiElement { - def lowerBound: TypeResult[ScType] - def upperBound: TypeResult[ScType] + def lowerBound: TypeResult + + def upperBound: TypeResult def viewBound: Seq[ScType] = Nil def contextBound: Seq[ScType] = Nil diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala index 489c7a5db04..991d9f25585 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTemplateDefinition.scala @@ -156,7 +156,7 @@ trait ScTemplateDefinition extends ScNamedElement with PsiClassAdapter with Type PsiSuperMethodImplUtil.getVisibleSignatures(this) } - def getTypeWithProjections(thisProjections: Boolean = false): TypeResult[ScType] + def getTypeWithProjections(thisProjections: Boolean = false): TypeResult def members: Seq[ScMember] = extendsBlock.members ++ syntheticMembers def functions: Seq[ScFunction] = extendsBlock.functions diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala index ede54f75f1a..a4ff546b3a0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScConstructorImpl.scala @@ -84,21 +84,21 @@ class ScConstructorImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } - def shapeType(i: Int): TypeResult[ScType] = { + def shapeType(i: Int): TypeResult = { val seq = shapeMultiType(i) if (seq.length == 1) seq.head else Failure("Can't resolve type") } - def shapeMultiType(i: Int): Seq[TypeResult[ScType]] = innerMultiType(i, isShape = true) + def shapeMultiType(i: Int): Seq[TypeResult] = innerMultiType(i, isShape = true) - def multiType(i: Int): Seq[TypeResult[ScType]] = innerMultiType(i, isShape = false) + def multiType(i: Int): Seq[TypeResult] = innerMultiType(i, isShape = false) - private def innerMultiType(i: Int, isShape: Boolean): Seq[TypeResult[ScType]] = { + private def innerMultiType(i: Int, isShape: Boolean): Seq[TypeResult] = { def FAILURE = Failure("Can't resolve type") def workWithResolveResult(constr: PsiMethod, r: ScalaResolveResult, subst: ScSubstitutor, s: ScSimpleTypeElement, - ref: ScStableCodeReferenceElement): TypeResult[ScType] = { + ref: ScStableCodeReferenceElement): TypeResult = { val clazz = constr.containingClass val tp = r.getActualElement match { case ta: ScTypeAliasDefinition => subst.subst(ta.aliasedType.getOrElse(return FAILURE)) @@ -160,10 +160,10 @@ class ScConstructorImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } - def processSimple(s: ScSimpleTypeElement): Seq[TypeResult[ScType]] = { + def processSimple(s: ScSimpleTypeElement): Seq[TypeResult] = { s.reference match { case Some(ref) => - val buffer = new ArrayBuffer[TypeResult[ScType]] + val buffer = new ArrayBuffer[TypeResult] val resolve = if (isShape) ref.shapeResolveConstr else ref.resolveAllConstructors resolve.foreach { case r@ScalaResolveResult(constr: PsiMethod, subst) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScFieldIdImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScFieldIdImpl.scala index 6bdd03021ff..7baac5491fc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScFieldIdImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScFieldIdImpl.scala @@ -13,7 +13,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base._ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScTypedDeclaration, ScValue, ScVariable} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScImportableDeclarationsOwner import org.jetbrains.plugins.scala.lang.psi.stubs.ScFieldIdStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult /** @@ -28,8 +27,8 @@ class ScFieldIdImpl private(stub: ScFieldIdStub, node: ASTNode) override def toString: String = "Field identifier: " + ifReadAllowed(name)("") - def `type`(): TypeResult[ScType] = getParent /*id list*/ .getParent match { - case typed: ScTypedDeclaration => typed.`type` + def `type`(): TypeResult = getParent /*id list*/ .getParent match { + case typed: ScTypedDeclaration => typed.`type`() //partial matching } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala index 918725bc438..5dff750e458 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScInterpolatedStringLiteralImpl.scala @@ -4,7 +4,6 @@ package lang.psi.impl.base import com.intellij.lang.ASTNode import org.jetbrains.plugins.scala.lang.psi.api.base.{InterpolatedStringType, ScInterpolatedStringLiteral} import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScMethodCall, ScReferenceExpression} -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ import scala.meta.intellij.QuasiquoteInferUtil @@ -22,7 +21,7 @@ class ScInterpolatedStringLiteralImpl(node: ASTNode) extends ScLiteralImpl(node) case _ => null } - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { getStringContextExpression match { case Some(mc: ScMethodCall) => mc.getInvokedExpr match { case expr: ScReferenceExpression if QuasiquoteInferUtil.isMetaQQ(expr) => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala index 4a769d9c429..691aede7c1a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScLiteralImpl.scala @@ -37,7 +37,7 @@ class ScLiteralImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScLite override def toString: String = "Literal" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { val child = getFirstChild.getNode val inner = child.getElementType match { case ScalaTokenTypes.kNULL => Null diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala index 55bb67c5930..e32ccd7b1eb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScTypeBoundsOwnerImpl.scala @@ -13,9 +13,9 @@ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} trait ScTypeBoundsOwnerImpl extends ScTypeBoundsOwner { - def lowerBound: TypeResult[ScType] = typeOf(lowerTypeElement, isLower = true) + def lowerBound: TypeResult = typeOf(lowerTypeElement, isLower = true) - def upperBound: TypeResult[ScType] = typeOf(upperTypeElement, isLower = false) + def upperBound: TypeResult = typeOf(upperTypeElement, isLower = false) protected def extractBound(in: ScType, isLower: Boolean): ScType = in @@ -72,7 +72,7 @@ trait ScTypeBoundsOwnerImpl extends ScTypeBoundsOwner { node.getTreeParent.removeRange(node, null) } - private def typeOf(typeElement: Option[ScTypeElement], isLower: Boolean): TypeResult[ScType] = + private def typeOf(typeElement: Option[ScTypeElement], isLower: Boolean): TypeResult = typeElement match { case Some(elem) => elem.`type`().map(extractBound(_, isLower)) case None => Right(if (isLower) api.Nothing else api.Any) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala index e41adbd5215..63de9f70dd2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScCompositePatternImpl.scala @@ -9,7 +9,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** @@ -27,7 +26,7 @@ class ScCompositePatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) w override def toString: String = "CompositePattern" - override def `type`(): TypeResult[ScType] = { + override def `type`(): TypeResult = { this.expectedType match { case Some(expected) => Right(expected) case _ => super.`type`() //Failure diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala index 0cfe56c631a..e399e3b6eeb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScConstructorPatternImpl.scala @@ -71,7 +71,7 @@ class ScConstructorPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) } } - override def `type`(): TypeResult[ScType] = { + override def `type`(): TypeResult = { ref.bind() match { case Some(r) => r.element match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala index cbbe4f86892..fd4e422578b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScInfixPatternImpl.scala @@ -9,7 +9,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** @@ -27,7 +26,7 @@ class ScInfixPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) with override def toString: String = "InfixPattern" - override def `type`(): TypeResult[ScType] = { + override def `type`(): TypeResult = { this.expectedType match { case Some(x) => Right(x) case _ => Failure("cannot define expected type") diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScLiteralPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScLiteralPatternImpl.scala index 7c9ca6e06fa..5396a75577c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScLiteralPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScLiteralPatternImpl.scala @@ -9,7 +9,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult /** @@ -27,5 +26,5 @@ class ScLiteralPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with override def toString: String = "LiteralPattern" - override def `type`(): TypeResult[ScType] = getLiteral.`type`() + override def `type`(): TypeResult = getLiteral.`type`() } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala index d075c0872e1..9c8f45c3a37 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScNamingPatternImpl.scala @@ -12,8 +12,8 @@ import org.jetbrains.plugins.scala.extensions.ifReadAllowed import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ +import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** * @author Alexander Podkhalyuzin @@ -33,7 +33,7 @@ class ScNamingPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with def isWildcard: Boolean = findChildByType[PsiElement](ScalaTokenTypes.tUNDER) != null - override def `type`(): TypeResult[ScType] = { + override def `type`(): TypeResult = { if (getLastChild.isInstanceOf[ScSeqWildcard]) { return this.expectedType match { case Some(x) => Right(x) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScParenthesisedPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScParenthesisedPatternImpl.scala index 3dd43a48052..1fc4662f6f4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScParenthesisedPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScParenthesisedPatternImpl.scala @@ -9,7 +9,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult /** @@ -26,5 +25,5 @@ class ScParenthesisedPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (nod override def toString: String = "PatternInParenthesis" - override def `type`(): TypeResult[ScType] = this.flatMapType(subpattern) + override def `type`(): TypeResult = this.flatMapType(subpattern) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala index 185f679559f..7dc86ca2919 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScReferencePatternImpl.scala @@ -48,7 +48,7 @@ class ScReferencePatternImpl private(stub: ScReferencePatternStub, node: ASTNode override def toString: String = "ReferencePattern: " + ifReadAllowed(name)("") - override def `type`(): TypeResult[ScType] = { + override def `type`(): TypeResult = { this.expectedType match { case Some(x) => Right(x) case _ => Failure("Cannot define expected type") diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScStableReferenceElementPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScStableReferenceElementPatternImpl.scala index 2a44ad24e53..36a917176fe 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScStableReferenceElementPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScStableReferenceElementPatternImpl.scala @@ -9,7 +9,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScStableReferenceElementPattern -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult /** @@ -26,5 +25,5 @@ class ScStableReferenceElementPatternImpl(node : ASTNode) extends ScalaPsiElemen override def toString: String = "StableElementPattern" - override def `type`(): TypeResult[ScType] = this.flatMapType(getReferenceExpression) + override def `type`(): TypeResult = this.flatMapType(getReferenceExpression) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala index ad49c6edb9c..15f59156cdb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScTypedPatternImpl.scala @@ -47,11 +47,11 @@ class ScTypedPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S override def toString: String = "TypedPattern: " + ifReadAllowed(name)("") - override def `type`(): TypeResult[ScType] = { + override def `type`(): TypeResult = { typePattern match { case Some(tp) => if (tp.typeElement == null) return Failure("No type element for type pattern") - val typeElementType: TypeResult[ScType] = + val typeElementType: TypeResult = tp.typeElement.`type`().map { case tp: ScExistentialType => val skolem = tp.quantified diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala index 96d95f70671..25cdc95972a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/patterns/ScWildcardPatternImpl.scala @@ -29,7 +29,7 @@ class ScWildcardPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) wi override def toString: String = "WildcardPattern" - override def `type`(): TypeResult[ScType] = this.expectedType match { + override def `type`(): TypeResult = this.expectedType match { case Some(x) => Right(x) case _ => Failure("cannot determine expected type") } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala index 8e2b2f46b2a..21457632f4d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScCompoundTypeElementImpl.scala @@ -9,15 +9,15 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.types._ +import org.jetbrains.plugins.scala.lang.psi.types.ScCompoundType import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScCompoundType, ScType} /** * @author Alexander Podkhalyuzin */ class ScCompoundTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScCompoundTypeElement { - protected def innerType: TypeResult[ScType] = { + protected def innerType: TypeResult = { val componentsTypes = components.map(_.`type`().getOrAny) val compoundType = refinement.map { r => ScCompoundType.fromPsi(componentsTypes, r.holders, r.types) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala index 8db8da4a74a..b2313f3da63 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScExistentialTypeElementImpl.scala @@ -22,9 +22,9 @@ import _root_.scala.collection.mutable.ListBuffer */ class ScExistentialTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScExistentialTypeElement { - protected def innerType: TypeResult[ScType] = { + protected def innerType: TypeResult = { val q = quantified.`type`() - val problems: ListBuffer[TypeResult[ScType]] = new ListBuffer + val problems: ListBuffer[TypeResult] = new ListBuffer problems += q val wildcards: List[ScExistentialArgument] = { var buff: ListBuffer[ScExistentialArgument] = new ListBuffer diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala index f58a83863ca..218aa934182 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParameterizedTypeElementImpl.scala @@ -149,7 +149,7 @@ class ScParameterizedTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl( case _ => None } - override protected def innerType: TypeResult[ScType] = { + override protected def innerType: TypeResult = { computeDesugarizedType match { case Some(typeElement) => return typeElement.`type`() diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala index d49ab28697e..2fb13638057 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScParenthesisedTypeElementImpl.scala @@ -9,7 +9,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.types._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -18,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ */ class ScParenthesisedTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScParenthesisedTypeElement { - protected def innerType: TypeResult[ScType] = typeElement match { + protected def innerType: TypeResult = typeElement match { case Some(el) => el.`type`() case None => Right(Unit) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala index 1b68839d882..733b4ec4cd8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSelfTypeElementImpl.scala @@ -32,7 +32,7 @@ class ScSelfTypeElementImpl private(stub: ScSelfTypeElementStub, node: ASTNode) def nameId: PsiElement = findChildByType[PsiElement](TokenSets.SELF_TYPE_ID) - def `type`(): TypeResult[ScType] = { + def `type`(): TypeResult = { val parent = PsiTreeUtil.getParentOfType(this, classOf[ScTemplateDefinition]) assert(parent != null) typeElement match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala index 1076313459f..b29fdbb90fc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScSimpleTypeElementImpl.scala @@ -36,13 +36,13 @@ import org.jetbrains.plugins.scala.macroAnnotations.{CachedWithRecursionGuard, M */ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScSimpleTypeElement { - protected def innerType: TypeResult[ScType] = innerNonValueType(inferValueType = true) + protected def innerType: TypeResult = innerNonValueType(inferValueType = true) - override def getTypeNoConstructor: TypeResult[ScType] = innerNonValueType(inferValueType = true, noConstructor = true) + override def getTypeNoConstructor: TypeResult = innerNonValueType(inferValueType = true, noConstructor = true) @CachedWithRecursionGuard(this, Failure("Recursive non value type of type element"), ModCount.getBlockModificationCount) - override def getNonValueType(withUnnecessaryImplicitsUpdate: Boolean = false): TypeResult[ScType] = + override def getNonValueType(withUnnecessaryImplicitsUpdate: Boolean = false): TypeResult = innerNonValueType(inferValueType = false, withUnnecessaryImplicitsUpdate = withUnnecessaryImplicitsUpdate) @volatile @@ -61,7 +61,7 @@ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w implicitParameters } - private def innerNonValueType(inferValueType: Boolean, noConstructor: Boolean = false, withUnnecessaryImplicitsUpdate: Boolean = false): TypeResult[ScType] = { + private def innerNonValueType(inferValueType: Boolean, noConstructor: Boolean = false, withUnnecessaryImplicitsUpdate: Boolean = false): TypeResult = { ProgressManager.checkCanceled() def parametrise(tp: ScType, clazz: PsiClass, subst: ScSubstitutor): ScType = { @@ -287,7 +287,7 @@ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w } val constrRef = ref.isConstructorReference && !noConstructor - def updateImplicitsWithoutLocalTypeInference(r: TypeResult[ScType], ss: ScSubstitutor): TypeResult[ScType] = { + def updateImplicitsWithoutLocalTypeInference(r: TypeResult, ss: ScSubstitutor): TypeResult = { if (withUnnecessaryImplicitsUpdate) { r.map { tp => @@ -363,7 +363,7 @@ class ScSimpleTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w object ScSimpleTypeElementImpl { - def calculateReferenceType(ref: ScStableCodeReferenceElement, shapesOnly: Boolean = false): TypeResult[ScType] = { + def calculateReferenceType(ref: ScStableCodeReferenceElement, shapesOnly: Boolean = false): TypeResult = { import ref.projectContext val (resolvedElement, fromType) = (if (!shapesOnly) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala index 8d14934dd33..6000442b8a3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala @@ -27,7 +27,7 @@ import org.jetbrains.plugins.scala.macroAnnotations.{CachedWithRecursionGuard, M * Date: 13.03.2008 */ class ScTypeProjectionImpl(node: ASTNode) extends ScReferenceElementImpl(node) with ScTypeProjection { - protected def innerType: TypeResult[ScType] = { + protected def innerType: TypeResult = { this.bind() match { case Some(ScalaResolveResult(elem, _)) => typeElement.`type`().map { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala index 127b1f7e6ca..255e5dae100 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeVariableTypeElementImpl.scala @@ -7,16 +7,16 @@ import org.jetbrains.plugins.scala.extensions.ifReadAllowed import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElementImpl import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeVariableTypeElement +import org.jetbrains.plugins.scala.lang.psi.types.ScExistentialArgument import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing} import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScType} /** * @author Alefas * @since 26/09/14. */ class ScTypeVariableTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTypeVariableTypeElement { - override protected def innerType: TypeResult[ScType] = + override protected def innerType: TypeResult = Right(ScExistentialArgument(name, List.empty, Nothing, Any)) override def nameId: PsiElement = findChildByType[PsiElement](ScalaTokenTypes.tIDENTIFIER) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScWildcardTypeElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScWildcardTypeElementImpl.scala index 0569b1bbe1c..af9d91ef3e7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScWildcardTypeElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScWildcardTypeElementImpl.scala @@ -10,7 +10,7 @@ import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.types._ import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult -import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScExistentialType, ScType} +import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScExistentialType} /** * @author Alexander Podkhalyuzin @@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.{ScExistentialArgument, ScExis */ class ScWildcardTypeElementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTypeBoundsOwnerImpl with ScWildcardTypeElement { - protected def innerType: TypeResult[ScType] = { + protected def innerType: TypeResult = { for { lb <- lowerBound ub <- upperBound diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala index 7597ac843e1..d5615dc0379 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala @@ -11,7 +11,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScClassParameter import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScVariable} import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil @@ -26,7 +25,7 @@ import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} class ScAssignStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScAssignStmt { override def toString: String = "AssignStatement" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { getLExpression match { case call: ScMethodCall => call.`type`() case _ => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala index d23eed518be..d32abe86923 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala @@ -13,7 +13,6 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.StdKinds import org.jetbrains.plugins.scala.lang.resolve.processor.ImplicitCompletionProcessor @@ -349,7 +348,7 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S } } - override protected def innerType: TypeResult[ScType] = { + override protected def innerType: TypeResult = { getDesugarizedExpr match { case Some(newExpr) => newExpr.getNonValueType() case None => Failure("Cannot create expression") diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala index a2564b20b3f..d3e175a081a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala @@ -10,9 +10,9 @@ import com.intellij.psi.scope._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, ScParameters} +import org.jetbrains.plugins.scala.lang.psi.types.api import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} /** * @author Alexander Podkhalyuzin @@ -49,7 +49,7 @@ class ScFunctionExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S } } - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { val paramTypes = parameters.map(_.`type`().getOrNothing) val maybeResultType = result.map(_.`type`().getOrAny) val functionType = FunctionType(maybeResultType.getOrElse(api.Unit), paramTypes) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala index ff1c293bfba..0e604ecb73b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala @@ -70,7 +70,7 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } - private def convertReferencedType(typeResult: TypeResult[ScType]): TypeResult[ScType] = { + private def convertReferencedType(typeResult: TypeResult): TypeResult = { var refType = typeResult.getOrElse(return typeResult) if (!refType.isInstanceOf[ScTypePolymorphicType]) refType = processType(refType, isShape = false) refType match { @@ -82,7 +82,7 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } - private def shapeType(typeResult: TypeResult[ScType]): TypeResult[ScType] = { + private def shapeType(typeResult: TypeResult): TypeResult = { var refType = typeResult.getOrElse(return typeResult) if (!refType.isInstanceOf[ScTypePolymorphicType]) refType = processType(refType, isShape = true) refType match { @@ -93,21 +93,21 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { val typeResult = referencedExpr.getNonValueType() convertReferencedType(typeResult) } - def shapeType: TypeResult[ScType] = { - val typeResult: TypeResult[ScType] = referencedExpr match { + def shapeType: TypeResult = { + val typeResult: TypeResult = referencedExpr match { case ref: ScReferenceExpression => ref.shapeType case expr => expr.getNonValueType() } shapeType(typeResult) } - def shapeMultiType: Array[TypeResult[ScType]] = { - val typeResult: Array[TypeResult[ScType]] = referencedExpr match { + def shapeMultiType: Array[TypeResult] = { + val typeResult: Array[TypeResult] = referencedExpr match { case ref: ScReferenceExpression => ref.shapeMultiType case expr => Array(expr.getNonValueType()) } @@ -121,8 +121,8 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } - def multiType: Array[TypeResult[ScType]] = { - val typeResult: Array[TypeResult[ScType]] = referencedExpr match { + def multiType: Array[TypeResult] = { + val typeResult: Array[TypeResult] = referencedExpr match { case ref: ScReferenceExpression => ref.multiType case expr => Array(expr.getNonValueType()) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala index 3f579169c15..3089471e735 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala @@ -10,9 +10,9 @@ import com.intellij.psi.{PsiElement, PsiElementVisitor} import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ +import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** * @author Alexander Podkhalyuzin @@ -66,7 +66,7 @@ class ScIfStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScIfStm Option(rightParenthesis) } - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { (thenBranch, elseBranch) match { case (Some(t), Some(e)) => for (tt <- t.`type`(); et <- e.`type`()) yield { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala index 22a580240f7..91cfa79e938 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala @@ -9,7 +9,6 @@ import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult import scala.collection.Seq @@ -35,7 +34,7 @@ class ScInfixExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScIn } } - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { operation.bind() match { //this is assignment statement: x += 1 equals to x = x + 1 case Some(r) if r.element.name + "=" == operation.refName => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala index 03d070dd403..54c92b369c4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala @@ -27,7 +27,7 @@ class ScMatchStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScMa override def toString: String = "MatchStatement" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { val branchesTypes = getBranches.map(_.`type`().getOrNothing) val branchesLub = branchesTypes.foldLeft(Nothing: ScType)(_.lub(_)) Right(branchesLub) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala index 1a4abead2f3..ccbb7db09cc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScNewTemplateDefinitionImpl.scala @@ -49,7 +49,7 @@ class ScNewTemplateDefinitionImpl private (stub: ScTemplateDefinitionStub, node: case parents: ScClassParents if parents.typeElements.length == 1 => parents }.flatMap(_.constructor) - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { constructor match { case Some(constructor) => constructor.reference match { @@ -141,7 +141,7 @@ class ScNewTemplateDefinitionImpl private (stub: ScTemplateDefinitionStub, node: override def getImplementsListTypes: Array[PsiClassType] = innerExtendsListTypes - def getTypeWithProjections(thisProjections: Boolean = false): TypeResult[ScType] = `type`() //no projections for new template definition + def getTypeWithProjections(thisProjections: Boolean = false): TypeResult = `type`() //no projections for new template definition override def isInheritor(baseClass: PsiClass, deep: Boolean): Boolean = super[ScNewTemplateDefinition].isInheritor(baseClass, deep) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala index 4a38bb7f506..b658150b39a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala @@ -8,7 +8,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** @@ -20,7 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScParenthesisedExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScParenthesisedExpr { override def toString: String = "ExpressionInParenthesis" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { expr match { case Some(x: ScExpression) => val res = x.getNonValueType() diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala index c5efad2d71f..7bed9b22da7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala @@ -182,8 +182,8 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } } // See SCL-3092 - def multiType: Array[TypeResult[ScType]] = { - val buffer = ArrayBuffer[TypeResult[ScType]]() + def multiType: Array[TypeResult] = { + val buffer = ArrayBuffer[TypeResult]() val iterator = multiResolve(incomplete = false).iterator while (iterator.hasNext) { iterator.next() match { @@ -194,22 +194,22 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no buffer.toArray } - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { this.bind() match { case Some(srr) => convertBindToType(srr) case _ => resolveFailure } } - def shapeType: TypeResult[ScType] = { + def shapeType: TypeResult = { shapeResolve match { case Array(bind: ScalaResolveResult) if bind.isApplicable() => convertBindToType(bind) case _ => resolveFailure } } - def shapeMultiType: Array[TypeResult[ScType]] = { - val buffer = ArrayBuffer[TypeResult[ScType]]() + def shapeMultiType: Array[TypeResult] = { + val buffer = ArrayBuffer[TypeResult]() val iterator = shapeResolve.iterator while (iterator.hasNext) { iterator.next() match { @@ -228,7 +228,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no } } - protected def convertBindToType(bind: ScalaResolveResult): TypeResult[ScType] = { + protected def convertBindToType(bind: ScalaResolveResult): TypeResult = { val fromType: Option[ScType] = bind.fromType val unresolvedTypeParameters: Seq[TypeParameter] = bind.unresolvedTypeParameters.getOrElse(Seq.empty) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala index b6063bb268d..680f422ce6f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala @@ -11,7 +11,6 @@ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -29,7 +28,7 @@ class ScReturnStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScR override def toString: String = "ReturnStatement" - protected override def innerType: TypeResult[ScType] = Right(Nothing) + protected override def innerType: TypeResult = Right(Nothing) //Failure("Cannot infer type of `return' expression", Some(this)) def returnKeyword: PsiElement = findChildByType[PsiElement](ScalaTokenTypes.kRETURN) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala index 39146a46da3..fd6bdc2d530 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala @@ -63,7 +63,7 @@ class ScSelfInvocationImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with proc.candidates.toSeq.map(_.element) } - private def workWithBindInternal(bindInternal: Option[PsiElement], i: Int): TypeResult[ScType] = { + private def workWithBindInternal(bindInternal: Option[PsiElement], i: Int): TypeResult = { val (res: ScType, clazz: ScTemplateDefinition) = bindInternal match { case Some(c: ScMethodLike) => val methodType = c.nestedMethodType(i).getOrElse(return Failure("Not enough parameter sections")) @@ -78,16 +78,16 @@ class ScSelfInvocationImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with } } - def shapeType(i: Int): TypeResult[ScType] = { + def shapeType(i: Int): TypeResult = { val option = bindInternal(shapeResolve = true) workWithBindInternal(option, i) } - def shapeMultiType(i: Int): Seq[TypeResult[ScType]] = { + def shapeMultiType(i: Int): Seq[TypeResult] = { bindMultiInternal(shapeResolve = true).map(pe => workWithBindInternal(Some(pe), i)) } - def multiType(i: Int): Seq[TypeResult[ScType]] = { + def multiType(i: Int): Seq[TypeResult] = { bindMultiInternal(shapeResolve = false).map(pe => workWithBindInternal(Some(pe), i)) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala index 6ed695e8520..9144a8406ff 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala @@ -24,7 +24,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScThisReference { override def toString: String = "ThisReference" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { import scala.meta.intellij.psiExt.TemplateDefExt refTemplate match { case Some(td) if td.isMetaAnnotatationImpl => createTypeFromText("scala.meta.Stat", this, null).asTypeResult @@ -56,7 +56,7 @@ class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with } object ScThisReferenceImpl { - def getThisTypeForTypeDefinition(td: ScTemplateDefinition, expr: ScExpression): TypeResult[ScType] = { + def getThisTypeForTypeDefinition(td: ScTemplateDefinition, expr: ScExpression): TypeResult = { import td.projectContext // SLS 6.5: If the expression’s expected type is a stable type, // or C .this occurs as the prefix of a selection, its type is C.this.type, diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala index 45c9345a9fa..9f5a9869d8e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala @@ -8,7 +8,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -26,7 +25,7 @@ class ScThrowStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTh override def toString: String = "ThrowStatement" - protected override def innerType: TypeResult[ScType] = Right(Nothing) + protected override def innerType: TypeResult = Right(Nothing) def body: Option[ScExpression] = findChild(classOf[ScExpression]) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala index e280b5274a9..835ca572b65 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala @@ -11,7 +11,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{Compatibility, ScType, ScTypeExt} +import org.jetbrains.plugins.scala.lang.psi.types.{Compatibility, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.lang.resolve.processor.MethodResolveProcessor import org.jetbrains.plugins.scala.project.ProjectContext @@ -32,7 +32,7 @@ class ScTryStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryS import ScTryStmtImpl._ - protected override def innerType: TypeResult[ScType] = + protected override def innerType: TypeResult = tryBlock.`type`().flatMap { tryBlockType => val maybeExpression = catchBlock.flatMap(_.expression) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala index eee7fdda40e..c28e1f5c779 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala @@ -8,7 +8,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api.{TupleType, Unit} import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -18,7 +17,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScTupleImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTuple { override def toString: String = "Tuple" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { val result = exprs.map(_.`type`().getOrAny) match { case Seq() => Unit case components => TupleType(components) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala index ebbd2515696..4c36960929e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala @@ -8,7 +8,6 @@ import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** @@ -19,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScTypedStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTypedStmt { override def toString: String = "TypedStatement" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { typeElement match { case Some(te) => te.`type`() case None if !expr.isInstanceOf[ScUnderscoreSection] => expr.`type`() diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala index 09417d23a33..1a46ace4d83 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala @@ -25,10 +25,10 @@ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult class ScUnderscoreSectionImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScUnderscoreSection { override def toString: String = "UnderscoreSection" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { bindingExpr match { case Some(ref: ScReferenceExpression) => - def fun(): TypeResult[ScType] = { + def fun(): TypeResult = { ref.getNonValueType().map { case ScTypePolymorphicType(internalType, typeParameters) => ScTypePolymorphicType(ScMethodType(internalType, Nil, isImplicit = false), typeParameters) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala index c8cddf5bfc6..2b2ca97e78b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala @@ -6,7 +6,6 @@ package expr import com.intellij.lang.ASTNode import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -17,5 +16,5 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ class ScUnitExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScUnitExpr { override def toString: String = "UnitExpression" - protected override def innerType: TypeResult[ScType] = Right(Unit) + protected override def innerType: TypeResult = Right(Unit) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala index 736f3843423..de36d220e50 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlExprImpl.scala @@ -20,7 +20,7 @@ class ScXmlExprImpl(node: ASTNode) extends ScalaPsiElementImpl (node) with ScXml override def toString: String = "XmlExpression" - protected override def innerType: TypeResult[ScType] = { + protected override def innerType: TypeResult = { def getType(s: String): ScType = { val typez = ScalaPsiManager.instance(getProject).getCachedClasses(getResolveScope, s).filter(!_.isInstanceOf[ScObject]) if (typez.length != 0) ScalaType.designator(typez(0)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala index e7474452f6a..a5ec448ceb9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/xml/ScXmlPatternImpl.scala @@ -10,7 +10,6 @@ import com.intellij.psi._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScPattern, ScPatterns} import org.jetbrains.plugins.scala.lang.psi.api.expr.xml._ -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -41,7 +40,7 @@ class ScXmlPatternImpl(node: ASTNode) extends ScalaPsiElementImpl (node) with Sc override def toString: String = "XmlPattern" - override def `type`(): TypeResult[ScType] = { + override def `type`(): TypeResult = { val clazz = ScalaPsiManager.instance(getProject).getCachedClass(getResolveScope, "scala.xml.Node").orNull if (clazz == null) return Failure("not found scala.xml.Node") Right(ScDesignatorType(clazz)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala index a36efe52e07..ed12278c142 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDeclarationImpl.scala @@ -11,7 +11,6 @@ import org.jetbrains.plugins.scala.lang.parser.ScalaElementTypes import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScFunctionStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -35,7 +34,7 @@ class ScFunctionDeclarationImpl private (stub: ScFunctionStub, node: ASTNode) override def toString: String = "ScFunctionDeclaration: " + ifReadAllowed(name)("") - override protected def returnTypeInner: TypeResult[ScType] = returnTypeElement match { + override protected def returnTypeInner: TypeResult = returnTypeElement match { case Some(t) => t.`type`() case None => Right(Unit) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala index 2f428682c6b..c02d3fb5fb7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScFunctionDefinitionImpl.scala @@ -18,8 +18,8 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createBlockFromExpr import org.jetbrains.plugins.scala.lang.psi.stubs.ScFunctionStub +import org.jetbrains.plugins.scala.lang.psi.types.api import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} /** * @author Alexander Podkhalyuzin @@ -70,7 +70,7 @@ class ScFunctionDefinitionImpl protected (stub: ScFunctionStub, node: ASTNode) override def toString: String = "ScFunctionDefinition: " + ifReadAllowed(name)("") - override protected def returnTypeInner: TypeResult[ScType] = returnTypeElement match { + override protected def returnTypeInner: TypeResult = returnTypeElement match { case None if !hasAssign => Right(api.Unit) case None => body match { case Some(b) => b.`type`() diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala index 897af91eb8b..bd1982ebc29 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScMacroDefinitionImpl.scala @@ -13,7 +13,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.stubs.ScFunctionStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.Any import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -64,7 +63,7 @@ class ScMacroDefinitionImpl private (stub: ScFunctionStub, node: ASTNode) override def toString: String = "ScMacroDefinition: " + ifReadAllowed(name)("") - override protected def returnTypeInner: TypeResult[ScType] = returnTypeElement match { + override protected def returnTypeInner: TypeResult = returnTypeElement match { case Some(rte: ScTypeElement) => rte.`type`() case None => Right(Any) // TODO look up type from the macro impl. } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala index 1bbdedbe26a..32566651da8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScPatternDefinitionImpl.scala @@ -15,7 +15,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScValueStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** @@ -50,7 +49,7 @@ class ScPatternDefinitionImpl private (stub: ScValueStub, node: ASTNode) def declaredElements: Seq[ScBindingPattern] = bindings - def `type`(): TypeResult[ScType] = { + def `type`(): TypeResult = { typeElement match { case Some(te) => te.`type`() case None if expr.nonEmpty => expr.get.`type`() diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala index d57cebabc3a..4c684a99dfb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScTypeAliasDeclarationImpl.scala @@ -22,7 +22,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createIdentifier import org.jetbrains.plugins.scala.lang.psi.stubs.ScTypeAliasStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.api.{Any, Nothing} import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -53,12 +52,12 @@ class ScTypeAliasDeclarationImpl private (stub: ScTypeAliasStub, node: ASTNode) override def toString: String = "ScTypeAliasDeclaration: " + ifReadAllowed(name)("") - def lowerBound: TypeResult[ScType] = lowerTypeElement match { + def lowerBound: TypeResult = lowerTypeElement match { case Some(te) => te.`type`() case None => Right(Nothing) } - def upperBound: TypeResult[ScType] = upperTypeElement match { + def upperBound: TypeResult = upperTypeElement match { case Some(te) => te.`type`() case None => Right(Any) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala index 880e9e64844..ed3058b35c1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScValueDeclarationImpl.scala @@ -13,7 +13,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base._ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScValueStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** @@ -33,7 +32,7 @@ class ScValueDeclarationImpl private (stub: ScValueStub, node: ASTNode) def declaredElements: Seq[ScFieldId] = getIdList.fieldIds - override def `type`(): TypeResult[ScType] = typeElement match { + override def `type`(): TypeResult = typeElement match { case Some(te) => te.`type`() case None => Failure(ScalaBundle.message("no.type.element.found", getText)) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDeclarationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDeclarationImpl.scala index 9a46e33c19b..49dceeb6108 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDeclarationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDeclarationImpl.scala @@ -13,7 +13,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base._ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScVariableStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult @@ -30,7 +29,7 @@ class ScVariableDeclarationImpl private (stub: ScVariableStub, node: ASTNode) override def toString: String = "ScVariableDeclaration: " + ifReadAllowed(declaredNames.mkString(", "))("") - def `type`(): TypeResult[ScType] = this.flatMapType(typeElement) + def `type`(): TypeResult = this.flatMapType(typeElement) def declaredElements: Seq[ScFieldId] = getIdList.fieldIds diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala index 2aa6b8ad725..9436db4e3b5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/ScVariableDefinitionImpl.scala @@ -15,7 +15,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.psi.api.statements._ import org.jetbrains.plugins.scala.lang.psi.stubs.ScVariableStub -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -47,7 +46,7 @@ class ScVariableDefinitionImpl private (stub: ScVariableStub, node: ASTNode) case ScPatternList(patterns) => patterns.flatMap(_.bindings) } - def `type`(): TypeResult[ScType] = typeElement match { + def `type`(): TypeResult = typeElement match { case Some(te) => te.`type`() case None => expr.map(_.`type`()) .getOrElse(Failure("Cannot infer type without an expression")) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala index a9017bfdac3..a8afa4bc1b8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/statements/params/ScParameterImpl.scala @@ -72,8 +72,8 @@ class ScParameterImpl protected (stub: ScParameterStub, nodeType: ScParamElement def typeElement: Option[ScTypeElement] = byPsiOrStub(paramType.flatMap(_.typeElement.toOption))(_.typeElement) - def `type`(): TypeResult[ScType] = { - def success(t: ScType): TypeResult[ScType] = Right(t) + def `type`(): TypeResult = { + def success(t: ScType): TypeResult = Right(t) //todo: this is very error prone way to calc type, when usually we need real parameter type getStub match { case null => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala index c0d9d385c91..88b278b507c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala @@ -86,7 +86,7 @@ abstract class ScTypeDefinitionImpl protected (stub: ScTemplateDefinitionStub, .exists(isInheritor(_, deep = true)) } - def `type`(): TypeResult[ScType] = { + def `type`(): TypeResult = { val parentClass: ScTemplateDefinition = containingClass if (typeParameters.isEmpty) { if (parentClass != null) { @@ -105,7 +105,7 @@ abstract class ScTypeDefinitionImpl protected (stub: ScTemplateDefinitionStub, } } - def getTypeWithProjections(thisProjections: Boolean = false): TypeResult[ScType] = { + def getTypeWithProjections(thisProjections: Boolean = false): TypeResult = { def args = typeParameters.map(TypeParameterType(_)) def innerType = if (typeParameters.isEmpty) ScalaType.designator(this) else ScParameterizedType(ScalaType.designator(this), args) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala index bd735baf6e1..1dea4351e14 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ImplicitCollector.scala @@ -383,7 +383,7 @@ class ImplicitCollector(place: PsiElement, } } - private def updateNonValueType(nonValueType0: ScType): TypeResult[ScType] = { + private def updateNonValueType(nonValueType0: ScType): TypeResult = { InferUtil.updateAccordingToExpectedType( Right(nonValueType0), fromImplicitParameters = true, diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala index 288fd1acf39..90b913900a1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/implicits/ScImplicitlyConvertible.scala @@ -197,7 +197,7 @@ object ScImplicitlyConvertible { val argumentType = firstParameter.`type`() - def substitute(maybeType: TypeResult[ScType]) = + def substitute(maybeType: TypeResult) = maybeType.map(substitutor.subst) .getOrNothing @@ -248,7 +248,7 @@ object ScImplicitlyConvertible { val nameAndIds = function.typeParameters.map(_.nameAndId).toSet def hasRecursiveTypeParameters(`type`: ScType): Boolean = `type`.hasRecursiveTypeParameters(nameAndIds) - def substitute(maybeType: TypeResult[ScType]) = maybeType + def substitute(maybeType: TypeResult) = maybeType .toOption .map(substitutor.subst) .map(unSubst.subst) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala index 1dbd0d23578..425a4064ff3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightBindingPattern.scala @@ -22,7 +22,7 @@ class ScLightBindingPattern(rt: ScType, val b: ScBindingPattern) override def getParent: PsiElement = b.getParent - override def `type`(): TypeResult[ScType] = Right(rt) + override def `type`(): TypeResult = Right(rt) override def getOriginalElement: PsiElement = super[ScBindingPattern].getOriginalElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala index 471ee21c5dd..d68f9cd3356 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFieldId.scala @@ -32,7 +32,7 @@ class ScLightFieldId(rt: ScType, val f: ScFieldId) override protected def findChildByClassScala[T >: Null <: ScalaPsiElement](clazz: Class[T]): T = throw new UnsupportedOperationException("Operation on light element") - override def `type`(): TypeResult[ScType] = Right(rt) + override def `type`(): TypeResult = Right(rt) override def getParent: PsiElement = f.getParent //to find right context } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala index 3270969bd2c..c230a7ed17c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDeclaration.scala @@ -28,11 +28,11 @@ class ScLightFunctionDeclaration(pTypes: Seq[Seq[ScType]], tParams: Seq[TypePara override def paramClauses: ScParameters = new ScLightParameters(pTypes, fun) - override protected def returnTypeInner: TypeResult[ScType] = Right(rt) + override protected def returnTypeInner: TypeResult = Right(rt) - override def definedReturnType: TypeResult[ScType] = Right(rt) + override def definedReturnType: TypeResult = Right(rt) - override def declaredType: TypeResult[ScType] = Right(rt) + override def declaredType: TypeResult = Right(rt) override def hasExplicitType: Boolean = true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala index 09c22e7a714..d50eded2ab1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightFunctionDefinition.scala @@ -26,11 +26,11 @@ class ScLightFunctionDefinition(pTypes: Seq[Seq[ScType]], tParams: Seq[TypeParam override def paramClauses: ScParameters = new ScLightParameters(pTypes, fun) - override protected def returnTypeInner: TypeResult[ScType] = Right(rt) + override protected def returnTypeInner: TypeResult = Right(rt) - override def definedReturnType: TypeResult[ScType] = Right(rt) + override def definedReturnType: TypeResult = Right(rt) - override def declaredType: TypeResult[ScType] = Right(rt) + override def declaredType: TypeResult = Right(rt) override def hasExplicitType: Boolean = true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala index 9940ad2ccf7..8c9fbfa617e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightParameter.scala @@ -19,7 +19,7 @@ class ScLightParameter(val param: ScParameter, tp: ScType, i: Int) extends LightElement(param.getManager, param.getLanguage) with ScParameter { override def nameId: PsiElement = param.nameId - override def `type`(): TypeResult[ScType] = Right(tp) + override def `type`(): TypeResult = Right(tp) override def deprecatedName: Option[String] = param.deprecatedName diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala index aded82e9150..5f9d087d4c5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDeclaration.scala @@ -8,8 +8,8 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.ScModifierList import org.jetbrains.plugins.scala.lang.psi.api.expr.ScAnnotation import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDeclaration import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParamClause +import org.jetbrains.plugins.scala.lang.psi.types.TypeAliasSignature import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, TypeAliasSignature} /** * @author Alefas @@ -21,9 +21,9 @@ class ScLightTypeAliasDeclaration(s: TypeAliasSignature, val ta: ScTypeAliasDecl override def nameId: PsiElement = ta.nameId - override def upperBound: TypeResult[ScType] = Right(s.upperBound) + override def upperBound: TypeResult = Right(s.upperBound) - override def lowerBound: TypeResult[ScType] = Right(s.lowerBound) + override def lowerBound: TypeResult = Right(s.lowerBound) override def getOriginalElement: PsiElement = super[ScTypeAliasDeclaration].getOriginalElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala index aefe72966b3..642a4636089 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeAliasDefinition.scala @@ -9,8 +9,8 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScAnnotation import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParamClause +import org.jetbrains.plugins.scala.lang.psi.types.TypeAliasSignature import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, TypeAliasSignature} /** * @author Alefas @@ -22,11 +22,11 @@ class ScLightTypeAliasDefinition(s: TypeAliasSignature, val ta: ScTypeAliasDefin override def nameId: PsiElement = ta.nameId - override def upperBound: TypeResult[ScType] = Right(s.upperBound) + override def upperBound: TypeResult = Right(s.upperBound) - override def lowerBound: TypeResult[ScType] = Right(s.lowerBound) + override def lowerBound: TypeResult = Right(s.lowerBound) - override def aliasedType: TypeResult[ScType] = Right(s.lowerBound) + override def aliasedType: TypeResult = Right(s.lowerBound) override def aliasedTypeElement: Option[ScTypeElement] = ta.aliasedTypeElement diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala index 61def783037..71a48ee7247 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/light/scala/ScLightTypeParam.scala @@ -8,9 +8,9 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeParametersOwner import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.PsiClassFake +import org.jetbrains.plugins.scala.lang.psi.types.api import org.jetbrains.plugins.scala.lang.psi.types.api.TypeParameter import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, api} import org.jetbrains.plugins.scala.project.ProjectContext /** @@ -26,9 +26,9 @@ class ScDelegatingLightTypeParam(t: TypeParameter, val tParam: ScTypeParam) override val typeParamId: Long = tParam.typeParamId - override def upperBound: TypeResult[ScType] = Right(t.upperType) + override def upperBound: TypeResult = Right(t.upperType) - override def lowerBound: TypeResult[ScType] = Right(t.lowerType) + override def lowerBound: TypeResult = Right(t.lowerType) override def getIndex: Int = tParam.getIndex @@ -93,9 +93,9 @@ class ScExistentialLightTypeParam(override val name: String)(implicit pc: Projec override def isHigherKindedTypeParameter: Boolean = false - override def lowerBound: TypeResult[ScType] = Right(api.Nothing) + override def lowerBound: TypeResult = Right(api.Nothing) - override def upperBound: TypeResult[ScType] = Right(api.Any) + override def upperBound: TypeResult = Right(api.Any) override def toString: String = name diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala index 56a287bb302..fc1c6aeaf3e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/Compatibility.scala @@ -51,11 +51,11 @@ object Compatibility { @CachedWithRecursionGuard(place, (Right(typez), Set.empty), ModCount.getBlockModificationCount) - private def eval(typez: ScType, expectedOption: Option[ScType]): (TypeResult[ScType], Set[ImportUsed]) = { + private def eval(typez: ScType, expectedOption: Option[ScType]): (TypeResult, Set[ImportUsed]) = { expectedOption match { case Some(expected) if typez.conforms(expected) => (Right(typez), Set.empty) case Some(expected) => - val defaultResult: (TypeResult[ScType], Set[ImportUsed]) = (Right(typez), Set.empty) + val defaultResult: (TypeResult, Set[ImportUsed]) = (Right(typez), Set.empty) implicit val elementScope = place.elementScope val functionType = FunctionType(expected, Seq(typez)) @@ -87,14 +87,14 @@ object Compatibility { } def getTypeAfterImplicitConversion(checkImplicits: Boolean, isShape: Boolean, - expectedOption: Option[ScType]): (TypeResult[ScType], collection.Set[ImportUsed]) = { + expectedOption: Option[ScType]): (TypeResult, collection.Set[ImportUsed]) = { if (expr != null) { val expressionTypeResult = expr.getTypeAfterImplicitConversion(checkImplicits, isShape, expectedOption) (expressionTypeResult.tr, expressionTypeResult.importsUsed) } else { import scala.collection.Set - def default: (TypeResult[ScType], Set[ImportUsed]) = (Right(typez), Set.empty) + def default: (TypeResult, Set[ImportUsed]) = (Right(typez), Set.empty) if (isShape || !checkImplicits || place == null) default else eval(typez, expectedOption) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala index 79624704622..cec6a221ed5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/ScalaType.scala @@ -31,7 +31,7 @@ object ScalaType { // TODO perhaps we need to choose the lower bound if we are in a contravariant position. We get away // with this as we currently only rely on this method to determine covariant types: the parameter // types of FunctionN, or the elements of TupleN - def expandAliases(tp: ScType, visited: Set[ScType] = Set.empty): TypeResult[ScType] = { + def expandAliases(tp: ScType, visited: Set[ScType] = Set.empty): TypeResult = { if (visited contains tp) return Right(tp) tp match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Typeable.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Typeable.scala index b36f53b2f9b..b733d00b4a8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Typeable.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Typeable.scala @@ -3,7 +3,7 @@ package types package result trait Typeable { - def `type`(): TypeResult[ScType] + def `type`(): TypeResult } object Typeable { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala index 610783c4008..1536498d6d1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala @@ -8,13 +8,13 @@ import org.jetbrains.plugins.scala.project.ProjectContext package object result { type Failure = (String, ProjectContext) - type TypeResult[T <: ScType] = Either[Failure, ScType] + type TypeResult = Either[Failure, ScType] object Failure { def apply(cause: String) - (implicit context: ProjectContext): TypeResult[ScType] = Left(cause, context) + (implicit context: ProjectContext): TypeResult = Left(cause, context) - def unapply(result: TypeResult[ScType]): Option[String] = result match { + def unapply(result: TypeResult): Option[String] = result match { case Left((cause, _)) => Some(cause) case _ => None } @@ -22,13 +22,13 @@ package object result { implicit class OptionTypeExt(val maybeRight: Option[ScType]) extends AnyVal { - def asTypeResult(implicit context: ProjectContext): TypeResult[ScType] = maybeRight match { + def asTypeResult(implicit context: ProjectContext): TypeResult = maybeRight match { case Some(result) => Right(result) case None => Failure("") } } - implicit class TypeResultExt(val result: TypeResult[ScType]) extends AnyVal { + implicit class TypeResultExt(val result: TypeResult) extends AnyVal { def get: ScType = getOrApiType(null) @@ -46,11 +46,11 @@ package object result { implicit class TypeableExt(val typeable: ScalaPsiElement with Typeable) extends AnyVal { def flatMap[E <: ScalaPsiElement](maybeElement: Option[E]) - (function: E => TypeResult[ScType]): TypeResult[ScType] = + (function: E => TypeResult): TypeResult = maybeElement.map(function) .getOrElse(Failure("No element found")) - def flatMapType[E <: ScalaPsiElement with Typeable](maybeElement: Option[E]): TypeResult[ScType] = + def flatMapType[E <: ScalaPsiElement with Typeable](maybeElement: Option[E]): TypeResult = flatMap(maybeElement)(_.`type`()) private implicit def context: ProjectContext = typeable diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScTypeUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScTypeUtil.scala index 99cf9b2f548..a447a2ec0a1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScTypeUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScTypeUtil.scala @@ -21,5 +21,5 @@ object ScTypeUtil { case t => t } - case class AliasType(ta: ScTypeAlias, lower: TypeResult[ScType], upper: TypeResult[ScType]) + case class AliasType(ta: ScTypeAlias, lower: TypeResult, upper: TypeResult) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala index ec92450b3e6..984f1582d61 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/BaseProcessor.scala @@ -185,7 +185,7 @@ abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) case ScDesignatorType(o: ScObject) => processElement(o, ScSubstitutor.empty, place, state, visitedProjections = visitedProjections, visitedTypeParameter = visitedTypeParameter) case ScDesignatorType(e: ScTypedDefinition) if place.isInstanceOf[ScTypeProjection] => - val result: TypeResult[ScType] = + val result: TypeResult = e match { case p: ScParameter => p.getRealParameterType case _ => e.`type`() @@ -279,7 +279,7 @@ abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) case clazz: PsiClass => TypeDefinitionMembers.processDeclarations(clazz, BaseProcessor.this, state.put(ScSubstitutor.key, newSubst), null, place) case des: ScTypedDefinition => - val typeResult: TypeResult[ScType] = + val typeResult: TypeResult = des match { case p: ScParameter => p.getRealParameterType case _ => des.`type`() diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala index 554d1a5f0e4..0bf7898a8ad 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/ScEquivalenceUtil.scala @@ -5,8 +5,8 @@ import com.intellij.psi.{PsiClass, PsiElement, PsiPackage} import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAlias import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject +import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult -import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** * @author Alexander Podkhalyuzin @@ -43,7 +43,7 @@ object ScEquivalenceUtil { } private def areTypeAliasesEquivalent(ta1: ScTypeAlias, ta2: ScTypeAlias): Boolean = { - def equiv(tr1: TypeResult[ScType], tr2: TypeResult[ScType]): Boolean = + def equiv(tr1: TypeResult, tr2: TypeResult): Boolean = (tr1, tr2) match { case (Right(left), Right(right)) => left.equiv(right) case _ => false diff --git a/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala b/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala index 9bbeb60450e..212b3c4a275 100644 --- a/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala +++ b/scala/scala-impl/src/scala/meta/intellij/QuasiquoteInferUtil.scala @@ -9,7 +9,6 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createTypeFromText import org.jetbrains.plugins.scala.lang.psi.impl.base.patterns.ScInterpolationPatternImpl import org.jetbrains.plugins.scala.lang.psi.impl.expr.ScMethodCallImpl -import org.jetbrains.plugins.scala.lang.psi.types.ScType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.Parameter import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult @@ -69,7 +68,7 @@ object QuasiquoteInferUtil extends scala.meta.quasiquotes.QuasiquoteParsers { } } - def getMetaQQExprType(pat: ScInterpolatedStringLiteral): TypeResult[ScType] = { + def getMetaQQExprType(pat: ScInterpolatedStringLiteral): TypeResult = { ProgressManager.checkCanceled() implicit val context: ProjectContext = pat.projectContext diff --git a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala index c21b4034250..95278d92e3a 100644 --- a/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TypeAdapter.scala @@ -94,7 +94,7 @@ trait TypeAdapter { } } - def toType(tr: TypeResult[ptype.ScType]): m.Type = { + def toType(tr: TypeResult): m.Type = { import org.jetbrains.plugins.scala.lang.psi.types.result._ tr match { case Right(res) => toType(res) @@ -258,7 +258,7 @@ trait TypeAdapter { m.Type.Bounds(tp.lowerTypeElement.map(toType), tp.upperTypeElement.map(toType))//.setTypechecked } - def returnType(tr: ptype.result.TypeResult[ptype.ScType]): m.Type = { + def returnType(tr: ptype.result.TypeResult): m.Type = { import ptype.result._ tr match { case Right(t) => toType(t) diff --git a/scala/scala-impl/src/scala/meta/trees/Utils.scala b/scala/scala-impl/src/scala/meta/trees/Utils.scala index 8abc1fef542..c1b51775e67 100644 --- a/scala/scala-impl/src/scala/meta/trees/Utils.scala +++ b/scala/scala-impl/src/scala/meta/trees/Utils.scala @@ -107,7 +107,7 @@ trait Utils { implicit class RichScExpression(expr: ScExpression) { import expr.projectContext - def withSubstitutionCaching[T](fun: TypeResult[ScType] => T): T = { + def withSubstitutionCaching[T](fun: TypeResult => T): T = { if (dumbMode) { val maybeType = expr match { case ts: ScTypedStmt => createTypeFromText(ts.getText, expr, null) @@ -142,7 +142,7 @@ trait Utils { implicit class RichScTypedDefinition(expr: ScTypedDefinition) { import expr.projectContext - def getTypeWithCachedSubst: TypeResult[ScType] = { + def getTypeWithCachedSubst: TypeResult = { if (dumbMode) { expr match { case ts: ScTypedStmt => createTypeFromText(ts.getText, expr, null).asTypeResult From 3667cac1e8d6bb62d4a7d60e71e802e45006ad13 Mon Sep 17 00:00:00 2001 From: Roman Shein Date: Mon, 16 Oct 2017 13:32:28 +0300 Subject: [PATCH 054/141] Moved tests (accidentally violated directory hierarchy) --- .../utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala | 2 +- .../utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala | 2 +- .../utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala | 2 +- .../{ => scala2_11}/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/{ => scala2_11}/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala (74%) rename scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/{ => scala2_11}/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala (73%) rename scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/{ => scala2_11}/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala (93%) rename scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/{ => scala2_11}/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala (86%) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala similarity index 74% rename from scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala rename to scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala index 0419b2280a4..bf9563c7636 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala @@ -1,4 +1,4 @@ -package org.jetbrains.plugins.scala.testingSupport.utest.utest_0_5_4 +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_11.utest_0_5_4 import org.jetbrains.plugins.scala.testingSupport.utest.UTestPackageTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala similarity index 73% rename from scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala rename to scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala index 6e6f265a80e..bb105c7f26b 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala @@ -1,4 +1,4 @@ -package org.jetbrains.plugins.scala.testingSupport.utest.utest_0_5_4 +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_11.utest_0_5_4 import org.jetbrains.plugins.scala.testingSupport.utest.UTestSimpleTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala similarity index 93% rename from scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala rename to scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala index 93997472912..b5a4f246160 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala @@ -1,4 +1,4 @@ -package org.jetbrains.plugins.scala.testingSupport.utest.utest_0_5_4 +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_11.utest_0_5_4 import org.jetbrains.plugins.scala.testingSupport.utest.UTestStaticStringTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala similarity index 86% rename from scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala rename to scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala index ad44d6913cb..fd3c1db16e2 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestTestBase_2_11_0_5_4.scala @@ -1,4 +1,4 @@ -package org.jetbrains.plugins.scala.testingSupport.utest.utest_0_5_4 +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_11.utest_0_5_4 import org.jetbrains.plugins.scala.base.libraryLoaders.{ThirdPartyLibraryLoader, UTestLoader} import org.jetbrains.plugins.scala.testingSupport.utest.UTestTestCase From 3bd0114db6e110840f562a846bc3fae88bf55edd Mon Sep 17 00:00:00 2001 From: Roman Shein Date: Thu, 26 Oct 2017 17:31:00 +0300 Subject: [PATCH 055/141] #SCL-12800 fixed Added more tests for testing support --- .../test/AbstractTestRunConfiguration.scala | 30 ++++---- .../test/structureView/TestNodeProvider.scala | 16 ++-- .../ThirdPartyLibraryLoader.scala | 3 +- .../Scalatest2_12_3_0_4_Base.scala | 20 +++++ ...latest2_12_3_0_4_DuplicateConfigTest.scala | 12 +++ .../Scalatest2_12_3_0_4_FindersApiTest.scala | 12 +++ .../Scalatest2_12_3_0_4_GoToSourceTest.scala | 12 +++ .../Scalatest2_12_3_0_4_IngoredTestTest.scala | 12 +++ ...latest2_12_3_0_4_NestedSameNamesTest.scala | 12 +++ .../Scalatest2_12_3_0_4_PackageTest.scala | 12 +++ ...calatest2_12_3_0_4_SelectedTestsTest.scala | 12 +++ ...test2_12_3_0_4_SingleTestTestDynamic.scala | 14 ++++ ...test2_12_3_0_4_SpecialCharactersTest.scala | 12 +++ ...Scalatest2_12_3_0_4_StaticStringTest.scala | 14 ++++ ...calatest2_12_3_0_4_StructureViewTest.scala | 14 ++++ .../Scalatest2_12_3_0_4_WholeSuiteTest.scala | 12 +++ ...ecs2_2_12_4_0_0FileStructureViewTest.scala | 12 +++ .../Specs2_2_12_4_0_0_Base.scala | 75 +++++++++++++++++++ ...pecs2_2_12_4_0_0_DuplicateConfigTest.scala | 12 +++ .../Specs2_2_12_4_0_0_GoToSourceTest.scala | 12 +++ .../Specs2_2_12_4_0_0_ObjectSpecTest.scala | 12 +++ .../Specs2_2_12_4_0_0_PackageTest.scala | 12 +++ .../Specs2_2_12_4_0_0_RegExpTest.scala | 12 +++ .../Specs2_2_12_4_0_0_SCL7228Test.scala | 12 +++ .../Specs2_2_12_4_0_0_SingleTestTest.scala | 12 +++ ...cs2_2_12_4_0_0_SingleTestTestDynamic.scala | 13 ++++ ...cs2_2_12_4_0_0_SpecialCharactersTest.scala | 12 +++ .../Specs2_2_12_4_0_0_StaticStringTest.scala | 12 +++ .../Specs2_2_12_4_0_0_WholeSuiteTest.scala | 12 +++ .../UTestPackageTest_2_11_0_5_4.scala | 3 + .../UTestSimpleTest_2_11_0_5_4.scala | 3 + .../UTestStaticStringTest_2_11_0_5_4.scala | 3 + .../UTestPackageTest_2_12_0_5_4.scala | 14 ++++ .../UTestSimpleTest_2_12_0_5_4.scala | 14 ++++ .../UTestStaticStringTest_2_12_0_5_4.scala | 46 ++++++++++++ .../UTestTestBase_2_12_0_5_4.scala | 21 ++++++ 36 files changed, 520 insertions(+), 23 deletions(-) create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_DuplicateConfigTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_FindersApiTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_GoToSourceTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_IngoredTestTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_NestedSameNamesTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_PackageTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SelectedTestsTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SingleTestTestDynamic.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SpecialCharactersTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StaticStringTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StructureViewTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_WholeSuiteTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0FileStructureViewTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_DuplicateConfigTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_GoToSourceTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_ObjectSpecTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_PackageTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_RegExpTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SCL7228Test.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTestDynamic.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SpecialCharactersTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_StaticStringTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_WholeSuiteTest.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestPackageTest_2_12_0_5_4.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestSimpleTest_2_12_0_5_4.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestStaticStringTest_2_12_0_5_4.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestTestBase_2_12_0_5_4.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala index 53a3f23166f..daa9deadc5d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala @@ -50,7 +50,7 @@ import org.jetbrains.sbt.shell.{SbtProcessManager, SbtShellCommunication, Settin import scala.annotation.tailrec import scala.beans.BeanProperty -import scala.collection.JavaConversions._ +import scala.collection.JavaConverters._ import scala.collection.mutable import scala.collection.mutable.ArrayBuffer import scala.concurrent.ExecutionContext.Implicits.global @@ -66,7 +66,7 @@ abstract class AbstractTestRunConfiguration(val project: Project, val name: String, val configurationProducer: TestConfigurationProducer, private var envs: java.util.Map[String, String] = - new mutable.HashMap[String, String](), + new java.util.HashMap[String, String](), private var addIntegrationTestsClasspath: Boolean = false) extends ModuleBasedConfiguration[RunConfigurationModule](name, new RunConfigurationModule(project), @@ -257,7 +257,8 @@ abstract class AbstractTestRunConfiguration(val project: Project, getConfigurationModule.getModule } - def getValidModules: java.util.List[Module] = getProject.modulesWithScala + def getValidModules: java.util.List[Module] = + getProject.modulesWithScala.asJava def classKey: String = "-s" def testNameKey: String = "-testName" @@ -410,8 +411,11 @@ abstract class AbstractTestRunConfiguration(val project: Project, protected def findTestsByFqnCondition(classCondition: String => Boolean, testCondition: String => Boolean, classToTests: mutable.Map[String, Set[String]]): Unit = { - val suiteClasses = AllClassesSearch.search(getSearchScope.intersectWith(GlobalSearchScopesCore.projectTestScope(project)), - project).filter(c => classCondition(c.qualifiedName)).filterNot(isInvalidSuite) + val suiteClasses = AllClassesSearch + .search(getSearchScope.intersectWith(GlobalSearchScopesCore.projectTestScope(project)), project) + .asScala + .filter(c => classCondition(c.qualifiedName)).filterNot(isInvalidSuite) + //we don't care about linearization here, so can process in arbitrary order @tailrec def getTestNames(classesToVisit: List[ScTypeDefinition], visited: Set[ScTypeDefinition] = Set.empty, @@ -585,11 +589,11 @@ abstract class AbstractTestRunConfiguration(val project: Project, vmParams = PathMacroManager.getInstance(module).expandPath(vmParams) } - val mutableEnvVariables = new mutable.HashMap[String, String]() ++ getEnvVariables + val mutableEnvVariables = getEnvVariables params.setEnv(mutableEnvVariables) //expand environment variables in vmParams - for (entry <- params.getEnv.entrySet) { + params.getEnv.entrySet.forEach { entry => vmParams = StringUtil.replace(vmParams, "$" + entry.getKey + "$", entry.getValue, false) } @@ -641,13 +645,13 @@ abstract class AbstractTestRunConfiguration(val project: Project, val printer: PrintStream = new PrintStream(outputStream) params.getProgramParametersList.add("@" + fileWithParams.getPath) - (printer.println, _ => printer.close()) + (printer.println, (_: Unit) => printer.close()) } catch { case ioException: IOException => throw new ExecutionException("Failed to create dynamic classpath file with command-line args.", ioException) } } else { - (params.getProgramParametersList.add(_), _ => ()) + (params.getProgramParametersList.add(_), (_: Unit) => ()) } addParametersString(getTestArgs, myAdd) @@ -763,8 +767,8 @@ abstract class AbstractTestRunConfiguration(val project: Project, JDOMExternalizer.write(element, "useUiWithSbt", useUiWithSbt) val classRegexps: Map[String, String] = Map(zippedRegexps.zipWithIndex.map{case ((c, _), i) => (i.toString, c)}:_*) val testRegexps: Map[String, String] = Map(zippedRegexps.zipWithIndex.map{case ((_, t), i) => (i.toString, t)}:_*) - JDOMExternalizer.writeMap(element, classRegexps, "classRegexps", "pattern") - JDOMExternalizer.writeMap(element, testRegexps, "testRegexps", "pattern") + JDOMExternalizer.writeMap(element, classRegexps.asJava, "classRegexps", "pattern") + JDOMExternalizer.writeMap(element, testRegexps.asJava, "testRegexps", "pattern") JDOMExternalizer.writeMap(element, envs, "envs", "envVar") PathMacroManager.getInstance(getProject).collapsePathsRecursively(element) } @@ -785,10 +789,10 @@ abstract class AbstractTestRunConfiguration(val project: Project, testArgs = JDOMExternalizer.readString(element, "params") workingDirectory = JDOMExternalizer.readString(element, "workingDirectory") val classRegexpsMap = mutable.Map[String, String]() - JDOMExternalizer.readMap(element, classRegexpsMap, "classRegexps", "pattern") + JDOMExternalizer.readMap(element, classRegexpsMap.asJava, "classRegexps", "pattern") classRegexps = loadRegexps(classRegexpsMap) val testRegexpssMap = mutable.Map[String, String]() - JDOMExternalizer.readMap(element, testRegexpssMap, "testRegexps", "pattern") + JDOMExternalizer.readMap(element, testRegexpssMap.asJava, "testRegexps", "pattern") testRegexps = loadRegexps(testRegexpssMap) JDOMExternalizer.readMap(element, envs, "envs", "envVar") val s = JDOMExternalizer.readString(element, "searchForTest") diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/structureView/TestNodeProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/structureView/TestNodeProvider.scala index 840e71da394..49d2ff87a63 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/structureView/TestNodeProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/structureView/TestNodeProvider.scala @@ -155,7 +155,7 @@ object TestNodeProvider { expr.getNode.getFirstChildNode.getText private def processChildren[T <: PsiElement](children: Array[T], - processFun: (T, Project) => Option[TestStructureViewElement], + processFun: (T, Project) => Option[TreeElement], project: Project): Array[TreeElement] = { children.map(element => processFun(element, project)).filter(_.isDefined).map(_.get) } @@ -432,7 +432,7 @@ object TestNodeProvider { //-----uTest----- private def extractUTest(expr: ScMethodCall, project: Project): util.Collection[TreeElement] = { - def extractUTestInner(expr: PsiElement, project: Project): Option[TestStructureViewElement] = { + def extractUTestInner(expr: PsiElement, project: Project): Option[TreeElement] = { if (isUTestInfixExpr(expr)) { Some(new TestStructureViewElement(expr, getInfixExprTestName(expr.asInstanceOf[ScInfixExpr]), processChildren(getInnerExprs(expr), extractUTestInner, project))) @@ -442,10 +442,10 @@ object TestNodeProvider { } else None } if (isUTestSuiteApplyCall(expr) || isUTestTestsCall(expr)) { - import scala.collection.JavaConversions._ + import scala.collection.JavaConverters._ expr.args.findFirstChildByType(ScalaElementTypes.BLOCK_EXPR) match { case blockExpr: ScBlockExpr => (for (methodExpr <- blockExpr.children if methodExpr.isInstanceOf[ScInfixExpr] || methodExpr.isInstanceOf[ScMethodCall]) - yield extractUTestInner(methodExpr, project)).filter(_.isDefined).map(_.get).toList + yield extractUTestInner(methodExpr, project)).filter(_.isDefined).map(_.get).toList.asJava case _ => new util.ArrayList[TreeElement] } } else new util.ArrayList[TreeElement]() @@ -537,16 +537,16 @@ object TestNodeProvider { } } val suiteName = aSuite.getQualifiedName - import scala.collection.JavaConversions._ + import scala.collection.JavaConverters._ val nodeProvider = new TestNodeProvider getTestLeaves(configurationProducer match { case _: UTestConfigurationProducer => - new ScalaTypeDefinitionStructureViewElement(aSuite).getChildren.toList flatMap { - case scVal: ScalaValueStructureViewElement if !scVal.isInherited => nodeProvider.provideNodes(scVal).toList + new ScalaTypeDefinitionStructureViewElement(aSuite).getChildren flatMap { + case scVal: ScalaValueStructureViewElement if !scVal.isInherited => nodeProvider.provideNodes(scVal).asScala case _ => List.empty } case _ => - nodeProvider.provideNodes(new ScalaTypeDefinitionStructureViewElement(aSuite)) + nodeProvider.provideNodes(new ScalaTypeDefinitionStructureViewElement(aSuite)).asScala }).map { e => Option(configurationProducer.getLocationClassAndTest(new PsiLocation(e.psiElement))) filter { case (suite, testName) => diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index 68a9997c23d..f34cc2a4f9d 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -120,10 +120,9 @@ case class ScalaTestLoader(override val version: String, override val vendor: String = "org.scalatest" } -case class ScalaXmlLoader()(implicit val module: Module) extends IvyLibraryLoaderAdapter { +case class ScalaXmlLoader(override val version: String = "1.0.1")(implicit val module: Module) extends IvyLibraryLoaderAdapter { override val name: String = "scala-xml" override val vendor: String = "org.scala-lang.modules" - override val version: String = "1.0.1" override val ivyType: IvyType = Bundles } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala new file mode 100644 index 00000000000..6fc2770eb5e --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala @@ -0,0 +1,20 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import com.intellij.openapi.module.Module +import org.jetbrains.plugins.scala.base.libraryLoaders._ +import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_12} +import org.jetbrains.plugins.scala.testingSupport.scalatest.ScalaTestTestCase + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +abstract class Scalatest2_12_3_0_4_Base extends ScalaTestTestCase { + + override implicit val version: ScalaVersion = Scala_2_12 + + override protected def additionalLibraries: Seq[ThirdPartyLibraryLoader] = { + implicit val module: Module = getModule + Seq(ScalaTestLoader("3.0.4", IvyLibraryLoader.Bundles), ScalaXmlLoader("1.0.5"), ScalacticLoader("3.0.4", IvyLibraryLoader.Bundles)) + } +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_DuplicateConfigTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_DuplicateConfigTest.scala new file mode 100644 index 00000000000..4a98c1a7933 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_DuplicateConfigTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.ScalaTestDuplicateConfigTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_DuplicateConfigTest extends Scalatest2_12_3_0_4_Base with ScalaTestDuplicateConfigTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_FindersApiTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_FindersApiTest.scala new file mode 100644 index 00000000000..449381989ae --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_FindersApiTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.finders.FindersApiTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_FindersApiTest extends Scalatest2_12_3_0_4_Base with FindersApiTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_GoToSourceTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_GoToSourceTest.scala new file mode 100644 index 00000000000..d1cfb4820ba --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_GoToSourceTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.ScalaTest2GoToSourceTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_GoToSourceTest extends Scalatest2_12_3_0_4_Base with ScalaTest2GoToSourceTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_IngoredTestTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_IngoredTestTest.scala new file mode 100644 index 00000000000..c4f8188ed27 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_IngoredTestTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.IgnoredSpecTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_IngoredTestTest extends Scalatest2_12_3_0_4_Base with IgnoredSpecTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_NestedSameNamesTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_NestedSameNamesTest.scala new file mode 100644 index 00000000000..b5c53741771 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_NestedSameNamesTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.NestedSameNamesTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_NestedSameNamesTest extends Scalatest2_12_3_0_4_Base with NestedSameNamesTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_PackageTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_PackageTest.scala new file mode 100644 index 00000000000..99a9e964d12 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_PackageTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.ScalaTestPackageTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_PackageTest extends Scalatest2_12_3_0_4_Base with ScalaTestPackageTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SelectedTestsTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SelectedTestsTest.scala new file mode 100644 index 00000000000..b33e8a7431a --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SelectedTestsTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.singleTest.ScalaTestSelectedTests +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_SelectedTestsTest extends Scalatest2_12_3_0_4_Base with ScalaTestSelectedTests diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SingleTestTestDynamic.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SingleTestTestDynamic.scala new file mode 100644 index 00000000000..92bc2cfcbba --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SingleTestTestDynamic.scala @@ -0,0 +1,14 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.singleTest.FunSuiteSingleTestTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_SingleTestTestDynamic extends Scalatest2_12_3_0_4_Base with FunSuiteSingleTestTest { + override val useDynamicClassPath = true +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SpecialCharactersTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SpecialCharactersTest.scala new file mode 100644 index 00000000000..2bfbe0095fb --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_SpecialCharactersTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.SpecialCharactersTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_SpecialCharactersTest extends Scalatest2_12_3_0_4_Base with SpecialCharactersTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StaticStringTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StaticStringTest.scala new file mode 100644 index 00000000000..acae164c8f4 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StaticStringTest.scala @@ -0,0 +1,14 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.staticStringTest._ +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_StaticStringTest extends Scalatest2_12_3_0_4_Base with FeatureSpecStaticStringTest with + FlatSpecStaticStringTest with FreeSpecStaticStringTest with FunSpecStaticStringTest with FunSuiteStaticStringTest with + PropSpecStaticStringTest with WordSpecStaticStringTest with MethodsStaticStringTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StructureViewTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StructureViewTest.scala new file mode 100644 index 00000000000..fff163ab61b --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_StructureViewTest.scala @@ -0,0 +1,14 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.fileStructureView._ +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_StructureViewTest extends Scalatest2_12_3_0_4_Base with FeatureSpecFileStructureViewTest +with FlatSpecFileStructureViewTest with FreeSpecFileStructureViewTest with FunSuiteFileStructureViewTest +with PropSpecFileStructureViewTest with WordSpecFileStructureViewTest with FunSpecFileStructureViewTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_WholeSuiteTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_WholeSuiteTest.scala new file mode 100644 index 00000000000..40285a7bf93 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_WholeSuiteTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.scalatest.scala2_12.scalatest3_0_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.scalatest.ScalaTestWholeSuiteTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 10.03.2017 + */ +@Category(Array(classOf[SlowTests])) +class Scalatest2_12_3_0_4_WholeSuiteTest extends Scalatest2_12_3_0_4_Base with ScalaTestWholeSuiteTest diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0FileStructureViewTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0FileStructureViewTest.scala new file mode 100644 index 00000000000..c5beca98df7 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0FileStructureViewTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2FileStructureViewTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 20.04.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0FileStructureViewTest extends Specs2FileStructureViewTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala new file mode 100644 index 00000000000..fc86f888c0f --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala @@ -0,0 +1,75 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import com.intellij.openapi.module.Module +import org.jetbrains.plugins.scala.base.libraryLoaders.IvyLibraryLoader.{Bundles, IvyType} +import org.jetbrains.plugins.scala.base.libraryLoaders._ +import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_12} +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2TestCase + +/** + * @author Roman.Shein + * @since 11.01.2015. + */ +trait Specs2_2_12_4_0_0_Base extends Specs2TestCase { + + override implicit val version: ScalaVersion = Scala_2_12 + + override protected def additionalLibraries: Seq[ThirdPartyLibraryLoader] = { + import Specs2_2_12_4_0_0_Base._ + + implicit val module: Module = getModule + Seq(Specs2CommonLoader(), Specs2CoreLoader(), Specs2MatcherLoader()) + } +} + +object Specs2_2_12_4_0_0_Base { + + abstract class Specs2_3_BaseLoader(implicit module: Module) extends Specs2BaseLoader { + override val version: String = "4.0.0" + } + + case class Specs2CommonLoader()(implicit val module: Module) extends Specs2_3_BaseLoader { + override val name: String = "specs2-common" + } + + case class Specs2CoreLoader()(implicit val module: Module) extends Specs2_3_BaseLoader { + override val name: String = "specs2-core" + } + + case class Specs2MatcherLoader()(implicit val module: Module) extends Specs2_3_BaseLoader { + override val name: String = "specs2-matcher" + } + + case class ScalaZEffectLoader()(implicit val module: Module) extends ScalaZBaseLoader { + override val name: String = "scalaz-effect" + } + + case class ScalaZStreamLoader()(implicit val module: Module) extends ScalaZBaseLoader { + override val name: String = "scalaz-stream" + override val vendor: String = "org.scalaz.stream" + override val version: String = "0.6a" + } + + case class ShapelessLoader()(implicit val module: Module) extends IvyLibraryLoaderAdapter { + override val name: String = "shapeless" + override val vendor: String = "com.chuusai" + override val version: String = "2.0.0" + override val ivyType: IvyType = Bundles + } + + abstract class SCodecBaseLoader(implicit module: Module) extends IvyLibraryLoaderAdapter { + override val vendor: String = "org.typelevel" + override val ivyType: IvyType = Bundles + } + + case class SCodecCoreLoader()(implicit val module: Module) extends SCodecBaseLoader { + override val name: String = "scodec-core" + override val version: String = "1.7.0-SNAPSHOT" + } + + case class SCodecBitsLoader()(implicit val module: Module) extends SCodecBaseLoader { + override val name: String = "scodec-bits" + override val version: String = "1.1.0-SNAPSHOT" + } + +} \ No newline at end of file diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_DuplicateConfigTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_DuplicateConfigTest.scala new file mode 100644 index 00000000000..e03404923b9 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_DuplicateConfigTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2DuplicateConfigTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 27.01.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_DuplicateConfigTest extends Specs2DuplicateConfigTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_GoToSourceTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_GoToSourceTest.scala new file mode 100644 index 00000000000..72fef79b66f --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_GoToSourceTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2GoToSourceTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 27.01.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_GoToSourceTest extends Specs2GoToSourceTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_ObjectSpecTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_ObjectSpecTest.scala new file mode 100644 index 00000000000..410a3ad17ff --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_ObjectSpecTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2ObjectSpecTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 11.01.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_ObjectSpecTest extends Specs2ObjectSpecTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_PackageTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_PackageTest.scala new file mode 100644 index 00000000000..e9b132e3697 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_PackageTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2PackageTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 06.09.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_PackageTest extends Specs2PackageTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_RegExpTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_RegExpTest.scala new file mode 100644 index 00000000000..f955f2c412d --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_RegExpTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2RegExpTestNameTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 03.07.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_RegExpTest extends Specs2RegExpTestNameTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SCL7228Test.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SCL7228Test.scala new file mode 100644 index 00000000000..2066f0840bc --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SCL7228Test.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.SCL7228Test +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 11.01.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_SCL7228Test extends SCL7228Test with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTest.scala new file mode 100644 index 00000000000..845acf26769 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2SingleTestTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 11.01.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_SingleTestTest extends Specs2SingleTestTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTestDynamic.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTestDynamic.scala new file mode 100644 index 00000000000..0dbb15edf68 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SingleTestTestDynamic.scala @@ -0,0 +1,13 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 11.01.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_SingleTestTestDynamic extends Specs2_2_12_4_0_0_SingleTestTest { + override val useDynamicClassPath = true +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SpecialCharactersTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SpecialCharactersTest.scala new file mode 100644 index 00000000000..08ea1cba765 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_SpecialCharactersTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2SpecialCharactersTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 27.01.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_SpecialCharactersTest extends Specs2SpecialCharactersTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_StaticStringTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_StaticStringTest.scala new file mode 100644 index 00000000000..c54cb89903b --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_StaticStringTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2StaticStringTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 18.06.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_StaticStringTest extends Specs2StaticStringTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_WholeSuiteTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_WholeSuiteTest.scala new file mode 100644 index 00000000000..cf318a3772f --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_WholeSuiteTest.scala @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.scala.testingSupport.specs2.specs2_2_12_4_0_0 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.specs2.Specs2WholeSuiteTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 11.02.2015. + */ +@Category(Array(classOf[SlowTests])) +class Specs2_2_12_4_0_0_WholeSuiteTest extends Specs2WholeSuiteTest with Specs2_2_12_4_0_0_Base diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala index bf9563c7636..f978ea2a68a 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestPackageTest_2_11_0_5_4.scala @@ -1,11 +1,14 @@ package org.jetbrains.plugins.scala.testingSupport.utest.scala2_11.utest_0_5_4 import org.jetbrains.plugins.scala.testingSupport.utest.UTestPackageTest +import org.jetbrains.plugins.scala.SlowTests +import org.junit.experimental.categories.Category /** * @author Roman.Shein * @since 05.09.2015. */ +@Category(Array(classOf[SlowTests])) class UTestPackageTest_2_11_0_5_4 extends UTestTestBase_2_11_0_5_4 with UTestPackageTest { } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala index bb105c7f26b..b36c6e1c7ce 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestSimpleTest_2_11_0_5_4.scala @@ -1,11 +1,14 @@ package org.jetbrains.plugins.scala.testingSupport.utest.scala2_11.utest_0_5_4 import org.jetbrains.plugins.scala.testingSupport.utest.UTestSimpleTest +import org.jetbrains.plugins.scala.SlowTests +import org.junit.experimental.categories.Category /** * @author Roman.Shein * @since 04.09.2015. */ +@Category(Array(classOf[SlowTests])) class UTestSimpleTest_2_11_0_5_4 extends UTestTestBase_2_11_0_5_4 with UTestSimpleTest { } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala index b5a4f246160..48c4506f085 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_11/utest_0_5_4/UTestStaticStringTest_2_11_0_5_4.scala @@ -1,11 +1,14 @@ package org.jetbrains.plugins.scala.testingSupport.utest.scala2_11.utest_0_5_4 import org.jetbrains.plugins.scala.testingSupport.utest.UTestStaticStringTest +import org.jetbrains.plugins.scala.SlowTests +import org.junit.experimental.categories.Category /** * @author Roman.Shein * @since 04.09.2015. */ +@Category(Array(classOf[SlowTests])) class UTestStaticStringTest_2_11_0_5_4 extends UTestTestBase_2_11_0_5_4 with UTestStaticStringTest { protected val testsTestName = "UTestTests" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestPackageTest_2_12_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestPackageTest_2_12_0_5_4.scala new file mode 100644 index 00000000000..0c4435af0ae --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestPackageTest_2_12_0_5_4.scala @@ -0,0 +1,14 @@ +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_12.utest_0_5_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.utest.UTestPackageTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 05.09.2015. + */ +@Category(Array(classOf[SlowTests])) +class UTestPackageTest_2_12_0_5_4 extends UTestTestBase_2_12_0_5_4 with UTestPackageTest { + +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestSimpleTest_2_12_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestSimpleTest_2_12_0_5_4.scala new file mode 100644 index 00000000000..8e480cb5095 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestSimpleTest_2_12_0_5_4.scala @@ -0,0 +1,14 @@ +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_12.utest_0_5_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.utest.UTestSimpleTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 04.09.2015. + */ +@Category(Array(classOf[SlowTests])) +class UTestSimpleTest_2_12_0_5_4 extends UTestTestBase_2_12_0_5_4 with UTestSimpleTest { + +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestStaticStringTest_2_12_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestStaticStringTest_2_12_0_5_4.scala new file mode 100644 index 00000000000..d675cfc7485 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestStaticStringTest_2_12_0_5_4.scala @@ -0,0 +1,46 @@ +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_12.utest_0_5_4 + +import org.jetbrains.plugins.scala.SlowTests +import org.jetbrains.plugins.scala.testingSupport.utest.UTestStaticStringTest +import org.junit.experimental.categories.Category + +/** + * @author Roman.Shein + * @since 04.09.2015. + */ +@Category(Array(classOf[SlowTests])) +class UTestStaticStringTest_2_12_0_5_4 extends UTestTestBase_2_12_0_5_4 with UTestStaticStringTest { + + protected val testsTestName = "UTestTests" + + protected val testsTestFileName: String = testsTestName + ".scala" + + addSourceFile(testsTestFileName, + s""" + |import utest._ + |$testSuiteSecondPrefix + | + |object $testsTestName extends TestSuite { + | val tests = Tests { + | "foo" - {} + | } + |} + """.stripMargin) + + def testLeft(): Unit = { + checkTestsTest(5, 7, "") + } + + def testRight(): Unit = { + checkTestsTest(5, 18, "") + } + + def testInner(): Unit = { + checkTestsTest(6, 6, "foo") + } + + protected def checkTestsTest(lineNumber: Int, position: Int, expectedName: String): Unit = { + assert(checkConfigAndSettings(createTestFromLocation(lineNumber, position, testsTestFileName), + testsTestName, "tests" + (if (expectedName.isEmpty) "" else "\\" + expectedName))) + } +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestTestBase_2_12_0_5_4.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestTestBase_2_12_0_5_4.scala new file mode 100644 index 00000000000..61dd6d300bc --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/utest/scala2_12/utest_0_5_4/UTestTestBase_2_12_0_5_4.scala @@ -0,0 +1,21 @@ +package org.jetbrains.plugins.scala.testingSupport.utest.scala2_12.utest_0_5_4 + +import org.jetbrains.plugins.scala.base.libraryLoaders.{ThirdPartyLibraryLoader, UTestLoader} +import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_12} +import org.jetbrains.plugins.scala.testingSupport.utest.UTestTestCase + +/** + * @author Roman.Shein + * @since 02.09.2015. + */ +abstract class UTestTestBase_2_12_0_5_4 extends UTestTestCase { + + override implicit val version: ScalaVersion = Scala_2_12 + + override protected def additionalLibraries: Seq[ThirdPartyLibraryLoader] = { + implicit val module = getModule + Seq(UTestLoader("0.5.4")) + } + + override protected val testSuiteSecondPrefix = "" +} From d6b5f28dfb6c13f4a1c051a7de1523eef6d11aa2 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 11:37:33 +0300 Subject: [PATCH 056/141] an attempt to "fix" strange intermittent test (cherry picked from commit 648a6ec) --- scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala b/scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala index 9818ed64a43..538de2f35b1 100644 --- a/scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala +++ b/scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala @@ -1,4 +1,4 @@ -object Test { +class Test { val ↑ = 3 val x$u20A2 = 4 From c0599a0d041035859c73e2033fac0ca9e1686268 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Thu, 26 Oct 2017 17:49:24 +0300 Subject: [PATCH 057/141] Failure type alias replaced #SCL-12743 --- .../scala/lang/psi/types/result/Failure.scala | 35 +++++++++++++++++++ .../scala/lang/psi/types/result/package.scala | 15 ++------ 2 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala new file mode 100644 index 00000000000..8a778151431 --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala @@ -0,0 +1,35 @@ +package org.jetbrains.plugins.scala.lang.psi +package types +package result + +import org.jetbrains.plugins.scala.project.ProjectContext + +class Failure private(private val cause: String, + private val context: ProjectContext) { + + + override def toString = s"Failure($cause)" + + + override def equals(other: Any): Boolean = other match { + case that: Failure => cause == that.cause && context == that.context + case _ => false + } + + override def hashCode(): Int = + 31 * cause.hashCode + context.hashCode() +} + +object Failure { + + import scala.util.{Either, Left} + + def apply(cause: String) + (implicit context: ProjectContext): Either[Failure, ScType] = + Left(new Failure(cause, context)) + + def unapply(result: Either[Failure, ScType]): Option[String] = result match { + case Left(failure) => Some(failure.cause) + case _ => None + } +} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala index 1536498d6d1..0497e861701 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/package.scala @@ -7,18 +7,9 @@ import org.jetbrains.plugins.scala.project.ProjectContext package object result { - type Failure = (String, ProjectContext) - type TypeResult = Either[Failure, ScType] - - object Failure { - def apply(cause: String) - (implicit context: ProjectContext): TypeResult = Left(cause, context) + import scala.util.{Either, Left, Right} - def unapply(result: TypeResult): Option[String] = result match { - case Left((cause, _)) => Some(cause) - case _ => None - } - } + type TypeResult = Either[Failure, ScType] implicit class OptionTypeExt(val maybeRight: Option[ScType]) extends AnyVal { @@ -38,7 +29,7 @@ package object result { private def getOrApiType(apiType: StdTypes => ScType): ScType = result match { case Right(value) => value - case Left((_, projectContext)) if apiType != null => apiType(projectContext.stdTypes) + case Left(failure) if apiType != null => apiType(failure.context.stdTypes) case _ => throw new NoSuchElementException("Failure.get") } } From 2173f1182c99c802b1e7fbaa4e724ee7d92121d2 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Fri, 27 Oct 2017 12:10:26 +0300 Subject: [PATCH 058/141] compilation fixed #SCL-12743 --- .../plugins/scala/lang/psi/types/result/Failure.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala index 8a778151431..e3573a3b04e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/types/result/Failure.scala @@ -4,8 +4,8 @@ package result import org.jetbrains.plugins.scala.project.ProjectContext -class Failure private(private val cause: String, - private val context: ProjectContext) { +class Failure private(private[result] val cause: String, + private[result] val context: ProjectContext) { override def toString = s"Failure($cause)" From 1e401c68fd19eae5c6b3b65f918537a0094560cb Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Tue, 24 Oct 2017 18:33:53 +0300 Subject: [PATCH 059/141] Ammonite: process selector $ivy imports #SCL-12790 fixed --- .../AmmoniteUnresolvedLibraryInspection.scala | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUnresolvedLibraryInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUnresolvedLibraryInspection.scala index 0a39b61cf14..2c9a3529d45 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUnresolvedLibraryInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUnresolvedLibraryInspection.scala @@ -4,7 +4,9 @@ import com.intellij.codeInspection.{ProblemHighlightType, ProblemsHolder} import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.codeInspection.AbstractInspection -import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement +import org.jetbrains.plugins.scala.extensions.implementation.iterator.ParentsIterator +import org.jetbrains.plugins.scala.lang.psi.api.base.{ScReferenceElement, ScStableCodeReferenceElement} +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.{ScImportExpr, ScImportSelector} /** * User: Dmitry.Naydanov @@ -12,17 +14,18 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElemen */ class AmmoniteUnresolvedLibraryInspection extends AbstractInspection("Unresolved Ivy import") { override protected def actionFor(implicit holder: ProblemsHolder): PartialFunction[PsiElement, Any] = { - case stableRef: ScStableCodeReferenceElement => - stableRef.qualifier match { - case Some(x) => x.refName match { - case "$ivy" => - if (stableRef.resolve() == null) { - holder.registerProblem(stableRef, "Cannot resolve import", ProblemHighlightType.WEAK_WARNING, null: TextRange, - new CreateImportedLibraryQuickFix(stableRef)) - } - case _ => - } - case _ => + case stableRef: ScStableCodeReferenceElement => stableRef.qualifier.foreach(processExpr(stableRef, _, holder)) + case selector: ScImportSelector => + new ParentsIterator(selector).find { + case expr: ScImportExpr => selector.reference.foreach(processExpr(_, expr.qualifier, holder)) + true + case _ => false } } + + private def processExpr(ref: ScReferenceElement, qualifier: ScStableCodeReferenceElement, holder: ProblemsHolder) { + if (qualifier == null || qualifier.refName != "$ivy" || ref.resolve() != null) return + holder.registerProblem(ref, "Cannot resolve import", ProblemHighlightType.WEAK_WARNING, null: TextRange, + new CreateImportedLibraryQuickFix(ref)) + } } From 8550e7037f2c10dc8ab1ab70b658ece21c3989a2 Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Wed, 25 Oct 2017 17:53:00 +0300 Subject: [PATCH 060/141] Ammonite: jar file pattern iterating simplified --- .../scala/worksheet/ammonite/AmmoniteUtil.scala | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala index 32a8ab40d53..8ea78369f5f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala @@ -189,7 +189,7 @@ object AmmoniteUtil { private var it = ps.iterator setCurrent() - override def add(): Boolean = it.hasNext && {setCurrent(); true} + override def add(): Boolean = {it.hasNext && {setCurrent(); true} || {current = None; false}} override def hasNext: Boolean = it.hasNext override def reset(): Unit = { it = ps.iterator @@ -210,16 +210,9 @@ object AmmoniteUtil { private def advance() { if (!currentDigit.add()) { - val bf = currentDigit - while (!currentDigit.add() && it.hasNext) { - currentDigit = it.next() - } - + while (!currentDigit.add() && it.hasNext) currentDigit = it.next() if (currentDigit.getCurrent.isEmpty) return - pathParts.takeWhile(_ != currentDigit).foreach(_.reset()) - bf.reset() - currentDigit = pathParts.head it = pathParts.iterator } @@ -243,6 +236,11 @@ object AmmoniteUtil { case Array(single) => SimplePart(single) case multiple => OrPart(multiple) } + }.foldRight(List.empty[PathPart[String]]){ + case (SimplePart(part), SimplePart(pp) :: tail) => + SimplePart(part + File.separator + pp) :: tail + case (otherPart, list) => + otherPart :: list } }.find(predicate) } From 75e0956f09d1f94f336b8e82cd47521120f3ff09 Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Wed, 25 Oct 2017 18:42:31 +0300 Subject: [PATCH 061/141] Ammonite: bug with resolve ivy selector imports fixed --- .../scala/worksheet/ammonite/AmmoniteUtil.scala | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala index 8ea78369f5f..33751d78a21 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteUtil.scala @@ -12,9 +12,10 @@ import com.intellij.psi.scope.PsiScopeProcessor import com.intellij.psi.util.PsiUtilCore import com.intellij.util.containers.ContainerUtilRt import org.jetbrains.jps.model.java.JavaSourceRootType +import org.jetbrains.plugins.scala.extensions.implementation.iterator.ParentsIterator import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.{ScReferenceElement, ScStableCodeReferenceElement} -import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.{ScImportExpr, ScImportStmt} +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.{ScImportExpr, ScImportSelector, ScImportStmt} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.api.{FileDeclarationsHolder, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.{ScalaFileImpl, ScalaPsiElementFactory} @@ -123,7 +124,17 @@ object AmmoniteUtil { def scriptResolveSbtDependency(refElement: ScStableCodeReferenceElement): Option[PsiDirectory] = { def scriptResolveIvy(refElement: ScStableCodeReferenceElement) = refElement.getText == ROOT_IVY - refElement.qualifier match { + def qual(scRef: ScStableCodeReferenceElement) = { + scRef.getParent match { + case selector: ScImportSelector => + new ParentsIterator(selector).collectFirst { + case expr: ScImportExpr => expr.qualifier + } + case _ => scRef.qualifier + } + } + + qual(refElement) match { case Some(q) if scriptResolveIvy(q) => findLibrary(refElement) flatMap { lib => getResolveItem(lib, refElement.getProject) From f3d54ee67510b606102fb41c5bfca7c22410304a Mon Sep 17 00:00:00 2001 From: "dmitry.naydanov" Date: Thu, 26 Oct 2017 19:01:12 +0300 Subject: [PATCH 062/141] Ammonite: navigation to imported script files simplified #SCL-12786 fixed --- .../ammonite/AmmoniteGotoHandler.scala | 32 +++++++++++++------ .../AmmoniteScriptWrappersHolder.scala | 27 ++++------------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteGotoHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteGotoHandler.scala index 1d6fe1ef2bc..5a26e45e6c3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteGotoHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteGotoHandler.scala @@ -3,11 +3,12 @@ package org.jetbrains.plugins.scala.worksheet.ammonite import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.editor.Editor -import com.intellij.psi.PsiElement +import com.intellij.psi.{PsiElement, PsiFile, PsiNamedElement} import org.jetbrains.plugins.scala.extensions.implementation.iterator.ParentsIterator import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScMember import org.jetbrains.plugins.scala.worksheet.GotoOriginalHandlerUtil /** @@ -24,19 +25,32 @@ class AmmoniteGotoHandler extends GotoDeclarationHandler { } sourceElement.getParent match { - case ref: ScReferenceElement => + case ref: ScReferenceElement => ref.resolve() match { - case scalaPsi: ScalaPsiElement if GotoOriginalHandlerUtil.findPsi(scalaPsi.getContainingFile).isDefined => - new ParentsIterator(scalaPsi, false).collectFirst { - case p if GotoOriginalHandlerUtil.findPsi(p).isDefined => GotoOriginalHandlerUtil.findPsi(p).get - }.toArray + case scalaPsi: ScalaPsiElement => findPreImage(scalaPsi).toArray case _ => PsiElement.EMPTY_ARRAY } case _ => PsiElement.EMPTY_ARRAY } } - - override def getActionText(context: DataContext): String = "GoTo" -} + + private def findPreImage(scalaPsi: PsiElement): Option[PsiElement] = { + val originalElement = scalaPsi match { + case mem: ScMember => mem.getSyntheticNavigationElement match { + case Some(v) => v + case _ => scalaPsi + } + case _ => scalaPsi + } + + GotoOriginalHandlerUtil.findPsi(originalElement.getContainingFile).flatMap { + case preImage: PsiFile => + Option(preImage.findElementAt(originalElement.getTextRange.getStartOffset - AmmoniteScriptWrappersHolder.getOffsetFix(preImage))) + case _ => None + }.map(findNamedParent) + } + + private def findNamedParent(element: PsiElement) = new ParentsIterator(element, false).find(_.isInstanceOf[PsiNamedElement]).getOrElse(element) +} \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteScriptWrappersHolder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteScriptWrappersHolder.scala index eb666c9db9f..00a31f507f4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteScriptWrappersHolder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/worksheet/ammonite/AmmoniteScriptWrappersHolder.scala @@ -2,12 +2,10 @@ package org.jetbrains.plugins.scala.worksheet.ammonite import com.intellij.openapi.components.AbstractProjectComponent import com.intellij.openapi.project.Project -import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile -import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScDeclaration, ScFunctionDefinition, ScPatternDefinition, ScVariableDefinition} -import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTemplateDefinition, ScTypeDefinition} +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory -import org.jetbrains.plugins.scala.project.ProjectContext import org.jetbrains.plugins.scala.worksheet.GotoOriginalHandlerUtil import scala.collection.mutable @@ -21,24 +19,9 @@ class AmmoniteScriptWrappersHolder(project: Project) extends AbstractProjectComp private def createWrapper(from: ScalaFile) = { val obj = GotoOriginalHandlerUtil.createPsi((from: ScalaFile) => ScalaPsiElementFactory.createObjectWithContext( - s" object ${from.getName.stripSuffix(s".${AmmoniteUtil.AMMONITE_EXTENSION}")} { }", from, from.getFirstChild + s"object ${AmmoniteScriptWrappersHolder.getWrapperName(from)} {\n${from.getText} }", from, from.getFirstChild ), from) - GotoOriginalHandlerUtil.storePsi(obj.getContainingFile, from) - - def storeInfo(psi: PsiElement) { - val psiElement = GotoOriginalHandlerUtil.createPsi((p: PsiElement) => ScalaPsiElementFactory.createElementFromText(p.getText)( //todo - new ProjectContext(from.getProject)), psi) - obj.extendsBlock.templateBody.foreach { body => body.addBefore(psiElement, body.getLastChild)} - } - - from.getChildren.foreach { - case decl: ScDeclaration => storeInfo(decl) - case df@(_: ScVariableDefinition | _: ScTemplateDefinition | _: ScFunctionDefinition | _: ScPatternDefinition | _: ScTypeDefinition) => - storeInfo(df) - case _ => - } - obj } @@ -58,4 +41,8 @@ class AmmoniteScriptWrappersHolder(project: Project) extends AbstractProjectComp object AmmoniteScriptWrappersHolder { def getInstance(project: Project): AmmoniteScriptWrappersHolder = project.getComponent(classOf[AmmoniteScriptWrappersHolder]) + + def getWrapperName(from: PsiFile): String = from.getName.stripSuffix(s".${AmmoniteUtil.AMMONITE_EXTENSION}") + + def getOffsetFix(from: PsiFile): Int = (getWrapperName(from) + "object {\n").length } \ No newline at end of file From 2fcaf8673afb495898836b88b3e761728c5fdcb2 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 27 Oct 2017 12:55:52 +0200 Subject: [PATCH 063/141] fix scalatest/scalactic/scalaxml loading in tests --- project/dependencies.scala | 3 ++- .../scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala | 2 +- .../scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index ee8dfabce75..b08d5eb94b2 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -190,7 +190,8 @@ object DependencyGroups { "org.scalatest" % "scalatest_2.11" % "2.2.1", "org.scalatest" % "scalatest_2.11" % "3.0.1", "org.scalactic" % "scalactic_2.11" % "3.0.1", -// "org.scalatest" % "scalatest_2.12" % "3.0.1", + "org.scalactic" % "scalactic_2.12" % "3.0.4", + "org.scalatest" % "scalatest_2.12" % "3.0.4", "org.scalameta" % s"paradise_$scalaVersion" % paradiseVersion exclude("org.scalameta", s"scalameta_$scalaBinaryVersion"), "org.scalameta" % "scalameta_2.11" % scalaMetaVersion, "org.scalameta" % "scalameta_2.12" % scalaMetaVersion, diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index f34cc2a4f9d..10e69248c0f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -120,7 +120,7 @@ case class ScalaTestLoader(override val version: String, override val vendor: String = "org.scalatest" } -case class ScalaXmlLoader(override val version: String = "1.0.1")(implicit val module: Module) extends IvyLibraryLoaderAdapter { +case class ScalaXmlLoader(override val version: String = "1.0.6")(implicit val module: Module) extends IvyLibraryLoaderAdapter { override val name: String = "scala-xml" override val vendor: String = "org.scala-lang.modules" override val ivyType: IvyType = Bundles diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala index 6fc2770eb5e..a82786e4a70 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala @@ -15,6 +15,6 @@ abstract class Scalatest2_12_3_0_4_Base extends ScalaTestTestCase { override protected def additionalLibraries: Seq[ThirdPartyLibraryLoader] = { implicit val module: Module = getModule - Seq(ScalaTestLoader("3.0.4", IvyLibraryLoader.Bundles), ScalaXmlLoader("1.0.5"), ScalacticLoader("3.0.4", IvyLibraryLoader.Bundles)) + Seq(ScalaTestLoader("3.0.4", IvyLibraryLoader.Bundles), ScalaXmlLoader(), ScalacticLoader("3.0.4", IvyLibraryLoader.Bundles)) } } From d052dd00c576761ffa00dcb461218e8db30aa98d Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Thu, 26 Oct 2017 16:48:07 +0300 Subject: [PATCH 064/141] usages of deprecated classes removed #SCL-12408 fixed --- .../plugins/scala/caches/RecursionManager.scala | 9 +++++---- .../plugins/scala/lang/psi/impl/ScalaPsiManager.scala | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/caches/RecursionManager.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/caches/RecursionManager.scala index 46640d1f076..601d46e5e5d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/caches/RecursionManager.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/caches/RecursionManager.scala @@ -1,14 +1,15 @@ package org.jetbrains.plugins.scala.caches import java.util -import java.util.Objects import java.util.concurrent.ConcurrentMap +import java.util.{Objects, Map => JMap} + +import scala.collection.JavaConverters._ import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.util.Computable -import com.intellij.util.containers.{ContainerUtil, SoftHashMap, SoftKeySoftValueHashMap} +import com.intellij.util.containers.ContainerUtil import gnu.trove.{THashMap, THashSet} -import scala.collection.JavaConverters._ /** * Nikolay.Tropin @@ -127,7 +128,7 @@ object RecursionManager { var depth: Int = 0 val progressMap: util.LinkedHashMap[MyKey[_], Integer] = new util.LinkedHashMap[MyKey[_], Integer] val key2ReentrancyDuringItsCalculation: THashMap[MyKey[_], MyKey[_]] = new THashMap[MyKey[_], MyKey[_]] - val intermediateCache: SoftHashMap[MyKey[_], SoftKeySoftValueHashMap[MyKey[_], AnyRef]] = new SoftHashMap[MyKey[_], SoftKeySoftValueHashMap[MyKey[_], AnyRef]] + val intermediateCache: JMap[MyKey[_], JMap[MyKey[_], AnyRef]] = ContainerUtil.createSoftMap() var enters: Int = 0 var exits: Int = 0 diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiManager.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiManager.scala index 336e5b21b5b..0530dfd0856 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiManager.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiManager.scala @@ -21,7 +21,7 @@ import com.intellij.psi.search.{DelegatingGlobalSearchScope, GlobalSearchScope, import com.intellij.psi.stubs.{StubIndex, StubIndexKey} import com.intellij.psi.util.PsiModificationTracker import com.intellij.util.ArrayUtil -import com.intellij.util.containers.{ContainerUtil, WeakValueHashMap} +import com.intellij.util.containers.ContainerUtil import org.jetbrains.annotations.TestOnly import org.jetbrains.plugins.scala.caches.{CachesUtil, ScalaShortNamesCacheManager} import org.jetbrains.plugins.scala.extensions._ @@ -285,7 +285,7 @@ class ScalaPsiManager(val project: Project) { } private val syntheticPackagesCreator = new SyntheticPackageCreator(project) - private val syntheticPackages = new WeakValueHashMap[String, AnyRef] + private val syntheticPackages = ContainerUtil.createWeakValueMap[String, AnyRef]() private val emptyMarker: AnyRef = new Object def syntheticPackage(fqn: String): ScSyntheticPackage = { From e770c760ec637cf846967ca1a04903206d9b3892 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Thu, 26 Oct 2017 18:58:51 +0300 Subject: [PATCH 065/141] test moved to failing category --- .../projectHighlighting/ScalaLibraryHighlightingTest.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala index c4528f55018..2d4f6faa294 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/projectHighlighting/ScalaLibraryHighlightingTest.scala @@ -2,7 +2,7 @@ package org.jetbrains.plugins.scala.projectHighlighting import com.intellij.openapi.vfs.{VfsUtilCore, VirtualFile} import com.intellij.psi.PsiManager -import org.jetbrains.plugins.scala.{ScalaFileType, SlowTests} +import org.jetbrains.plugins.scala.{PerfCycleTests, ScalaFileType} import org.jetbrains.plugins.scala.base.ScalaLightCodeInsightFixtureTestAdapter import org.jetbrains.plugins.scala.base.libraryLoaders.IvyLibraryLoader.Sources import org.jetbrains.plugins.scala.base.libraryLoaders.ScalaLibraryLoader @@ -35,7 +35,7 @@ abstract class ScalaLibraryHighlightingTest extends ScalaLightCodeInsightFixture } } -@Category(Array(classOf[SlowTests])) +@Category(Array(classOf[PerfCycleTests])) class ScalaLibraryHighlightingTest_2_12 extends ScalaLibraryHighlightingTest { override implicit val version: ScalaVersion = Scala_2_12 } \ No newline at end of file From 50681544a269c01e5e1b6041f3715ccdd7beb916 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 10:50:49 +0300 Subject: [PATCH 066/141] a couple of convenience methods #SCL-12690 --- .../plugins/scala/editor/package.scala | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala new file mode 100644 index 00000000000..cb294419b79 --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala @@ -0,0 +1,37 @@ +package org.jetbrains.plugins.scala + +import com.intellij.openapi.editor.ex.EditorEx +import com.intellij.openapi.editor.{Document, Editor} +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.tree.IElementType +import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes +import org.jetbrains.plugins.scala.lang.scaladoc.lexer.ScalaDocElementType + +/** + * Nikolay.Tropin + * 27-Oct-17 + */ +package object editor { + implicit class DocumentExt(val document: Document) extends AnyVal { + def commit(project: Project): Unit = PsiDocumentManager.getInstance(project).commitDocument(document) + } + + implicit class EditorExt(val editor: Editor) extends AnyVal { + def offset: Int = editor.getCaretModel.getOffset + + def commitDocument(project: Project): Unit = editor.getDocument.commit(project) + + def inScalaString(offset: Int): Boolean = inTokenType(offset, ScalaTokenTypes.STRING_LITERAL_TOKEN_SET.contains) + + def inDocComment(offset: Int): Boolean = inTokenType(offset, _.isInstanceOf[ScalaDocElementType]) + + private def inTokenType(offset: Int, predicate: IElementType => Boolean): Boolean = { + if (offset == 0 || offset >= editor.getDocument.getTextLength) return false + + val highlighter = editor.asInstanceOf[EditorEx].getHighlighter + val iterator = highlighter.createIterator(offset - 1) + predicate(iterator.getTokenType) + } + } +} \ No newline at end of file From baef2426d56eefcd1c14ff441afe130e1773abbc Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 11:28:52 +0300 Subject: [PATCH 067/141] commit document in enter handlers fixed: better check if this handler is applicable, commit document before accessing psi #SCL-12690 fixed --- .../META-INF/scala-plugin-common.xml | 2 +- .../AddUnitTypeEnterHandler.scala | 38 ++++++++++++++----- .../EnterBetweenClosureBracesHandler.scala | 13 +++++-- .../InterpolatedStringEnterHandler.scala | 15 ++++++-- .../MultilineStringEnterHandler.scala | 22 ++++++++--- .../ScalaDocParamEnterHandlerDelegate.scala | 11 +++--- 6 files changed, 72 insertions(+), 29 deletions(-) rename scala/scala-impl/src/org/jetbrains/plugins/scala/{lang/completion/handlers => editor/enterHandler}/ScalaDocParamEnterHandlerDelegate.scala (90%) diff --git a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml index ef1822aca03..e732678bc4b 100644 --- a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml +++ b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml @@ -272,7 +272,7 @@ - + diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/AddUnitTypeEnterHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/AddUnitTypeEnterHandler.scala index bc492a7076f..80a2012dabd 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/AddUnitTypeEnterHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/AddUnitTypeEnterHandler.scala @@ -1,15 +1,17 @@ package org.jetbrains.plugins.scala -package editor.enterHandler +package editor +package enterHandler import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate.Result import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegateAdapter import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.editor.Editor -import com.intellij.psi.{PsiDocumentManager, PsiElement, PsiFile, PsiWhiteSpace} +import com.intellij.psi.{PsiElement, PsiFile, PsiWhiteSpace} import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.formatting.settings.ScalaCodeStyleSettings import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement +import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.expr.ScBlockExpr import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition @@ -19,16 +21,13 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition */ class AddUnitTypeEnterHandler extends EnterHandlerDelegateAdapter { override def postProcessEnter(file: PsiFile, editor: Editor, dataContext: DataContext): Result = { - val project = file.getProject - val scalaSettings = ScalaCodeStyleSettings.getInstance(project) - if (!scalaSettings.ENFORCE_FUNCTIONAL_SYNTAX_FOR_UNIT) return Result.Continue + if (!isApplicable(file, editor)) return Result.Continue val document = editor.getDocument - PsiDocumentManager.getInstance(project).commitDocument(document) - val caretModel = editor.getCaretModel - val offset = caretModel.getOffset - val element = file.findElementAt(offset) + editor.commitDocument(file.getProject) + + val element = file.findElementAt(editor.offset) if (element == null) return Result.Continue @@ -44,7 +43,6 @@ class AddUnitTypeEnterHandler extends EnterHandlerDelegateAdapter { if (funDef.findFirstChildByType(ScalaTokenTypes.tASSIGN) == null) extensions.inWriteAction { document.insertString(prev.getTextRange.getEndOffset, ": Unit =") - PsiDocumentManager.getInstance(project).commitDocument(document) } case _ => } @@ -53,4 +51,24 @@ class AddUnitTypeEnterHandler extends EnterHandlerDelegateAdapter { Result.Default } + + private def isApplicable(file: PsiFile, editor: Editor): Boolean = { + val project = file.getProject + val settings = ScalaCodeStyleSettings.getInstance(project) + + file.isInstanceOf[ScalaFile] && + settings.ENFORCE_FUNCTIONAL_SYNTAX_FOR_UNIT && + prevNonWhitespace(editor) == '{' + } + + private def prevNonWhitespace(editor: Editor): Char = { + val chars = editor.getDocument.getImmutableCharSequence + var offset = editor.offset + var found = ' ' + while (found.isWhitespace && offset > 0) { + offset -= 1 + found = chars.charAt(offset) + } + found + } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/EnterBetweenClosureBracesHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/EnterBetweenClosureBracesHandler.scala index 512e3ee4835..b026cfa786d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/EnterBetweenClosureBracesHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/EnterBetweenClosureBracesHandler.scala @@ -1,4 +1,5 @@ -package org.jetbrains.plugins.scala.editor.enterHandler +package org.jetbrains.plugins.scala.editor +package enterHandler import com.intellij.codeInsight.CodeInsightSettings import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate.Result @@ -31,13 +32,17 @@ class EnterBetweenClosureBracesHandler extends EnterHandlerDelegateAdapter { if (!file.isInstanceOf[ScalaFile]) { return Result.Continue } + val project = file.getProject + val document: Document = editor.getDocument val text: CharSequence = document.getCharsSequence val offset: Int = caretOffset.get.intValue if (!CodeInsightSettings.getInstance.SMART_INDENT_ON_ENTER) return Result.Continue val nextCharOffset: Int = CharArrayUtil.shiftForward(text, offset, " \t") if (!isValidOffset(nextCharOffset, text) || text.charAt(nextCharOffset) != '}') return Result.Continue - PsiDocumentManager.getInstance(file.getProject).commitDocument(editor.getDocument) + + document.commit(project) + val element = Option(file.findElementAt(offset)) if (element.map(e => PsiTreeUtil.skipSiblingsBackward(e, classOf[PsiWhiteSpace])).exists{ case fun: ScFunctionExpr => @@ -48,9 +53,9 @@ class EnterBetweenClosureBracesHandler extends EnterHandlerDelegateAdapter { } && element.map(_.getParent).exists(_.isInstanceOf[ScBlock])) { originalHandler.execute(editor, editor.getCaretModel.getCurrentCaret, dataContext) - PsiDocumentManager.getInstance(file.getProject).commitDocument(document) + document.commit(project) try { - CodeStyleManager.getInstance(file.getProject).adjustLineIndent(file, editor.getCaretModel.getOffset) + CodeStyleManager.getInstance(project).adjustLineIndent(file, editor.getCaretModel.getOffset) } catch { case e: IncorrectOperationException => LOG.error(e) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/InterpolatedStringEnterHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/InterpolatedStringEnterHandler.scala index 7ee8f1959f1..81adc8d719b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/InterpolatedStringEnterHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/InterpolatedStringEnterHandler.scala @@ -1,5 +1,6 @@ package org.jetbrains.plugins.scala -package editor.enterHandler +package editor +package enterHandler import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate.Result import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegateAdapter @@ -8,10 +9,12 @@ import com.intellij.lexer.StringLiteralLexer import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.actionSystem.EditorActionHandler +import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.util.Ref import com.intellij.psi.{PsiElement, PsiFile, StringEscapesTokenTypes} -import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes +import org.jetbrains.plugins.scala.lang.editor.ScalaQuoteHandler import org.jetbrains.plugins.scala.lang.parser.ScalaElementTypes +import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral /** @@ -22,7 +25,13 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral class InterpolatedStringEnterHandler extends EnterHandlerDelegateAdapter { override def preprocessEnter(file: PsiFile, editor: Editor, caretOffset: Ref[Integer], caretAdvance: Ref[Integer], dataContext: DataContext, originalHandler: EditorActionHandler): Result = { - var offset = editor.getCaretModel.getOffset + + var offset = caretOffset.get().intValue() + + if (!file.isInstanceOf[ScalaFile] || !editor.inScalaString(offset)) return Result.Continue + + editor.commitDocument(file.getProject) + val element = file.findElementAt(offset) import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes._ diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/MultilineStringEnterHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/MultilineStringEnterHandler.scala index d074d71a494..1ce4205c4cd 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/MultilineStringEnterHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/MultilineStringEnterHandler.scala @@ -1,5 +1,6 @@ package org.jetbrains.plugins.scala -package editor.enterHandler +package editor +package enterHandler import com.intellij.codeInsight.CodeInsightSettings import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate.Result @@ -9,7 +10,7 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.actionSystem.EditorActionHandler import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.{Ref, TextRange} -import com.intellij.psi.{PsiDocumentManager, PsiFile} +import com.intellij.psi.PsiFile import org.jetbrains.plugins.scala.format.StringConcatenationParser import org.jetbrains.plugins.scala.lang.formatting.settings.ScalaCodeStyleSettings import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile @@ -29,10 +30,14 @@ class MultilineStringEnterHandler extends EnterHandlerDelegateAdapter { override def preprocessEnter(file: PsiFile, editor: Editor, caretOffsetRef: Ref[Integer], caretAdvance: Ref[Integer], dataContext: DataContext, originalHandler: EditorActionHandler): Result = { - val document = editor.getDocument - val text = document.getText + val caretOffset = caretOffsetRef.get.intValue + if (!file.isInstanceOf[ScalaFile] || !editor.inScalaString(caretOffset)) return Result.Continue + + val document = editor.getDocument + val text = document.getImmutableCharSequence + if (caretOffset == 0 || caretOffset >= text.length()) return Result.Continue val element = file findElementAt caretOffset @@ -42,7 +47,7 @@ class MultilineStringEnterHandler extends EnterHandlerDelegateAdapter { val ch1 = text.charAt(caretOffset - 1) val ch2 = text.charAt(caretOffset) - whiteSpaceAfterCaret = text.substring(caretOffset).takeWhile(c => c == ' ' || c == '\t') + whiteSpaceAfterCaret = whitespaceAfter(text, caretOffset) document.deleteString(caretOffset, caretOffset + whiteSpaceAfterCaret.length) if ((ch1 != '(' || ch2 != ')')&&(ch1 != '{' || ch2 != '}') || !CodeInsightSettings.getInstance.SMART_INDENT_ON_ENTER) @@ -60,7 +65,7 @@ class MultilineStringEnterHandler extends EnterHandlerDelegateAdapter { val project = file.getProject val document = editor.getDocument - PsiDocumentManager.getInstance(project).commitDocument(document) + document.commit(project) val caretModel = editor.getCaretModel val offset = caretModel.getOffset @@ -248,4 +253,9 @@ class MultilineStringEnterHandler extends EnterHandlerDelegateAdapter { Result.Stop } + + private def whitespaceAfter(chars: CharSequence, offset: Int): String = { + val iterator = Iterator.range(offset, chars.length() - 1).map(chars.charAt) + iterator.takeWhile(c => c == ' ' || c == '\t').mkString + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/handlers/ScalaDocParamEnterHandlerDelegate.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/ScalaDocParamEnterHandlerDelegate.scala similarity index 90% rename from scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/handlers/ScalaDocParamEnterHandlerDelegate.scala rename to scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/ScalaDocParamEnterHandlerDelegate.scala index 8f041b7e3fa..e16f12056a4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/handlers/ScalaDocParamEnterHandlerDelegate.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/enterHandler/ScalaDocParamEnterHandlerDelegate.scala @@ -1,5 +1,5 @@ -package org.jetbrains.plugins.scala -package lang.completion.handlers +package org.jetbrains.plugins.scala.editor +package enterHandler import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate.Result import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegateAdapter @@ -7,6 +7,7 @@ import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.{PsiDocumentManager, PsiFile} +import org.jetbrains.plugins.scala.extensions import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.scaladoc.lexer.ScalaDocTokenType import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocTag @@ -18,11 +19,12 @@ import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocTag class ScalaDocParamEnterHandlerDelegate extends EnterHandlerDelegateAdapter { override def postProcessEnter(file: PsiFile, editor: Editor, dataContext: DataContext): Result = { - if (!file.isInstanceOf[ScalaFile]) { + if (!file.isInstanceOf[ScalaFile] || !editor.inDocComment(editor.offset)) { return Result.Continue } val document = editor.getDocument - PsiDocumentManager.getInstance(file.getProject).commitDocument(document) + val project = file.getProject + document.commit(project) val scalaFile = file.asInstanceOf[ScalaFile] val caretOffset = editor.getCaretModel.getOffset @@ -63,7 +65,6 @@ class ScalaDocParamEnterHandlerDelegate extends EnterHandlerDelegateAdapter { val toInsert = StringUtil.repeat(" ", endOffset - startOffset) extensions.inWriteAction { document.insertString(caretOffset, toInsert) - PsiDocumentManager.getInstance(file.getProject).commitDocument(document) } } From bdb0aca1be7ea3fe062ed8bfd00c8bde9a1dfb97 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 13:41:31 +0300 Subject: [PATCH 068/141] tests fixed #SCL-12690 --- .../plugins/scala/editor/package.scala | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala index cb294419b79..1907f1c4949 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/editor/package.scala @@ -5,7 +5,7 @@ import com.intellij.openapi.editor.{Document, Editor} import com.intellij.openapi.project.Project import com.intellij.psi.PsiDocumentManager import com.intellij.psi.tree.IElementType -import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes +import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes._ import org.jetbrains.plugins.scala.lang.scaladoc.lexer.ScalaDocElementType /** @@ -22,15 +22,24 @@ package object editor { def commitDocument(project: Project): Unit = editor.getDocument.commit(project) - def inScalaString(offset: Int): Boolean = inTokenType(offset, ScalaTokenTypes.STRING_LITERAL_TOKEN_SET.contains) + def inScalaString(offset: Int): Boolean = { + val afterInterpolatedInjection = + isTokenType(offset - 1, t => t == tRBRACE || t == tIDENTIFIER) && + isTokenType(offset, t => t == tINTERPOLATED_STRING || t == tINTERPOLATED_STRING_END) - def inDocComment(offset: Int): Boolean = inTokenType(offset, _.isInstanceOf[ScalaDocElementType]) + val previousIsStringToken = + isTokenType(offset - 1, t => STRING_LITERAL_TOKEN_SET.contains(t) || t == tINTERPOLATED_STRING_ESCAPE) - private def inTokenType(offset: Int, predicate: IElementType => Boolean): Boolean = { - if (offset == 0 || offset >= editor.getDocument.getTextLength) return false + previousIsStringToken || afterInterpolatedInjection + } + + def inDocComment(offset: Int): Boolean = isTokenType(offset - 1, _.isInstanceOf[ScalaDocElementType]) + + private def isTokenType(offset: Int, predicate: IElementType => Boolean): Boolean = { + if (offset < 0 || offset >= editor.getDocument.getTextLength) return false val highlighter = editor.asInstanceOf[EditorEx].getHighlighter - val iterator = highlighter.createIterator(offset - 1) + val iterator = highlighter.createIterator(offset) predicate(iterator.getTokenType) } } From 770b019db2fa800db00407621a42d2da91f364d1 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 12:19:06 +0300 Subject: [PATCH 069/141] IDEA version updated to Public Preview --- project/dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index ee8dfabce75..3b9378fae66 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -5,7 +5,7 @@ object Versions { val scalaBinaryVersion: String = Scala.binary_2_12 val sbtVersion: String = Sbt.latest val zincVersion = "1.0.0" - val ideaVersion = "173.3302.5" + val ideaVersion = "173.3415.22" val sbtStructureVersion: String = "2017.2" val sbtIdeaShellVersion: String = "2017.2" val aetherVersion = "1.0.0.v20140518" From 5e02c85019e0ac0aff177adbb448accce3cb5a19 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 12:28:51 +0300 Subject: [PATCH 070/141] ignore duplicate entry exception on plugin packaging --- project/Packaging.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/Packaging.scala b/project/Packaging.scala index 555558d6061..bd23bb8263e 100644 --- a/project/Packaging.scala +++ b/project/Packaging.scala @@ -1,5 +1,5 @@ import java.io._ -import java.util.zip.{ZipInputStream, ZipOutputStream} +import java.util.zip.{ZipException, ZipInputStream, ZipOutputStream} import sbt.Keys._ import sbt._ @@ -132,6 +132,7 @@ object Packaging { } outStream.closeEntry() } catch { + case ze: ZipException if ze.getMessage.startsWith("duplicate entry") => //ignore case e: IOException => println(s"$e") } entry = inStream.getNextEntry From 12bd27aa4a5df76c1e53da7347440bf9567229a3 Mon Sep 17 00:00:00 2001 From: Albert Meltzer Date: Mon, 2 Oct 2017 18:17:12 +0300 Subject: [PATCH 071/141] upgrade embedded scalastyle to 1.0.0 #SCL-12301 fixed (cherry picked from commit d771514) --- project/dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index 3b9378fae66..c334e8bafc7 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -84,7 +84,7 @@ object Dependencies { val commonsLang: ModuleID = "commons-lang" % "commons-lang" % "2.6" val junitInterface: ModuleID = "com.novocode" % "junit-interface" % "0.11" % "test" - val scalastyle: ModuleID = "org.scalastyle" %% "scalastyle" % "0.9.0" + val scalastyle: ModuleID = "org.scalastyle" %% "scalastyle" % "1.0.0" val scalariform: ModuleID = "org.scalariform" %% "scalariform" % "0.2.2" val macroParadise: ModuleID = "org.scalameta" % "paradise" % paradiseVersion cross CrossVersion.full val scalaMetaCore: ModuleID = "org.scalameta" %% "scalameta" % scalaMetaVersion withSources() exclude("com.google.protobuf", "protobuf-java") From da427bae35973dcbaeadad4a8cdc7b86b85965ab Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 14:55:15 +0300 Subject: [PATCH 072/141] intermittent test converted to parser test --- .../data/unicodeNames/unicode-decode.test | 105 ++++++++++++++++++ .../scalacTests/pos/unicode-decode.scala | 9 -- 2 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 scala/scala-impl/testdata/parser/data/unicodeNames/unicode-decode.test delete mode 100644 scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala diff --git a/scala/scala-impl/testdata/parser/data/unicodeNames/unicode-decode.test b/scala/scala-impl/testdata/parser/data/unicodeNames/unicode-decode.test new file mode 100644 index 00000000000..e93d68c116c --- /dev/null +++ b/scala/scala-impl/testdata/parser/data/unicodeNames/unicode-decode.test @@ -0,0 +1,105 @@ +object Test { + + val ↑ = 3 + val x$u20A2 = 4 + val y$ub = 5 + val y$u0A = 6 + val z$up = 2 + +} +----- +ScalaFile + ScObject: Test + AnnotationsList + + Modifiers + + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiElement(identifier)('Test') + PsiWhiteSpace(' ') + ExtendsBlock + ScTemplateBody + PsiElement({)('{') + PsiWhiteSpace('\n\n ') + ScPatternDefinition: ↑ + AnnotationsList + + Modifiers + + PsiElement(val)('val') + PsiWhiteSpace(' ') + ListOfPatterns + ReferencePattern: ↑ + PsiElement(identifier)('↑') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + Literal + PsiElement(integer)('3') + PsiWhiteSpace('\n ') + ScPatternDefinition: x$u20A2 + AnnotationsList + + Modifiers + + PsiElement(val)('val') + PsiWhiteSpace(' ') + ListOfPatterns + ReferencePattern: x$u20A2 + PsiElement(identifier)('x$u20A2') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + Literal + PsiElement(integer)('4') + PsiWhiteSpace('\n ') + ScPatternDefinition: y$ub + AnnotationsList + + Modifiers + + PsiElement(val)('val') + PsiWhiteSpace(' ') + ListOfPatterns + ReferencePattern: y$ub + PsiElement(identifier)('y$ub') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + Literal + PsiElement(integer)('5') + PsiWhiteSpace('\n ') + ScPatternDefinition: y$u0A + AnnotationsList + + Modifiers + + PsiElement(val)('val') + PsiWhiteSpace(' ') + ListOfPatterns + ReferencePattern: y$u0A + PsiElement(identifier)('y$u0A') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + Literal + PsiElement(integer)('6') + PsiWhiteSpace('\n ') + ScPatternDefinition: z$up + AnnotationsList + + Modifiers + + PsiElement(val)('val') + PsiWhiteSpace(' ') + ListOfPatterns + ReferencePattern: z$up + PsiElement(identifier)('z$up') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + Literal + PsiElement(integer)('2') + PsiWhiteSpace('\n\n') + PsiElement(})('}') \ No newline at end of file diff --git a/scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala b/scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala deleted file mode 100644 index 538de2f35b1..00000000000 --- a/scala/scala-impl/testdata/scalacTests/pos/unicode-decode.scala +++ /dev/null @@ -1,9 +0,0 @@ -class Test { - - val ↑ = 3 - val x$u20A2 = 4 - val y$ub = 5 - val y$u0A = 6 - val z$up = 2 - -} From 9fb7c5a081b5f3e4a09333fbf18064cb934e24a3 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 25 Oct 2017 18:38:19 +0300 Subject: [PATCH 073/141] Collection inspection: convert Option(Constant) to Some(Constant) #SCL-11890 Fixed --- .../META-INF/scala-plugin-common.xml | 19 +++++---- .../OptionWithConstant.html | 18 +++++++++ .../InspectionBundle.properties | 1 + .../OptionWithConstantInspection.scala | 21 ++++++++++ .../collections/OptionWithConstantTest.scala | 39 +++++++++++++++++++ 5 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 scala/scala-impl/resources/inspectionDescriptions/OptionWithConstant.html create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantInspection.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantTest.scala diff --git a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml index e732678bc4b..578c81081ab 100644 --- a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml +++ b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml @@ -1217,7 +1217,6 @@ displayName="Collect and headOption to collectFirst" groupPath="Scala,Collections" groupName="Simplifications: other" shortName="CollectHeadOption" level="WARNING" enabledByDefault="true" language="Scala"/> - - + displayName="Emulated Option(x)" groupPath="Scala,Collections" groupName="Options" + shortName="IfElseToOption" level="WARNING" + enabledByDefault="true" language="Scala"/> + + + +Replaces Option(Constant) with Some(Constant). + +

+Before: +

+Option("a")
+
+
+After: +
+Some("a")
+
+

+ + + \ No newline at end of file diff --git a/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties b/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties index a8e68668818..395746cfe6d 100644 --- a/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties +++ b/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties @@ -92,6 +92,7 @@ replace.with.contains=Replace with .contains replace.with.not.contains=Replace with !.contains replace.with.forall=Replace with .forall replace.with.exists=Replace with .exists +replace.with.some=Replace with Some ifstmt.to.headOption=If-else to headOption ifstmt.to.lastOption=If-else to lastOption diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantInspection.scala new file mode 100644 index 00000000000..d95bfb3ee51 --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantInspection.scala @@ -0,0 +1,21 @@ +package org.jetbrains.plugins.scala.codeInspection.collections + +import org.jetbrains.plugins.scala.codeInspection.InspectionBundle +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression + +/** + * @author t-kameyama + */ +class OptionWithConstantInspection extends OperationOnCollectionInspection { + override def possibleSimplificationTypes: Array[SimplificationType] = Array(OptionWithConstant) +} + +object OptionWithConstant extends SimplificationType { + override def hint: String = InspectionBundle.message("replace.with.some") + + override def getSimplification(expr: ScExpression): Option[Simplification] = expr match { + case `scalaOption`(literal(constant)) if constant != "null" => + Some(replace(expr).withText(s"Some($constant)").highlightFrom(expr)) + case _ => None + } +} \ No newline at end of file diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantTest.scala new file mode 100644 index 00000000000..f6587b4c986 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/OptionWithConstantTest.scala @@ -0,0 +1,39 @@ +package org.jetbrains.plugins.scala +package codeInspection +package collections + +import com.intellij.testFramework.EditorTestUtil + +/** + * @author t-kameyama + */ +class OptionWithConstantTest extends OperationsOnCollectionInspectionTest { + + import EditorTestUtil.{SELECTION_END_TAG => END, SELECTION_START_TAG => START} + + override protected val classOfInspection: Class[_ <: OperationOnCollectionInspection] = + classOf[OptionWithConstantInspection] + + override protected val hint: String = InspectionBundle.message("replace.with.some") + + def testString(): Unit = { + doTest( + s"""${START}Option("constant")$END""", + """Option("constant")""", + """Some("constant")""" + ) + } + + def testInt(): Unit = { + doTest( + s"${START}Option(1)$END", + "Option(1)", + "Some(1)" + ) + } + + def testNull(): Unit = { + checkTextHasNoErrors("Option(null)") + } + +} From 472955fd7ee614cf27569f3c63875272b6fdc23b Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Thu, 26 Oct 2017 10:26:24 +0300 Subject: [PATCH 074/141] Collection inspection: Option: don't emulate "flatten" #SCL-9790 Fixed --- .../EmulateFlattenInspection.scala | 17 ++++++- .../codeInspection/collections/package.scala | 9 ++-- .../EmulateFlattenInspectionTest.scala | 47 +++++++++++++++++++ 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspection.scala index b49182a547d..ff8ae98b31d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspection.scala @@ -3,6 +3,7 @@ package org.jetbrains.plugins.scala.codeInspection.collections import org.jetbrains.plugins.scala.codeInspection.InspectionBundle import org.jetbrains.plugins.scala.extensions.ResolvesTo import org.jetbrains.plugins.scala.lang.psi.api.expr._ +import org.jetbrains.plugins.scala.lang.psi.types.ScParameterizedType /** * @author Lukasz Piepiora @@ -18,11 +19,15 @@ object FlattenSimplification extends SimplificationType { override def getSimplification(expr: ScExpression): Option[Simplification] = expr match { - case seqOfSeqs `.flatMap` (identityOperation()) => - Some(replace(expr).withText(invocationText(seqOfSeqs, "flatten"))) + case seqOfSeqs `.flatMap` (identityOperation()) => toSimplification(expr, seqOfSeqs) + case qual `.getOrElse` (scalaNone()) if isNestedOption(qual) => toSimplification(expr, qual) + case qual `.map` (underscore() `.get` ()) if isNestedOption(qual) => toSimplification(expr, qual) case _ => None } + private def toSimplification(expr: ScExpression, qual: ScExpression): Some[Simplification] = + Some(replace(expr).withText(invocationText(qual, "flatten"))) + private object identityOperation { def unapply(expr: ScExpression): Boolean = stripped(expr) match { case identity(underscore()) => true @@ -51,4 +56,12 @@ object FlattenSimplification extends SimplificationType { } } + private def isNestedOption(qual: ScExpression) = qual.`type`().toOption.map(_.tryExtractDesignatorSingleton) match { + case Some(outer: ScParameterizedType) if isOption(outer.designator) => outer.typeArguments match { + case Seq(inner: ScParameterizedType) => isOption(inner.designator) + case _ => false + } + case _ => false + } + } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala index b5188899a2f..bb6c2c3ac9b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala @@ -368,14 +368,17 @@ package object collections { } def isOfClassFrom(expr: ScExpression, patterns: Array[String]): Boolean = - Option(expr).flatMap(_.`type`().toOption) - .flatMap(_.tryExtractDesignatorSingleton.extractClass) - .exists(qualifiedNameFitToPatterns(_, patterns)) + expr.`type`().toOption.exists(isOfClassFrom(_, patterns)) + + def isOfClassFrom(`type`: ScType, patterns: Array[String]): Boolean = + `type`.tryExtractDesignatorSingleton.extractClass.exists(qualifiedNameFitToPatterns(_, patterns)) private def qualifiedNameFitToPatterns(clazz: PsiClass, patterns: Array[String]) = Option(clazz).flatMap(c => Option(c.qualifiedName)) .exists(ScalaNamesUtil.nameFitToPatterns(_, patterns, strict = false)) + def isOption(`type`: ScType): Boolean = isOfClassFrom(`type`, likeOptionClasses) + def isOption(expr: ScExpression): Boolean = isOfClassFrom(expr, likeOptionClasses) def isArray(expr: ScExpression): Boolean = expr match { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspectionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspectionTest.scala index 6d5505f6e30..1a00d445980 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspectionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/EmulateFlattenInspectionTest.scala @@ -104,6 +104,38 @@ class EmulateFlattenInspectionTest extends OperationsOnCollectionInspectionTest testQuickFix(text, result, hint) } + def testSuggestes12(): Unit = { + val selected = s"val o = Option(Option(1)); o.${START}getOrElse(None)$END" + checkTextHasError(selected) + val text = "val o = Option(Option(1)); o.getOrElse(None)" + val result = "val o = Option(Option(1)); o.flatten" + testQuickFix(text, result, hint) + } + + def testSuggestes13(): Unit = { + val selected = s"Option(Option(1)).${START}getOrElse(None)$END" + checkTextHasError(selected) + val text = "Option(Option(1)).getOrElse(None)" + val result = "Option(Option(1)).flatten" + testQuickFix(text, result, hint) + } + + def testSuggestes14(): Unit = { + val selected = s"val o = Option(Option(1)); o.${START}map(_.get)$END" + checkTextHasError(selected) + val text = "val o = Option(Option(1)); o.map(_.get)" + val result = "val o = Option(Option(1)); o.flatten" + testQuickFix(text, result, hint) + } + + def testSuggestes15(): Unit = { + val selected = s"Option(Option(1)).${START}map(_.get)$END" + checkTextHasError(selected) + val text = "Option(Option(1)).map(_.get)" + val result = "Option(Option(1)).flatten" + testQuickFix(text, result, hint) + } + def testNotSuggests1(): Unit = { val text = s"Seq(Seq(1), Seq(2), Seq(3)).flatMap(x => identity(Seq(1, 2, 3)))" checkTextHasNoErrors(text) @@ -123,4 +155,19 @@ class EmulateFlattenInspectionTest extends OperationsOnCollectionInspectionTest val text = s"List(List(1), List(2), List(3)).flatMap(1 :: _ )" checkTextHasNoErrors(text) } + + def testNotSuggests5(): Unit = { + val text = s"Option(Option(1)).getOrElse(Option(2))" + checkTextHasNoErrors(text) + } + + def testNotSuggests6(): Unit = { + val text = s"Option(Option(1), 2).getOrElse(None)" + checkTextHasNoErrors(text) + } + + def testNotSuggests7(): Unit = { + val text = s"Option(List(1)).getOrElse(None)" + checkTextHasNoErrors(text) + } } From dc106b7f18b98f260071088ca6c379f2675a9c2c Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 15:21:21 +0300 Subject: [PATCH 075/141] description updated #SCL-9790 --- .../inspectionDescriptions/ReplaceWithFlatten.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scala/scala-impl/resources/inspectionDescriptions/ReplaceWithFlatten.html b/scala/scala-impl/resources/inspectionDescriptions/ReplaceWithFlatten.html index 518a2f2418d..0dbf9a12abf 100644 --- a/scala/scala-impl/resources/inspectionDescriptions/ReplaceWithFlatten.html +++ b/scala/scala-impl/resources/inspectionDescriptions/ReplaceWithFlatten.html @@ -9,6 +9,9 @@ Seq(Seq(1, 2, 3), Seq(4, 5), Seq(6, 7)).flatMap(x => identity(x)) Seq(Seq(2, 7, 1), Seq(8, 2), Seq(8, 1)).flatMap(x => x) Set(Set(1), Set(2), Set(3)).flatMap(x => x) + +nestedOption.getOrElse(None) +nestedOption.map(_.get)
@@ -18,6 +21,9 @@ Seq(Seq(1, 2, 3), Seq(4, 5), Seq(6, 7)).flatten Seq(Seq(2, 7, 1), Seq(8, 2), Seq(8, 1)).flatten Set(Set(1), Set(2), Set(3)).flatten + +nestedOption.flatten +nestedOption.flatten

From e557c0157a240d8a3edc5967290daf9027b65650 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Thu, 26 Oct 2017 12:49:20 +0300 Subject: [PATCH 076/141] Collection inspection: replace map.lift(n) with map.get(n) #SCL-8320 fixed --- .../META-INF/scala-plugin-common.xml | 5 +++ .../inspectionDescriptions/MapLift.html | 5 +++ .../InspectionBundle.properties | 1 + .../collections/MapLiftInspection.scala | 24 ++++++++++++++ .../collections/MapLiftTest.scala | 33 +++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 scala/scala-impl/resources/inspectionDescriptions/MapLift.html create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftInspection.scala create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftTest.scala diff --git a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml index 578c81081ab..fa34ff5e511 100644 --- a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml +++ b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml @@ -1234,6 +1234,11 @@ displayName="Redundant get when getting a value from Map" groupPath="Scala,Collections" groupName="Maps" shortName="MapGetGet" level="WARNING" enabledByDefault="true" language="Scala"/> + + + +Replaces map.lift(n) with map.get(n). + + \ No newline at end of file diff --git a/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties b/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties index 395746cfe6d..5ab3b820b76 100644 --- a/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties +++ b/scala/scala-impl/resources/org/jetbrains/plugins/scala/codeInspection/InspectionBundle.properties @@ -93,6 +93,7 @@ replace.with.not.contains=Replace with !.contains replace.with.forall=Replace with .forall replace.with.exists=Replace with .exists replace.with.some=Replace with Some +replace.with.get=Replace with .get ifstmt.to.headOption=If-else to headOption ifstmt.to.lastOption=If-else to lastOption diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftInspection.scala new file mode 100644 index 00000000000..120e08e9112 --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftInspection.scala @@ -0,0 +1,24 @@ +package org.jetbrains.plugins.scala.codeInspection.collections + +import org.jetbrains.plugins.scala.codeInspection.InspectionBundle +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression + +/** + * @author t-kameyama + */ +class MapLiftInspection extends OperationOnCollectionInspection { + override def possibleSimplificationTypes: Array[SimplificationType] = Array(MapList) +} + +object MapList extends SimplificationType { + override def hint: String = InspectionBundle.message("replace.with.get") + + override def getSimplification(expr: ScExpression): Option[Simplification] = { + expr match { + case qual `.lift` (n) if isMap(qual) => + Some(replace(expr).withText(invocationText(qual, "get", n)).highlightFrom(qual)) + case _ => None + } + } + +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftTest.scala new file mode 100644 index 00000000000..382b3b18092 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/collections/MapLiftTest.scala @@ -0,0 +1,33 @@ +package org.jetbrains.plugins.scala.codeInspection.collections + +import com.intellij.testFramework.EditorTestUtil.{SELECTION_END_TAG => END, SELECTION_START_TAG => START} +import org.jetbrains.plugins.scala.codeInspection.InspectionBundle + +/** + * @author t-kameyama + */ +class MapLiftTest extends OperationsOnCollectionInspectionTest { + + override protected val classOfInspection: Class[_ <: OperationOnCollectionInspection] = + classOf[MapLiftInspection] + + override protected val hint: String = + InspectionBundle.message("replace.with.get") + + def test1(): Unit = { + doTest( + s"Map(1 -> 2).${START}lift(1)$END", + "Map(1 -> 2).lift(1)", + "Map(1 -> 2).get(1)" + ) + } + + def test2(): Unit = { + doTest( + s"Map(1 -> 2) ${START}lift 1$END", + "Map(1 -> 2) lift 1", + "Map(1 -> 2) get 1" + ) + } + +} From 0f610fa91ec154451efabcbd8c97fee9fb250276 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 27 Oct 2017 16:56:08 +0300 Subject: [PATCH 077/141] test fixed #SCL-12690 --- .../scala/lang/scaladoc/ScalaDocEnterActionTestBase.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/scaladoc/ScalaDocEnterActionTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/scaladoc/ScalaDocEnterActionTestBase.scala index d08c3563e17..34893e546ae 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/scaladoc/ScalaDocEnterActionTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/scaladoc/ScalaDocEnterActionTestBase.scala @@ -4,7 +4,9 @@ package lang.scaladoc import com.intellij.openapi.actionSystem.{DataContext, IdeActions} import com.intellij.openapi.editor.actionSystem.EditorActionManager import org.jetbrains.plugins.scala.base.ScalaLightPlatformCodeInsightTestCaseAdapter +import org.jetbrains.plugins.scala.editor.DocumentExt import org.jetbrains.plugins.scala.lang.formatting.settings.ScalaCodeStyleSettings +import org.junit.Assert /** * User: Dmitry Naydanov @@ -36,7 +38,8 @@ abstract class ScalaDocEnterActionTestBase extends ScalaLightPlatformCodeInsight } } }) + getEditorAdapter.getDocument.commit(getProjectAdapter) - assert(transform(getFileAdapter.getText).equals(assumedStub)) + Assert.assertEquals(transform(getFileAdapter.getText), assumedStub) } } \ No newline at end of file From 41add448b784455ce93a2b0184cfb5fc8fd92a39 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Fri, 27 Oct 2017 17:21:40 +0300 Subject: [PATCH 078/141] progress feedback for adding SBT dependency fix #SCL-12813 --- .../intention/sbt/AddSbtDependencyFix.scala | 77 ++++++++++++++----- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index c6fa4dfac07..700be21fbc9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -1,10 +1,11 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt -import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator import com.intellij.codeInsight.intention.{IntentionAction, LowPriorityAction} +import com.intellij.notification.{Notification, NotificationType} +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.editor.Editor import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder -import com.intellij.openapi.externalSystem.util.{ExternalSystemApiUtil, ExternalSystemUtil} +import com.intellij.openapi.externalSystem.util.ExternalSystemUtil import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.module.{ModuleManager, ModuleUtilCore} import com.intellij.openapi.progress.{ProgressIndicator, ProgressManager, Task} @@ -14,6 +15,7 @@ import com.intellij.psi.{PsiElement, PsiFile, PsiManager} import org.jetbrains.plugins.scala.annotator.intention.sbt.AddSbtDependencyUtils._ import org.jetbrains.plugins.scala.annotator.intention.sbt.ui.SbtArtifactSearchWizard import org.jetbrains.plugins.scala.debugger.evaluation.ScalaCodeFragment +import org.jetbrains.plugins.scala.extensions import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr @@ -42,7 +44,10 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio override def invoke(project: Project, editor: Editor, file: PsiFile): Unit = { def filterByScalaVer(artifacts: Set[ArtifactInfo]): Set[ArtifactInfo] = { val scalaVer = refElement.module.flatMap(_.scalaSdk.map(_.languageLevel.version)) - scalaVer.map(version => artifacts.filter(_.artifactId.endsWith(version))).getOrElse(artifacts) + scalaVer + .map(version => artifacts.filter(_.artifactId.endsWith(version))) + .map(res => if (res.nonEmpty) res else artifacts) + .getOrElse(artifacts) } val baseDir: VirtualFile = project.getBaseDir val sbtFileOpt: Option[VirtualFile] = { @@ -55,21 +60,57 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio val resolver: SbtResolver = SbtResolver.localCacheResolver(None) - for { - sbtFile <- sbtFileOpt - ivyIndex <- resolver.getIndex(project) - artifactInfoSet = ivyIndex.searchArtifactInfo(getReferenceText) - psiSbtFile = PsiManager.getInstance(project).findFile(sbtFile).asInstanceOf[ScalaFile] - depPlaces = getDependencyPlaces(project, psiSbtFile) - matchingScala = filterByScalaVer(artifactInfoSet) - wizard = new SbtArtifactSearchWizard(project, matchingScala, depPlaces) - (infoOption, fileLineOption) = wizard.search() - artifactInfo <- infoOption - fileLine <- fileLineOption - } { - addDependency(fileLine.element, artifactInfo)(project) - refresh(project) - } + ProgressManager.getInstance().run(new Task.Modal(project, getText, true) { + + override def run(indicator: ProgressIndicator): Unit = { + import com.intellij.notification.Notifications.Bus + def error(msg: String): Unit = Bus.notify(new Notification(getText, getText, msg, NotificationType.ERROR)) + def getDeps: Set[ArtifactInfo] = { + indicator.setText("Searching for artifacts...") + val fqName = extensions.inReadAction(getReferenceText) + val artifactInfoSet = resolver.getIndex(project) + .map(_.searchArtifactInfo(fqName)) + .getOrElse(Set.empty) + extensions.inReadAction(filterByScalaVer(artifactInfoSet)) + } + + def getPlaces: Seq[DependencyPlaceInfo] = { + indicator.setText("Finding SBT dependency declarations...") + val depPlaces = extensions.inReadAction( + for { + sbtFile <- sbtFileOpt + psiSbtFile = PsiManager.getInstance(project).findFile(sbtFile).asInstanceOf[ScalaFile] + depPlaces = getDependencyPlaces(project, psiSbtFile) + } yield depPlaces + ) + depPlaces.getOrElse(Seq.empty) + } + + indicator.setIndeterminate(true) + + val deps = getDeps + if (deps.isEmpty) { + error("No dependencies found for given import") + return + } + + val places = getPlaces + if (places.isEmpty) { + error("No places to add a dependency found") + return + } + + ApplicationManager.getApplication.invokeLater { () => + val wizard = new SbtArtifactSearchWizard(project, deps, places) + wizard.search() match { + case (Some(artifactInfo), Some(fileLine)) => + addDependency(fileLine.element, artifactInfo)(project) + refresh(project) + case _ => + } + } + } + }) } private def getDependencyPlaces(project: Project, psiSbtFile: ScalaFile): Seq[DependencyPlaceInfo] = { From 6bc85c21db00bef4cf3c0a848010c3beef902f68 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Fri, 27 Oct 2017 23:01:33 +0300 Subject: [PATCH 079/141] major UI refactoring of SBT dependency suggester fix #SCL-12804 fix #SCL-12644 --- .../scala/annotator/ScalaAnnotator.scala | 4 +- .../intention/sbt/AddSbtDependencyFix.scala | 19 +- .../ui/SbtArtifactChooseDependencyStep.scala | 15 +- .../sbt/ui/SbtArtifactSearchPanel.scala | 113 ++------- .../sbt/ui/SbtArtifactSearchWizard.scala | 17 +- .../sbt/ui/SbtPossiblePlacesPanel.scala | 225 ++++++------------ .../sbt/ui/SbtPossiblePlacesStep.scala | 21 +- 7 files changed, 137 insertions(+), 277 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index 8b115025261..d8eef3cf139 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -797,7 +797,7 @@ abstract class ScalaAnnotator extends Annotator annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) annotation.registerFix(ReportHighlightingErrorQuickFix) registerCreateFromUsageFixesFor(refElement, annotation) - annotation.registerFix(new AddSbtDependencyFix(refElement)) + annotation.registerFix(new AddSbtDependencyFix(SmartPointerManager.getInstance(refElement.getProject).createSmartPsiElementPointer(refElement))) } } @@ -867,7 +867,7 @@ abstract class ScalaAnnotator extends Annotator annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) annotation.registerFix(ReportHighlightingErrorQuickFix) registerCreateFromUsageFixesFor(refElement, annotation) - annotation.registerFix(new AddSbtDependencyFix(refElement)) + annotation.registerFix(new AddSbtDependencyFix(SmartPointerManager.getInstance(refElement.getProject).createSmartPsiElementPointer(refElement))) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index 700be21fbc9..18d3cf94325 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -11,9 +11,10 @@ import com.intellij.openapi.module.{ModuleManager, ModuleUtilCore} import com.intellij.openapi.progress.{ProgressIndicator, ProgressManager, Task} import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile -import com.intellij.psi.{PsiElement, PsiFile, PsiManager} +import com.intellij.psi.{PsiElement, PsiFile, PsiManager, SmartPsiElementPointer} import org.jetbrains.plugins.scala.annotator.intention.sbt.AddSbtDependencyUtils._ import org.jetbrains.plugins.scala.annotator.intention.sbt.ui.SbtArtifactSearchWizard +import org.jetbrains.plugins.scala.codeInspection.AbstractFixOnPsiElement import org.jetbrains.plugins.scala.debugger.evaluation.ScalaCodeFragment import org.jetbrains.plugins.scala.extensions import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile @@ -29,12 +30,13 @@ import org.jetbrains.sbt.settings.SbtSystemSettings /** * Created by afonichkin on 7/7/17. */ -class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionAction with LowPriorityAction { +class AddSbtDependencyFix(refElement: SmartPsiElementPointer[ScReferenceElement]) extends IntentionAction with LowPriorityAction { override def isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean = { - refElement.isValid && + val element = refElement.getElement + element.isValid && file != null && file.isInstanceOf[ScalaFile] && - refElement.getManager.isInProject(file) && + element.getManager.isInProject(file) && ! file.isInstanceOf[ScalaCodeFragment] && ! SbtSystemSettings.getInstance(project).getLinkedProjectsSettings.isEmpty } @@ -42,8 +44,9 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio override def getText: String = "Add sbt dependency..." override def invoke(project: Project, editor: Editor, file: PsiFile): Unit = { + val element = refElement.getElement def filterByScalaVer(artifacts: Set[ArtifactInfo]): Set[ArtifactInfo] = { - val scalaVer = refElement.module.flatMap(_.scalaSdk.map(_.languageLevel.version)) + val scalaVer = element.module.flatMap(_.scalaSdk.map(_.languageLevel.version)) scalaVer .map(version => artifacts.filter(_.artifactId.endsWith(version))) .map(res => if (res.nonEmpty) res else artifacts) @@ -122,7 +125,7 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio val sbtProjects: Seq[ScPatternDefinition] = getTopLevelSbtProjects(psiSbtFile) - val moduleName = ModuleUtilCore.findModuleForPsiElement(refElement).getName + val moduleName = ModuleUtilCore.findModuleForPsiElement(refElement.getElement).getName val modules = ModuleManager.getInstance(project).getModules val projToAffectedModules = sbtProjects.map(proj => proj -> modules.map(_.getName).filter(containsModuleName(proj, _))).toMap @@ -155,7 +158,7 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio proj.getText.contains("\"" + moduleName + "\"") private def getReferenceText: String = { - var result = refElement + var result = refElement.getElement while (result.getParent.isInstanceOf[ScReferenceElement]) { result = result.getParent.asInstanceOf[ScReferenceElement] } @@ -166,4 +169,6 @@ class AddSbtDependencyFix(refElement: ScReferenceElement) extends IntentionActio override def getFamilyName = "Add sbt dependencies" override def startInWriteAction(): Boolean = false + + } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala index e47c745c241..ec13a5b1073 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactChooseDependencyStep.scala @@ -3,26 +3,29 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt.ui import javax.swing.{Icon, JComponent} import com.intellij.ide.wizard.Step +import com.intellij.util.ui.JBUI import org.jetbrains.sbt.resolvers.ArtifactInfo /** * Created by afonichkin on 7/19/17. */ -class SbtArtifactChooseDependencyStep(wizard: SbtArtifactSearchWizard, artifactInfoSet: Set[ArtifactInfo]) - extends SbtArtifactSearchPanel(wizard, artifactInfoSet) with Step { +class SbtArtifactChooseDependencyStep(wizard: SbtArtifactSearchWizard, artifactInfoSet: Set[ArtifactInfo]) extends Step { + + private val panel = new SbtArtifactSearchPanel(wizard, artifactInfoSet) override def _init(): Unit = { wizard.setTitle("sbt artifact search") - updateUI() + wizard.setSize(JBUI.scale(300), JBUI.scale(400)) + wizard.getContentComponent.updateUI() } override def getIcon: Icon = null override def _commit(finishChosen: Boolean): Unit = { - wizard.resultArtifact = getResult + wizard.resultArtifact = Option(panel.myResultList.getSelectedValue) } - override def getPreferredFocusedComponent: JComponent = this + override def getPreferredFocusedComponent: JComponent = panel - override def getComponent: JComponent = this + override def getComponent: JComponent = panel } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala index 542d3408117..e3ad9fee0da 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala @@ -1,114 +1,51 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt.ui -import java.awt.{BorderLayout, Component} +import java.awt.BorderLayout import javax.swing._ -import javax.swing.event.{TreeModelListener, TreeSelectionEvent, TreeSelectionListener} -import javax.swing.tree.{TreeCellRenderer, TreeModel, TreePath, TreeSelectionModel} +import javax.swing.event._ import com.intellij.icons.AllIcons -import com.intellij.ui.treeStructure.Tree -import com.intellij.ui.{ScrollPaneFactory, SimpleColoredComponent, SimpleTextAttributes} -import com.intellij.util.ui.UIUtil +import com.intellij.util.text.VersionComparatorUtil.compare +import com.intellij.ui._ +import com.intellij.ui.components.JBList import org.jetbrains.sbt.resolvers.ArtifactInfo +import scala.collection.JavaConverters.asJavaCollectionConverter + /** * Created by afonichkin on 7/13/17. */ class SbtArtifactSearchPanel(wizard: SbtArtifactSearchWizard, artifactInfoSet: Set[ArtifactInfo]) extends JPanel { - var canGoNext: Boolean = false - val myResultList: Tree = new Tree() + val myResultList = new JBList[ArtifactInfo]() init() def init(): Unit = { - myResultList.setExpandableItemsEnabled(false) - - if (artifactInfoSet.isEmpty) - myResultList.getEmptyText.setText("Nothing to show") - else - myResultList.getEmptyText.setText("Loading...") - - myResultList.setRootVisible(false) - myResultList.setShowsRootHandles(true) - - myResultList.setModel(new MyTreeModel(artifactInfoSet.toSeq)) - myResultList.getSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION) - + val artifacts = artifactInfoSet + .toSeq + .sortWith((a, b) => + a.groupId >= b.groupId && + a.artifactId >= b.artifactId && + compare(a.version, b.version) >= 0 + ) + + myResultList.setModel(new DependencyListModel(artifacts)) + myResultList.getSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) setLayout(new BorderLayout()) val pane = ScrollPaneFactory.createScrollPane(myResultList) pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) // Don't remove this line. - add(pane, BorderLayout.CENTER) - myResultList.setCellRenderer(new MyCellRenderer) - - myResultList.addTreeSelectionListener(new TreeSelectionListener { - override def valueChanged(treeSelectionEvent: TreeSelectionEvent): Unit = { - canGoNext = treeSelectionEvent.getNewLeadSelectionPath != null - wizard.updateWizardButtons() - } - }) + myResultList.setCellRenderer(new DependencyListCellRenderer()) + myResultList.addListSelectionListener((_: ListSelectionEvent) => wizard.updateButtons(false, !myResultList.isSelectionEmpty, true)) } - def getResult: Option[ArtifactInfo] = { - for (path: TreePath <- myResultList.getSelectionPaths) { - path.getLastPathComponent match { - case info: ArtifactInfo => return Some(info) - case _ => - } + private class DependencyListModel(elems: Seq[ArtifactInfo]) extends CollectionListModel[ArtifactInfo](elems.asJavaCollection) + private class DependencyListCellRenderer extends ColoredListCellRenderer[ArtifactInfo] { + override def customizeCellRenderer(list: JList[_ <: ArtifactInfo], value: ArtifactInfo, index: Int, selected: Boolean, hasFocus: Boolean): Unit = { + setIcon(AllIcons.Modules.Library) + append(s"${value.groupId}:${value.artifactId}:${value.version}") } - None - } - - private class MyTreeModel(elements: Seq[ArtifactInfo]) extends TreeModel { - override def getIndexOfChild(parent: scala.Any, child: scala.Any): Int = elements.indexOf(child) - - override def valueForPathChanged(treePath: TreePath, o: scala.Any): Unit = {} - - override def getChild(parent: scala.Any, index: Int): AnyRef = elements(index) - - override def addTreeModelListener(treeModelListener: TreeModelListener): Unit = {} - - override def isLeaf(node: scala.Any): Boolean = node != elements - - override def removeTreeModelListener(treeModelListener: TreeModelListener): Unit = {} - - override def getChildCount(o: scala.Any): Int = elements.size - - override def getRoot: AnyRef = elements - } - - private class MyCellRenderer extends JPanel with TreeCellRenderer { - val myComponent: SimpleColoredComponent = new SimpleColoredComponent - - init() - - def init(): Unit = { - myComponent.setOpaque(false) - myComponent.setIconOpaque(false) - add(myComponent) - } - - override def getTreeCellRendererComponent(tree: JTree, value: scala.Any, selected: Boolean, expanded: Boolean, - leaf: Boolean, row: Int, hasFocus: Boolean): Component = { - myComponent.clear() - - setBackground(if (selected) UIUtil.getTreeSelectionBackground else tree.getBackground) - - value match { - case info: ArtifactInfo => - myComponent.setIcon(AllIcons.Nodes.PpLib) - myComponent.append(info.groupId + ":", getGrayAttributes(selected)) - myComponent.append(info.artifactId, SimpleTextAttributes.REGULAR_ATTRIBUTES) - myComponent.append(":" + info.version, getGrayAttributes(selected)) - case _ => - } - - this - } - - private def getGrayAttributes(selected: Boolean): SimpleTextAttributes = - if (!selected) SimpleTextAttributes.GRAY_ATTRIBUTES else SimpleTextAttributes.REGULAR_ATTRIBUTES } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchWizard.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchWizard.scala index a303a81ea41..82e5cea1db0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchWizard.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchWizard.scala @@ -17,29 +17,22 @@ class SbtArtifactSearchWizard(project: Project, artifactInfoSet: Set[ArtifactInf var resultArtifact: Option[ArtifactInfo] = _ var resultFileLine: Option[DependencyPlaceInfo] = _ - override def init(): Unit = { - super.init() - } - override def getHelpID: String = null def search(): (Option[ArtifactInfo], Option[DependencyPlaceInfo]) = { if (!showAndGet()) { return (None, None) } - (resultArtifact, resultFileLine) } - override def canGoNext: Boolean = { - if (getCurrentStepObject == sbtArtifactSearchStep) { - sbtArtifactSearchStep.canGoNext - } else { - sbtPossiblePlacesStep.canGoNext - } - } addStep(sbtArtifactSearchStep) addStep(sbtPossiblePlacesStep) init() + + override def dispose(): Unit = { + sbtPossiblePlacesStep.panel.releaseEditor() + super.dispose() + } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index f9050f14f52..8c828c26abd 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -1,9 +1,8 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt.ui -import java.awt.{BorderLayout, Component, Dimension} -import javax.swing.event.{TreeModelListener, TreeSelectionEvent, TreeSelectionListener} -import javax.swing.tree.{TreeCellRenderer, TreeModel, TreePath, TreeSelectionModel} -import javax.swing.{JPanel, JTree, ScrollPaneConstants} +import java.awt.BorderLayout +import javax.swing._ +import javax.swing.event._ import com.intellij.icons.AllIcons import com.intellij.openapi.editor.colors.CodeInsightColors @@ -13,187 +12,105 @@ import com.intellij.openapi.editor.markup.{HighlighterLayer, HighlighterTargetAr import com.intellij.openapi.editor.{Editor, EditorFactory, LogicalPosition, ScrollType} import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.project.Project -import com.intellij.psi.PsiElement -import com.intellij.ui.treeStructure.Tree -import com.intellij.ui.{ScrollPaneFactory, SimpleColoredComponent, SimpleTextAttributes} -import com.intellij.util.ui.UIUtil -import org.jetbrains.plugins.scala.ScalaFileType +import com.intellij.ui._ +import com.intellij.ui.components.JBList import org.jetbrains.plugins.scala.annotator.intention.sbt.{AddSbtDependencyUtils, DependencyPlaceInfo} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory +import org.jetbrains.plugins.scala.{ScalaFileType, extensions} + +import scala.collection.JavaConverters.asJavaCollectionConverter /** * Created by afonichkin on 7/19/17. */ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, fileLines: Seq[DependencyPlaceInfo]) extends JPanel { - val myResultList: Tree = new Tree() - var myCurFileLine: DependencyPlaceInfo = _ - - var canGoNext: Boolean = false - - val myLayout = new BorderLayout() - var myCurEditor: Editor = _ + val myResultList: JBList[DependencyPlaceInfo] = new JBList[DependencyPlaceInfo]() + var myCurEditor: Editor = createEditor() - val EDITOR_TOP_MARGIN = 7 + private val EDITOR_TOP_MARGIN = 7 init() def init(): Unit = { - myResultList.setExpandableItemsEnabled(false) - - if (fileLines.isEmpty) - myResultList.getEmptyText.setText("Nothing to show") - else - myResultList.getEmptyText.setText("Loading...") - - myResultList.setRootVisible(false) - myResultList.setShowsRootHandles(true) - - myResultList.setModel(new MyTreeModel(fileLines)) - myResultList.getSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION) - - setLayout(myLayout) - - val pane = ScrollPaneFactory.createScrollPane(myResultList) - pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) // Don't remove this line. - - add(pane, BorderLayout.CENTER) - - myResultList.setCellRenderer(new MyCellRenderer) - - myResultList.addTreeSelectionListener((treeSelectionEvent: TreeSelectionEvent) => { - val path = treeSelectionEvent.getNewLeadSelectionPath - if (path == null) { - canGoNext = false - myCurFileLine = null - updateEditor() - } else { - path.getLastPathComponent match { - case fileLine: DependencyPlaceInfo if myCurFileLine != fileLine => - canGoNext = true - myCurFileLine = fileLine - updateEditor() - case _ => - } - } - wizard.updateWizardButtons() - }) - } + setLayout(new BorderLayout()) - private def updateEditor(): Unit = { - if (myCurFileLine == null) { - remove(myLayout.getLayoutComponent(BorderLayout.SOUTH)) - updateUI() - } else { - val editor = createEditor(myCurFileLine.path) - val editorHighlighter = EditorHighlighterFactory.getInstance.createEditorHighlighter(project, ScalaFileType.INSTANCE) - editor.asInstanceOf[EditorEx].setHighlighter(editorHighlighter) - editor.getCaretModel.moveToOffset(myCurFileLine.offset) - val scrollingModel = editor.getScrollingModel - scrollingModel.scrollToCaret(ScrollType.CENTER) - val oldPos = editor.offsetToLogicalPosition(myCurFileLine.offset) - scrollingModel.scrollTo(new LogicalPosition(math.max(1, oldPos.line - EDITOR_TOP_MARGIN), oldPos.column), ScrollType.CENTER) - - releaseEditor() - myCurEditor = editor - - add(editor.getComponent, BorderLayout.SOUTH) - updateUI() - } - } + val splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT) - def releaseEditor(): Unit = { - val prevSouthComponent = myLayout.getLayoutComponent(BorderLayout.SOUTH) - if (prevSouthComponent != null) - remove(prevSouthComponent) + myResultList.setModel(new CollectionListModel[DependencyPlaceInfo](fileLines.asJavaCollection)) + myResultList.getSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) - if (myCurEditor != null) - EditorFactory.getInstance.releaseEditor(myCurEditor) - } + val scrollPane = ScrollPaneFactory.createScrollPane(myResultList) + scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) // Don't remove this line. + splitPane.setContinuousLayout(true) + splitPane.add(scrollPane) + splitPane.add(myCurEditor.getComponent) - private def createEditor(path: String): Editor = { - val document = FileDocumentManager.getInstance.getDocument(project.getBaseDir.findFileByRelativePath(path)) - val tmpFile = ScalaPsiElementFactory.createScalaFileFromText(document.getText)(project) - var tmpElement = tmpFile.findElementAt(myCurFileLine.element.getTextOffset) - while (tmpElement.getTextRange != myCurFileLine.element.getTextRange) - tmpElement = tmpElement.getParent + add(splitPane, BorderLayout.CENTER) - val dep: PsiElement = AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project).get + GuiUtils.replaceJSplitPaneWithIDEASplitter(splitPane) + myResultList.setCellRenderer(new PlacesCellRenderer) - val viewer = EditorFactory.getInstance.createViewer( - EditorFactory.getInstance().createDocument(tmpFile.getText) - ) - - val scheme = viewer.getColorsScheme - val attributes = scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) - - viewer.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, dep.getTextRange.getEndOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE) - - - viewer.getComponent.updateUI() - - viewer - } - - def getResult: Option[DependencyPlaceInfo] = { - for (path: TreePath <- myResultList.getSelectionPaths) { - path.getLastPathComponent match { - case info: DependencyPlaceInfo => return Some(info) - case _ => + myResultList.addListSelectionListener { (_: ListSelectionEvent) => + val place = myResultList.getSelectedValue + if (place != null) { + if (myCurEditor == null) + myCurEditor = createEditor() + updateEditor(place) } + wizard.updateButtons(true, place != null, false) } - None } - private class MyTreeModel(elements: Seq[DependencyPlaceInfo]) extends TreeModel { - override def getIndexOfChild(parent: scala.Any, child: scala.Any): Int = elements.indexOf(child) - - override def valueForPathChanged(treePath: TreePath, o: scala.Any): Unit = {} - - override def getChild(parent: scala.Any, index: Int): AnyRef = elements(index) - - override def addTreeModelListener(treeModelListener: TreeModelListener): Unit = {} - - override def isLeaf(node: scala.Any): Boolean = node != elements - - override def removeTreeModelListener(treeModelListener: TreeModelListener): Unit = {} + private def updateEditor(myCurFileLine: DependencyPlaceInfo): Unit = { + val document = FileDocumentManager.getInstance.getDocument(project.getBaseDir.findFileByRelativePath(myCurFileLine.path)) + val tmpFile = ScalaPsiElementFactory.createScalaFileFromText(document.getText)(project) + var tmpElement = tmpFile.findElementAt(myCurFileLine.element.getTextOffset) + while (tmpElement.getTextRange != myCurFileLine.element.getTextRange) { + tmpElement = tmpElement.getParent + } + val dep = AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project).get - override def getChildCount(o: scala.Any): Int = elements.size + extensions.inWriteAction { + myCurEditor.getDocument.setText(tmpFile.getText) + } - override def getRoot: AnyRef = elements + myCurEditor.getCaretModel.moveToOffset(myCurFileLine.offset) + val scrollingModel = myCurEditor.getScrollingModel + val oldPos = myCurEditor.offsetToLogicalPosition(myCurFileLine.offset) + scrollingModel.scrollTo(new LogicalPosition(math.max(1, oldPos.line - EDITOR_TOP_MARGIN), oldPos.column), + ScrollType.CENTER) + val attributes = myCurEditor.getColorsScheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) + myCurEditor.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, + dep.getTextRange.getEndOffset, + HighlighterLayer.SELECTION, + attributes, + HighlighterTargetArea.EXACT_RANGE + ) } - private class MyCellRenderer extends JPanel with TreeCellRenderer { - val myComponent: SimpleColoredComponent = new SimpleColoredComponent - - init() - - def init(): Unit = { - myComponent.setOpaque(false) - myComponent.setIconOpaque(false) - add(myComponent) + def releaseEditor(): Unit = { + if (myCurEditor != null && !myCurEditor.isDisposed) { + EditorFactory.getInstance.releaseEditor(myCurEditor) + myCurEditor = null } + } - override def getTreeCellRendererComponent(tree: JTree, value: scala.Any, selected: Boolean, expanded: Boolean, - leaf: Boolean, row: Int, hasFocus: Boolean): Component = { - myComponent.clear() - - setBackground(if (selected) UIUtil.getTreeSelectionBackground else tree.getBackground) - - value match { - case info: DependencyPlaceInfo => - myComponent.setIcon(AllIcons.Nodes.PpFile) - myComponent.append(info.path + ":", SimpleTextAttributes.REGULAR_ATTRIBUTES) - myComponent.append(info.line.toString, getGrayAttributes(selected)) - if (info.affectedProjects.nonEmpty) - myComponent.append(" (" + info.affectedProjects.map(_.toString).mkString(", ") + ")", SimpleTextAttributes.REGULAR_ATTRIBUTES) - case _ => - } + private def createEditor(): Editor = { + val viewer = EditorFactory.getInstance.createViewer(EditorFactory.getInstance().createDocument("")) + val editorHighlighter = EditorHighlighterFactory.getInstance.createEditorHighlighter(project, ScalaFileType.INSTANCE) + viewer.asInstanceOf[EditorEx].setHighlighter(editorHighlighter) + viewer + } - this + private class PlacesCellRenderer extends ColoredListCellRenderer[DependencyPlaceInfo] { + override def customizeCellRenderer(list: JList[_ <: DependencyPlaceInfo], info: DependencyPlaceInfo, index: Int, selected: Boolean, hasFocus: Boolean): Unit = { + setIcon(AllIcons.Nodes.PpFile) + append(info.path + ":", SimpleTextAttributes.REGULAR_ATTRIBUTES) + append(info.line.toString, getGrayAttributes(selected)) + if (info.affectedProjects.nonEmpty) + append(" (" + info.affectedProjects.map(_.toString).mkString(", ") + ")", SimpleTextAttributes.REGULAR_ATTRIBUTES) } - private def getGrayAttributes(selected: Boolean): SimpleTextAttributes = if (!selected) SimpleTextAttributes.GRAY_ATTRIBUTES else SimpleTextAttributes.REGULAR_ATTRIBUTES } - } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala index 88804b08324..252b81791f8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala @@ -6,30 +6,35 @@ import com.intellij.ide.wizard.Step import com.intellij.openapi.project.Project import com.intellij.util.ui.JBUI import org.jetbrains.plugins.scala.annotator.intention.sbt.DependencyPlaceInfo +import org.jetbrains.plugins.scala.extensions /** * Created by afonichkin on 7/19/17. */ class SbtPossiblePlacesStep(wizard: SbtArtifactSearchWizard, project: Project, fileLines: Seq[DependencyPlaceInfo]) - extends SbtPossiblePlacesPanel(project, wizard, fileLines) with Step { + extends Step { + + val panel = new SbtPossiblePlacesPanel(project, wizard, fileLines) override def _init(): Unit = { wizard.setTitle("Place to add dependency") - wizard.setSize(JBUI.scale(600), JBUI.scale(750)) - updateUI() + wizard.setSize(JBUI.scale(800), JBUI.scale(7950)) + panel.myResultList.clearSelection() + extensions.inWriteAction { + panel.myCurEditor.getDocument.setText("// Select a place from the list above to enable this preview") + } + panel.updateUI() } - override def getComponent: JComponent = this + override def getComponent: JComponent = panel override def _commit(finishChosen: Boolean): Unit = { if (finishChosen) { - wizard.resultFileLine = getResult + wizard.resultFileLine = Option(panel.myResultList.getSelectedValue) } - - releaseEditor() } override def getIcon: Icon = null - override def getPreferredFocusedComponent: JComponent = this + override def getPreferredFocusedComponent: JComponent = panel } From 79e6c98f4eb24438c60ce26352172c065f0165be Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Sat, 28 Oct 2017 13:06:41 +0200 Subject: [PATCH 080/141] ensure scala-xml lib is available for tests in both scala 2.12 and 2.11 versions --- project/dependencies.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index b08d5eb94b2..121198d8290 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -152,7 +152,6 @@ object DependencyGroups { val testDownloader = Seq( - scalaXml, "com.chuusai" % "shapeless_2.11" % "2.0.0", "com.fommil" % "stalactite_2.11" % "0.0.3", "com.github.julien-truffaut" %% "monocle-core" % monocleVersion, @@ -168,8 +167,9 @@ object DependencyGroups { "com.typesafe.akka" % "akka-stream_2.11" % "2.4.19", "com.typesafe.play" % "play_2.10" % "2.4.10", "com.typesafe.slick" % "slick_2.11" % "3.2.1", -// "io.spray" %% "spray-routing" % "1.3.4", "org.scala-lang.modules" % "scala-async_2.11" % "0.9.5", + "org.scala-lang.modules" % "scala-xml_2.11" % "1.0.6", + "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6", "org.specs2" % "specs2_2.10" % "2.4.6", "org.scala-js" % "scalajs-library_2.10" % "0.6.14", "org.scalaz" % "scalaz-core_2.10" % scalazVersion, From 4a68e0d1d997efb5c164fb0845aa543aca7fef9a Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Sat, 28 Oct 2017 13:51:16 +0200 Subject: [PATCH 081/141] add missing specs2-core dependency --- project/dependencies.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index 121198d8290..47c3216068c 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -170,14 +170,15 @@ object DependencyGroups { "org.scala-lang.modules" % "scala-async_2.11" % "0.9.5", "org.scala-lang.modules" % "scala-xml_2.11" % "1.0.6", "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6", - "org.specs2" % "specs2_2.10" % "2.4.6", "org.scala-js" % "scalajs-library_2.10" % "0.6.14", "org.scalaz" % "scalaz-core_2.10" % scalazVersion, "org.scalaz" % "scalaz-concurrent_2.10" % scalazVersion, "org.scalaz" % "scalaz-core_2.11" % scalazVersion, "org.scalaz" % "scalaz-concurrent_2.11" % scalazVersion, "org.scalaz.stream" % "scalaz-stream_2.11" % "0.6a", + "org.specs2" % "specs2_2.10" % "2.4.6", "org.specs2" % "specs2_2.11" % "2.4.15", + "org.specs2" % "specs2-core_2.12" % "4.0.0", "org.specs2" % "specs2-core_2.11" % "3.0.1", "org.specs2" % "specs2-common_2.11" % "3.0.1", "org.specs2" % "specs2-matcher_2.11" % "3.0.1", From 24d0a3a349e7bb6d78c3cc626fc77d00f2a91a0c Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 27 Oct 2017 12:55:52 +0200 Subject: [PATCH 082/141] fix scalatest/scalactic/scalaxml loading in tests --- project/dependencies.scala | 3 ++- .../scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala | 2 +- .../scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index c334e8bafc7..397594b13a9 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -190,7 +190,8 @@ object DependencyGroups { "org.scalatest" % "scalatest_2.11" % "2.2.1", "org.scalatest" % "scalatest_2.11" % "3.0.1", "org.scalactic" % "scalactic_2.11" % "3.0.1", -// "org.scalatest" % "scalatest_2.12" % "3.0.1", + "org.scalactic" % "scalactic_2.12" % "3.0.4", + "org.scalatest" % "scalatest_2.12" % "3.0.4", "org.scalameta" % s"paradise_$scalaVersion" % paradiseVersion exclude("org.scalameta", s"scalameta_$scalaBinaryVersion"), "org.scalameta" % "scalameta_2.11" % scalaMetaVersion, "org.scalameta" % "scalameta_2.12" % scalaMetaVersion, diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala index f34cc2a4f9d..10e69248c0f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/libraryLoaders/ThirdPartyLibraryLoader.scala @@ -120,7 +120,7 @@ case class ScalaTestLoader(override val version: String, override val vendor: String = "org.scalatest" } -case class ScalaXmlLoader(override val version: String = "1.0.1")(implicit val module: Module) extends IvyLibraryLoaderAdapter { +case class ScalaXmlLoader(override val version: String = "1.0.6")(implicit val module: Module) extends IvyLibraryLoaderAdapter { override val name: String = "scala-xml" override val vendor: String = "org.scala-lang.modules" override val ivyType: IvyType = Bundles diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala index 6fc2770eb5e..a82786e4a70 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/scalatest/scala2_12/scalatest3_0_4/Scalatest2_12_3_0_4_Base.scala @@ -15,6 +15,6 @@ abstract class Scalatest2_12_3_0_4_Base extends ScalaTestTestCase { override protected def additionalLibraries: Seq[ThirdPartyLibraryLoader] = { implicit val module: Module = getModule - Seq(ScalaTestLoader("3.0.4", IvyLibraryLoader.Bundles), ScalaXmlLoader("1.0.5"), ScalacticLoader("3.0.4", IvyLibraryLoader.Bundles)) + Seq(ScalaTestLoader("3.0.4", IvyLibraryLoader.Bundles), ScalaXmlLoader(), ScalacticLoader("3.0.4", IvyLibraryLoader.Bundles)) } } From 5900b6a5ae0faa2b3845e564fb315474d597b804 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Sat, 28 Oct 2017 13:06:41 +0200 Subject: [PATCH 083/141] ensure scala-xml lib is available for tests in both scala 2.12 and 2.11 versions --- project/dependencies.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index 397594b13a9..3acf912594a 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -152,7 +152,6 @@ object DependencyGroups { val testDownloader = Seq( - scalaXml, "com.chuusai" % "shapeless_2.11" % "2.0.0", "com.fommil" % "stalactite_2.11" % "0.0.3", "com.github.julien-truffaut" %% "monocle-core" % monocleVersion, @@ -168,8 +167,9 @@ object DependencyGroups { "com.typesafe.akka" % "akka-stream_2.11" % "2.4.19", "com.typesafe.play" % "play_2.10" % "2.4.10", "com.typesafe.slick" % "slick_2.11" % "3.2.1", -// "io.spray" %% "spray-routing" % "1.3.4", "org.scala-lang.modules" % "scala-async_2.11" % "0.9.5", + "org.scala-lang.modules" % "scala-xml_2.11" % "1.0.6", + "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6", "org.specs2" % "specs2_2.10" % "2.4.6", "org.scala-js" % "scalajs-library_2.10" % "0.6.14", "org.scalaz" % "scalaz-core_2.10" % scalazVersion, From 7a9ca0a515e920800b166cdd5ae32e96813adab7 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Sat, 28 Oct 2017 13:51:16 +0200 Subject: [PATCH 084/141] add missing specs2-core dependency --- project/dependencies.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index 3acf912594a..3b4eb37850d 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -170,14 +170,15 @@ object DependencyGroups { "org.scala-lang.modules" % "scala-async_2.11" % "0.9.5", "org.scala-lang.modules" % "scala-xml_2.11" % "1.0.6", "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6", - "org.specs2" % "specs2_2.10" % "2.4.6", "org.scala-js" % "scalajs-library_2.10" % "0.6.14", "org.scalaz" % "scalaz-core_2.10" % scalazVersion, "org.scalaz" % "scalaz-concurrent_2.10" % scalazVersion, "org.scalaz" % "scalaz-core_2.11" % scalazVersion, "org.scalaz" % "scalaz-concurrent_2.11" % scalazVersion, "org.scalaz.stream" % "scalaz-stream_2.11" % "0.6a", + "org.specs2" % "specs2_2.10" % "2.4.6", "org.specs2" % "specs2_2.11" % "2.4.15", + "org.specs2" % "specs2-core_2.12" % "4.0.0", "org.specs2" % "specs2-core_2.11" % "3.0.1", "org.specs2" % "specs2-common_2.11" % "3.0.1", "org.specs2" % "specs2-matcher_2.11" % "3.0.1", From c41b8be4e937e9f1a92d50e4d59cb9de8376fc78 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sat, 28 Oct 2017 21:37:30 +0300 Subject: [PATCH 085/141] pass smart element pointers to expand line marker callback fix #SCL-12805 --- .../macros/expansion/MacroExpansionLineMarkerProvider.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpansionLineMarkerProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpansionLineMarkerProvider.scala index 0e960c53e42..ec526c8407c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpansionLineMarkerProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpansionLineMarkerProvider.scala @@ -11,7 +11,7 @@ import com.intellij.navigation.GotoRelatedItem import com.intellij.openapi.compiler.{CompileContext, CompileStatusNotification, CompilerManager} import com.intellij.openapi.editor.markup.GutterIconRenderer import com.intellij.openapi.util.TextRange -import com.intellij.psi.{PsiElement, PsiManager} +import com.intellij.psi.{PsiElement, PsiManager, SmartPointerManager, SmartPsiElementPointer} import com.intellij.util.Function import org.jetbrains.plugins.scala.ScalaBundle import org.jetbrains.plugins.scala.extensions._ @@ -41,12 +41,13 @@ abstract class MacroExpansionLineMarkerProvider extends RelatedItemLineMarkerPro protected def createNotCompiledLineMarker(element: PsiElement, annot: ScAnnotation): Marker = { import org.jetbrains.plugins.scala.project._ + val eltPointer = SmartPointerManager.getInstance(element.getProject).createSmartPsiElementPointer(element) newMarker(element, AllIcons.General.Help, ScalaBundle.message("scala.meta.recompile")) { elt => CompilerManager.getInstance(elt.getProject).make(annot.constructor.reference.get.resolve().module.get, new CompileStatusNotification { override def finished(aborted: Boolean, errors: Int, warnings: Int, compileContext: CompileContext): Unit = { if (!compileContext.getProject.isDisposed) - DaemonCodeAnalyzer.getInstance(elt.getProject).restart(elt.getContainingFile) + DaemonCodeAnalyzer.getInstance(eltPointer.getElement.getProject).restart(eltPointer.getElement.getContainingFile) } } ) From 9ec32eaf919912f2afe156d3a78efe86d33483d6 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sat, 28 Oct 2017 22:53:48 +0300 Subject: [PATCH 086/141] convert default values for parameters fix #SCL-12816 --- .../scala-impl/src/scala/meta/trees/TreeAdapter.scala | 11 ++++++----- .../scala/meta/converter/TreeConverterDefnTest.scala | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala index cf097004241..79cfbfdc9fa 100644 --- a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala @@ -541,10 +541,11 @@ trait TreeAdapter { } protected def convertParam(param: params.ScParameter): m.Term.Param = { - val mods = convertMods(param) ++ (if (param.isImplicitParameter) Seq(m.Mod.Implicit()) else Seq.empty) - if (param.isVarArgs) - m.Term.Param(mods, toTermName(param), param.typeElement.map(tp => m.Type.Arg.Repeated(toType(tp))), None) - else - m.Term.Param(mods, toTermName(param), param.typeElement.map(toType), None) + val mods = convertMods(param) ++ (if (param.isImplicitParameter) Seq(m.Mod.Implicit()) else Seq.empty) + val default = param.getActualDefaultExpression.map(expression) + if (param.isVarArgs) + m.Term.Param(mods, toTermName(param), param.typeElement.map(tp => m.Type.Arg.Repeated(toType(tp))), default) + else + m.Term.Param(mods, toTermName(param), param.typeElement.map(toType), default) } } diff --git a/scala/scala-impl/test/scala/meta/converter/TreeConverterDefnTest.scala b/scala/scala-impl/test/scala/meta/converter/TreeConverterDefnTest.scala index 68367adbc2e..e760cfe5c74 100644 --- a/scala/scala-impl/test/scala/meta/converter/TreeConverterDefnTest.scala +++ b/scala/scala-impl/test/scala/meta/converter/TreeConverterDefnTest.scala @@ -117,4 +117,11 @@ class TreeConverterDefnTest extends TreeConverterTestBaseWithLibrary { Defn.Def(Nil, Term.Name("f"), Nil, Nil, None, Term.Block(List(Term.Apply(Term.Name("f"), Nil), Term.Apply(Term.Name("f"), Nil), Lit.Int(42)))) ) } + + def testDefaultValue(): Unit = { + doTest( + "def f(a: Int = 42) = a", + Defn.Def(Nil, Term.Name("f"), Nil, List(List(Term.Param(Nil, Term.Name("a"), Some(Type.Name("Int")), Some(Lit.Int(42))))), None, Term.Name("a")) + ) + } } From c394785d84706c483828f3ec0a69c56bec6476cb Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sat, 28 Oct 2017 23:55:26 +0300 Subject: [PATCH 087/141] use up-to-date scala versions in meta annotation tests --- .../scala/meta/ScalaMetaLibrariesOwner.scala | 4 ++-- .../annotations/MetaAnnotationTestBase.scala | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala b/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala index ba1e10c0f6c..721bc76233a 100644 --- a/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala +++ b/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala @@ -2,11 +2,11 @@ package scala.meta import com.intellij.openapi.module.Module import org.jetbrains.plugins.scala.base.libraryLoaders.{IvyLibraryLoaderAdapter, ThirdPartyLibraryLoader} -import org.jetbrains.plugins.scala.debugger.{ScalaSdkOwner, ScalaVersion, Scala_2_11_11} +import org.jetbrains.plugins.scala.debugger.{ScalaSdkOwner, ScalaVersion, Scala_2_12} trait ScalaMetaLibrariesOwner extends ScalaSdkOwner { - override implicit val version: ScalaVersion = Scala_2_11_11 + override implicit val version: ScalaVersion = Scala_2_12 import ScalaMetaLibrariesOwner._ diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala index 4b49719b0d4..51ddbf44d27 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala @@ -4,6 +4,7 @@ import java.io.File import com.intellij.ProjectTopics import com.intellij.compiler.server.BuildManager +import com.intellij.lang.annotation.HighlightSeverity import com.intellij.openapi.editor.markup.GutterIconRenderer import com.intellij.openapi.module.{JavaModuleType, Module} import com.intellij.openapi.project.Project @@ -30,6 +31,7 @@ import org.junit.Assert import org.junit.Assert.fail import org.junit.experimental.categories.Category +import scala.collection.JavaConverters.collectionAsScalaIterableConverter import scala.meta.ScalaMetaLibrariesOwner.MetaBaseLoader import scala.meta.{Compilable, ScalaMetaLibrariesOwner} @@ -95,7 +97,7 @@ abstract class MetaAnnotationTestBase extends JavaCodeInsightFixtureTestCase wit protected def compileMetaSource(source: String = FileUtil.loadFile(new File(getTestDataPath, s"${getTestName(false)}.scala"))): List[String] = { addMetaSource(source) - val cache = new CompilationCache(metaModule, Seq(version.major, ScalaMetaLibrariesOwner.metaVersion)) + val cache = new CompilationCache(metaModule, Seq(version.minor, ScalaMetaLibrariesOwner.metaVersion)) cache.withModuleOutputCache(List[String]()) { setUpCompiler enableParadisePlugin() @@ -112,10 +114,20 @@ abstract class MetaAnnotationTestBase extends JavaCodeInsightFixtureTestCase wit protected def enableParadisePlugin(): Unit = { val profile = ScalaCompilerConfiguration.instanceIn(project).defaultProfile val settings = profile.getSettings - settings.plugins :+= MetaParadiseLoader()(metaModule).path + val path = MetaParadiseLoader()(metaModule).path + assert(new File(path).exists(), "Paradise plugin not found, aborting compilation") + settings.plugins :+= path profile.setSettings(settings) } + protected def checkNoErrorHighlights(expectedMessagePrefix: String = ""): Unit = { + val errors = myFixture.doHighlighting(HighlightSeverity.ERROR).asScala + val (related, unrelated) = errors.partition(_.getDescription.startsWith(expectedMessagePrefix)) + val suffix = if (unrelated.size > 1) s"\nOther errors found:\n${unrelated.mkString("\n")}" else "" + val prefix = related.mkString("\n") + if (related.nonEmpty) + Assert.fail(prefix + suffix) + } protected def checkExpansionEquals(code: String, expectedExpansion: String): Unit = { import scala.meta.intellij.psiExt._ From 410464c33c20a57d8a2efb3d1ea2d76ebf8a97a0 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sat, 28 Oct 2017 23:56:24 +0300 Subject: [PATCH 088/141] directly invoke 2.12 annotations since plugin is now 2.12 based --- .../src/scala/meta/intellij/MetaExpansionsManager.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala b/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala index b76177cfbb2..b3935d73a5a 100644 --- a/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala +++ b/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala @@ -19,7 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.expr.ScAnnotation import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTemplateDefinition, ScTypeDefinition} import org.jetbrains.plugins.scala.macroAnnotations.{CachedInsidePsiElement, ModCount} -import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_11 +import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.{Scala_2_11, Scala_2_12} import scala.collection.immutable import scala.meta.parsers.Parse @@ -90,9 +90,9 @@ class MetaExpansionsManager(project: Project) extends AbstractProjectComponent(p val outDirs: List[URL] = projectOutputDirs(module.getProject).map(str => new File(str).toURI.toURL) val fullCP: immutable.Seq[URL] = outDirs ++ dependencyCP :+ pluginCP // a quick way to test for compatible meta version - check jar name in classpath - if (annot.scalaLanguageLevelOrDefault == Scala_2_11 && dependencyCP.exists(_.toString.contains(s"trees_2.11-$META_MAJOR_VERSION"))) + if (annot.scalaLanguageLevelOrDefault == Scala_2_12 && dependencyCP.exists(_.toString.contains(s"trees_2.12-$META_MAJOR_VERSION"))) new URLClassLoader(fullCP, getClass.getClassLoader) - else if (annot.scalaLanguageLevelOrDefault == Scala_2_11) + else if (annot.scalaLanguageLevelOrDefault == Scala_2_12) new MetaClassLoader(fullCP) else new MetaClassLoader(fullCP, incompScala = true) From dad37fe0ec75f7b0b27abf53167d852ed50fb68a Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sun, 29 Oct 2017 00:05:46 +0300 Subject: [PATCH 089/141] process type parameters from desugared element fix #SCL-12582 --- .../psi/api/toplevel/typedef/ScTypeDefinition.scala | 3 +++ .../toplevel/typedef/ScTypeDefinitionImpl.scala | 6 ++++++ .../meta/annotations/MetaAnnotationBugsTest.scala | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTypeDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTypeDefinition.scala index ff40e795fdf..6feeef1da43 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTypeDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/toplevel/typedef/ScTypeDefinition.scala @@ -15,6 +15,7 @@ import org.jetbrains.plugins.scala.caches.CachesUtil import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.adapters.PsiClassAdapter import org.jetbrains.plugins.scala.lang.psi.api.statements._ +import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.{createObjectWithContext, createTypeElementFromText} import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.SyntheticMembersInjector import org.jetbrains.plugins.scala.lang.psi.types.PhysicalSignature @@ -71,6 +72,8 @@ trait ScTypeDefinition extends ScTemplateDefinition with ScMember case td: ScTypeDefinition => td } + override def typeParameters: Seq[ScTypeParam] + override def syntheticTypeDefinitionsImpl: Seq[ScTypeDefinition] = SyntheticMembersInjector.injectInners(this) override def syntheticMembersImpl: Seq[ScMember] = SyntheticMembersInjector.injectMembers(this) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala index 88b278b507c..2addbfda72f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/toplevel/typedef/ScTypeDefinitionImpl.scala @@ -27,6 +27,7 @@ import org.jetbrains.plugins.scala.lang.lexer._ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.ScModifierList import org.jetbrains.plugins.scala.lang.psi.api.expr.ScBlock +import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScPackaging import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.{ScExtendsBlock, ScTemplateBody, ScTemplateParents} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ @@ -52,6 +53,11 @@ abstract class ScTypeDefinitionImpl protected (stub: ScTemplateDefinitionStub, override def hasTypeParameters: Boolean = typeParameters.nonEmpty + override def typeParameters: Seq[ScTypeParam] = desugaredElement match { + case Some(td: ScTypeDefinition) => td.typeParameters + case _ => super.typeParameters + } + override def add(element: PsiElement): PsiElement = { element match { case member: PsiMember if member.getLanguage.isKindOf(JavaLanguage.INSTANCE) => diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala index 55617200181..ecf6f4c754e 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationBugsTest.scala @@ -267,4 +267,17 @@ class MetaAnnotationBugsTest extends MetaAnnotationTestBase { assertEquals("Reference should resolve to single element in trait", 1, resTrait.size) } + def testSCL12582_2(): Unit = { + compileAnnotBody(s""" q"trait $testClassName[F[_]]" """) + createFile( + s""" + |@$annotName + |trait $testClassName + |class Foo extends $testClassName[Foo] + """.stripMargin + ) + + checkNoErrorHighlights("Wrong number of type parameters.") + } + } From b5f08931f75d9dc7485c424b26e3c8eb4d6515e0 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sun, 29 Oct 2017 00:07:39 +0300 Subject: [PATCH 090/141] replace 2.12 jar-based cross-version meta tests with 2.11 since the project itself is now on 2.12 --- ...ationJarTest212.scala => MetaAnnotationJarTest211.scala} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename scala/scala-impl/test/scala/meta/annotations/{MetaAnnotationJarTest212.scala => MetaAnnotationJarTest211.scala} (68%) diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest212.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest211.scala similarity index 68% rename from scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest212.scala rename to scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest211.scala index 6f833ce57ea..4087fd32850 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest212.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationJarTest211.scala @@ -1,7 +1,7 @@ package scala.meta.annotations import org.jetbrains.plugins.scala.SlowTests -import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_12} +import org.jetbrains.plugins.scala.debugger.{ScalaVersion, Scala_2_11} import org.junit.experimental.categories.Category /** @@ -9,6 +9,6 @@ import org.junit.experimental.categories.Category * @since 26.03.17. */ @Category(Array(classOf[SlowTests])) -class MetaAnnotationJarTest212 extends MetaAnnotationJarTest { - override implicit val version: ScalaVersion = Scala_2_12 +class MetaAnnotationJarTest211 extends MetaAnnotationJarTest { + override implicit val version: ScalaVersion = Scala_2_11 } From dc4b381836b13b74eef48b290e2a7f11539f524f Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sun, 29 Oct 2017 00:39:27 +0300 Subject: [PATCH 091/141] add workaround for freestyle macros fix #SCL-12582 --- .../jetbrains/plugins/scala/annotator/ScalaAnnotator.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index d8eef3cf139..5c99765a040 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -1123,10 +1123,16 @@ abstract class ScalaAnnotator extends Annotator } private def checkAbsentTypeArgs(simpleTypeElement: ScSimpleTypeElement, holder: AnnotationHolder): Unit = { + // Dirty hack(see SCL-12582): we shouldn't complain about missing type args since they will be added by a macro after expansion + def isFreestyleAnnotated(ah: ScAnnotationsHolder): Boolean = { + (ah.findAnnotationNoAliases("freestyle.free") != null) || + ah.findAnnotationNoAliases("freestyle.module") != null + } def needTypeArgs: Boolean = { def noHigherKinds(owner: ScTypeParametersOwner) = !owner.typeParameters.exists(_.typeParameters.nonEmpty) val canHaveTypeArgs = simpleTypeElement.reference.map(_.resolve()).exists { + case ah: ScAnnotationsHolder if isFreestyleAnnotated(ah) => false case c: PsiClass => c.hasTypeParameters case owner: ScTypeParametersOwner => owner.typeParameters.nonEmpty case _ => false From 463993513bb8cfc230eef4dc378e699bbb60d15a Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Sun, 29 Oct 2017 01:05:38 +0300 Subject: [PATCH 092/141] review fixes for #SCL-12523 --- .../src/scala/meta/trees/TreeAdapter.scala | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala index 79cfbfdc9fa..8d96a9b9f29 100644 --- a/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala +++ b/scala/scala-impl/src/scala/meta/trees/TreeAdapter.scala @@ -4,9 +4,9 @@ import com.intellij.openapi.progress.ProgressManager import com.intellij.psi._ import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.api.base._ -import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements._ +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, api => p, types => ptype} @@ -20,23 +20,24 @@ trait TreeAdapter { def ideaToMeta(tree: PsiElement): m.Tree = { ProgressManager.checkCanceled() + tree match { - case t: ScValueDeclaration => toVal(t) - case t: ScVariableDeclaration => toVar(t) - case t: ScTypeAliasDeclaration => toTypeDecl(t) - case t: ScTypeAliasDefinition => toTypeDefn(t) - case t: ScFunctionDeclaration => toFunDecl(t) - case t: ScPatternDefinition => toPatternDefinition(t) - case t: ScVariableDefinition => toVarDefn(t) - case t: ScFunctionDefinition => toFunDefn(t) - case t: ScMacroDefinition => toMacroDefn(t) - case t: ScPrimaryConstructor => ctor(Some(t)) - case t: ScTrait => toTrait(t) - case t: ScClass => toClass(t) - case t: ScObject => toObject(t) - case t: ScAnnotation => toAnnot(t) - case t: ScExpression => expression(Some(t)).get - case t: p.toplevel.imports.ScImportStmt => m.Import(Seq(t.importExprs.map(imports):_*)) + case t: ScValueDeclaration => toVal(t) + case t: ScVariableDeclaration => toVar(t) + case t: ScTypeAliasDeclaration => toTypeDecl(t) + case t: ScTypeAliasDefinition => toTypeDefn(t) + case t: ScFunctionDeclaration => toFunDecl(t) + case t: ScPatternDefinition => toPatternDefinition(t) + case t: ScVariableDefinition => toVarDefn(t) + case t: ScFunctionDefinition => toFunDefn(t) + case t: ScMacroDefinition => toMacroDefn(t) + case t: ScPrimaryConstructor => ctor(Some(t)) + case t: ScTrait => toTrait(t) + case t: ScClass => toClass(t) + case t: ScObject => toObject(t) + case t: ScAnnotation => toAnnot(t) + case t: ScExpression => expression(Some(t)).get + case t: ScImportStmt => m.Import(Seq(t.importExprs.map(imports):_*)) case t: PsiClass => toClass(t) case t: PsiMethod => t ??? @@ -77,8 +78,7 @@ trait TreeAdapter { } def toVarDefn(t: ScVariableDefinition): m.Defn.Var = { - def pattern(bp: ScBindingPattern) = m.Pat.Var.Term(toTermName(bp)) - m.Defn.Var(convertMods(t), Seq(t.bindings.map(pattern): _*), t.declaredType.map(toType(_)), expression(t.expr)) + m.Defn.Var(convertMods(t), Seq(t.pList.patterns.map(pattern): _*), t.declaredType.map(toType(_)), expression(t.expr)) } def toFunDecl(t: ScFunctionDeclaration): m.Decl.Def = { @@ -473,7 +473,7 @@ trait TreeAdapter { case ScLiteral(c: java.lang.Character) => Lit.Char(c) case ScLiteral(b: java.lang.Byte) => Lit.Byte(b) case ScLiteral(s: String) => Lit.String(s) - case ScLiteral(null) => Lit.Null() + case ScLiteral(null) => Lit.Null(()) case _ if l.isSymbol && paradiseCompatibilityHacks => Lit.String(l.getValue.toString) // apparently, Lit.Symbol is no more in paradise case _ if l.isSymbol => Lit.Symbol(l.getValue.asInstanceOf[Symbol]) // symbol literals in meta contain a string as their value case other => other ?! From bc39f26b83fc5abc4d4666855a16c355b49ae332 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 30 Oct 2017 12:41:25 +0100 Subject: [PATCH 093/141] just some inspectioning --- .../TypeInferenceBenchmarkBase.scala | 4 +-- .../TypeInferenceBenchmarks.scala | 2 +- .../adjustTypes/tests/AdjustTypesTests.scala | 34 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarkBase.scala b/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarkBase.scala index 2c61f7eda75..65b5082fc8a 100644 --- a/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarkBase.scala +++ b/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarkBase.scala @@ -40,7 +40,7 @@ abstract class TypeInferenceBenchmarkBase(testName: String) extends TypeInferenc @Warmup(iterations = 3, time = 10, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 10, time = 3, timeUnit = TimeUnit.SECONDS) @Benchmark - def exprTypeUncached(bh: Blackhole) = syncInEdt { + def exprTypeUncached(bh: Blackhole): Unit = syncInEdt { bh.consume(expr.`type`()) scalaPsiManager.clearAllCaches() psiModTracker.incCounter() @@ -50,7 +50,7 @@ abstract class TypeInferenceBenchmarkBase(testName: String) extends TypeInferenc @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) @Benchmark - def exprTypeCachedJavaStructure(bh: Blackhole) = syncInEdt { + def exprTypeCachedJavaStructure(bh: Blackhole): Unit = syncInEdt { bh.consume(expr.`type`()) scalaPsiManager.clearCachesOnChange() } diff --git a/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala b/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala index 8c4a703a3d7..4cfe28ee47b 100644 --- a/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala +++ b/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala @@ -46,5 +46,5 @@ class Slick extends TypeInferenceBenchmarkBase("Slick") { class Cats extends TypeInferenceBenchmarkBase("Cats") { override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(CatsLoader()(module)) + Array(CatsLoader()) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala index 8f618fabb38..4526de7b1d8 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala @@ -10,35 +10,35 @@ import org.jetbrains.plugins.scala.lang.adjustTypes.AdjustTypesTestBase */ class AdjustTypesTests extends AdjustTypesTestBase { - def testSimpleJava() = doTest() + def testSimpleJava(): Unit = doTest() - def testParameterizedJava() = doTest() + def testParameterizedJava(): Unit = doTest() - def testJavaWithImportAlias() = doTest() + def testJavaWithImportAlias(): Unit = doTest() - def testNameConflicts() = doTest() + def testNameConflicts(): Unit = doTest() - def testJavaInnerClasses() = doTest() + def testJavaInnerClasses(): Unit = doTest() - def testPackagings() = doTest() + def testPackagings(): Unit = doTest() - def testAmbiguity() = doTest() + def testAmbiguity(): Unit = doTest() - def testSeveralLevelImports() = doTest() + def testSeveralLevelImports(): Unit = doTest() - def testTypeAlias() = doTest() + def testTypeAlias(): Unit = doTest() - def testTypeProjection() = doTest() + def testTypeProjection(): Unit = doTest() - def testThisType() = doTest() + def testThisType(): Unit = doTest() - def testPrefixed() = doTest() + def testPrefixed(): Unit = doTest() - def testImportedInnerClass() = doTest() + def testImportedInnerClass(): Unit = doTest() - def testInheritedTypeInObject() = doTest() + def testInheritedTypeInObject(): Unit = doTest() - def testRecursiveTypeAlias() = doTest() + def testRecursiveTypeAlias(): Unit = doTest() } class AdjustCatsTypeTest extends AdjustTypesTestBase { @@ -46,11 +46,11 @@ class AdjustCatsTypeTest extends AdjustTypesTestBase { override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = Array(CatsLoader()(module)) - def testSCL10006() = doTest() + def testSCL10006(): Unit = doTest() } class AdjustTypeScalaReflectTest extends AdjustTypesTestBase { override def isIncludeReflectLibrary: Boolean = true - def testClassTag() = doTest() + def testClassTag(): Unit = doTest() } \ No newline at end of file From 04917b52926dc0e96776e5a955b23e63d1cf9ac3 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Mon, 30 Oct 2017 17:24:34 +0300 Subject: [PATCH 094/141] compilation fix --- .../lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala b/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala index 4cfe28ee47b..8c4a703a3d7 100644 --- a/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala +++ b/scala/benchmarks/test/org/jetbrains/plugins/scala/lang/benchmarks/typeInference/TypeInferenceBenchmarks.scala @@ -46,5 +46,5 @@ class Slick extends TypeInferenceBenchmarkBase("Slick") { class Cats extends TypeInferenceBenchmarkBase("Cats") { override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(CatsLoader()) + Array(CatsLoader()(module)) } From 361556f8c932bd113d7f3dfc50c4965e59bf9b77 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Mon, 30 Oct 2017 15:34:45 +0300 Subject: [PATCH 095/141] double evaluation fixed #SCL-12823 in progress --- .../findUsages/ScalaUsageTypeProvider.scala | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala index deda2eb6048..5b8163952d1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala @@ -37,7 +37,7 @@ final class ScalaUsageTypeProvider extends UsageTypeProviderEx { (element, targets) match { case (referenceElement: ScReferenceElement, Array(only: PsiElementUsageTarget)) if isConstructorPatternReference(referenceElement) && !referenceElement.isReferenceTo(only.getElement) => - Some(parameterInPattern) + Some(ParameterInPattern) case _ => element.withParentsInFile .flatMap(usageType) @@ -56,7 +56,7 @@ object ScalaUsageTypeProvider { expression.bind() .map(resolvedElement) .collect { - case function: ScFunction if function.isApplyMethod => methodApply + case function: ScFunction if function.isApplyMethod => MethodApply case definition: ScFunctionDefinition if isAncestor(definition, expression, false) => RECURSION }.orNull } @@ -71,29 +71,29 @@ object ScalaUsageTypeProvider { if (patterns.exists(isPatternAncestor)) CLASS_CATCH_CLAUSE_PARAMETER_DECLARATION else pattern match { - case ScTypedPattern(typeElement) if isPatternAncestor(typeElement) => classTypedPattern - case _: ScConstructorPattern | _: ScInfixPattern => extractor + case ScTypedPattern(typeElement) if isPatternAncestor(typeElement) => ClassTypedPattern + case _: ScConstructorPattern | _: ScInfixPattern => Extractor case _ => null } } implicit def stringToUsageType(name: String): UsageType = new UsageType(name) - val extractor: UsageType = "Extractor" - val classTypedPattern: UsageType = "Typed Pattern" - val typedStatement: UsageType = "Typed Statement" - val methodApply: UsageType = "Method `apply`" - val thisReference: UsageType = "This Reference" - val accessModifier: UsageType = "Access Modifier" - val packageClause: UsageType = "Package Clause" - val functionExpression: UsageType = "Function expression" - val namedParameter: UsageType = "Named parameter" - val prefixInterpolatedString: UsageType = "Interpolated string prefix" - val parameterInPattern: UsageType = "Parameter in pattern" - val selfType: UsageType = "Self type" - val typeBound: UsageType = "Type bound" - val typeAlias: UsageType = "Type alias" - val secondaryConstructor: UsageType = "Secondary constructor" + val Extractor: UsageType = "Extractor" + val ClassTypedPattern: UsageType = "Typed Pattern" + val TypedStatement: UsageType = "Typed Statement" + val MethodApply: UsageType = "Method `apply`" + val ThisReference: UsageType = "This Reference" + val AccessModifier: UsageType = "Access Modifier" + val PackageClause: UsageType = "Package Clause" + val FunctionExpression: UsageType = "Function expression" + val NamedParameter: UsageType = "Named parameter" + val PrefixInterpolatedString: UsageType = "Interpolated string prefix" + val ParameterInPattern: UsageType = "Parameter in pattern" + val SelfType: UsageType = "Self type" + val TypeBound: UsageType = "Type bound" + val TypeAlias: UsageType = "Type alias" + val SecondaryConstructor: UsageType = "Secondary constructor" private def usageType(element: PsiElement): Option[UsageType] = Option(nullableUsageType(element)) @@ -115,18 +115,18 @@ object ScalaUsageTypeProvider { case parameter: ScParameter if isAppropriate(parameter) => CLASS_METHOD_PARAMETER_DECLARATION case pattern: ScPattern => patternUsageType(pattern) case typeElement: ScTypeElement => typeUsageType(typeElement) - case _: ScInterpolatedStringPartReference => prefixInterpolatedString + case _: ScInterpolatedStringPartReference => PrefixInterpolatedString case expression: ScReferenceExpression => referenceExpressionUsageType(expression) case expression: ScAnnotationExpr if existsAppropriate(expression.constr.reference) => ANNOTATION - case reference: ScThisReference if existsAppropriate(reference.reference) => thisReference + case reference: ScThisReference if existsAppropriate(reference.reference) => ThisReference case reference: ScSuperReference if existsAppropriate(reference.reference) => DELEGATE_TO_SUPER - case _: ScAccessModifier => accessModifier - case packaging: ScPackaging if existsAppropriate(packaging.reference) => packageClause + case _: ScAccessModifier => AccessModifier + case packaging: ScPackaging if existsAppropriate(packaging.reference) => PackageClause case assignment: ScAssignStmt if isAppropriate(assignment.getLExpression) => - if (assignment.isNamedParameter) namedParameter else WRITE - case MethodValue(_) => functionExpression + if (assignment.isNamedParameter) NamedParameter else WRITE + case MethodValue(_) => FunctionExpression case _: ScBlock | _: ScTemplateBody | _: ScEarlyDefinitions => READ - case invocation: ScSelfInvocation if !isAppropriate(invocation.args.orNull) => secondaryConstructor + case invocation: ScSelfInvocation if !isAppropriate(invocation.args.orNull) => SecondaryConstructor case _ => null } } @@ -159,10 +159,10 @@ object ScalaUsageTypeProvider { case classParameter: ScClassParameter if isAppropriate(classParameter.typeElement) && classParameter.isEffectiveVal => CLASS_FIELD_DECLARATION case typedStmt: ScTypedStmt if isAppropriate(typedStmt.typeElement) => - typedStatement - case _: ScSelfTypeElement => selfType - case _: ScTypeAliasDeclaration | _: ScTypeParam => typeBound - case _: ScTypeAliasDefinition => typeAlias + TypedStatement + case _: ScSelfTypeElement => SelfType + case _: ScTypeAliasDeclaration | _: ScTypeParam => TypeBound + case _: ScTypeAliasDefinition => TypeAlias case _ => null } } From 8df17b4e26b590bd10461decd8a0cdd124ebc771 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Mon, 30 Oct 2017 17:37:00 +0300 Subject: [PATCH 096/141] fix typo in window dimensions fix #SCL-12804 --- .../annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala index 252b81791f8..6cd92ef4868 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesStep.scala @@ -18,7 +18,7 @@ class SbtPossiblePlacesStep(wizard: SbtArtifactSearchWizard, project: Project, f override def _init(): Unit = { wizard.setTitle("Place to add dependency") - wizard.setSize(JBUI.scale(800), JBUI.scale(7950)) + wizard.setSize(JBUI.scale(800), JBUI.scale(750)) panel.myResultList.clearSelection() extensions.inWriteAction { panel.myCurEditor.getDocument.setText("// Select a place from the list above to enable this preview") From 2c29abf6326e33b8a82a3eaaf5e39ae0d27c7876 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Mon, 30 Oct 2017 17:38:02 +0300 Subject: [PATCH 097/141] change SBT file icon in add dependency dialog fix #SCL-12824 --- .../annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index 8c828c26abd..12566cbdb5e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -104,7 +104,7 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, private class PlacesCellRenderer extends ColoredListCellRenderer[DependencyPlaceInfo] { override def customizeCellRenderer(list: JList[_ <: DependencyPlaceInfo], info: DependencyPlaceInfo, index: Int, selected: Boolean, hasFocus: Boolean): Unit = { - setIcon(AllIcons.Nodes.PpFile) + setIcon(org.jetbrains.plugins.scala.icons.Icons.SBT_FILE) append(info.path + ":", SimpleTextAttributes.REGULAR_ATTRIBUTES) append(info.line.toString, getGrayAttributes(selected)) if (info.affectedProjects.nonEmpty) From b656bf992135ab549ee1dbc896ae83f84a6d50a9 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Mon, 30 Oct 2017 20:30:02 +0300 Subject: [PATCH 098/141] fix project leaks: never store hard references to modules\projects in test class fields --- .../jetbrains/plugins/scala/debugger/ScalaVersion.scala | 8 ++++++-- .../scala/meta/annotations/MetaAnnotationTestBase.scala | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala index f52337efed8..fef698d41bd 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala @@ -6,6 +6,8 @@ import com.intellij.openapi.util.Disposer import org.jetbrains.plugins.scala.TestFixtureProvider import org.jetbrains.plugins.scala.base.libraryLoaders.LibraryLoader +import scala.collection.mutable.ListBuffer + /** * @author Nikolay.Tropin */ @@ -48,16 +50,18 @@ trait ScalaSdkOwner { protected def librariesLoaders: Seq[LibraryLoader] - private lazy val myLoaders = librariesLoaders + private lazy val myLoaders: ListBuffer[LibraryLoader] = ListBuffer() protected def setUpLibraries(): Unit = { - myLoaders.foreach { loader => + librariesLoaders.foreach { loader => + myLoaders += loader loader.init } } protected def disposeLibraries(): Unit = { myLoaders.foreach(Disposer.dispose) + myLoaders.clear() } } diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala index 51ddbf44d27..9b26f1c8a7f 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala @@ -40,7 +40,7 @@ abstract class MetaAnnotationTestBase extends JavaCodeInsightFixtureTestCase wit import MetaAnnotationTestBase._ - override implicit lazy val project: Project = getProject + override implicit def project: Project = getProject override implicit protected def module: Module = metaModule var metaModule: Module = _ override def rootProject = getProject @@ -62,7 +62,6 @@ abstract class MetaAnnotationTestBase extends JavaCodeInsightFixtureTestCase wit override def setUp(): Unit = { super.setUp() - val project = getProject project.getMessageBus .connect(getTestRootDisposable) .subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener { From 55c90b70114eaffb448cb48270b2a04edcac6862 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 30 Oct 2017 16:21:00 +0100 Subject: [PATCH 099/141] remove sbt shell action, it is subsumed by the sbt shell component --- scala/scala-impl/resources/META-INF/SBT.xml | 10 ------ .../shell/action/SbtShellStartAction.scala | 36 ------------------- 2 files changed, 46 deletions(-) delete mode 100644 scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala diff --git a/scala/scala-impl/resources/META-INF/SBT.xml b/scala/scala-impl/resources/META-INF/SBT.xml index 58c960aa977..70d643799d3 100644 --- a/scala/scala-impl/resources/META-INF/SBT.xml +++ b/scala/scala-impl/resources/META-INF/SBT.xml @@ -122,10 +122,6 @@ - - - - - - - diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala deleted file mode 100644 index ec7c742ff02..00000000000 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/action/SbtShellStartAction.scala +++ /dev/null @@ -1,36 +0,0 @@ -package org.jetbrains.sbt.shell.action - -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.externalSystem.action.ExternalSystemAction -import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys -import org.jetbrains.plugins.scala.icons.Icons -import org.jetbrains.sbt.project.SbtProjectSystem -import org.jetbrains.sbt.settings.SbtSystemSettings -import org.jetbrains.sbt.shell.SbtProcessManager - -/** - * Created by jast on 2016-11-04. - */ -class SbtShellStartAction extends ExternalSystemAction { - - setText("Run sbt shell") - - override def update(e: AnActionEvent): Unit = { - super.update(e) - e.getPresentation.setIcon(Icons.SBT_SHELL) - } - - override def actionPerformed(event: AnActionEvent): Unit = { - SbtProcessManager.forProject(event.getProject).openShellRunner(focus = true) - } - - // hide for non-sbt project toolwindows - override def isVisible(e: AnActionEvent): Boolean = - super.isVisible(e) && - (SbtProjectSystem.Id == getSystemId(e) || - e.getProject != null && - ExternalSystemDataKeys.VIEW.getData(e.getDataContext) == null && - !SbtSystemSettings.getInstance(e.getProject).getLinkedProjectsSettings.isEmpty) - - override def isEnabled(e: AnActionEvent): Boolean = hasProject(e) -} From 1851aac1609fe1be812d073fd3799822462eb818 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 30 Oct 2017 17:10:55 +0100 Subject: [PATCH 100/141] don't always open sbt shell when running task through shell. fix some premature disposal. --- .../test/AbstractTestRunConfiguration.scala | 2 +- .../jetbrains/sbt/shell/SbtProcessManager.scala | 12 +++++------- .../org/jetbrains/sbt/shell/SbtShellRunner.scala | 14 ++++++-------- .../sbt/shell/SbtShellToolWindowFactory.scala | 2 +- .../org/jetbrains/sbt/shell/communication.scala | 2 +- .../sbt/shell/SbtProjectPlatformTestCase.scala | 2 +- 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala index daa9deadc5d..89005621804 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestRunConfiguration.scala @@ -669,7 +669,7 @@ abstract class AbstractTestRunConfiguration(val project: Project, //use a process running sbt val sbtProcessManager = SbtProcessManager.forProject(project) //make sure the process is initialized - val shellRunner = sbtProcessManager.openShellRunner() + val shellRunner = sbtProcessManager.acquireShellRunner //TODO: this null is really weird SbtProcessHandlerWrapper(shellRunner createProcessHandler null) } else startProcess() diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala index bbbf19d80a8..cbd43384f07 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala @@ -9,8 +9,8 @@ import com.intellij.openapi.components.AbstractProjectComponent import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ProjectRootManager +import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.io.FileUtil -import com.intellij.util.ui.UIUtil import org.jetbrains.plugins.scala.buildinfo.BuildInfo import org.jetbrains.plugins.scala.project.Version import org.jetbrains.sbt.SbtUtil @@ -193,14 +193,14 @@ class SbtProcessManager(project: Project) extends AbstractProjectComponent(proje def removeListener(listener: ProcessAdapter): Unit = acquireShellProcessHandler.removeProcessListener(listener) - /** Supply a printwriter that writes to the current process. */ + /** Supply a PrintWriter that writes to the current process. */ def usingWriter[T](f: PrintWriter => T): T = { val writer = new PrintWriter(new OutputStreamWriter(acquireShellProcessHandler.getProcessInput)) f(writer) } - /** Creates the SbtShellRunner view, or focuses it if it already exists. */ - def openShellRunner(focus: Boolean = false): SbtShellRunner = processData.synchronized { + /** Creates the SbtShellRunner view, and focuses it if requested. */ + def acquireShellRunner: SbtShellRunner = processData.synchronized { val theRunner = processData match { case Some(ProcessData(_, runner)) if runner.getConsoleView.isRunning => @@ -209,8 +209,6 @@ class SbtProcessManager(project: Project) extends AbstractProjectComponent(proje updateProcessData().runner } - ShellUIUtil.inUIsync(if (!SbtRunner.isInTest) theRunner.openShell(focus)) - theRunner } @@ -222,7 +220,7 @@ class SbtProcessManager(project: Project) extends AbstractProjectComponent(proje def destroyProcess(): Unit = processData.synchronized { processData match { case Some(ProcessData(handler, runner)) => - runner.dispose() + Disposer.dispose(runner) handler.destroyProcess() processData = None case None => // nothing to do diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala index bcb9176b6a0..f218b5a98dc 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala @@ -36,7 +36,9 @@ class SbtShellRunner(project: Project, consoleTitle: String, debugConnection: Op private lazy val myConsoleView: LanguageConsoleImpl = ShellUIUtil.inUIsync { - SbtShellConsoleView(project, debugConnection) + val cv = SbtShellConsoleView(project, debugConnection) + Disposer.register(this, cv) + cv } // lazy so that getProcessHandler will return something initialized when this is first accessed @@ -138,13 +140,13 @@ class SbtShellRunner(project: Project, consoleTitle: String, debugConnection: Op toolWindow.getContentManager.setSelectedContent(content, focus) } - def addToolWindowContent(@NotNull toolWindow: ToolWindow, @NotNull content: Content): Unit = { + private def addToolWindowContent(@NotNull toolWindow: ToolWindow, @NotNull content: Content): Unit = { val twContentManager = toolWindow.getContentManager twContentManager.removeAllContents(true) twContentManager.addContent(content) } - def createToolWindowContent: Content = { + private def createToolWindowContent: Content = { //Create runner UI layout val factory = RunnerLayoutUi.Factory.getInstance(project) val layoutUi = factory.create("sbt-shell-toolwindow-runner", "", "session", project) @@ -166,10 +168,7 @@ class SbtShellRunner(project: Project, consoleTitle: String, debugConnection: Op content } - override def dispose(): Unit = { - myConsoleView.dispose() - Disposer.dispose(myConsoleView) - } + override def dispose(): Unit = {} object SbtShellRootType extends ConsoleRootType("sbt.shell", getConsoleTitle) @@ -185,4 +184,3 @@ class SbtShellRunner(project: Project, consoleTitle: String, debugConnection: Op } } } - diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala index e4cc879c781..f64e0f9a1f1 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellToolWindowFactory.scala @@ -31,7 +31,7 @@ class SbtShellToolWindowFactory extends ToolWindowFactory with DumbAware { override def createToolWindowContent(project: Project, toolWindow: ToolWindow): Unit = { val pm = SbtProcessManager.forProject(project) - pm.openShellRunner() + pm.acquireShellRunner.openShell(false) } // don't auto-activate because starting sbt shell is super heavy weight diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala index 493b7fd8465..5ffa02db9a4 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala @@ -36,7 +36,7 @@ class SbtShellCommunication(project: Project) extends AbstractProjectComponent(p eventHandler: EventAggregator[A], showShell: Boolean): Future[A] = { val listener = new CommandListener(default, eventHandler) - if (showShell) process.openShellRunner() + process.acquireShellRunner commands.put((cmd, listener)) listener.future } diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala index b6b68246af1..1c9239f694f 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/SbtProjectPlatformTestCase.scala @@ -59,7 +59,7 @@ abstract class SbtProjectPlatformTestCase extends PlatformTestCase { //TODO this is hacky, but sometimes 'main' gets leaked ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication, "ForkJoinPool") myComm = SbtShellCommunication.forProject(getProject) - myRunner = SbtProcessManager.forProject(getProject).openShellRunner() + myRunner = SbtProcessManager.forProject(getProject).acquireShellRunner myRunner.getProcessHandler.addProcessListener(logger) } From bdf6927071dc19742d0f4a559147d4ebd48621b3 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 30 Oct 2017 18:48:27 +0100 Subject: [PATCH 101/141] output additional information in build toolwindow. #SCL-11525 --- .../sbt/project/SbtProjectResolver.scala | 44 ++++++++++++-- .../sbt/project/structure/SbtRunner.scala | 57 ++++++++++++++++--- 2 files changed, 88 insertions(+), 13 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectResolver.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectResolver.scala index 2aa1d8beb0c..b45ac580ca2 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectResolver.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/SbtProjectResolver.scala @@ -2,8 +2,10 @@ package org.jetbrains.sbt package project import java.io.File +import java.util.UUID import com.intellij.openapi.externalSystem.model.project.{ProjectData => ESProjectData, _} +import com.intellij.openapi.externalSystem.model.task.event._ import com.intellij.openapi.externalSystem.model.task.{ExternalSystemTaskId, ExternalSystemTaskNotificationListener} import com.intellij.openapi.externalSystem.model.{DataNode, ExternalSystemException} import com.intellij.openapi.externalSystem.service.project.ExternalSystemProjectResolver @@ -20,6 +22,7 @@ import org.jetbrains.sbt.resolvers.{SbtMavenResolver, SbtResolver} import org.jetbrains.sbt.structure.ProjectData import org.jetbrains.sbt.structure.XmlSerializer._ import org.jetbrains.sbt.{structure => sbtStructure} +import scala.collection.JavaConverters._ import scala.util.{Failure, Success} @@ -54,12 +57,24 @@ class SbtProjectResolver extends ExternalSystemProjectResolver[SbtExecutionSetti val results = runner.read(new File(root), options, importFromShell = settings.useShellForImport) - results - .map { case (elem, messages) => - val warnings = messages.lines.filter(isWarningOrError) - if (warnings.nonEmpty) - listener.onTaskOutput(id, WarningMessage(warnings.mkString("\n")), false) + val importTaskId = s"import:${UUID.randomUUID()}" + val importTaskDescriptor = + new TaskOperationDescriptorImpl("import to IntelliJ project model", System.currentTimeMillis(), "project-model-import") + + // side-effecty status reporting + results.foreach { case (_, messages) => + val convertStartEvent = new ExternalSystemStartEventImpl(importTaskId, null, importTaskDescriptor) + val event = new ExternalSystemTaskExecutionEvent(id, convertStartEvent) + listener.onStatusChange(event) + + val warnings = messages.lines.filter(isWarningOrError) + if (warnings.nonEmpty) + listener.onTaskOutput(id, WarningMessage(warnings.mkString(System.lineSeparator)), false) + } + + val conversionResult = results + .map { case (elem, _) => val data = elem.deserialize[sbtStructure.StructureData].right.get convert(root, data, settings.jdk).toDataNode } @@ -70,7 +85,24 @@ class SbtProjectResolver extends ExternalSystemProjectResolver[SbtExecutionSetti case x: Exception => Failure(new ExternalSystemException(x)) } - .get // ok to throw here, that's the way ExternalSystem likes it + + // more side-effecty reporting + conversionResult.transform ( + _ => Success(new SuccessResultImpl(0, System.currentTimeMillis(), true)), /* TODO starttime*/ + x => Success( + new FailureResultImpl(0, System.currentTimeMillis(), + List.empty[com.intellij.openapi.externalSystem.model.task.event.Failure].asJava // TODO error list + ) + ) + ).foreach { result => + val convertFinishedEvent = new ExternalSystemFinishEventImpl[TaskOperationDescriptor]( + importTaskId, null, importTaskDescriptor, result + ) + val event = new ExternalSystemTaskExecutionEvent(id, convertFinishedEvent) + listener.onStatusChange(event) + } + + conversionResult.get // ok to throw here, that's the way ExternalSystem likes it } diff --git a/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala b/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala index 8af039d2f95..6d0fb3c0b4d 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/project/structure/SbtRunner.scala @@ -3,10 +3,13 @@ package project.structure import java.io.{FileNotFoundException, _} import java.nio.charset.Charset +import java.util.UUID import java.util.concurrent.atomic.AtomicBoolean import com.intellij.execution.process.OSProcessHandler import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.externalSystem.model.ExternalSystemException +import com.intellij.openapi.externalSystem.model.task.event._ import com.intellij.openapi.externalSystem.model.task.{ExternalSystemTaskId, ExternalSystemTaskNotificationEvent, ExternalSystemTaskNotificationListener} import org.jetbrains.plugins.scala.project.Version import org.jetbrains.sbt.SbtUtil._ @@ -53,7 +56,7 @@ class SbtRunner(vmExecutable: File, vmOptions: Seq[String], environment: Map[Str val messageResult: Try[String] = { if (useShellImport) { val shell = SbtShellCommunication.forProject(project) - dumpFromShell(shell, structureFilePath, options) + dumpFromShell(directory, shell, structureFilePath, options) } else dumpFromProcess(directory, structureFilePath, options: Seq[String], majorSbtVersion) } @@ -80,27 +83,67 @@ class SbtRunner(vmExecutable: File, vmOptions: Seq[String], environment: Map[Str private val statusUpdate = (message:String) => listener.onStatusChange(new ExternalSystemTaskNotificationEvent(id, message.trim)) - private def dumpFromShell(shell: SbtShellCommunication, structureFilePath: String, options: Seq[String]): Try[String] = { + private def dumpFromShell(dir: File, shell: SbtShellCommunication, structureFilePath: String, options: Seq[String]): Try[String] = { + + listener.onStart(id, dir.getCanonicalPath) val optString = options.mkString(" ") val setCmd = s"""set _root_.org.jetbrains.sbt.StructureKeys.sbtStructureOptions in Global := "$optString"""" val cmd = s";reload; $setCmd ;*/*:dumpStructureTo $structureFilePath" - val output = - shell.command(cmd, new StringBuilder, messageAggregator(id, statusUpdate), showShell = true) + + val taskDescriptor = new TaskOperationDescriptorImpl("project structure dump", System.currentTimeMillis(), "project-structure-dump") + val aggregator = esMessageAggregator(id, s"dump:${UUID.randomUUID()}", taskDescriptor, shell, listener) + val output = shell.command(cmd, new StringBuilder, aggregator, showShell = false) Await.ready(output, Duration.Inf) + output.value.get.map(_.toString()) } /** Aggregates (messages, warnings) and updates external system listener. */ - private def messageAggregator(id: ExternalSystemTaskId, statusUpdate: String=>Unit): EventAggregator[StringBuilder] = { + private def messageAggregator(statusUpdate: String=>Unit): EventAggregator[StringBuilder] = { case (m,TaskStart) => m case (m,TaskComplete) => m case (messages, Output(message)) => val text = message.trim if (text.nonEmpty) statusUpdate(text) - messages.append("\n").append(text) + messages.append(System.lineSeparator).append(text) + } + + private def esMessageAggregator(id: ExternalSystemTaskId, + dumpTaskId: String, + taskDescriptor: TaskOperationDescriptor, + shell: SbtShellCommunication, + notifications: ExternalSystemTaskNotificationListener): EventAggregator[StringBuilder] = { + case (messages, TaskStart) => + val startEvent = new ExternalSystemStartEventImpl[TaskOperationDescriptor](dumpTaskId, null, taskDescriptor) + val event = new ExternalSystemTaskExecutionEvent(id, startEvent) + notifications.onStatusChange(event) messages + case (messages, TaskComplete) => + val endEvent = new ExternalSystemFinishEventImpl[TaskOperationDescriptor]( + dumpTaskId, null, taskDescriptor, + new SuccessResultImpl(0, System.currentTimeMillis(), true) + ) + val event = new ExternalSystemTaskExecutionEvent(id, endEvent) + notifications.onStatusChange(event) + messages + case (messages, Output(text)) => + if (text.contains("(i)gnore")) { + val ex = new ExternalSystemException("Error importing sbt project. Please check sbt shell output.") + shell.send("i" + System.lineSeparator) + listener.onFailure(id, ex) + } else { + + val progressEvent = new ExternalSystemStatusEventImpl[TaskOperationDescriptor]( + dumpTaskId, null, taskDescriptor, messages.size, -1, "lines" + ) + val event = new ExternalSystemTaskExecutionEvent(id, progressEvent) + + notifications.onStatusChange(event) + notifications.onTaskOutput(id, text, true) + } + messages.append(System.lineSeparator).append(text.trim) } private def shellImportSupported(sbtVersion: Version): Boolean = @@ -158,7 +201,7 @@ class SbtRunner(vmExecutable: File, vmOptions: Seq[String], environment: Map[Str def update(textRaw: String): Unit = { val text = textRaw.trim - output.append("\n").append(text) + output.append(System.lineSeparator).append(text) if (text.nonEmpty) statusUpdate(text) } From d3a075fdb00830e171395a627d90f6eeb6f4c012 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Mon, 30 Oct 2017 19:02:50 +0100 Subject: [PATCH 102/141] don't assert expected type in sbt annotator. #EA-107497 fixed --- .../src/org/jetbrains/sbt/annotator/SbtAnnotator.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala b/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala index 7c76509bacc..978a2f1d79e 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/annotator/SbtAnnotator.scala @@ -103,8 +103,8 @@ object SbtAnnotator { (for { typeName <- allowedTypes expectedType <- createTypeFromText(typeName, expression.getContext, expression) + if !expectedType.isAny // this shouldn't happen if context is setup corretly } yield { - assert(!expectedType.isAny, s"created type was Any, expected $typeName") lazy val typeAfterImplicits = expression.getTypeAfterImplicitConversion(expectedOption = Option(expectedType)).tr.getOrNothing expressionType.conforms(expectedType) || typeAfterImplicits.conforms(expectedType) }).exists(identity) From 21c6bab94d0e479658ac360c76f5284b1a1436c9 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Mon, 30 Oct 2017 16:26:49 +0300 Subject: [PATCH 103/141] fix running debugger test: better name for method with runnable result type, only adding breakpoints need to be run in transaction #SCL-12826 --- .../plugins/scala/extensions/package.scala | 6 +- .../IntroduceTypeAlias.scala | 4 +- .../inplace/ScalaInplaceRenameHandler.scala | 4 +- .../util/ScalaRefactoringUtil.scala | 2 +- .../debugger/ScalaDebuggerTestCase.scala | 69 ++++++++++--------- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala index 3e0baf9a368..29efd74901b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala @@ -704,10 +704,14 @@ package object extensions { ApplicationManager.getApplication.invokeAndWait(() => body) } - def inTransactionLater(disposable: Disposable)(body: => Unit): Runnable = { + def callbackInTransaction(disposable: Disposable)(body: => Unit): Runnable = { TransactionGuard.getInstance().submitTransactionLater(disposable, body) } + def invokeAndWaitInTransaction(disposable: Disposable)(body: => Unit): Unit = { + TransactionGuard.getInstance().submitTransactionAndWait(disposable, body) + } + private def preservingControlFlow(body: => Unit) { try { body diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala index bf5ec991b95..1598cf5cf86 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala @@ -18,7 +18,7 @@ import com.intellij.psi._ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil import com.intellij.psi.util.PsiTreeUtil.{findElementOfClassAtRange, getChildOfType, getParentOfType} import org.jetbrains.plugins.scala.ScalaBundle -import org.jetbrains.plugins.scala.extensions.{inTransactionLater, inWriteAction, startCommand} +import org.jetbrains.plugins.scala.extensions.{callbackInTransaction, inWriteAction, startCommand} import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.base.types._ @@ -334,7 +334,7 @@ trait IntroduceTypeAlias { } } - val callback: Runnable = inTransactionLater(editor.getProject) { + val callback: Runnable = callbackInTransaction(editor.getProject) { pass(list.getSelectedValue.asInstanceOf[T]) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala index 649416deff9..0e0ee094af6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala @@ -10,7 +10,7 @@ import com.intellij.psi.util.PsiUtilBase import com.intellij.psi.{PsiElement, PsiNamedElement} import com.intellij.refactoring.rename.inplace.InplaceRefactoring import com.intellij.refactoring.rename.{PsiElementRenameHandler, RenamePsiElementProcessor} -import org.jetbrains.plugins.scala.extensions.{Both, inTransactionLater} +import org.jetbrains.plugins.scala.extensions.{Both, callbackInTransaction} import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScNewTemplateDefinition @@ -45,7 +45,7 @@ trait ScalaInplaceRenameHandler { def showSubstitutePopup(title: String, positive: String, subst: => PsiNamedElement): Unit = { val cancel = ScalaBundle.message("rename.cancel") val list = JListCompatibility.createJBListFromListData(positive, cancel) - val callback = inTransactionLater(editor.getProject) { + val callback = callbackInTransaction(editor.getProject) { list.getSelectedValue match { case s: String if s == positive => val file = subst.getContainingFile.getVirtualFile diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala index 210612a83f5..96e8e54665a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala @@ -560,7 +560,7 @@ object ScalaRefactoringUtil { } }) - val callback: Runnable = inTransactionLater(editor.getProject) { + val callback: Runnable = callbackInTransaction(editor.getProject) { pass(list.getSelectedValue.asInstanceOf[T]) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala index 56d50c0de34..c09736b3a97 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala @@ -17,7 +17,7 @@ import com.intellij.execution.process.{ProcessAdapter, ProcessEvent, ProcessHand import com.intellij.execution.runners.{ExecutionEnvironmentBuilder, ProgramRunner} import com.intellij.execution.ui.RunContentDescriptor import com.intellij.openapi.module.Module -import com.intellij.openapi.util.Key +import com.intellij.openapi.util.{Key, Ref} import com.intellij.psi.PsiCodeFragment import com.intellij.psi.search.GlobalSearchScope import com.intellij.testFramework.EdtTestUtil @@ -30,7 +30,6 @@ import org.jetbrains.plugins.scala.debugger.breakpoints.ScalaLineBreakpointType import org.jetbrains.plugins.scala.debugger.evaluation.ScalaCodeFragmentFactory import org.jetbrains.plugins.scala.extensions._ import org.junit.Assert - import scala.collection.mutable import scala.util.{Failure, Success, Try} @@ -45,38 +44,40 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { private val breakpoints: mutable.Set[(String, Int, Integer)] = mutable.Set.empty protected def runDebugger(mainClass: String = mainClassName, debug: Boolean = false)(callback: => Unit) { - inTransactionLater(getProject) { - var processHandler: ProcessHandler = null - if (needMake) { - make() - saveChecksums() - } - addBreakpoints() - val runner = ProgramRunner.PROGRAM_RUNNER_EP.getExtensions.find { - _.getClass == classOf[GenericDebuggerRunner] - }.get - processHandler = runProcess(mainClass, getModule, classOf[DefaultDebugExecutor], new ProcessAdapter { + if (needMake) { + make() + saveChecksums() + } + addBreakpoints() + val runner = ProgramRunner.PROGRAM_RUNNER_EP.getExtensions.find { + _.getClass == classOf[GenericDebuggerRunner] + }.get + + val processHandler = Ref.create[ProcessHandler] + EdtTestUtil.runInEdtAndWait(() => { + val handler = runProcess(mainClass, getModule, classOf[DefaultDebugExecutor], new ProcessAdapter { override def onTextAvailable(event: ProcessEvent, outputType: Key[_]) { val text = event.getText if (debug) print(text) } }, runner) + processHandler.set(handler) + }) - try { - callback - } finally { + try { + callback + } finally { - EdtTestUtil.runInEdtAndWait(() => { - clearXBreakpoints() - getDebugProcess.stop(true) - processHandler.destroyProcess() - }) - } + EdtTestUtil.runInEdtAndWait(() => { + clearXBreakpoints() + getDebugProcess.stop(true) + processHandler.get.destroyProcess() + }) } - } + protected def runProcess(className: String, module: Module, executorClass: Class[_ <: Executor], @@ -122,16 +123,18 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { protected def clearBreakpoints(): Unit = breakpoints.clear() private def addBreakpoints() { - breakpoints.foreach { - case (fileName, line, ordinal) => - val ioFile = new File(srcDir, fileName) - val file = getVirtualFile(ioFile) - val xBreakpointManager = XDebuggerManager.getInstance(getProject).getBreakpointManager - val properties = new JavaLineBreakpointProperties - properties.setLambdaOrdinal(ordinal) - inWriteAction { - xBreakpointManager.addLineBreakpoint(scalaLineBreakpointType, file.getUrl, line, properties) - } + invokeAndWaitInTransaction(getProject) { + breakpoints.foreach { + case (fileName, line, ordinal) => + val ioFile = new File(srcDir, fileName) + val file = getVirtualFile(ioFile) + val xBreakpointManager = XDebuggerManager.getInstance(getProject).getBreakpointManager + val properties = new JavaLineBreakpointProperties + properties.setLambdaOrdinal(ordinal) + inWriteAction { + xBreakpointManager.addLineBreakpoint(scalaLineBreakpointType, file.getUrl, line, properties) + } + } } } From f435a92a7bd86767e76887ac764957982bef795c Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Mon, 30 Oct 2017 19:19:50 +0300 Subject: [PATCH 104/141] plugin path in tests fixed, don't rely on working dir #SCL-12826 --- .../plugins/scala/compiler/RemoteServerConnectorBase.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/compiler/RemoteServerConnectorBase.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/compiler/RemoteServerConnectorBase.scala index 78e886c5ab5..13c85f46039 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/compiler/RemoteServerConnectorBase.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/compiler/RemoteServerConnectorBase.scala @@ -10,7 +10,6 @@ import com.intellij.openapi.roots.OrderEnumerator import com.intellij.openapi.util.io.FileUtil import com.intellij.util.{PathUtil, PlatformUtils} import org.jetbrains.jps.incremental.scala.data.SbtData -import org.jetbrains.plugins.scala import org.jetbrains.plugins.scala.project._ import org.jetbrains.plugins.scala.project.settings.ScalaCompilerSettings @@ -31,8 +30,8 @@ abstract class RemoteServerConnectorBase(module: Module, filesToCompile: Seq[Fil private val libRoot = { if (ApplicationManager.getApplication.isUnitTestMode) { - if (PlatformUtils.isIdeaCommunity) new File("./target/plugin/Scala/lib").getAbsoluteFile - else new File("../../target/plugin/Scala/lib").getAbsoluteFile + val pluginPath = System.getProperty("plugin.path") + new File(pluginPath, "lib") } else new File(PathUtil.getJarPathForClass(getClass)).getParentFile } From 98005571d389bd1fd9a4b1d0ba80380aa010b412 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Tue, 31 Oct 2017 12:41:00 +0300 Subject: [PATCH 105/141] jmhBenchmarks subproject disabled --- build.sbt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 01a260e6a97..a7450b5c442 100644 --- a/build.sbt +++ b/build.sbt @@ -196,10 +196,10 @@ lazy val sbtLaunchTestDownloader = ideSkipProject := true ) -lazy val jmhBenchmarks = - newProject("benchmarks", file("scala/benchmarks")) - .dependsOn(scalaImpl % "test->test") - .enablePlugins(JmhPlugin) +//lazy val jmhBenchmarks = +// newProject("benchmarks", file("scala/benchmarks")) +// .dependsOn(scalaImpl % "test->test") +// .enablePlugins(JmhPlugin) // Testing keys and settings import Common.TestCategory._ From 2e2c152e03924af63482cbced3d2a0246dbbbb31 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Tue, 31 Oct 2017 12:41:12 +0300 Subject: [PATCH 106/141] yourkit probes deleted, nobody uses them --- probes/src/examples/AWTEvents.java | 99 --- probes/src/examples/Databases.java | 660 ------------------ probes/src/examples/Files.java | 529 -------------- probes/src/examples/JNDI.java | 163 ----- probes/src/examples/JUnitTests.java | 231 ------ probes/src/examples/Messages.java | 54 -- probes/src/examples/Processes.java | 515 -------------- probes/src/examples/Servlets.java | 219 ------ probes/src/examples/Sockets.java | 365 ---------- probes/src/examples/TestNG.java | 70 -- probes/src/examples/Threads.java | 201 ------ .../plugins/scala/probes/ClearCaches.java | 30 - .../plugins/scala/probes/Conformance.java | 61 -- .../scala/probes/FindMethodsByName.java | 38 - .../plugins/scala/probes/GetNode.java | 61 -- .../plugins/scala/probes/GetType.java | 63 -- .../jetbrains/plugins/scala/probes/Pair.java | 14 - .../plugins/scala/probes/ResolveProbes.java | 69 -- .../plugins/scala/probes/TypeText.java | 43 -- .../plugins/scala/probes/Utilities.java | 144 ---- 20 files changed, 3629 deletions(-) delete mode 100644 probes/src/examples/AWTEvents.java delete mode 100644 probes/src/examples/Databases.java delete mode 100644 probes/src/examples/Files.java delete mode 100644 probes/src/examples/JNDI.java delete mode 100644 probes/src/examples/JUnitTests.java delete mode 100644 probes/src/examples/Messages.java delete mode 100644 probes/src/examples/Processes.java delete mode 100644 probes/src/examples/Servlets.java delete mode 100644 probes/src/examples/Sockets.java delete mode 100644 probes/src/examples/TestNG.java delete mode 100644 probes/src/examples/Threads.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/ClearCaches.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/Conformance.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/FindMethodsByName.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/GetNode.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/GetType.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/Pair.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/ResolveProbes.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/TypeText.java delete mode 100644 probes/src/org/jetbrains/plugins/scala/probes/Utilities.java diff --git a/probes/src/examples/AWTEvents.java b/probes/src/examples/AWTEvents.java deleted file mode 100644 index 5b85d1c54df..00000000000 --- a/probes/src/examples/AWTEvents.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; -import com.yourkit.runtime.Callback; - -import java.awt.event.InputEvent; -import java.awt.event.InvocationEvent; - -/** - * Detect long running AWT/Swing events - */ -public final class AWTEvents { - public static final String TABLE_NAME = "Long AWT Event"; - - private static final class EventTable extends Table { - private final ClassNameColumn myEventClass = new ClassNameColumn("Event Class"); - private final ClassNameColumn myRunnableClass = new ClassNameColumn("Runnable Class"); - - public EventTable() { - super( - AWTEvents.class, - TABLE_NAME, - - // It makes no sense to record stack trace - - Table.LASTING_EVENTS | - Table.RECORD_THREAD - ); - } - } - private static final EventTable T_EVENT = new EventTable(); - static { - // Record only events longer than 300 milliseconds - T_EVENT.setMinimumRecordedLastingEventTime(300); - } - - @MethodPattern("java.awt.EventQueue:dispatchEvent(java.awt.AWTEvent)") - public static final class EventQueue_dispatchEvent_Probe { - public static int onEnter(@Param(1) final Object event) { - if (event instanceof InputEvent) { - // these events are of no interest - return Table.NO_ROW; - } - - return T_EVENT.createRow(); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @Param(1) final Object event, - @ThrownException final Throwable e - ) { - T_EVENT.myEventClass.setValue(rowIndex, event.getClass()); - - if (event instanceof InvocationEvent) { - try { - final Object runnableValue = Callback.getFieldObjectValue(event, "runnable", Runnable.class); - if (runnableValue != null) { - T_EVENT.myRunnableClass.setValue(rowIndex, runnableValue.getClass()); - } - } - catch (final Throwable ignored) { - } - } - - T_EVENT.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/examples/Databases.java b/probes/src/examples/Databases.java deleted file mode 100644 index 90f3419c082..00000000000 --- a/probes/src/examples/Databases.java +++ /dev/null @@ -1,660 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; - -import javax.sql.DataSource; -import javax.sql.PooledConnection; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.Statement; - -public final class Databases { - public static final String TABLE_NAME = "Database"; - - private static final Object ourLock = new Object(); - - private static final WeakKeyMap ourDataSource2Context = new WeakKeyMap(); - - /** - * Non-prepared statement's batch - */ - private static final WeakKeyMap ourStatement2Batch = new WeakKeyMap(); - - private static final MasterResourceRegistry ourConnections = new MasterResourceRegistry( - Databases.class, - "Database", - "Database connection", - "Database" // column name - ) { - @Override - protected String retrieveResourceName(final Connection connection) throws Exception { - final DatabaseMetaData metaData = connection.getMetaData(); - return metaData == null ? null : metaData.getURL(); - } - }; - - private static final DependentResourceRegistry ourStatements = new DependentResourceRegistry( - ourConnections, - "Statement", - "Database statement (not prepared)", - null // we don't need a string column to identify non-prepared statements - ) { - @Override - protected Connection retrieveParent(final Statement resource) throws Exception { - return resource.getConnection(); - } - }; - - private static final class QueryTable extends Table { - private final StringColumn mySQL = new StringColumn("SQL"); - - public QueryTable() { - super(ourStatements.getResourceTable(), "Query", Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final QueryTable T_QUERY = new QueryTable(); - - private static final DependentResourceRegistry ourPreparedStatements = new DependentResourceRegistry( - ourConnections, - "Prepared Statement", - "Database prepared statement", - "SQL" // column name - ) { - @Override - protected Connection retrieveParent(final PreparedStatement resource) throws Exception { - return resource.getConnection(); - } - }; - - private static final class PreparedStatementQueryTable extends Table { - public PreparedStatementQueryTable() { - super(ourPreparedStatements.getResourceTable(), "Query", Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final PreparedStatementQueryTable T_PREPARED_STATEMENT_QUERY = new PreparedStatementQueryTable(); - - - private static final String BATCH_OPERATION_ADD = "Add"; - private static final String BATCH_OPERATION_CLEAR = "Clear"; - - private static final class PreparedStatementBatchTable extends Table { - private final StringColumn myOperation = new StringColumn("Operation"); - - public PreparedStatementBatchTable() { - super(ourPreparedStatements.getResourceTable(), "Batch", Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final PreparedStatementBatchTable T_PREPARED_STATEMENT_BATCH = new PreparedStatementBatchTable(); - - private static final class BatchTable extends Table { - private final StringColumn myOperation = new StringColumn("Operation"); - private final StringColumn mySQL = new StringColumn("SQL"); - - public BatchTable() { - super(ourStatements.getResourceTable(), "Batch", Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final BatchTable T_BATCH = new BatchTable(); - - - @MethodPattern( - { - "java.sql.DriverManager:getConnection(String, java.util.Properties, java.lang.ClassLoader)", - "-org.springframework.jdbc.*:*(*)" - } - ) - public static final class DriverManager_getConnection_Probe { - public static long onEnter() { - return ourConnections.openOnEnter(); - } - - public static void onExit( - @OnEnterResult final long resourceID, - @ReturnValue final Connection connection, - @ThrownException final Throwable e, - @Param(1) final String database - ) { - ourConnections.openOnExit( - resourceID, - database, - connection, - e, - FailedEventPolicy.DISCARD - ); - } - } - - @MethodPattern( - { - "*:connect(String, java.util.Properties) java.sql.Connection", - "-org.springframework.jdbc.*:*(*)" - } - ) - @InstanceOf("java.sql.Driver") - public static final class Driver_connect_Probe { - public static long onEnter() { - return ourConnections.openOnEnter(); - } - - public static void onExit( - @OnEnterResult final long resourceID, - @Param(1) final String url, - @ThrownException final Throwable e, - @ReturnValue final Connection connection - ) { - ourConnections.openOnExit( - resourceID, - url, - connection, - e, - FailedEventPolicy.DISCARD - ); - } - } - - @MethodPattern("javax.naming.InitialContext:lookup(String)") - public static final class InitialContext_lookup_Probe { - public static void onReturn( - @ReturnValue final Object returnValue, - @Param(1) final String context - ) { - if (context != null && (returnValue instanceof DataSource)) { - synchronized (ourLock) { - ourDataSource2Context.put((DataSource)returnValue, context); - } - } - } - } - - @MethodPattern( - { - "org.apache.commons.dbcp.BasicDataSource:setUrl(String)", - "org.apache.derby.jdbc.ClientBaseDataSource:setDatabaseName(String)" - } - ) - public static final class DataSource_setName_Probe { - public static void onReturn( - @This final DataSource dataSource, - @Param(1) final String url - ) { - if (url == null) { - return; - } - synchronized (ourLock) { - ourDataSource2Context.put(dataSource, url); - } - } - } - - @MethodPattern( - { - "*:getConnection() java.sql.Connection", - "-org.springframework.jdbc.*:*(*)" - } - ) - public static final class DataSource_getConnection_Probe { - public static long onEnter() { - return ourConnections.openOnEnter(); - } - - public static void onExit( - @OnEnterResult final long resourceID, - @This final DataSource dataSource, - @ReturnValue final Connection connection, - @ThrownException final Throwable e - ) { - final String nameFromDataSource; - synchronized (ourLock) { - nameFromDataSource = ourDataSource2Context.get(dataSource); - } - - ourConnections.openOnExit( - resourceID, - nameFromDataSource, - connection, - e, - FailedEventPolicy.DISCARD - ); - } - } - - @MethodPattern( - { - "*:getConnection() java.sql.Connection", - "-org.springframework.jdbc.*:*(*)" - } - ) - public static final class PooledConnection_getConnection_Probe { - public static long onEnter(@This final PooledConnection pooledConnection) { - if (pooledConnection instanceof DataSource) { - return Table.NO_ROW; - } - - return ourConnections.openOnEnter(); - } - - public static void onExit( - @OnEnterResult final long resourceID, - @ReturnValue final Connection connection, - @ThrownException final Throwable e - ) { - ourConnections.openOnExit( - resourceID, - null, // the name will be obtained with retrieveResourceName() - connection, - e, - FailedEventPolicy.DISCARD - ); - } - } - - @MethodPattern( - { - "*:execute(String, int) boolean", - "*:execute(String) boolean", - "*:execute(String, int[]) boolean", - "*:execute(String, String[]) boolean", - "*:executeQuery(String) java.sql.ResultSet", - "*:executeUpdate(String, int[]) int", - "*:executeUpdate(String) int", - "*:executeUpdate(String, int) int", - "*:executeUpdate(String, String[]) int" - } - ) - public static final class Statement_execute_Probe { - public static int onEnter( - @This final Statement statement, - @Param(1) final String query - ) { - if (statement instanceof PreparedStatement) { - return Table.NO_ROW; - } - - final int statementRowIndex = getOrCreateStatement(statement); - if (Table.shouldIgnoreRow(statementRowIndex)) { - return Table.NO_ROW; - } - - final int rowIndex = T_QUERY.createRow(statementRowIndex); - if (Table.shouldIgnoreRow(rowIndex)) { - return Table.NO_ROW; - } - - T_QUERY.mySQL.setValue(rowIndex, query == null ? "" : query); - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_QUERY.closeRow(rowIndex, e); - } - } - - @MethodPattern( - { - "*:execute() boolean", - "*:executeQuery() java.sql.ResultSet", - "*:executeUpdate() int" - } - ) - public static final class PreparedStatement_execute_Probe { - public static int onEnter(@This final PreparedStatement statement) { - final int statementRowIndex = getOrCreateStatement(statement); - return T_PREPARED_STATEMENT_QUERY.createRow(statementRowIndex); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_PREPARED_STATEMENT_QUERY.closeRow(rowIndex, e); - } - } - - @MethodPattern("*:addBatch(String) void") - public static final class Statement_addBatch_Probe { - public static int onEnter( - @This final Statement statement, - @Param(1) final String query - ) { - if (statement instanceof PreparedStatement) { - return Table.NO_ROW; - } - - // add the query to the batch - synchronized (ourStatement2Batch) { - StringBuilder batch = ourStatement2Batch.get(statement); - if (batch == null) { - batch = new StringBuilder(); - ourStatement2Batch.put(statement, batch); - } - if (batch.length() != 0) { - batch.append("\n"); - } - batch.append(query); - } - - final int statementRowIndex = getOrCreateStatement(statement); - if (Table.shouldIgnoreRow(statementRowIndex)) { - return Table.NO_ROW; - } - - final int rowIndex = T_BATCH.createRow(statementRowIndex); - if (Table.shouldIgnoreRow(rowIndex)) { - return Table.NO_ROW; - } - - T_BATCH.mySQL.setValue(rowIndex, query); - T_BATCH.myOperation.setValue(rowIndex, BATCH_OPERATION_ADD); - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_BATCH.closeRow(rowIndex, e); - } - } - - @MethodPattern("*:addBatch() void") - public static final class PreparedStatement_addBatch_Probe { - public static int onEnter(@This final PreparedStatement statement) { - final int statementRowIndex = getOrCreateStatement(statement); - if (Table.shouldIgnoreRow(statementRowIndex)) { - return Table.NO_ROW; - } - - final int rowIndex = T_PREPARED_STATEMENT_BATCH.createRow(statementRowIndex); - if (Table.shouldIgnoreRow(rowIndex)) { - return Table.NO_ROW; - } - - T_PREPARED_STATEMENT_BATCH.myOperation.setValue(rowIndex, BATCH_OPERATION_ADD); - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_PREPARED_STATEMENT_BATCH.closeRow(rowIndex, e); - } - } - - @MethodPattern("*:executeBatch() int[]") - public static final class Statement_executeBatch_Probe { - public static int onEnter(@This final Statement statement) { - final int statementRowIndex = getOrCreateStatement(statement); - if (Table.shouldIgnoreRow(statementRowIndex)) { - return Table.NO_ROW; - } - - if (statement instanceof PreparedStatement) { - return T_PREPARED_STATEMENT_QUERY.createRow(statementRowIndex); - } - else { - final int rowIndex = T_QUERY.createRow(statementRowIndex); - - final StringBuilder builder; - synchronized (ourStatement2Batch) { - // JDBC specification: - // "The statement's batch is reset to empty once executeBatch returns." - - builder = ourStatement2Batch.remove(statement); - } - - if (builder != null) { - T_QUERY.mySQL.setValue(rowIndex, builder.toString()); - } - return rowIndex; - } - } - - public static void onExit( - @This final Statement statement, - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - if (statement instanceof PreparedStatement) { - T_PREPARED_STATEMENT_QUERY.closeRow(rowIndex, e); - } - else { - T_QUERY.closeRow(rowIndex, e); - } - } - } - - @MethodPattern("*:clearBatch() void") - public static final class Statement_clearBatch_Probe { - public static int onEnter(@This final Statement statement) { - if (statement instanceof PreparedStatement) { - return Table.NO_ROW; - } - - synchronized (ourStatement2Batch) { - ourStatement2Batch.remove(statement); - } - - final int statementRowIndex = getOrCreateStatement(statement); - if (Table.shouldIgnoreRow(statementRowIndex)) { - return Table.NO_ROW; - } - - final int rowIndex = T_BATCH.createRow(statementRowIndex); - if (Table.shouldIgnoreRow(rowIndex)) { - return Table.NO_ROW; - } - - T_BATCH.mySQL.setValue(rowIndex, ""); - T_BATCH.myOperation.setValue(rowIndex, BATCH_OPERATION_CLEAR); - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_BATCH.closeRow(rowIndex, e); - } - } - - @MethodPattern("*:clearBatch() void") - public static final class PreparedStatement_clearBatch_Probe { - public static int onEnter(@This final PreparedStatement statement) { - final int statementRowIndex = getOrCreateStatement(statement); - if (Table.shouldIgnoreRow(statementRowIndex)) { - return Table.NO_ROW; - } - - final int rowIndex = T_PREPARED_STATEMENT_BATCH.createRow(statementRowIndex); - if (Table.shouldIgnoreRow(rowIndex)) { - return Table.NO_ROW; - } - - T_PREPARED_STATEMENT_BATCH.myOperation.setValue(rowIndex, BATCH_OPERATION_CLEAR); - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_PREPARED_STATEMENT_BATCH.closeRow(rowIndex, e); - } - } - - @MethodPattern( - { - "*:close() void", - "-java.io.*:*()", - "-java.nio.*:*()", - "-sun.nio.*:*()", - "-java.net.*:*()", - "-*$$Lambda$*:*()", - "-com.sun.xml.*:*()", - "-*xerces*:*()", - "-*Stream*:*()", - "-*Socket*:*()", - "-*File*:*()" - } - ) - public static final class Connection_close_Probe { - public static int onEnter(@This final Connection connection) { - return ourConnections.closeOnEnter(connection); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - ourConnections.closeOnExit(rowIndex, e); - } - } - - @MethodPattern( - { - "*:close() void", - "-java.io.*:*()", - "-java.nio.*:*()", - "-sun.nio.*:*()", - "-java.net.*:*()", - "-*$$Lambda$*:*()", - "-com.sun.xml.*:*()", - "-*xerces*:*()", - "-*Stream*:*()", - "-*Socket*:*()", - "-*File*:*()" - } - ) - public static final class Statement_close_Probe { - public static int onEnter(@This final Statement statement) { - if (statement instanceof PreparedStatement) { - return ourPreparedStatements.closeOnEnter((PreparedStatement)statement); - } - else { - return ourStatements.closeOnEnter(statement); - } - } - - public static void onExit( - @This final Statement statement, - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - if (statement instanceof PreparedStatement) { - ourPreparedStatements.closeOnExit(rowIndex, e); - } - else { - ourStatements.closeOnExit(rowIndex, e); - } - } - } - - @MethodPattern( - { - "*:createStatement(int, int, int) java.sql.Statement", - "*:createStatement(int, int) java.sql.Statement", - "*:createStatement() java.sql.Statement" - } - ) - public static final class Connection_createStatement_Probe { - public static long onEnter() { - return ourStatements.openOnEnter(); - } - - public static void onExit( - @OnEnterResult final long resourceID, - @This final Connection connection, - @ReturnValue final Statement statement, - @ThrownException final Throwable e - ) { - ourStatements.openOnExit( - resourceID, - "", // no name - statement, - connection, - e, - FailedEventPolicy.DISCARD - ); - } - } - - @MethodPattern( - { - "*:prepareCall(String, int, int, int)", - "*:prepareCall(String, int, int)", - "*:prepareCall(String)", - "*:prepareStatement(String, int)", - "*:prepareStatement(String, String[])", - "*:prepareStatement(String, int, int, int)", - "*:prepareStatement(String)", - "*:prepareStatement(String, int, int)", - "*:prepareStatement(String, int[])" - } - ) - public static final class Connection_prepareStatement_Probe { - public static long onEnter() { - return ourPreparedStatements.openOnEnter(); - } - - public static void onExit( - @OnEnterResult final long resourceID, - @This final Connection connection, - @Param(1) final String query, - @ReturnValue final PreparedStatement preparedStatement, - @ThrownException final Throwable e - ) { - ourPreparedStatements.openOnExit( - resourceID, - query, - preparedStatement, - connection, - e, - FailedEventPolicy.DISCARD - ); - } - } - - private static int getOrCreateStatement(final Statement statement) { - if (statement instanceof PreparedStatement) { - return ourPreparedStatements.getOrCreate((PreparedStatement)statement); - } - else { - return ourStatements.getOrCreate(statement); - } - } -} diff --git a/probes/src/examples/Files.java b/probes/src/examples/Files.java deleted file mode 100644 index 59390ea99de..00000000000 --- a/probes/src/examples/Files.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; -import com.yourkit.runtime.Callback; - -import java.io.FileDescriptor; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.RandomAccessFile; -import java.nio.channels.FileChannel; - -public final class Files { - public static final String TABLE_NAME = "File"; - - public static final String SYSTEM_IN_PSEUDO_PATH = ""; - public static final String SYSTEM_OUT_PSEUDO_PATH = ""; - public static final String SYSTEM_ERR_PSEUDO_PATH = ""; - - /** - * Mapping between file and row index in T_FILE table - */ - private static final MasterResourceRegistry ourFiles = new MasterResourceRegistry( - Files.class, - TABLE_NAME, - null, // no additional description for a file - "Path" - ) { - @Override - protected String retrieveResourceName(final Object resource) { - return retrieveFilePath(resource); - } - }; - - private static final TableIntBytes T_READ = new TableIntBytes(ourFiles, "Read", Table.MASK_FOR_LASTING_EVENTS); - - private static final TableIntBytes T_WRITE = new TableIntBytes(ourFiles, "Write", Table.MASK_FOR_LASTING_EVENTS); - - private static final TableLongBytes T_CHANNEL_READ = new TableLongBytes(ourFiles, "Channel Read", Table.MASK_FOR_LASTING_EVENTS); - - private static final TableLongBytes T_CHANNEL_WRITE = new TableLongBytes(ourFiles, "Channel Write", Table.MASK_FOR_LASTING_EVENTS); - - @MethodPattern( - { - "java.io.FileOutputStream:open(String)", - "java.io.FileOutputStream:open(String, boolean)" - } - ) - public static final class FileOutputStream_open_Probe { - public static long onEnter() { - return ourFiles.openOnEnter(); - } - - public static void onExit( - @This final FileOutputStream stream, - @Param(1) final String path, - @OnEnterResult final long resourceID, - @ThrownException final Throwable e - ) { - ourFiles.openOnExit( - resourceID, - path, - stream, - e, - FailedEventPolicy.RECORD - ); - } - } - - @MethodPattern("java.io.FileOutputStream:close()") - public static final class FileOutputStream_close_Probe { - public static int onEnter(@This final FileOutputStream stream) { - return ourFiles.closeOnEnter(stream); - } - - public static void onExit( - @OnEnterResult final int row, - @ThrownException final Throwable e - ) { - ourFiles.closeOnExit(row, e); - } - } - - @MethodPattern( - { - "java.io.FileOutputStream:writeBytes(byte[], int, int)", - "java.io.FileOutputStream:writeBytes(byte[], int, int, boolean)" - } - ) - public static final class FileOutputStream_writeBytes_Probe { - public static int onEnter( - @This final FileOutputStream fileOutputStream, - @Param(3) final int bytesWritten - ) { - return writeOnEnter(fileOutputStream, bytesWritten); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - writeOnExit(rowIndex, e); - } - } - - @MethodPattern("java.io.FileOutputStream:write(int)") - public static final class FileOutputStream_write_Probe { - public static int onEnter(@This final FileOutputStream fileOutputStream) { - return writeOnEnter(fileOutputStream, 1 /* one byte to be written */); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - writeOnExit(rowIndex, e); - } - } - - @MethodPattern("java.io.FileInputStream:open(String)") - public static final class FileInputStream_open_Probe { - public static long onEnter() { - return ourFiles.openOnEnter(); - } - - public static void onExit( - @This final FileInputStream stream, - @Param(1) final String path, - @OnEnterResult final long resourceID, - @ThrownException final Throwable e - ) { - ourFiles.openOnExit( - resourceID, - path, - stream, - e, - FailedEventPolicy.RECORD - ); - } - } - - @MethodPattern("java.io.FileInputStream:close()") - public static final class FileInputStream_close_Probe { - public static int onEnter(@This final FileInputStream stream) { - return ourFiles.closeOnEnter(stream); - } - - public static void onExit( - @ThrownException final Throwable e, - @OnEnterResult final int row - ) { - ourFiles.closeOnExit(row, e); - } - } - - @MethodPattern("java.io.FileInputStream:read()") - public static final class FileInputStream_read_Probe { - public static int onEnter(@This final FileInputStream fileInputStream) { - return readOnEnter(fileInputStream); - } - - public static void onExit( - @OnEnterResult final int readRowIndex, - @ReturnValue final int returnValue, - @ThrownException final Throwable e - ) { - // non negative return value means that a byte has been successfully read - final int readBytes = returnValue >= 0 ? 1 : 0; - readOnExit(readRowIndex, readBytes, e); - } - } - - @MethodPattern("java.io.FileInputStream:readBytes(byte[], int, int)") - public static final class FileInputStream_readBytes_Probe { - public static int onEnter(@This final FileInputStream fileInputStream) { - return readOnEnter(fileInputStream); - } - - public static void onExit( - @OnEnterResult final int readRowIndex, - @ReturnValue final int bytesRead, - @ThrownException final Throwable e - ) { - readOnExit(readRowIndex, bytesRead, e); - } - } - - @MethodPattern( - { - "java.io.RandomAccessFile:getChannel()", - "java.io.FileInputStream:getChannel()", - "java.io.FileOutputStream:getChannel()" - } - ) - public static final class GetChannel_Probe { - public static void onReturn( - @ReturnValue final FileChannel fileChannel, - @This final Object file - ) { - // associate channel with file resource - ourFiles.mapAlias(file, fileChannel); - } - } - - @MethodPattern( - { - "sun.nio.ch.FileChannelImpl:write(java.nio.ByteBuffer) int", - "sun.nio.ch.FileChannelImpl:write(java.nio.ByteBuffer, long) int", - "sun.nio.ch.FileChannelImpl:write(java.nio.ByteBuffer[], int, int) long", - "sun.nio.ch.FileChannelImpl:transferFrom(java.nio.channels.ReadableByteChannel, long, long)" - } - ) - public static final class FileChannel_write_Probe { - public static int onEnter( - @This final FileChannel fileChannel - ) { - return channelWriteOnEnter(fileChannel); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ReturnValue final long bytesWritten, - @ThrownException final Throwable e - ) { - channelWriteOnExit(rowIndex, bytesWritten, e); - } - } - - @MethodPattern( - { - "sun.nio.ch.FileChannelImpl:read(java.nio.ByteBuffer) int", - "sun.nio.ch.FileChannelImpl:read(java.nio.ByteBuffer, long) int", - "sun.nio.ch.FileChannelImpl:read(java.nio.ByteBuffer[], int, int) long", - "sun.nio.ch.FileChannelImpl:transferTo(long, long, java.nio.channels.WritableByteChannel)" - } - ) - public static final class FileChannel_read_Probe { - public static int onEnter( - @This final FileChannel fileChannel - ) { - return channelReadOnEnter(fileChannel); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ReturnValue final long bytesRead, - @ThrownException final Throwable e - ) { - channelReadOnExit(rowIndex, bytesRead, e); - } - } - - @MethodPattern("java.io.RandomAccessFile:open(String, int)") - public static final class RandomAccessFile_open_Probe { - public static long onEnter() { - return ourFiles.openOnEnter(); - } - - public static void onExit( - @This final RandomAccessFile file, - @Param(1) final String path, - @OnEnterResult final long resourceID, - @ThrownException final Throwable e - ) { - ourFiles.openOnExit( - resourceID, - path, - file, - e, - FailedEventPolicy.RECORD - ); - } - } - - @MethodPattern("java.io.RandomAccessFile:close()") - public static final class RandomAccessFile_close_Probe { - public static int onEnter(@This final RandomAccessFile file) { - return ourFiles.closeOnEnter(file); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - ourFiles.closeOnExit(rowIndex, e); - } - } - - @MethodPattern("java.io.RandomAccessFile:writeBytes(byte[], int, int)") - public static final class RandomAccessFile_writeBytes_Probe { - public static int onEnter( - @This final RandomAccessFile randomAccessFile, - @Param(3) final int bytesWritten - ) { - return readOnEnter(randomAccessFile, bytesWritten); - } - - public static void onExit( - @OnEnterResult final int writeRowIndex, - @ThrownException final Throwable e - ) { - writeOnExit(writeRowIndex, e); - } - } - - @MethodPattern("java.io.RandomAccessFile:write(int)") - public static final class RandomAccessFile_write_Probe { - public static int onEnter(@This final RandomAccessFile randomAccessFile) { - return readOnEnter(randomAccessFile, 1 /* one byte to write */); - } - - public static void onExit( - @OnEnterResult final int writeRowIndex, - @ThrownException final Throwable e - ) { - writeOnExit(writeRowIndex, e); - } - } - - @MethodPattern("java.io.RandomAccessFile:read()") - public static final class RandomAccessFile_read_Probe { - public static int onEnter(@This final RandomAccessFile randomAccessFile) { - return readOnEnter(randomAccessFile); - } - - public static void onExit( - @OnEnterResult final int readRowIndex, - @ReturnValue final int returnValue, - @ThrownException final Throwable e - ) { - // non negative return value means that a byte has been successfully read - final int readBytes = returnValue >= 0 ? 1 : 0; - readOnExit(readRowIndex, readBytes, e); - } - } - - @MethodPattern("java.io.RandomAccessFile:readBytes(byte[], int, int)") - public static final class RandomAccessFile_readBytes_Probe { - public static int onEnter(@This final RandomAccessFile randomAccessFile) { - return readOnEnter(randomAccessFile); - } - - public static void onExit( - @OnEnterResult final int readRowIndex, - @ReturnValue final int bytesRead, - @ThrownException final Throwable e - ) { - readOnExit(readRowIndex, bytesRead, e); - } - } - - private static String retrieveFilePath(final Object file) { - // Try to get the file path - { - String path = null; - try { - path = Callback.getFieldObjectValue(file, "path", String.class); - } - catch (final Throwable ignored) { - } - - if (path != null) { - return path; - } - } - - // Match the standard streams - { - Object fileDescriptor = null; - try { - fileDescriptor = Callback.getFieldObjectValue(file, "fd", FileDescriptor.class); - } - catch (final Throwable ignored) { - } - - if (fileDescriptor == FileDescriptor.in) { - return SYSTEM_IN_PSEUDO_PATH; - } - - if (fileDescriptor == FileDescriptor.out) { - return SYSTEM_OUT_PSEUDO_PATH; - } - - if (fileDescriptor == FileDescriptor.err) { - return SYSTEM_ERR_PSEUDO_PATH; - } - } - - // Name cannot be retrieved - return null; - } - - private static int getOrCreateFileRowByChannel(final FileChannel channel) { - int fileRow = ourFiles.get(channel); // get by alias - if (!Table.shouldIgnoreRow(fileRow)) { - return fileRow; - } - - Object file = null; - try { - file = Callback.getFieldObjectValue(channel, "parent", Object.class); - } - catch (final Exception ignored) { - } - - if ( - !(file instanceof FileInputStream) && - !(file instanceof FileOutputStream) && - !(file instanceof RandomAccessFile) - ) { - return Table.NO_ROW; - } - - fileRow = ourFiles.getOrCreate(file); - if (!Table.shouldIgnoreRow(fileRow)) { - // associate channel with file resource - ourFiles.mapAlias(file, channel); - } - - return fileRow; - } - - // Record individual I/O events for streams and random access files - - private static int readOnEnter(final FileInputStream fileInputStream) { - final int streamRowIndex = ourFiles.getOrCreate(fileInputStream); - return T_READ.createRow(streamRowIndex); - } - - private static int readOnEnter(final RandomAccessFile randomAccessFile) { - final int fileRowIndex = ourFiles.getOrCreate(randomAccessFile); - return T_READ.createRow(fileRowIndex); - } - - private static void readOnExit( - final int readRowIndex, - final int bytesRead, - @ThrownException final Throwable e - ) { - T_READ.setBytes(readRowIndex, bytesRead); - T_READ.closeRow(readRowIndex, e); - } - - private static int writeOnEnter( - final FileOutputStream fileOutputStream, - final int bytesWritten - ) { - final int streamRowIndex = ourFiles.getOrCreate(fileOutputStream); - - final int writeRowIndex = T_WRITE.createRow(streamRowIndex); - T_WRITE.setBytes(writeRowIndex, bytesWritten); - return writeRowIndex; - } - - private static int readOnEnter( - final RandomAccessFile randomAccessFile, - final int bytesWritten - ) { - final int fileRowIndex = ourFiles.getOrCreate(randomAccessFile); - - final int writeRowIndex = T_WRITE.createRow(fileRowIndex); - T_WRITE.setBytes(writeRowIndex, bytesWritten); - return writeRowIndex; - } - - private static void writeOnExit( - final int writeRowIndex, - @ThrownException final Throwable e - ) { - T_WRITE.closeRow(writeRowIndex, e); - } - - // Record individual I/O events for channels - - private static int channelReadOnEnter(final FileChannel fileChannel) { - return T_CHANNEL_READ.createRow(getOrCreateFileRowByChannel(fileChannel)); - } - - private static void channelReadOnExit( - final int rowIndex, - final long bytesRead, - @ThrownException final Throwable e - ) { - T_CHANNEL_READ.setBytes(rowIndex, bytesRead); - T_CHANNEL_READ.closeRow(rowIndex, e); - } - - private static int channelWriteOnEnter(final FileChannel fileChannel) { - return T_CHANNEL_WRITE.createRow(getOrCreateFileRowByChannel(fileChannel)); - } - - private static void channelWriteOnExit( - final int rowIndex, - final long bytesWritten, - @ThrownException final Throwable e - ) { - T_CHANNEL_WRITE.setBytes(rowIndex, bytesWritten); - T_CHANNEL_WRITE.closeRow(rowIndex, e); - } -} diff --git a/probes/src/examples/JNDI.java b/probes/src/examples/JNDI.java deleted file mode 100644 index 19e89cd3158..00000000000 --- a/probes/src/examples/JNDI.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; - -public class JNDI { - public static final String TABLE_NAME = "JNDI"; - - private static final class JNDITable extends Table { - private final StringColumn myName = new StringColumn("Name"); - - public JNDITable() { - super(JNDI.class, TABLE_NAME, Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final JNDITable T_JNDI = new JNDITable(); - - @MethodPattern( - { - "*C*t*x*:list(javax.naming.Name) javax.naming.NamingEnumeration", - "*C*t*x*:lookup(javax.naming.Name) Object", - "*C*t*x*:bind(javax.naming.Name, Object) void", - "*C*t*x*:listBindings(javax.naming.Name) javax.naming.NamingEnumeration", - "*C*t*x*:lookupLink(javax.naming.Name) Object", - "*C*t*x*:rebind(javax.naming.Name, Object) void", - "*C*t*x*:unbind(javax.naming.Name) void", - "*C*t*x*:rename(javax.naming.Name, javax.naming.Name) void", - "*C*t*x*:composeName(javax.naming.Name, javax.naming.Name) javax.naming.Name", - "*C*t*x*:createSubcontext(javax.naming.Name) javax.naming.Context", - "*C*t*x*:destroySubcontext(javax.naming.Name) void", - "*C*t*x*:getNameParser(javax.naming.Name) javax.naming.NameParser" - } - ) - @InstanceOf("javax.naming.Context") - public static final class NamingContext_1 { - public static int onEnter() { - return T_JNDI.createRow(); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_JNDI.closeRow(rowIndex, e); - } - } - - @MethodPattern( - { - "*C*t*x*:list(String) javax.naming.NamingEnumeration", - "*C*t*x*:lookup(String) Object", - "*C*t*x*:bind(String, Object) void", - "*C*t*x*:listBindings(String) javax.naming.NamingEnumeration", - "*C*t*x*:lookupLink(String) Object", - "*C*t*x*:rebind(String, Object) void", - "*C*t*x*:unbind(String) void" - } - ) - @InstanceOf("javax.naming.Context") - public static final class NamingContext_2 { - public static int onEnter(@Param(1) final String str) { - final int rowIndex = T_JNDI.createRow(); - if (str != null && str.length() > 0) { - T_JNDI.myName.setValue(rowIndex, str); - } - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_JNDI.closeRow(rowIndex, e); - } - } - - @MethodPattern( - { - "*C*t*x*:search(String, *) javax.naming.NamingEnumeration", - "*C*t*x*:getAttributes(String) javax.naming.directory.Attributes", - "*C*t*x*:getAttributes(String, String[]) javax.naming.directory.Attributes", - "*C*t*x*:bind(String, Object, javax.naming.directory.Attributes) void", - "*C*t*x*:createSubcontext(String, javax.naming.directory.Attributes) javax.naming.directory.DirContext", - "*C*t*x*:rebind(String, Object, javax.naming.directory.Attributes) void", - "*C*t*x*:getSchema(String) javax.naming.directory.DirContext", - "*C*t*x*:getSchemaClassDefinition(String) javax.naming.directory.DirContext", - "*C*t*x*:modifyAttributes(String, *) void" - } - ) - @InstanceOf("javax.naming.directory.DirContext") - public static final class DirContext_1 { - public static int onEnter(@Param(1) final String str) { - final int rowIndex = T_JNDI.createRow(); - if (str != null && str.length() > 0) { - T_JNDI.myName.setValue(rowIndex, str); - } - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_JNDI.closeRow(rowIndex, e); - } - } - - @MethodPattern( - { - "*C*t*x*:search(javax.naming.Name, *) javax.naming.NamingEnumeration", - "*C*t*x*:getAttributes(javax.naming.Name, String[]) javax.naming.directory.Attributes", - "*C*t*x*:getAttributes(javax.naming.Name) javax.naming.directory.Attributes", - "*C*t*x*:bind(javax.naming.Name, Object, javax.naming.directory.Attributes) void", - "*C*t*x*:createSubcontext(javax.naming.Name, javax.naming.directory.Attributes) javax.naming.directory.DirContext", - "*C*t*x*:rebind(javax.naming.Name, Object, javax.naming.directory.Attributes) void", - "*C*t*x*:getSchema(javax.naming.Name) javax.naming.directory.DirContext", - "*C*t*x*:getSchemaClassDefinition(javax.naming.Name) javax.naming.directory.DirContext", - "*C*t*x*:modifyAttributes(javax.naming.Name, *) void" - } - ) - @InstanceOf("javax.naming.directory.DirContext") - public static final class DirContext_2 { - public static int onEnter() { - return T_JNDI.createRow(); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_JNDI.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/examples/JUnitTests.java b/probes/src/examples/JUnitTests.java deleted file mode 100644 index 65753e34cb5..00000000000 --- a/probes/src/examples/JUnitTests.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; - -public final class JUnitTests { - private static final String TEST_SET_UP = "setUp"; - private static final String TEST_RUN = "run"; - private static final String TEST_TEAR_DOWN = "tearDown"; - - public static final String TABLE_NAME = "JUnit Test"; - - private static final class TestsTable extends Table { - private final ClassNameColumn myTestClass = new ClassNameColumn("Test Class"); - private final StringColumn myCategory = new StringColumn("Category"); - private final StringColumn myMethod = new StringColumn("Method"); - private final StringColumn myStatus = new StringColumn("Status"); - - public TestsTable() { - super( - JUnitTests.class, - TABLE_NAME, - Table.MASK_FOR_LASTING_EVENTS - ); - } - } - private static final TestsTable T_TESTS = new TestsTable(); - - // JUnit 3.8 and older: tests extend TestCase - - @MethodPattern("*Test:setUp()") - public static final class Old_SetUp_Probe { - public static int onEnter( - @ClassRef final Class testClass, - @MethodName final String methodName - ) { - if (!isTestCaseClass(testClass)) { - return Table.NO_ROW; - } - - return handleEnter(testClass, TEST_SET_UP, methodName); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - handleExit(rowIndex, e); - } - } - - @MethodPattern("*Test:test*()") - public static final class Old_Run_Probe { - public static int onEnter( - @ClassRef final Class testClass, - @MethodName final String methodName - ) { - if (!isTestCaseClass(testClass)) { - return Table.NO_ROW; - } - - return handleEnter(testClass, TEST_RUN, methodName); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - handleExit(rowIndex, e); - } - } - - @MethodPattern("*Test:tearDown()") - public static final class Old_TearDown_Probe { - public static int onEnter( - @ClassRef final Class testClass, - @MethodName final String methodName - ) { - if (!isTestCaseClass(testClass)) { - return Table.NO_ROW; - } - - return handleEnter(testClass, TEST_TEAR_DOWN, methodName); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - handleExit(rowIndex, e); - } - } - - private static boolean isTestCaseClass(final Class testClass) { - try { - if (testClass.getName().startsWith("junit.framework.")) { - // do nothing with JUnit internals - return false; - } - - for (Class aClass = testClass; aClass != null; aClass = aClass.getSuperclass()) { - if ("junit.framework.TestCase".equals(aClass.getName())) { - return true; - } - } - - return false; - } - catch (final Throwable ignored) { - return false; - } - } - - // JUnit 4.0 and newer: tests are annotated with @Before, @Test and @After - - @MethodPattern("*Test:@org.junit.Before *()") - public static final class SetUp_Probe { - public static int onEnter( - @ClassRef final Class testClass, - @MethodName final String methodName - ) { - return handleEnter(testClass, TEST_SET_UP, methodName); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - handleExit(rowIndex, e); - } - } - - @MethodPattern("*Test:@org.junit.Test *()") - public static final class Run_Probe { - public static int onEnter( - @ClassRef final Class testClass, - @MethodName final String methodName - ) { - return handleEnter(testClass, TEST_RUN, methodName); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - handleExit(rowIndex, e); - } - } - - @MethodPattern("*Test:@org.junit.After *()") - public static final class TearDown_Probe { - public static int onEnter( - @ClassRef final Class testClass, - @MethodName final String methodName - ) { - return handleEnter(testClass, TEST_TEAR_DOWN, methodName); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - handleExit(rowIndex, e); - } - } - - /** - * Create row - * @return row index - */ - private static int handleEnter( - final Class aClass, - final String category, - final String method - ) { - final int rowIndex = T_TESTS.createRow(); - T_TESTS.myTestClass.setValue(rowIndex, aClass); - T_TESTS.myCategory.setValue(rowIndex, category); - T_TESTS.myMethod.setValue(rowIndex, method); - T_TESTS.myStatus.setValue(rowIndex, "Running"); - - return rowIndex; - } - - /** - * Close row - * @param exception {@code null} if success - */ - private static void handleExit( - final int rowIndex, - final Throwable exception - ) { - if (exception == null) { - T_TESTS.myStatus.setValue(rowIndex, "Passed"); - } - else { - T_TESTS.myStatus.setValue(rowIndex, "Failed"); - } - - T_TESTS.closeRow(rowIndex, exception); - } -} diff --git a/probes/src/examples/Messages.java b/probes/src/examples/Messages.java deleted file mode 100644 index 1d1c6be5d49..00000000000 --- a/probes/src/examples/Messages.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.runtime.Callback; - -/** - * This class is not a probe class itself nor contains probe classes. - * Instead, it provides a utility method to store arbitrary text messages. - * They will be shown in "Event" tab as "Message". - */ -public final class Messages { - /** - * @param category free text description of message category, - * which can be used to filtering messages of different origin; must not be {@code null} - * @param message free text; must not be {@code null} - * @param detail additional description of the message; pass {@code null} for no description - */ - public static void message( - final String category, - final String message, - final String detail - ) { - Callback.messageToTable(category, message, detail != null ? detail : ""); - } -} diff --git a/probes/src/examples/Processes.java b/probes/src/examples/Processes.java deleted file mode 100644 index f78ea00a18c..00000000000 --- a/probes/src/examples/Processes.java +++ /dev/null @@ -1,515 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; -import com.yourkit.runtime.Callback; - -import java.io.*; -import java.lang.reflect.Field; -import java.util.HashSet; -import java.util.Map; - -public final class Processes { - public static final String TABLE_NAME = "Process"; - - private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows"); - - /** - * Mapping between tracked object (process or stream) to row index in T_PROCESS table - */ - private static final ObjectRowIndexMap ourObject2ProcessRowIndex = new ObjectRowIndexMap(); - private static final HashSet ourUnclosedRowIndices = new HashSet(); - /** - * Remember stderr streams to distinct them from stdout streams - */ - private static final ObjectSet ourErrorStreams = new ObjectSet(); - - private static final class ProcessTable extends Table { - private final StringColumn myCommand = new StringColumn("Command"); - private final StringColumn myDirectory = new StringColumn("Directory"); - private final StringColumn myEnvironment = new StringColumn("Environment"); - private final IntColumn myPID = new IntColumn("PID"); - - public ProcessTable() { - super(Processes.class, TABLE_NAME, Table.MASK_FOR_POINT_EVENTS); - } - } - private static final ProcessTable T_PROCESS = new ProcessTable(); - - private static final class IOOperationTable extends Table { - private final IntColumn myBytes = new IntColumn("Bytes"); - - public IOOperationTable(final String title) { - super(T_PROCESS, title, Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final IOOperationTable T_STDOUT = new IOOperationTable("Output Read"); - private static final IOOperationTable T_STDERR = new IOOperationTable("Error Read"); - private static final IOOperationTable T_STDIN = new IOOperationTable("Input Write"); - - private static final class ExitTable extends Table { - private final StringColumn myExitCode = new StringColumn("Exit Code"); // store as string to avoid redundant min-max columns in UI - - public ExitTable() { - super(T_PROCESS, "Exit", Table.MASK_FOR_POINT_EVENTS); - } - } - private static final ExitTable T_EXIT = new ExitTable(); - - static { - if (IS_WINDOWS) { - startProcessExitListenerThread(); - } - } - - private static void startProcessExitListenerThread() { - // A daemon thread to asynchronously monitor exited processes. - // We need it to handle processes for which waitFor() is not used. - final Thread thread = new Thread( - new Runnable() { - @Override - public void run() { - //noinspection InfiniteLoopStatement - while (true) { - try { - try { - Thread.sleep(1000); - } - catch (final InterruptedException ignored) { - continue; - } - - final int[] exitCodes = JVM.getExitedProcesses(); - if (exitCodes == null) { - continue; - } - - // if any waitFor() are waiting for this thread, give them chance to trigger first - try { - Thread.sleep(100); - } - catch (final InterruptedException ignored) { - continue; - } - - for (int i = 0; i < exitCodes.length; i += 2) { - final int rowIndex = exitCodes[i]; - final int exitCode = exitCodes[i+1]; - - handleProcessExit(rowIndex, exitCode); - } - } - catch (final Throwable e) { - Callback.messageToLogFile(Callback.getExceptionStackTrace(e)); - } - } - } - }, - "YJP-Process-Exit-Listener" - ); - thread.setDaemon(true); - thread.start(); - } - - private static void handleProcessExit(final int processRow, final int exitCode) { - if (Table.shouldIgnoreRow(processRow)) { - return; - } - - synchronized (ourUnclosedRowIndices) { - if (!ourUnclosedRowIndices.remove(processRow)) { - // the row has already been closed - return; - } - } - - final int exitRow = T_EXIT.createRow(processRow); - T_EXIT.myExitCode.setValue(exitRow, String.valueOf(exitCode)); - } - - /** - * Associate input streams with process - */ - @MethodPattern( - { - "java.lang.ProcessImpl:getInputStream()", - "java.lang.UNIXProcess:getInputStream()" - } - ) - public static final class ProcessImpl_getInputStream_Probe { - public static void onReturn( - @ReturnValue final InputStream stream, - @This final Process process - ) { - final int rowIndex = ourObject2ProcessRowIndex.get(process); - if (Table.shouldIgnoreRow(rowIndex)) { - return; - } - - final InputStream inputStream = getProperInputStream(stream); - if (inputStream == null) { - return; - } - - ourObject2ProcessRowIndex.put(inputStream, rowIndex); - } - } - - /** - * Associate error streams with process - */ - @MethodPattern( - { - "java.lang.ProcessImpl:getErrorStream()", - "java.lang.UNIXProcess:getErrorStream()" - } - ) - public static final class ProcessImpl_getErrorStream_Probe { - public static void onReturn( - @ReturnValue final InputStream stream, - @This final Process process - ) { - final int rowIndex = ourObject2ProcessRowIndex.get(process); - if (Table.shouldIgnoreRow(rowIndex)) { - return; - } - - final InputStream errorStream = getProperInputStream(stream); - if (errorStream == null) { - return; - } - - ourObject2ProcessRowIndex.put(errorStream, rowIndex); - ourErrorStreams.add(errorStream); - } - } - - /** - * Associate output streams with process - */ - @MethodPattern( - { - "java.lang.ProcessImpl:getOutputStream()", - "java.lang.UNIXProcess:getOutputStream()" - } - ) - public static final class ProcessImpl_getOutputStream_Probe { - public static void onReturn( - @ReturnValue final OutputStream stream, - @This final Process process - ) { - final int rowIndex = ourObject2ProcessRowIndex.get(process); - if (Table.shouldIgnoreRow(rowIndex)) { - return; - } - - final FileOutputStream outputStream = getFileOutputStream(stream); - if (outputStream == null) { - return; - } - - ourObject2ProcessRowIndex.put(outputStream, rowIndex); - } - } - - @MethodPattern("java.lang.UNIXProcess:waitForProcessExit(int)") - public static final class UnixProcess_waitForProcessExit_Probe { - public static void onReturn( - @ReturnValue final int exitCode, - @This final Process process - ) { - final int rowIndex = ourObject2ProcessRowIndex.get(process); - handleProcessExit(rowIndex, exitCode); - } - } - - @MethodPattern("java.lang.ProcessImpl:start(String[], java.util.Map, String, *)") - public static final class ProcessImpl_start_Probe { - public static void onReturn( - @ReturnValue final Process process, - @Param(1) final String[] cmd, - @Param(2) final Map env, - @Param(3) final String dir - ) { - if (process == null) { - return; - } - - final int rowIndex = T_PROCESS.createRow(); - if (Table.shouldIgnoreRow(rowIndex)) { - return; - } - - synchronized (ourUnclosedRowIndices) { - ourObject2ProcessRowIndex.put(process, rowIndex); - ourUnclosedRowIndices.add(rowIndex); - } - - T_PROCESS.myCommand.setValue(rowIndex, Callback.getCommandLineSpaceSeparated(cmd)); - T_PROCESS.myDirectory.setValue(rowIndex, dir); - T_PROCESS.myEnvironment.setValue(rowIndex, getEnvironmentAsString(env)); - T_PROCESS.myPID.setValue(rowIndex, getPID(process)); - - // ensure that we record the process exit code - if (IS_WINDOWS) { - JVM.registerProcessExitListener(process, rowIndex); - } - } - } - - @MethodPattern( - { - "java.lang.ProcessImpl:waitFor()", - "java.lang.UNIXProcess:waitFor()" - } - ) - public static final class ProcessImpl_waitFor_Probe { - public static void onReturn( - @This final Process process, - @ReturnValue final int exitCode - ) { - final int rowIndex = ourObject2ProcessRowIndex.get(process); - handleProcessExit(rowIndex, exitCode); - } - } - - @MethodPattern( - { - "java.io.FileOutputStream:writeBytes(byte[], int, int)", - "java.io.FileOutputStream:writeBytes(byte[], int, int, boolean)" - } - ) - public static final class FileOutputStream_writeBytes_Probe { - public static int onEnter( - @This final FileOutputStream fileOutputStream, - @Param(3) final int bytesWritten - ) { - return processWriteEnterImpl(fileOutputStream, bytesWritten); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - processWriteExitImpl(rowIndex, e); - } - } - - @MethodPattern("java.io.FileOutputStream:write(int)") - public static final class FileOutputStream_write_Probe { - public static int onEnter(@This final FileOutputStream fileOutputStream) { - return processWriteEnterImpl(fileOutputStream, 1 /* one byte to be written */); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - processWriteExitImpl(rowIndex, e); - } - } - - private static int processWriteEnterImpl(final FileOutputStream fileOutputStream, final int bytesWritten) { - final int rowIndex = ourObject2ProcessRowIndex.get(fileOutputStream); - if (Table.shouldIgnoreRow(rowIndex)) { - return Table.NO_ROW; - } - - final int writeRowIndex = T_STDIN.createRow(rowIndex); - T_STDIN.myBytes.setValueIfPositive(writeRowIndex, bytesWritten); - return writeRowIndex; - } - - private static void processWriteExitImpl( - final int rowIndex, - @ThrownException final Throwable e - ) { - T_STDIN.closeRow(rowIndex, e); - } - - @MethodPattern( - { - "java.io.FileInputStream:read()", - "java.lang.ProcessInputStream:read()" - } - ) - public static final class InputStream_read_Probe { - public static int onEnter(@This final InputStream inputStream) { - return processReadEnterImpl(inputStream); - } - - public static void onExit( - @This final InputStream inputStream, - @OnEnterResult final int readRowIndex, - @ReturnValue final int returnValue, - @ThrownException final Throwable e - ) { - // non negative return value means that a byte has been successfully read - final int readBytes = returnValue >= 0 ? 1 : 0; - processReadExitImpl(inputStream, readRowIndex, readBytes, e); - } - } - - @MethodPattern( - { - "java.io.FileInputStream:readBytes(byte[], int, int)", - // The following is for IBM Java on UNIX: - "java.lang.ProcessInputStream:read(byte[], int, int)", - "java.lang.ProcessInputStream:read(byte[])" - } - ) - public static final class InputStream_readBytes_Probe { - public static int onEnter(@This final InputStream inputStream) { - return processReadEnterImpl(inputStream); - } - - public static void onExit( - @This final InputStream inputStream, - @OnEnterResult final int readRowIndex, - @ReturnValue final int bytesRead, - @ThrownException final Throwable e - ) { - processReadExitImpl(inputStream, readRowIndex, bytesRead, e); - } - } - - /** - * Record individual read event - */ - private static int processReadEnterImpl(final InputStream inputStream) { - final int rowIndex = ourObject2ProcessRowIndex.get(inputStream); - if (Table.shouldIgnoreRow(rowIndex)) { - return Table.NO_ROW; - } - - final IOOperationTable readTable = ourErrorStreams.contains(inputStream) ? T_STDERR : T_STDOUT; - - return readTable.createRow(rowIndex); - } - - private static void processReadExitImpl( - final InputStream inputStream, - final int readRowIndex, - final int bytesRead, - @ThrownException final Throwable e - ) { - if (Table.shouldIgnoreRow(readRowIndex)) { - return; - } - - final IOOperationTable readTable = ourErrorStreams.contains(inputStream) ? T_STDERR : T_STDOUT; - - readTable.myBytes.setValueIfPositive(readRowIndex, bytesRead); - readTable.closeRow(readRowIndex, e); - } - - private static FileOutputStream getFileOutputStream(final OutputStream stream) { - if (stream instanceof BufferedOutputStream) { - try { - return Callback.getFieldObjectValue(stream, "out", OutputStream.class); - } - catch (final Throwable ignored) { - return null; - } - } - - if (stream instanceof FileOutputStream) { - return (FileOutputStream)stream; - } - - return null; - } - - private static InputStream getProperInputStream( final InputStream stream) { - if (stream instanceof BufferedInputStream) { - try { - return Callback.getFieldObjectValue(stream, "in", InputStream.class); - } - catch (final Throwable ignored) { - return null; - } - } - - if (stream instanceof FileInputStream) { - return stream; - } - - if ( - stream != null && - // cannot use instanceof for this non-public IBM Java class - "java.lang.ProcessInputStream".equals(stream.getClass().getName()) - ) { - return stream; - } - - return null; - } - - static String getEnvironmentAsString(final Map env) { - if (env == null) { - return ""; - } - - final StringBuilder sb = new StringBuilder(); - for (final Map.Entry e : env.entrySet()) { - sb.append(e.getKey()); - sb.append('='); - sb.append(e.getValue()); - sb.append('\n'); - } - - return sb.toString(); - } - - private static int getPID(final Process process) { - if (IS_WINDOWS) { - try { - final long handle = Callback.getFieldLongValue(process.getClass(), process, "handle"); - return Callback.getProcessID(handle); - } - catch (final Throwable ignored) { - } - } - else { - try { - final Field f = process.getClass().getDeclaredField("pid"); - f.setAccessible(true); - return f.getInt(process); - } - catch (final Throwable ignored) { - } - } - - // unknown - return 0; - } -} diff --git a/probes/src/examples/Servlets.java b/probes/src/examples/Servlets.java deleted file mode 100644 index d9f35c87ba9..00000000000 --- a/probes/src/examples/Servlets.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; -import com.yourkit.runtime.Callback; - -public final class Servlets { - public static final String TABLE_NAME = "JSP/Servlet"; - - private static final class RequestTable extends Table { - private final StringColumn myURI = new StringColumn("URI"); - private final StringColumn myQuery = new StringColumn("Query"); - - public RequestTable() { - super(Servlets.class, TABLE_NAME, Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final RequestTable T_REQUEST = new RequestTable(); - - // FIX 20150616_1 remember which servlet classes are HttpJspPage to speed up the servlet probe - private static final ObjectRowIndexMap ourClassIsJSPCached = new ObjectRowIndexMap(); - - private static boolean isJSP(final Class aClass) { - try { - final Class jspPageClass = Class.forName("javax.servlet.jsp.HttpJspPage", false, aClass.getClassLoader()); - return jspPageClass.isAssignableFrom(aClass); - } - catch (final Throwable ignored) { - return false; - } - } - - @MethodPattern( - { - "*:service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) void", - "-javax.servlet.http.HttpServlet:*(*)", - "-org.apache.jasper.*:*(*)" - } - ) - @InstanceOf("javax.servlet.http.HttpServlet") - public static final class Servlet_service_Probe { - public static int onEnter( - @ClassRef final Class aClass, - @Param(1) final Object request - ) { - int isJSP = ourClassIsJSPCached.get(aClass); - if (isJSP == Table.NO_ROW) { - isJSP = isJSP(aClass) ? -1 : -2; - ourClassIsJSPCached.putFirst(aClass, isJSP); - } - if (isJSP == -1) { - // ignore calls to Servlet's service() for jsp pages - return Table.NO_ROW; - } - - return createRequestRow(request); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_REQUEST.closeRow(rowIndex, e); - } - } - - @MethodPattern("*:_jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) void") - @InstanceOf("javax.servlet.jsp.HttpJspPage") - public static final class HttpJspPage_jspService_Probe { - public static int onEnter( - @Param(1) final Object request - ) { - return createRequestRow(request); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_REQUEST.closeRow(rowIndex, e); - } - } - - @MethodPattern("*:doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)") - @InstanceOf("javax.servlet.Filter") - public static final class Filter_doFilter_Probe { - public static int onEnter( - @Param(1) final Object request - ) { - return createRequestRow(request); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_REQUEST.closeRow(rowIndex, e); - } - } - - private static int createRequestRow(final Object request) { - final int rowIndex = T_REQUEST.createRow(); - if (Table.shouldIgnoreRow(rowIndex)) { - // optimization - return Table.NO_ROW; - } - - final String includeRequestURI = getRequestAttribute(request, "javax.servlet.include.request_uri"); - - final String requestURI; - final String query; - if (includeRequestURI == null || includeRequestURI.isEmpty()) { - requestURI = getRequestURI(request); - query = getQuery(request); - } - else { - requestURI = includeRequestURI; - query = getRequestAttribute(request, "javax.servlet.include.query_string"); - } - - T_REQUEST.myURI.setValue(rowIndex, requestURI); - T_REQUEST.myQuery.setValue(rowIndex, query); - - return rowIndex; - } - - /** - * This method uses reflection to avoid class-loading issues - */ - private static String getQuery(final Object request) { - if (request == null) { - return ""; - } - try { - return (String)Callback.callObjectMethod0(request.getClass(), request, "getQueryString", "()Ljava/lang/String;"); - } - catch (final Throwable ignored) { - return getQuery(tryGetWrappedRequest(request)); - } - } - - /** - * This method uses reflection to avoid class-loading issues - */ - static String getRequestURI(final Object request) { - if (request == null) { - return ""; - } - try { - return (String)Callback.callObjectMethod0(request.getClass(), request, "getRequestURI", "()Ljava/lang/String;"); - } - catch (final Throwable ignored) { - return getRequestURI(tryGetWrappedRequest(request)); - } - } - - /** - * This method uses reflection to avoid class-loading issues - */ - private static String getRequestAttribute(final Object request, final String attributeName) { - if (request == null) { - return ""; - } - try { - final Class requestClass = request.getClass(); - final String result = (String)Callback.callObjectMethod1( - requestClass, request, "getAttribute", "(Ljava/lang/String;)Ljava/lang/Object;", attributeName - ); - if (result != null && result.startsWith("//")) { - return result.substring(1); - } - return result; - } - catch (final Throwable ignored) { - return getRequestAttribute(tryGetWrappedRequest(request), attributeName); - } - } - - /** - * This method uses reflection to avoid class-loading issues - */ - private static Object tryGetWrappedRequest(final Object requestWrapper) { - try { - return Callback.callObjectMethod0(requestWrapper.getClass(), requestWrapper, "getRequest", "()Ljavax/servlet/ServletRequest;"); - } - catch (final Throwable ignored) { - return null; - } - } -} diff --git a/probes/src/examples/Sockets.java b/probes/src/examples/Sockets.java deleted file mode 100644 index baf6cd5fdf1..00000000000 --- a/probes/src/examples/Sockets.java +++ /dev/null @@ -1,365 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; -import com.yourkit.runtime.Callback; - -import java.io.InputStream; -import java.io.OutputStream; -import java.net.Socket; -import java.net.SocketAddress; -import java.nio.channels.SocketChannel; - -public final class Sockets { - public static final String TABLE_NAME = "Socket"; - - /** - * Resource can be Socket or directly opened SocketChannel - */ - private static final MasterResourceRegistry ourSockets = new MasterResourceRegistry( - Sockets.class, - TABLE_NAME, - null, - "Address" // column name - ) { - @Override - protected String retrieveResourceName(final Object resource) throws Exception { - final Socket socket = (Socket)(resource instanceof SocketChannel ? ((SocketChannel)resource).socket() : resource); - return - "[remote: " + - getPresentableAddress(socket.getRemoteSocketAddress()) + - ", local: " + - getPresentableAddress(socket.getLocalSocketAddress()) + - "]"; - } - }; - - private static final TableIntBytes T_STREAM_READ = new TableIntBytes(ourSockets, "Read", Table.MASK_FOR_LASTING_EVENTS); - private static final TableIntBytes T_STREAM_WRITE = new TableIntBytes(ourSockets, "Write", Table.MASK_FOR_LASTING_EVENTS); - - private static final TableLongBytes T_CHANNEL_READ = new TableLongBytes(ourSockets, "Channel Read", Table.MASK_FOR_LASTING_EVENTS); - private static final TableLongBytes T_CHANNEL_WRITE = new TableLongBytes(ourSockets, "Channel Write", Table.MASK_FOR_LASTING_EVENTS); - - /** - * Associate input streams with socket - */ - @MethodPattern("java.net.Socket:getInputStream()") - public static final class Socket_getInputStream_Probe { - public static void onReturn( - @ReturnValue final InputStream stream, - @This final Socket socket - ) { - // associate stream with socket resource - ourSockets.mapAlias(socket, stream); - } - } - - /** - * Associate output streams with socket - */ - @MethodPattern("java.net.Socket:getOutputStream()") - public static final class Socket_getOutputStream_Probe { - public static void onReturn( - @ReturnValue final OutputStream stream, - @This final Socket socket - ) { - // associate stream with socket resource - ourSockets.mapAlias(socket, stream); - } - } - - /** - * Record individual read event - */ - @MethodPattern( - "java.net.SocketInputStream:read(byte[], int, int)" - ) - public static final class SocketInputStream_read_Probe { - public static int onEnter(@This final InputStream stream) { - final int socketRowIndex = getOrCreateSocketRowFromStream(stream); - return T_STREAM_READ.createRow(socketRowIndex); - } - - public static void onExit( - @OnEnterResult final int readRowIndex, - @ReturnValue final int bytesRead, - @ThrownException final Throwable e - ) { - T_STREAM_READ.setBytes(readRowIndex, bytesRead); - T_STREAM_READ.closeRow(readRowIndex, e); - } - } - - @MethodPattern("java.net.ServerSocket:accept()") - public static final class ServerSocket_accept_Probe { - public static void onReturn(@ReturnValue final Socket socket) { - if (socket == null) { - return; - } - onSocketAccepted(socket, socket.getLocalSocketAddress()); - } - } - - private static void onSocketAccepted( final Object socket, final SocketAddress address) { - // Open as a lasting event, but we are not interested in the time spent in accept(). - // Instead, let's make it as short as possible by emulating enter and exit: - - final long resourceID = ourSockets.openOnEnter(); - ourSockets.openOnExit( - resourceID, - getPresentableAddress(address), - socket, - null, // no exception - FailedEventPolicy.DISCARD // use any value - it will not be used if exception is null - ); - } - - @MethodPattern("java.net.Socket:connect(java.net.SocketAddress, int)") - public static final class Socket_connect_Probe { - public static long onEnter() { - return ourSockets.openOnEnter(); - } - - public static void onExit( - @This final Socket socket, - @Param(1) final SocketAddress address, - @OnEnterResult final long resourceID, - @ThrownException final Throwable e - ) { - ourSockets.openOnExit( - resourceID, - getPresentableAddress(address), - socket, - e, - FailedEventPolicy.RECORD - ); - } - } - - /** - * Record individual write event - */ - @MethodPattern("java.net.SocketOutputStream:socketWrite(byte[], int, int)") - public static final class SocketOutputStream_write_Probe { - public static int onEnter( - @This final OutputStream stream, - @Param(3) final int writtenBytes - ) { - final int socketRowIndex = getOrCreateSocketRowFromStream(stream); - if (Table.shouldIgnoreRow(socketRowIndex)) { - // optimization - return Table.NO_ROW; - } - - final int rowIndex = T_STREAM_WRITE.createRow(socketRowIndex); - T_STREAM_WRITE.setBytes(rowIndex, writtenBytes); - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_STREAM_WRITE.closeRow(rowIndex, e); - } - } - - @MethodPattern("sun.nio.ch.ServerSocketChannelImpl:accept()") - public static final class ServerSocketChannel_accept_Probe { - public static void onReturn(@ReturnValue final SocketChannel socketChannel) { - if (socketChannel == null) { - return; - } - - final Socket socket = socketChannel.socket(); - if (socket == null) { - return; - } - - onSocketAccepted(socket, socket.getLocalSocketAddress()); - - // associate channel with socket resource - ourSockets.mapAlias(socket, socketChannel); - } - } - - @MethodPattern("sun.nio.ch.SocketChannelImpl:connect(java.net.SocketAddress)") - public static final class SocketChannel_connect_Probe { - public static long onEnter() { - return ourSockets.openOnEnter(); - } - - public static void onExit( - @This final SocketChannel socketChannel, - @Param(1) final SocketAddress address, - @OnEnterResult final long resourceID, - @ThrownException final Throwable e - ) { - ourSockets.openOnExit( - resourceID, - getPresentableAddress(address), - socketChannel, - e, - FailedEventPolicy.RECORD - ); - - // associate socket with channel - ourSockets.mapAlias(socketChannel, socketChannel.socket()); - } - } - - private static String getPresentableAddress( final SocketAddress address) { - return address != null ? address.toString() : null; - } - - private static int getOrCreateSocketRowFromChannel(final SocketChannel channel) { - final int rowIndex = ourSockets.get(channel); // get existing association - if (!Table.shouldIgnoreRow(rowIndex)) { - return rowIndex; - } - final int newRowIndex = ourSockets.getOrCreate(channel); - ourSockets.mapAlias(channel, channel.socket()); - return newRowIndex; - } - - private static int getOrCreateSocketRowFromStream(final Object stream) { - final int rowIndex = ourSockets.get(stream); // get by alias - if (!Table.shouldIgnoreRow(rowIndex)) { - return rowIndex; - } - Socket socket = null; - try { - socket = Callback.getFieldObjectValue(stream, "socket", Socket.class); - } - catch (final Throwable ignored) { - } - if (socket == null) { - return Table.NO_ROW; - } - - final int newRowIndex = ourSockets.getOrCreate(socket); - ourSockets.mapAlias(socket, stream); - return newRowIndex; - } - - /** - * Record individual write event - */ - @MethodPattern( - { - "sun.nio.ch.SocketChannelImpl:write(java.nio.ByteBuffer) int", - "sun.nio.ch.SocketChannelImpl:write(java.nio.ByteBuffer[], int, int) long" - } - ) - public static final class SocketChannel_write_Probe { - public static int onEnter(@This final SocketChannel socketChannel) { - final int socketRowIndex = getOrCreateSocketRowFromChannel(socketChannel); - - return T_CHANNEL_WRITE.createRow(socketRowIndex); - } - - public static void onExit( - @OnEnterResult final int writeRowIndex, - @ReturnValue final long bytesWritten, - @ThrownException final Throwable e - ) { - if (Table.shouldIgnoreRow(writeRowIndex)) { - // optimization - return; - } - - T_CHANNEL_WRITE.setBytes(writeRowIndex, bytesWritten); - T_CHANNEL_WRITE.closeRow(writeRowIndex, e); - } - } - - /** - * Record individual read event - */ - @MethodPattern( - { - "sun.nio.ch.SocketChannelImpl:read(java.nio.ByteBuffer) int", - "sun.nio.ch.SocketChannelImpl:read(java.nio.ByteBuffer[], int, int) long" - } - ) - public static final class SocketChannel_read_Probe { - public static int onEnter(@This final SocketChannel socketChannel) { - final int rowIndex = getOrCreateSocketRowFromChannel(socketChannel); - - return T_CHANNEL_READ.createRow(rowIndex); - } - - public static void onExit( - @OnEnterResult final int readRowIndex, - @ReturnValue final long bytesRead, - @ThrownException final Throwable e - ) { - if (Table.shouldIgnoreRow(readRowIndex)) { - // optimization - return; - } - - T_CHANNEL_READ.setBytes(readRowIndex, bytesRead); - T_CHANNEL_READ.closeRow(readRowIndex, e); - } - } - - // Close socket or channel - - @MethodPattern("java.net.Socket:close()") - public static final class Socket_close_Probe { - public static int onEnter(@This final Socket socket) { - return ourSockets.closeOnEnter(socket); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - ourSockets.closeOnExit(rowIndex, e); - } - } - - @MethodPattern("sun.nio.ch.SocketChannelImpl:implCloseSelectableChannel()") - public static final class SocketChannel_close_Probe { - public static int onEnter(@This final SocketChannel channel) { - return ourSockets.closeOnEnter(channel); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - ourSockets.closeOnExit(rowIndex, e); - } - } -} diff --git a/probes/src/examples/TestNG.java b/probes/src/examples/TestNG.java deleted file mode 100644 index e645b88c92a..00000000000 --- a/probes/src/examples/TestNG.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; - -public final class TestNG { - public static final String TABLE_NAME = "TestNG Method"; - - private static final class TestsTable extends Table { - private final ClassNameColumn myTestClass = new ClassNameColumn("Test Class"); - private final StringColumn myMethod = new StringColumn("Method"); - - public TestsTable() { - super(TestNG.class, TABLE_NAME, Table.MASK_FOR_LASTING_EVENTS); - } - } - private static final TestsTable T_TESTS = new TestsTable(); - - @MethodPattern({ - "*test*:@org.testng.annotations.Test *(*)", - "*Test*:@org.testng.annotations.Test *(*)" - }) - public static final class Test_Probe { - public static int onEnter( - @ClassRef final Class testClass, - @MethodName final String methodName - ) { - final int rowIndex = T_TESTS.createRow(); - T_TESTS.myMethod.setValue(rowIndex, methodName); - T_TESTS.myTestClass.setValue(rowIndex, testClass); - return rowIndex; - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_TESTS.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/examples/Threads.java b/probes/src/examples/Threads.java deleted file mode 100644 index 5012023e287..00000000000 --- a/probes/src/examples/Threads.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - Copyright (c) 2003-2016, YourKit - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of YourKit nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY YOURKIT "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL YOURKIT BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package examples; - -import com.yourkit.probes.*; - -/** - * Probes to monitor monitor some aspects of thread life cycle: - * where and when threads are created (instance of {@link Thread} or its subclass), - * started ({@link Thread#start()}), and their names changed ({@link Thread#setName(String)}) - * For detail, see Help. - */ -public final class Threads { - public static final String TABLE_NAME = "Thread"; - /** - * Mapping between Thread objects and row index in T_THREAD table - */ - private static final ObjectRowIndexMap ourThread2RowIndex = new ObjectRowIndexMap(); - - private static final ResourceTable T_THREAD = new ResourceTable( - Threads.class, - TABLE_NAME, - "Name" // resource name column - ); - - private static final class ThreadCreateTable extends Table { - public ThreadCreateTable() { - super(T_THREAD, "Create", Table.MASK_FOR_POINT_EVENTS); - } - } - private static final ThreadCreateTable T_CREATE = new ThreadCreateTable(); - - private static final class ThreadNameHistoryTable extends Table { - private final StringColumn myName = new StringColumn("Name"); - - public ThreadNameHistoryTable() { - super(T_THREAD, "Set Name", Table.MASK_FOR_POINT_EVENTS); - } - } - private static final ThreadNameHistoryTable T_NAME = new ThreadNameHistoryTable(); - - private static final class ThreadStartTable extends Table { - public ThreadStartTable() { - super(T_THREAD, "Start", Table.MASK_FOR_POINT_EVENTS); - } - } - private static final ThreadStartTable T_START = new ThreadStartTable(); - - private static final class ThreadRunTable extends Table { - public ThreadRunTable() { - super( - T_THREAD, - "Run", - LASTING_EVENTS | RECORD_THREAD // don't record stack trace - it's always .run() - ); - } - } - private static final ThreadRunTable T_RUN = new ThreadRunTable(); - - @MethodPattern("java.lang.Thread:(*)") - public static final class Thread_constructor_Probe { - public static int onEnter(@This final Object thread) { - if (!JVM.isLivePhase()) { - return Table.NO_ROW; - } - - final int existingRowIndex = ourThread2RowIndex.get(thread); - if (!Table.shouldIgnoreRow(existingRowIndex)) { - // skip nested constructor call - return Table.NO_ROW; - } - - final int rowIndex = T_THREAD.createRow(); - - // remember now to detect nested constructor calls - ourThread2RowIndex.put(thread, rowIndex); - - return rowIndex; - } - - public static void onExit( - @This final Object thread, - @OnEnterResult final int rowIndex - ) { - if (Table.shouldIgnoreRow(rowIndex)) { - return; - } - - String name = null; - try { - name = ((Thread)thread).getName(); - //noinspection ConstantConditions - if (name != null && name.startsWith("YJPAgent-")) { - // skip profiler internal threads - - T_THREAD.deleteRow(rowIndex); - ourThread2RowIndex.remove(thread); - return; - } - } - catch (final Throwable ignored) { - } - - // "Create" event - T_CREATE.createRow(rowIndex); - - T_THREAD.setResourceObject(rowIndex, thread); - // set current thread name - T_THREAD.setResourceName(rowIndex, name); - } - } - - @MethodPattern("java.lang.Thread:start()") - public static final class Thread_start_Probe { - public static void onEnter(@This final Object thread) { - if (!JVM.isLivePhase()) { - return; - } - - final int threadRowIndex = ourThread2RowIndex.get(thread); - T_START.createRow(threadRowIndex); - } - } - - @MethodPattern( - { - "java.lang.*:run()", // must explicitly add Thread and other core classes not covered with "*" - "*:run() void" - } - ) - public static final class Thread_run_Probe { - public static int onEnter(@This final Thread thread) { - if (!JVM.isLivePhase()) { - return Table.NO_ROW; - } - - final int threadRowIndex = ourThread2RowIndex.get(thread); - return T_RUN.createRow(threadRowIndex); - } - - public static void onExit( - @OnEnterResult final int runRow, - @ThrownException final Throwable e - ) { - T_RUN.closeRow(runRow, e); - } - } - - @MethodPattern("java.lang.Thread:setName(String)") - public static final class Thread_setName_Probe { - public static void onReturn( - @This final Object thread, - @Param(1) final String name - ) { - if (!JVM.isLivePhase()) { - return; - } - - final int rowIndex = ourThread2RowIndex.get(thread); - if (Table.shouldIgnoreRow(rowIndex)) { - // thread has not been created yet, or the event was cleared - return; - } - - // create name history record - final int historyRowIndex = T_NAME.createRow(rowIndex); - T_NAME.myName.setValue(historyRowIndex, name); - - // update current thread name - T_THREAD.setResourceName(rowIndex, name); - } - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/ClearCaches.java b/probes/src/org/jetbrains/plugins/scala/probes/ClearCaches.java deleted file mode 100644 index 30545a5bd71..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/ClearCaches.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import com.yourkit.probes.MethodName; -import com.yourkit.probes.MethodPattern; -import com.yourkit.probes.StringColumn; -import com.yourkit.probes.Table; - -/** - * @author Nikolay.Tropin - */ -public class ClearCaches { - private static class CachesTable extends Table { - private StringColumn methodName = new StringColumn("Method name"); - - public CachesTable() { - super(ClearCaches.class, "Clear caches", Table.MASK_FOR_POINT_EVENTS); - } - } - private static final CachesTable TABLE = new CachesTable(); - - @MethodPattern("org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager:clear*(*)") - public static final class Probe { - public static void onEnter( - @MethodName String mName - ) { - final int rowIndex = TABLE.createRow(); - TABLE.methodName.setValue(rowIndex, mName); - } - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/Conformance.java b/probes/src/org/jetbrains/plugins/scala/probes/Conformance.java deleted file mode 100644 index 3039bde3b83..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/Conformance.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import com.yourkit.probes.*; - -/** - * @author Nikolay.Tropin - */ -public class Conformance { - private static class ConformanceTable extends Table { - public final int minRecordMs = 2; - public final int minStacktraceMs = 10; - - private StringColumn leftType = new StringColumn("Left"); - private StringColumn rightType = new StringColumn("Right"); - private StringColumn result = new StringColumn("Result"); - private LongColumn noGcTime = new LongColumn("No GC time"); - - private StringColumn stacktrace = new StringColumn("Stacktrace"); - - public ConformanceTable() { - super(Conformance.class, "Conformance", Table.LASTING_EVENTS | Table.RECORD_THREAD); - setMinimumRecordedLastingEventTime(minRecordMs); - } - } - private static final ConformanceTable TABLE = new ConformanceTable(); - - @MethodPattern({ - "org.jetbrains.plugins.scala.lang.psi.types.api.Conformance$class:conformsInner(*)" - }) - public static final class Probe { - public static Pair onEnter() { - return new Pair(TABLE.createRow(), Utilities.gcTime()); - } - - public static void onExit( - @MethodTimeMs final long duration, - @OnEnterResult final Pair rowAndGc, - @ReturnValue final Object tuple, - @Param(2) final Object left, - @Param(3) final Object right, - @ThrownException final Throwable e - ) { - int rowIndex = rowAndGc.first; - long gcTime = Utilities.gcTime() - rowAndGc.second; - long noGcDuration = duration - gcTime; - if (noGcDuration >= TABLE.minRecordMs) { - TABLE.leftType.setValue(rowIndex, Utilities.presentableText(left)); - TABLE.rightType.setValue(rowIndex, Utilities.presentableText(right)); - TABLE.noGcTime.setValue(rowIndex, noGcDuration); - if (e == null) { - TABLE.result.setValue(rowIndex, Utilities.firstComponentText(tuple)); - } - if (noGcDuration >= TABLE.minStacktraceMs) { - TABLE.stacktrace.setValue(rowIndex, Utilities.currentStackTrace()); - } - } - TABLE.closeRow(rowIndex, e); - } - - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/FindMethodsByName.java b/probes/src/org/jetbrains/plugins/scala/probes/FindMethodsByName.java deleted file mode 100644 index f992035f0d5..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/FindMethodsByName.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import com.yourkit.probes.*; - -/** - * @author Nikolay.Tropin - */ -public class FindMethodsByName { - public static final String TABLE_NAME = "Find method by name"; - - private static final class ResultsTable extends Table { - private final StringColumn myMethodName = new StringColumn("Method"); - private final StringColumn myClassName = new StringColumn("Class"); - - public ResultsTable() { - super(FindMethodsByName.class, TABLE_NAME, Table.LASTING_EVENTS | Table.RECORD_THREAD); - } - } - private static final ResultsTable T_RESULTS = new ResultsTable(); - - @MethodPattern({"org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.ScTypeDefinitionImpl:findMethodsByName(*)"}) - public static final class Probe { - public static int onEnter() { - return T_RESULTS.createRow(); - } - - public static void onExit( - @Param(1) final String methodName, - @This final Object typeDef, - @OnEnterResult final int rowIndex, - @ThrownException final Throwable e - ) { - T_RESULTS.myMethodName.setValue(rowIndex, methodName); - T_RESULTS.myClassName.setValue(rowIndex, Utilities.name(typeDef)); - T_RESULTS.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/GetNode.java b/probes/src/org/jetbrains/plugins/scala/probes/GetNode.java deleted file mode 100644 index 579992648c9..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/GetNode.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import com.yourkit.probes.*; - -/** - * @author Nikolay.Tropin - */ -public class GetNode { - private static class TypeTextTable extends Table { - public final int minRecordMs = 2; - public final int minStacktraceMs = 10; - - private StringColumn element = new StringColumn("Element"); - private StringColumn stacktrace = new StringColumn("Stacktrace"); - private LongColumn noGcTime = new LongColumn("No GC time"); - - - public TypeTextTable() { - super(ResolveProbes.class, "getNode on Stub", Table.LASTING_EVENTS + Table.RECORD_THREAD); - setMinimumRecordedLastingEventTime(minRecordMs); - } - } - private static final TypeTextTable TABLE = new TypeTextTable(); - - - @MethodPattern({"com.intellij.extapi.psi.StubBasedPsiElementBase:getNode(*)"}) - public static class Probe { - public static Pair onEnter(@This final Object element) { - int row = Table.NO_ROW; - long gcTime = -1; - if (Utilities.isStub(element)) { - row = TABLE.createRow(); - gcTime = Utilities.gcTime(); - } - return new Pair(row, gcTime); - } - - public static void onExit( - @This final Object element, - @MethodTimeMs final long duration, - @OnEnterResult final Pair rowAndGc, - @ThrownException final Throwable e - ) { - int rowIndex = rowAndGc.first; - - if (rowIndex == Table.NO_ROW) return; - - long gcTime = Utilities.gcTime() - rowAndGc.second; - long noGcDuration = duration - gcTime; - - if (noGcDuration >= TABLE.minRecordMs) { - TABLE.noGcTime.setValue(rowIndex, noGcDuration); - TABLE.element.setValue(rowIndex, Utilities.toString(element)); - if (noGcDuration >= TABLE.minStacktraceMs) { - TABLE.stacktrace.setValue(rowIndex, Utilities.currentStackTrace()); - } - } - TABLE.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/GetType.java b/probes/src/org/jetbrains/plugins/scala/probes/GetType.java deleted file mode 100644 index c2fcce19d5e..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/GetType.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import com.yourkit.probes.*; - -/** - * @author Nikolay.Tropin - */ -public class GetType { - private static class GetTypeTable extends Table { - public final int minRecordMs = 2; - public final int minStacktraceMs = 10; - - private StringColumn exprText = new StringColumn("PsiElement"); - private StringColumn methodName = new StringColumn("Method"); - private LongColumn noGcTime = new LongColumn("No GC time"); - - private StringColumn computedType = new StringColumn("Computed type"); - private StringColumn stacktrace = new StringColumn("Stacktrace"); - - public GetTypeTable() { - super(GetType.class, "getType", Table.LASTING_EVENTS | Table.RECORD_THREAD); - setMinimumRecordedLastingEventTime(minRecordMs); - } - - } - private static final GetTypeTable TABLE = new GetTypeTable(); - - @MethodPattern({ - "org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression$class:getType(*)", - "org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression$class:expectedType(*)", - "org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement$class:getType(*)" - }) - public static final class Probe { - public static Pair onEnter() { - return new Pair(TABLE.createRow(), Utilities.gcTime()); - } - - public static void onExit( - @MethodTimeMs final long duration, - @MethodName final String mName, - @OnEnterResult final Pair rowAndGc, - @Param(1) final Object elem, - @ReturnValue final Object typeResult, - @ThrownException final Throwable e - ) { - int rowIndex = rowAndGc.first; - long gcTime = Utilities.gcTime() - rowAndGc.second; - long noGcDuration = duration - gcTime; - if (noGcDuration >= TABLE.minRecordMs) { - TABLE.exprText.setValue(rowIndex, Utilities.getText(elem)); - TABLE.methodName.setValue(rowIndex, mName); - TABLE.noGcTime.setValue(rowIndex, noGcDuration); - if (e == null) { - TABLE.computedType.setValue(rowIndex, Utilities.presentableTextFromTypeResult(typeResult)); - } - if (noGcDuration >= TABLE.minStacktraceMs) { - TABLE.stacktrace.setValue(rowIndex, Utilities.currentStackTrace()); - } - } - TABLE.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/Pair.java b/probes/src/org/jetbrains/plugins/scala/probes/Pair.java deleted file mode 100644 index 92b1f65df81..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/Pair.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -/** - * @author Nikolay.Tropin - */ -public class Pair { - public final A first; - public final B second; - - public Pair(A first, B second) { - this.first = first; - this.second = second; - } -} \ No newline at end of file diff --git a/probes/src/org/jetbrains/plugins/scala/probes/ResolveProbes.java b/probes/src/org/jetbrains/plugins/scala/probes/ResolveProbes.java deleted file mode 100644 index 28eef498925..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/ResolveProbes.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import com.yourkit.probes.*; - -import java.lang.reflect.Array; - -/** - * @author Nikolay.Tropin - */ -public class ResolveProbes { - private static class ResolveTable extends Table { - public final int minRecordMs = 2; - public final int minStacktraceMs = 10; - - private StringColumn refName = new StringColumn("RefName"); - private StringColumn target = new StringColumn("Target"); - private LongColumn noGcTime = new LongColumn("No GC time"); - - private StringColumn stacktrace = new StringColumn("Stacktrace"); - - public ResolveTable() { - super(ResolveProbes.class, "Resolve", Table.LASTING_EVENTS | Table.RECORD_THREAD); - setMinimumRecordedLastingEventTime(minRecordMs); - } - } - private static final ResolveTable TABLE = new ResolveTable(); - - - @MethodPattern({ - "org.jetbrains.plugins.scala.lang.resolve.ResolvableReferenceExpression$class:multiResolve(*)", - "org.jetbrains.plugins.scala.lang.resolve.ResolvableStableCodeReferenceElement$class:multiResolve(*)" - }) - public static class MultiResolveProbe { - public static Pair onEnter() { - return new Pair(TABLE.createRow(), Utilities.gcTime()); - } - - public static void onExit( - @MethodTimeMs final long duration, - @OnEnterResult final Pair rowAndGc, - @Param(1) final Object ref, - @Param(2) final boolean incomplete, - @ReturnValue final Object resolveResults, - @ThrownException final Throwable e - ) { - int rowIndex = rowAndGc.first; - long gcTime = Utilities.gcTime() - rowAndGc.second; - long noGcDuration = duration - gcTime; - if (noGcDuration >= TABLE.minRecordMs) { - TABLE.refName.setValue(rowIndex, Utilities.refName(ref)); - TABLE.noGcTime.setValue(rowIndex, noGcDuration); - if (e == null) { - int length = Array.getLength(resolveResults); - if (length > 0) { - Object rr = Array.get(resolveResults, 0); - TABLE.target.setValue(rowIndex, Utilities.getTargetName(rr)); - } - else { - TABLE.target.setValue(rowIndex, "No resolve"); - } - } - if (noGcDuration >= TABLE.minStacktraceMs) { - TABLE.stacktrace.setValue(rowIndex, Utilities.currentStackTrace()); - } - } - TABLE.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/TypeText.java b/probes/src/org/jetbrains/plugins/scala/probes/TypeText.java deleted file mode 100644 index 0e1317a35d0..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/TypeText.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import com.yourkit.probes.*; - -/** - * @author Nikolay.Tropin - */ -public class TypeText { - private static class TypeTextTable extends Table { - private StringColumn result = new StringColumn("Result"); - private StringColumn methodName = new StringColumn("Method Name"); - - public TypeTextTable() { - super(ResolveProbes.class, "Type text", Table.LASTING_EVENTS + Table.RECORD_THREAD); - setMinimumRecordedLastingEventTime(1); - } - } - private static final TypeTextTable TABLE = new TypeTextTable(); - - - @MethodPattern({ - "org.jetbrains.plugins.scala.lang.psi.types.api.ScTypePresentation$class:presentableText(*)", - "org.jetbrains.plugins.scala.lang.psi.types.api.ScTypePresentation$class:canonicalText(*)" - }) - public static class Probe { - public static int onEnter() { - return TABLE.createRow(); - } - - public static void onExit( - @OnEnterResult final int rowIndex, - @ReturnValue final String result, - @MethodName final String methodName, - @ThrownException final Throwable e - ) { - if (e == null) { - TABLE.result.setValue(rowIndex, result); - TABLE.methodName.setValue(rowIndex, methodName); - } - TABLE.closeRow(rowIndex, e); - } - } -} diff --git a/probes/src/org/jetbrains/plugins/scala/probes/Utilities.java b/probes/src/org/jetbrains/plugins/scala/probes/Utilities.java deleted file mode 100644 index 046083d9dd1..00000000000 --- a/probes/src/org/jetbrains/plugins/scala/probes/Utilities.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.jetbrains.plugins.scala.probes; - -import java.lang.management.GarbageCollectorMXBean; -import java.lang.management.ManagementFactory; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * @author Nikolay.Tropin - */ -public class Utilities { - - public static String currentStackTrace() { - StackTraceElement[] stackTrace = new Exception().getStackTrace(); - StringBuilder buffer = new StringBuilder(); - for (int i = 2; i < stackTrace.length; i++) { - StackTraceElement element = stackTrace[i]; - buffer.append(element.toString()).append("\n"); - } - return buffer.toString(); - } - - public static String getContainingFileName(Object psiElem) { - Object file = invokeMethod("getContainingFile", null, psiElem); - return file != null ? file.toString() : "null"; - } - - public static String refName(Object ref) { - return invokeMethod("refName", "not found", ref).toString(); - } - - public static String getName(Object namedPsiElem) { - return (String) invokeMethod("getName", "not found", namedPsiElem); - } - - public static String getTargetName(Object resolveResult) { - Object element = invokeMethod("getElement", null, resolveResult); - String fqn = getFQN(element); - return element != null ? element.getClass().getSimpleName() + ": " + fqn : "not found"; - } - - public static String getFQN(Object namedPsiElem) { - Class aClass = namedPsiElem.getClass(); - Method getQN = findMethodByName(aClass, "getQualifiedName"); - if (getQN != null) { - Object result = invokeMethod(getQN, "not found", namedPsiElem); - return result != null ? (String) result : getName(namedPsiElem); - } - - Method getContainingClass = findMethodByName(aClass, "getContainingClass"); - String name = invokeMethod("getName", "not found", namedPsiElem).toString(); - Object containingClass = getContainingClass != null ? invokeMethod(getContainingClass, null, namedPsiElem): null; - String qualifier = containingClass != null ? invokeMethod("getQualifiedName", "", containingClass) + "." : ""; - return qualifier + "." + name; - } - - public static int getOffset(Object psiElem) { - Object textRange = invokeMethod("getTextRange", null, psiElem); - if (textRange != null) { - return (Integer) invokeMethod("getStartOffset", -1, textRange); - } - else { - return -1; - } - } - - public static String getText(Object psiElem) { - return (String) invokeMethod("getText", "not found", psiElem); - } - - public static String toString(Object o) { - return (String) invokeMethod("toString", "toString failed", o); - } - - public static String name(Object psiElem) { - return invokeMethod("name", "not found", psiElem).toString(); - } - - public static String presentableTextFromTypeResult(Object typeResult) { - Class aClass = typeResult.getClass(); - boolean success = aClass.getSimpleName().equals("Success"); - boolean some = aClass.getSimpleName().equals("Some"); - if (success || some) { - Object scType = invokeMethod("get", null, typeResult); - if (scType != null) return invokeMethod("presentableText", "not found", scType).toString(); - } - return "not found"; - } - - public static String presentableText(Object scType) { - return (String) invokeMethod("presentableText", "not found", scType); - } - - public static String firstComponentText(Object tuple) { - return invokeMethod("_1", "not found", tuple).toString(); - } - - public static boolean isStub(Object psiElement) { - return invokeMethod("getStub", null, psiElement) != null; - } - - private static Object invokeMethod(String methodName, Object dflt, Object obj, Object... args) { - Class aClass = obj.getClass(); - Method method = findMethodByName(aClass, methodName); - if (method == null) throw new NoSuchMethodError("No method " + methodName + " found in " + obj.toString()); - return invokeMethod(method, dflt, obj, args); - } - - private static Object invokeMethod(Method method, Object dflt, Object obj, Object... args) { - try { - return method.invoke(obj, args); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - printException(e); - } - return dflt; - } - - private static Method findMethodByName(Class aClass, String methodName) { - for (Method method : aClass.getMethods()) { - if (method.getName().equals(methodName)) { - return method; - } - } - return null; - } - - private static void printException(Throwable e) { - Throwable cause = e.getCause(); - if (cause != null) System.out.println(e.toString() + " caused by " + cause.toString()); - else System.out.println(e.toString()); - } - - public static long gcTime() { - long res = 0; - for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { - long collectionTime = bean.getCollectionTime(); - if (collectionTime > 0) - res += collectionTime; - } - return res; - } -} From a523b28ded9e35ed5e946ed1957edb58764069e4 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Tue, 31 Oct 2017 11:32:58 +0300 Subject: [PATCH 107/141] parentOfType extension method --- .../CreateEntityQuickFix.scala | 4 +- .../StringToMultilineStringIntention.scala | 45 ++++++++++-------- .../intention/types/AddOrRemoveStrategy.scala | 3 +- .../types/ConvertFromInfixIntention.scala | 22 ++++----- ...ertImplicitBoundsToImplicitParameter.scala | 47 ++++++++++--------- .../impl/ScalaCommentContextType.scala | 6 +-- .../ScalaEvaluatorBuilderUtil.scala | 13 ++--- .../evaluator/ScalaCompilingEvaluator.scala | 8 ++-- .../evaluation/util/DebuggerUtil.scala | 17 ++++--- .../plugins/scala/extensions/package.scala | 9 ++-- .../macros/expansion/MacroExpandAction.scala | 12 ++--- .../ScalaFunctionParameterInfoHandler.scala | 41 ++++++++-------- .../scala/lang/psi/ScImportsHolder.scala | 7 ++- .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 31 ++++-------- .../psi/impl/base/ScAccessModifierImpl.scala | 17 ++++--- .../rename/RenameSuperMembersUtil.scala | 9 ++-- .../util/ScalaRefactoringUtil.scala | 24 ++++------ .../scala/overrideImplement/ScalaOIUtil.scala | 6 +-- .../test/AbstractTestFramework.scala | 20 ++++---- 19 files changed, 164 insertions(+), 177 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateEntityQuickFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateEntityQuickFix.scala index c07e61915d6..d8b0ca15c1c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateEntityQuickFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/createFromUsage/CreateEntityQuickFix.scala @@ -135,12 +135,12 @@ abstract class CreateEntityQuickFix(ref: ScReferenceExpression, entity: String, private def blockFor(exp: ScExpression): Try[ScExtendsBlock] = { object ParentExtendsBlock { - def unapply(e: PsiElement): Option[ScExtendsBlock] = Option(PsiTreeUtil.getParentOfType(exp, classOf[ScExtendsBlock])) + def unapply(e: PsiElement): Option[ScExtendsBlock] = exp.parentOfType(classOf[ScExtendsBlock]) } exp match { case InstanceOfClass(td: ScTemplateDefinition) => Success(td.extendsBlock) - case th: ScThisReference if PsiTreeUtil.getParentOfType(th, classOf[ScExtendsBlock], true) != null => + case th: ScThisReference if th.parentOfType(classOf[ScExtendsBlock]).isDefined => th.refTemplate match { case Some(ScTemplateDefinition.ExtendsBlock(block)) => Success(block) case None => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/literal/StringToMultilineStringIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/literal/StringToMultilineStringIntention.scala index 5cb5f248b46..f0d346635cc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/literal/StringToMultilineStringIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/literal/StringToMultilineStringIntention.scala @@ -10,34 +10,36 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiElement -import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.format.{Text, _} import org.jetbrains.plugins.scala.lang.psi.api.base.{ScInterpolatedStringLiteral, ScLiteral} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText +import org.jetbrains.plugins.scala.project.ProjectContext import org.jetbrains.plugins.scala.util.MultilineStringUtil._ class StringToMultilineStringIntention extends PsiElementBaseIntentionAction { + + import StringToMultilineStringIntention._ + def getFamilyName: String = "Regular/Multi-line String conversion" def isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean = { - val literalExpression: ScLiteral = PsiTreeUtil.getParentOfType(element, classOf[ScLiteral], false) - literalExpression match { - case null => false - case lit if lit.isMultiLineString => - setText("Convert to \"string\"") - true - case lit if lit.isString => - setText("Convert to \"\"\"string\"\"\"") - true - case _ => false + val maybeText = literalParent(element).collect { + case lit if lit.isMultiLineString => "Convert to \"string\"" + case lit if lit.isString => "Convert to \"\"\"string\"\"\"" } - } + maybeText.foreach(setText) + maybeText.isDefined + } override def invoke(project: Project, editor: Editor, element: PsiElement) { if (!element.isValid) return - val lit: ScLiteral = PsiTreeUtil.getParentOfType(element, classOf[ScLiteral], false) - if (lit == null || !lit.isString) return + + val lit = literalParent(element) + .filter(_.isString) + .getOrElse(return) + if (!FileModificationService.getInstance.preparePsiElementForWrite(element)) return val containingFile = element.getContainingFile @@ -46,8 +48,14 @@ class StringToMultilineStringIntention extends PsiElementBaseIntentionAction { UndoUtil.markPsiFileForUndo(containingFile) } +} + +object StringToMultilineStringIntention { - def regularToMultiline(literal: ScLiteral, editor: Editor) { + private def literalParent(element: PsiElement) = + element.parentOfType(classOf[ScLiteral], strict = false) + + private def regularToMultiline(literal: ScLiteral, editor: Editor): Unit = { import literal.projectContext val document = editor.getDocument @@ -72,8 +80,8 @@ class StringToMultilineStringIntention extends PsiElementBaseIntentionAction { } } - def multilineToRegular(literal: ScLiteral) { - implicit val projectContext = literal.projectContext + private def multilineToRegular(literal: ScLiteral): Unit = { + implicit val projectContext: ProjectContext = literal.projectContext literal match { case interpolated: ScInterpolatedStringLiteral => val prefix = interpolated.reference.map(_.getText).getOrElse("") @@ -84,7 +92,7 @@ class StringToMultilineStringIntention extends PsiElementBaseIntentionAction { StripMarginParser.parse(literal).getOrElse(Nil) case _ => InterpolatedStringParser.parse(interpolated).getOrElse(Nil) } - val content = InterpolatedStringFormatter.formatContent(parts, toMultiline = false) + val content = InterpolatedStringFormatter.formatContent(parts) val quote = "\"" val text = s"$prefix$quote$content$quote" val newLiteral = createExpressionFromText(text) @@ -109,6 +117,5 @@ class StringToMultilineStringIntention extends PsiElementBaseIntentionAction { case _ => } } - } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/AddOrRemoveStrategy.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/AddOrRemoveStrategy.scala index c974c0eb165..44af800a918 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/AddOrRemoveStrategy.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/AddOrRemoveStrategy.scala @@ -5,7 +5,6 @@ package types import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiElement -import com.intellij.psi.util.PsiTreeUtil.getParentOfType import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScTypedPattern import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement @@ -47,7 +46,7 @@ class AddOrRemoveStrategy(editor: Option[Editor] = None) extends AddOnlyStrategy val newParameter = createFunctionParameterFromText(parameter.name) - val pair: Option[(PsiElement, PsiElement)] = Option(getParentOfType(parameter, classOf[ScFunctionExpr], false)) + val pair: Option[(PsiElement, PsiElement)] = parameter.parentOfType(classOf[ScFunctionExpr], strict = false) .filter(_.parameters.size == 1) .flatMap(_.params.clauses.headOption) .filter { clause => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertFromInfixIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertFromInfixIntention.scala index ee84100deaf..789d9eaf29e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertFromInfixIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertFromInfixIntention.scala @@ -4,11 +4,10 @@ package intention package types import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction -import com.intellij.openapi.command.undo.UndoUtil +import com.intellij.openapi.command.undo.UndoUtil.markPsiFileForUndo import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement -import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScParenthesisedTypeElement, ScReferenceableInfixTypeElement} @@ -26,19 +25,20 @@ class ConvertFromInfixIntention extends PsiElementBaseIntentionAction { } } - override def invoke(project: Project, editor: Editor, element: PsiElement) { - val infixTypeElement = PsiTreeUtil.getParentOfType(element, classOf[ScReferenceableInfixTypeElement], false) + override def invoke(project: Project, editor: Editor, element: PsiElement): Unit = { + val infixTypeElement = Option(element).filter(_.isValid) + .flatMap(_.parentOfType(classOf[ScReferenceableInfixTypeElement], strict = false)) + .getOrElse(return) + + val replacement = infixTypeElement.computeDesugarizedType + .getOrElse(return) + val elementToReplace = infixTypeElement.getParent match { case x: ScParenthesisedTypeElement => x case _ => infixTypeElement } - if (element == null) return - infixTypeElement.computeDesugarizedType match { - case Some(replacement) => - elementToReplace.replace(replacement) - UndoUtil.markPsiFileForUndo(replacement.getContainingFile) - case _ => - } + elementToReplace.replace(replacement) + markPsiFileForUndo(replacement.getContainingFile) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertImplicitBoundsToImplicitParameter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertImplicitBoundsToImplicitParameter.scala index a7a96fdfb62..c1e8e7db5b7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertImplicitBoundsToImplicitParameter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/types/ConvertImplicitBoundsToImplicitParameter.scala @@ -10,8 +10,8 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.codeInsight.intention.types.ConvertImplicitBoundsToImplicitParameter._ -import org.jetbrains.plugins.scala.lang.psi.api.base.ScMethodLike -import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, ScParameterClause} +import org.jetbrains.plugins.scala.extensions.PsiElementExt +import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScParameterOwner} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTrait} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScTypeBoundsOwner, ScTypeParametersOwner} @@ -37,30 +37,35 @@ class ConvertImplicitBoundsToImplicitParameter extends PsiElementBaseIntentionAc object ConvertImplicitBoundsToImplicitParameter { - def canBeConverted(element: PsiElement): Boolean = { - val paramTypeElement: ScTypeBoundsOwner = PsiTreeUtil.getParentOfType(element, classOf[ScTypeBoundsOwner], false) - val scTypeParamOwner: ScTypeParametersOwner = PsiTreeUtil.getParentOfType(paramTypeElement, classOf[ScTypeParametersOwner], true) - paramTypeElement != null && paramTypeElement.hasImplicitBound && !scTypeParamOwner.isInstanceOf[ScTrait] - } - - def doConversion(element: PsiElement): Seq[ScParameter] = { - if (element == null || !element.isValid) return Seq.empty - val (function: ScMethodLike, paramOwner: ScParameterOwner, typeParamOwner: ScTypeParametersOwner) = - PsiTreeUtil.getParentOfType(element, classOf[ScParameterOwner], false) match { - case x: ScFunction => (x, x, x) - case x: ScClass => (x.constructor.getOrElse(return Seq.empty), x, x) - case _ => return Seq.empty + def canBeConverted(element: PsiElement): Boolean = + element.parentOfType(classOf[ScTypeBoundsOwner], strict = false) + .filter(_.hasImplicitBound) + .flatMap(_.parentOfType(classOf[ScTypeParametersOwner])) + .exists { + case _: ScTrait => false + case _ => true } + def doConversion(element: PsiElement): Seq[ScParameter] = { + val parameterOwner = Option(element).filter(_.isValid) + .flatMap(_.parentOfType(classOf[ScParameterOwner], strict = false)) + .getOrElse(return Seq.empty) + + val function = (parameterOwner match { + case function: ScFunction => Some(function) + case clazz: ScClass => clazz.constructor + case _ => None + }).getOrElse(return Seq.empty) + import function.projectContext - def removeImplicitBounds() { - typeParamOwner.typeParameters.foreach(_.removeImplicitBounds()) + def removeImplicitBounds(): Unit = parameterOwner match { + case parameterOwner: ScTypeParametersOwner => + val typeParameters = parameterOwner.typeParameters + typeParameters.foreach(_.removeImplicitBounds()) } - val declaredClauses: Seq[ScParameterClause] = paramOwner.allClauses - - declaredClauses.lastOption match { + parameterOwner.allClauses.lastOption match { case Some(paramClause) if paramClause.isImplicit => // Already has an implicit parameter clause: delete it, add the bounds, then // add the parameters from the deleted clause the the new one. @@ -84,7 +89,7 @@ object ConvertImplicitBoundsToImplicitParameter { case Some(implicitParamClause) if implicitParamClause.isImplicit => // for a constructor, might need to add an empty parameter section before the // implicit section. - val extra = function.effectiveParameterClauses.drop(declaredClauses.size).headOption + val extra = function.effectiveParameterClauses.drop(parameterOwner.allClauses.size).headOption var result: Seq[ScParameter] = Seq.empty for(c <- extra) { val newClause = createClauseFromText(c.getText) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/impl/ScalaCommentContextType.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/impl/ScalaCommentContextType.scala index 78adb339054..a87aee5b521 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/impl/ScalaCommentContextType.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/template/impl/ScalaCommentContextType.scala @@ -1,8 +1,8 @@ package org.jetbrains.plugins.scala.codeInsight.template.impl import com.intellij.codeInsight.template.TemplateContextType -import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiComment, PsiFile, PsiWhiteSpace} +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile /** @@ -21,7 +21,7 @@ object ScalaCommentContextType { case _: PsiWhiteSpace if offset > 0 => file.findElementAt(offset - 1) case elem => elem } - val comment = PsiTreeUtil.getParentOfType(element, classOf[PsiComment], false) - comment != null + + element.parentOfType(classOf[PsiComment], strict = false).isDefined } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala index 7375eccecb5..03ba9a4151f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaEvaluatorBuilderUtil.scala @@ -12,6 +12,7 @@ import com.intellij.psi.search.searches.ReferencesSearch import com.intellij.psi.util.CachedValueProvider.Result import com.intellij.psi.util.{CachedValueProvider, CachedValuesManager, PsiTreeUtil} import org.jetbrains.plugins.scala.debugger.ScalaPositionManager +import org.jetbrains.plugins.scala.debugger.ScalaPositionManager.InsideAsync import org.jetbrains.plugins.scala.debugger.evaluation.evaluator._ import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil import org.jetbrains.plugins.scala.extensions._ @@ -166,12 +167,8 @@ private[evaluation] trait ScalaEvaluatorBuilderUtil { def localFunName() = { val transformed = NameTransformer.encode(fun.name) fun match { - case ScalaPositionManager.InsideAsync(call) => - val containingFun = PsiTreeUtil.getParentOfType(fun, classOf[ScFunctionDefinition], true) - if (containingFun != null && call.isAncestorOf(containingFun)) - transformed - else - transformed + "$macro" + case InsideAsync(call) if !fun.parentOfType(classOf[ScFunctionDefinition]).exists(call.isAncestorOf(_)) => + transformed + "$macro" case _ => transformed } } @@ -719,7 +716,7 @@ private[evaluation] trait ScalaEvaluatorBuilderUtil { case _: ScGenerator | _: ScEnumerator if position != null && isNotUsedEnumerator(named, position.getElementAt) => throw EvaluationException(ScalaBundle.message("not.used.from.for.statement", name)) case LazyVal(_) => localLazyValEvaluator(named) - case ScalaPositionManager.InsideAsync(_) => + case InsideAsync(_) => val simpleLocal = new ScalaLocalVariableEvaluator(name, fileName) val fieldMacro = ScalaFieldEvaluator(new ScalaThisEvaluator(), name + "$macro") ScalaDuplexEvaluator(simpleLocal, fieldMacro) @@ -1482,7 +1479,7 @@ object ScalaEvaluatorBuilderUtil { case b: ScBlock if b.isAnonymousFunction => false //handled in isGenerateAnonfunSimple case e: ScExpression if ScalaPsiUtil.isByNameArgument(e) || ScalaPsiUtil.isArgumentOfFunctionType(e) => true case ScalaPsiUtil.MethodValue(_) => true - case Both(ChildOf(argExprs: ScArgumentExprList), ScalaPositionManager.InsideAsync(call)) + case Both(ChildOf(argExprs: ScArgumentExprList), InsideAsync(call)) if call.args == argExprs => true case _ => false } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala index 011efaeebd0..052121f8e0e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala @@ -15,7 +15,6 @@ import com.intellij.openapi.module.ModuleUtilCore import com.intellij.openapi.project.Project import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.{Key, TextRange} -import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiElement, PsiFile, PsiFileFactory} import com.sun.jdi._ import org.jetbrains.plugins.scala.debugger.evaluation._ @@ -243,9 +242,10 @@ private class GeneratedClass(fragment: ScalaCodeFragment, context: PsiElement, i case (stmt: ScBlockStatement) childOf (funDef: ScFunctionDefinition) if funDef.body.contains(stmt) => (stmt, funDef) case (stmt: ScBlockStatement) childOf (nonExpr: PsiElement) => (stmt, nonExpr) case _ => - val blockStmt = PsiTreeUtil.getParentOfType(elem, classOf[ScBlockStatement], true) - if (blockStmt == null) throw EvaluationException("Could not compile local class in this context") - else findAnchorAndParent(blockStmt) + elem.parentOfType(classOf[ScBlockStatement]) match { + case Some(blockStatement) => findAnchorAndParent(blockStatement) + case _ => throw EvaluationException("Could not compile local class in this context") + } } var (prevParent, parent) = findAnchorAndParent(context) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala index bbbb4c9f41e..548fa9288b8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala @@ -535,15 +535,14 @@ object DebuggerUtil { } @tailrec - def isLocalClass(td: PsiClass): Boolean = { - td.getParent match { - case _: ScTemplateBody => - val parent = PsiTreeUtil.getParentOfType(td, classOf[PsiClass], true) - if (parent == null || parent.isInstanceOf[ScNewTemplateDefinition]) return true - isLocalClass(parent) - case _: ScPackaging | _: ScalaFile => false - case _ => true - } + def isLocalClass(td: PsiClass): Boolean = td.getParent match { + case _: ScTemplateBody => + td.parentOfType(classOf[PsiClass]) match { + case Some(_: ScNewTemplateDefinition) | None => true + case Some(clazz) => isLocalClass(clazz) + } + case _: ScPackaging | _: ScalaFile => false + case _ => true } def getContainingMethod(elem: PsiElement): Option[PsiElement] = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala index 29efd74901b..e4accd9836e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala @@ -20,7 +20,7 @@ import com.intellij.psi.impl.source.{PostprocessReformattingAspect, PsiFileImpl} import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.stubs.{IStubElementType, StubElement} import com.intellij.psi.tree.{IElementType, TokenSet} -import com.intellij.psi.util.PsiTreeUtil +import com.intellij.psi.util.PsiTreeUtil.{getParentOfType, isAncestor} import com.intellij.util.{ArrayFactory, Processor} import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.scala.extensions.implementation.iterator._ @@ -267,6 +267,11 @@ package object extensions { def parent: Option[PsiElement] = Option(element.getParent) + def parentOfType[E <: PsiElement](clazz: Class[E], strict: Boolean = true): Option[E] = + Option(getParentOfType(element, clazz, strict)) + + def isAncestorOf(otherElement: PsiElement): Boolean = isAncestor(element, otherElement, true) + def parents: Iterator[PsiElement] = new ParentsIterator(element) def withParents: Iterator[PsiElement] = new ParentsIterator(element, strict = false) @@ -296,8 +301,6 @@ package object extensions { def nextSibilingsWithSelf: Iterator[PsiElement] = Iterator(element) ++ nextSiblings - def isAncestorOf(e: PsiElement): Boolean = PsiTreeUtil.isAncestor(element, e, true) - def contexts: Iterator[PsiElement] = new ContextsIterator(element) def withContexts: Iterator[PsiElement] = new ContextsIterator(element, strict = false) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpandAction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpandAction.scala index 034d8aa3210..3bfe2ce64e6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpandAction.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/macros/expansion/MacroExpandAction.scala @@ -18,16 +18,15 @@ import com.intellij.openapi.wm.ToolWindowId import com.intellij.psi._ import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.impl.source.tree.LeafPsiElement -import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugin.scala.util.MacroExpansion import org.jetbrains.plugins.scala.ScalaBundle import org.jetbrains.plugins.scala.extensions.{PsiElementExt, inWriteCommandAction} import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement +import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScAnnotation, ScBlock, ScMethodCall} import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition -import org.jetbrains.plugins.scala.lang.psi.api.{ScalaFile, ScalaRecursiveElementVisitor} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory import scala.annotation.tailrec @@ -40,16 +39,15 @@ class MacroExpandAction extends AnAction { import MacroExpandAction._ override def actionPerformed(e: AnActionEvent): Unit = { - - UsageTrigger.trigger(ScalaBundle.message("macro.expand.action.id")) val sourceEditor = FileEditorManager.getInstance(e.getProject).getSelectedTextEditor val psiFile = PsiDocumentManager.getInstance(e.getProject).getPsiFile(sourceEditor.getDocument).asInstanceOf[ScalaFile] val offset = sourceEditor.getCaretModel.getOffset - val annot = PsiTreeUtil.getParentOfType(psiFile.findElementAt(offset), classOf[ScAnnotation], false) - if (annot != null) - expandMetaAnnotation(annot) + + psiFile.findElementAt(offset) + .parentOfType(classOf[ScAnnotation], strict = false) + .foreach(expandMetaAnnotation) // expandSerialized(e, sourceEditor, psiFile) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala index 876ab58848b..c10efa4b867 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaFunctionParameterInfoHandler.scala @@ -595,28 +595,27 @@ class ScalaFunctionParameterInfoHandler extends ParameterInfoHandlerWithTabActio case self: ScSelfInvocation => val res: ArrayBuffer[Object] = new ArrayBuffer[Object] val i = self.arguments.indexOf(args.element) - val clazz = PsiTreeUtil.getParentOfType(self, classOf[ScClass], true) - clazz match { - case clazz: ScClass => - clazz.constructor match { - case Some(constr: ScPrimaryConstructor) if i < constr.effectiveParameterClauses.length => - res += ((constr, ScSubstitutor.empty, i)) - case Some(_) if i == 0 => res += "" - case None => res += "" - case _ => - } - for { - constr <- clazz.functions - if !constr.isInstanceOf[ScPrimaryConstructor] && - constr.isConstructor && - constr.clauses.map(_.clauses.length).getOrElse(1) > i - } { - if (!PsiTreeUtil.isAncestor(constr, self, true) && - constr.getTextRange.getStartOffset < self.getTextRange.getStartOffset) { - res += ((new PhysicalSignature(constr, ScSubstitutor.empty), i)) - } + + self.parentOfType(classOf[ScClass]).foreach { clazz => + clazz.constructor match { + case Some(constr: ScPrimaryConstructor) if i < constr.effectiveParameterClauses.length => + res += ((constr, ScSubstitutor.empty, i)) + case Some(_) if i == 0 => res += "" + case None => res += "" + case _ => + } + + for { + constr <- clazz.functions + if !constr.isInstanceOf[ScPrimaryConstructor] && + constr.isConstructor && + constr.clauses.map(_.clauses.length).getOrElse(1) > i + } { + if (!PsiTreeUtil.isAncestor(constr, self, true) && + constr.getTextRange.getStartOffset < self.getTextRange.getStartOffset) { + res += ((new PhysicalSignature(constr, ScSubstitutor.empty), i)) } - case _ => + } } res } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScImportsHolder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScImportsHolder.scala index 7478e0220c4..bb8fe76e442 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScImportsHolder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScImportsHolder.scala @@ -9,7 +9,6 @@ import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.impl.source.codeStyle.CodeEditUtil import com.intellij.psi.scope._ import com.intellij.psi.stubs.StubElement -import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.editor.importOptimizer._ import org.jetbrains.plugins.scala.extensions.{PsiElementExt, _} import org.jetbrains.plugins.scala.lang.formatting.settings.ScalaCodeStyleSettings @@ -166,12 +165,12 @@ trait ScImportsHolder extends ScalaPsiElement { def addImportsForPaths(paths: Seq[String], refsContainer: PsiElement = null): Unit = { import ScalaImportOptimizer._ - implicit val manager = getManager + implicit val manager: PsiManager = getManager def samePackage(path: String) = { val ref = createReferenceFromText(path) val pathQualifier = Option(ref).flatMap(_.qualifier.map(_.getText)).getOrElse("") - val ourPackageName: Option[String] = - Option(PsiTreeUtil.getParentOfType(this, classOf[ScPackaging], false)).map(_.fullPackageName) + val ourPackageName = this.parentOfType(classOf[ScPackaging], strict = false) + .map(_.fullPackageName) ourPackageName.contains(pathQualifier) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index 0ac785de8ec..de8770fb826 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -1426,28 +1426,15 @@ object ScalaPsiUtil { /** * If `param` is a synthetic parameter with a corresponding real parameter, return Some(realParameter), otherwise None */ - def parameterForSyntheticParameter(param: ScParameter): Option[ScParameter] = { - val fun = PsiTreeUtil.getParentOfType(param, classOf[ScFunction], true) - - def paramFromConstructor(td: ScClass) = td.constructor match { - case Some(constr) => constr.parameters.find(p => p.name == param.name) // TODO multiple parameter sections. - case _ => None - } - - if (fun == null) { - None - } else if (fun.isSyntheticCopy) { - fun.containingClass match { - case td: ScClass if td.isCase => paramFromConstructor(td) - case _ => None - } - } else if (fun.isSyntheticApply) { - getCompanionModule(fun.containingClass) match { - case Some(td: ScClass) if td.isCase => paramFromConstructor(td) - case _ => None - } - } else None - } + def parameterForSyntheticParameter(param: ScParameter): Option[ScParameter] = + param.parentOfType(classOf[ScFunction]).flatMap { + case fun if fun.isSyntheticCopy => Option(fun.containingClass) + case fun if fun.isSyntheticApply => getCompanionModule(fun.containingClass) + }.collect { + case td: ScClass if td.isCase => td + }.flatMap(_.constructor).toSeq + .flatMap(_.parameters) + .find(_.name == param.name) // TODO multiple parameter sections. def isReadonly(e: PsiElement): Boolean = { e match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScAccessModifierImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScAccessModifierImpl.scala index 45f2fbd0345..69fc6f20de8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScAccessModifierImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScAccessModifierImpl.scala @@ -7,7 +7,6 @@ package base import com.intellij.lang.ASTNode import com.intellij.openapi.util.TextRange import com.intellij.psi._ -import com.intellij.psi.util.PsiTreeUtil.getParentOfType import com.intellij.util.IncorrectOperationException import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes._ @@ -16,6 +15,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.ScAccessModifier import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScPackaging import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTypeDefinition} +import org.jetbrains.plugins.scala.lang.psi.impl.ScPackageImpl.ofPackageObject import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createIdentifier import org.jetbrains.plugins.scala.lang.psi.stubs.ScAccessModifierStub @@ -38,14 +38,13 @@ class ScAccessModifierImpl private(stub: ScAccessModifierStub, node: ASTNode) byStubOrPsi(_.idText)(Option(getNode.findChildByType(tIDENTIFIER)).map(_.getPsi.getText)) def scope: PsiNamedElement = - Option(getReference) map { - _.resolve - } collect { - case o: ScObject if o.isPackageObject => ScPackageImpl.ofPackageObject(o) - case named: PsiNamedElement => named - } getOrElse { - getParentOfType(this, classOf[ScTypeDefinition], true) - } + Option(getReference) + .flatMap(reference => Option(reference.resolve)) + .collect { + case o: ScObject if o.isPackageObject => ofPackageObject(o) + case named: PsiNamedElement => named + }.orElse(this.parentOfType(classOf[ScTypeDefinition])) + .orNull //return ref only for {private|protected}[Id], not for private[this] def isProtected: Boolean = byStubOrPsi(_.isProtected)(getNode.hasChildOfType(kPROTECTED)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/RenameSuperMembersUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/RenameSuperMembersUtil.scala index 1c15feb04d3..7b73e6cc114 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/RenameSuperMembersUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/RenameSuperMembersUtil.scala @@ -11,9 +11,9 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.Key import com.intellij.psi._ import com.intellij.psi.search.PsiElementProcessor -import com.intellij.psi.util.PsiTreeUtil import com.intellij.refactoring.rename.RenamePsiElementProcessor import org.jetbrains.annotations.NotNull +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScDeclaration, ScTypeAlias} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScNamedElement @@ -87,7 +87,8 @@ object RenameSuperMembersUtil { return } val allElements = superMembers :+ element - val classes: Seq[PsiClass] = allElements.map(PsiTreeUtil.getParentOfType(_, classOf[PsiClass], false)) + val classes = allElements.flatMap(_.parentOfType(classOf[PsiClass], strict = false)) + val oneSuperClass = superMembers.size == 1 val additional = if (oneSuperClass) Nil else Seq((renameAllMarker(element), null)) //option for rename all val classesToNamed = additional ++: Map(classes.zip(allElements): _*) @@ -97,7 +98,7 @@ object RenameSuperMembersUtil { def execute(aClass: PsiClass): Boolean = { if (aClass != renameAllMarker(aClass)) action(classesToNamed(aClass)) else { - val mainOne = classesToNamed(classes(0)) + val mainOne = classesToNamed(classes.head) superMembersToRename.clear() superMembersToRename ++= classes.dropRight(1).drop(1).map(classesToNamed) action(mainOne) @@ -107,7 +108,7 @@ object RenameSuperMembersUtil { } if (ApplicationManager.getApplication.isUnitTestMode) { - processor.execute(if (oneSuperClass) classes(0) else renameAllMarker(element)) //in unit tests uses base member or all base members + processor.execute(if (oneSuperClass) classes.head else renameAllMarker(element)) //in unit tests uses base member or all base members return } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala index 96e8e54665a..8b8d3f560ec 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala @@ -22,7 +22,7 @@ import com.intellij.psi._ import com.intellij.psi.search.searches.ReferencesSearch import com.intellij.psi.search.{GlobalSearchScope, LocalSearchScope} import com.intellij.psi.util.PsiTreeUtil -import com.intellij.psi.util.PsiTreeUtil.{findElementOfClassAtRange, getParentOfType} +import com.intellij.psi.util.PsiTreeUtil.{findElementOfClassAtRange, getParentOfType, isAncestor} import com.intellij.refactoring.util.CommonRefactoringUtil import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes @@ -36,7 +36,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScFuncti import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.{ScExtendsBlock, ScTemplateBody, ScTemplateParents} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScEarlyDefinitions, ScTypeParametersOwner} -import org.jetbrains.plugins.scala.lang.psi.api.{ScControlFlowOwner, ScalaFile, ScalaRecursiveElementVisitor} +import org.jetbrains.plugins.scala.lang.psi.api.{ScalaFile, ScalaRecursiveElementVisitor} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ import org.jetbrains.plugins.scala.lang.psi.stubs.util.ScalaStubsUtil import org.jetbrains.plugins.scala.lang.psi.types.ScType @@ -1099,7 +1099,7 @@ object ScalaRefactoringUtil { case _ => false } - if (funDef != null && PsiTreeUtil.isAncestor(candidate, funDef, true) && oneExprBody(funDef)) + if (funDef != null && isAncestor(candidate, funDef, true) && oneExprBody(funDef)) funDef.body.get else if (isCaseClausesBlock) container(candidate.getContext, file) else candidate @@ -1137,18 +1137,12 @@ object ScalaRefactoringUtil { case _ => ScalaBundle.message("cannot.extract.empty.message").toOption } - def hasOutsideUsages(elem: PsiElement): Boolean = { - val scope = new LocalSearchScope(PsiTreeUtil.getParentOfType(elem, classOf[ScControlFlowOwner], true)) - val refs = ReferencesSearch.search(elem, scope).findAll() - import scala.collection.JavaConverters.collectionAsScalaIterableConverter - for { - ref <- refs.asScala - if !elements.exists(PsiTreeUtil.isAncestor(_, ref.getElement, false)) - } { - return true - } - false - } + def hasOutsideUsages(elem: PsiElement): Boolean = + !elem.parentOfType(classOf[ScConstructorOwner]) + .map(new LocalSearchScope(_)).toSeq + .flatMap(scope => ReferencesSearch.search(elem, scope).findAll().asScala) + .map(_.getElement) + .forall(referenced => elements.exists(isAncestor(_, referenced, false))) val messages = elements.flatMap(errors).distinct if (messages.nonEmpty) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaOIUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaOIUtil.scala index 9287f0bffec..3cabeb30b82 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaOIUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/overrideImplement/ScalaOIUtil.scala @@ -71,9 +71,9 @@ object ScalaOIUtil { def invokeOverrideImplement(project: Project, editor: Editor, file: PsiFile, isImplement: Boolean, methodName: String = null) { - val elem = file.findElementAt(editor.getCaretModel.getOffset - 1) - val clazz = PsiTreeUtil.getParentOfType(elem, classOf[ScTemplateDefinition], /*strict = */false) - if (clazz == null) return + val clazz = file.findElementAt(editor.getCaretModel.getOffset - 1) + .parentOfType(classOf[ScTemplateDefinition], strict = false) + .getOrElse(return) val classMembers = if (isImplement) getMembersToImplement(clazz, withSelfType = true) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestFramework.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestFramework.scala index de3eb9aa64e..192cb256eda 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestFramework.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/testingSupport/test/AbstractTestFramework.scala @@ -6,11 +6,12 @@ import javax.swing.Icon import com.intellij.ide.fileTemplates.FileTemplateDescriptor import com.intellij.lang.Language import com.intellij.openapi.module.Module -import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiClass, PsiElement, PsiMethod} import com.intellij.testIntegration.JavaTestFramework +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.icons.Icons -import org.jetbrains.plugins.scala.lang.psi.{ElementScope, ScalaPsiUtil} +import org.jetbrains.plugins.scala.lang.psi.ElementScope +import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil.isInheritorDeep import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition import org.jetbrains.plugins.scala.lang.psi.light.PsiClassWrapper import org.jetbrains.sbt.project.modifier.SimpleBuildFileModifier @@ -40,20 +41,19 @@ abstract class AbstractTestFramework extends JavaTestFramework { def findSetUpMethod(clazz: PsiClass): PsiMethod = null def isTestClass(clazz: PsiClass, canBePotential: Boolean): Boolean = { - val parent: ScTypeDefinition = PsiTreeUtil.getParentOfType(clazz match { + val newClazz = clazz match { case wrapper: PsiClassWrapper => wrapper.definition case _ => clazz - }, classOf[ScTypeDefinition], false) - if (parent == null) return false + } + + val parent = newClazz.parentOfType(classOf[ScTypeDefinition], strict = false) + .getOrElse(return false) val elementScope = ElementScope(clazz.getProject) elementScope.getCachedClass(getMarkerClassFQName).isDefined && - getSuitePaths.flatMap { - elementScope.getCachedClass - }.exists { - ScalaPsiUtil.isInheritorDeep(parent, _) - } + getSuitePaths.flatMap(elementScope.getCachedClass) + .exists(isInheritorDeep(parent, _)) } override def getLanguage: Language = ScalaLanguage.INSTANCE From ed22d82e54150afad66d0ee49ba31a0e73c0c7ee Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Tue, 31 Oct 2017 15:03:57 +0300 Subject: [PATCH 108/141] ScalaPsiUtil.getParentOfType methods should be eliminated --- .../intention/AddBracesIntention.scala | 8 +- .../intention/RemoveBracesIntention.scala | 7 +- .../plugins/scala/extensions/package.scala | 8 +- .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 24 +----- .../inline/ScalaInlineHandler.scala | 6 +- .../ScalaIntroduceFieldHandlerBase.scala | 31 ++++---- .../IntroduceExpressions.scala | 2 +- .../ScalaInplaceVariableIntroducer.scala | 75 +++++++++---------- .../inplace/ScalaInplaceRenameHandler.scala | 15 ++-- .../util/ScalaRefactoringUtil.scala | 35 +++------ .../scala/lang/resolve/ResolveUtils.scala | 8 +- ...ctIntroduceVariableValidatorTestBase.scala | 9 ++- 12 files changed, 102 insertions(+), 126 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/AddBracesIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/AddBracesIntention.scala index d4708b28125..19d4f48276e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/AddBracesIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/AddBracesIntention.scala @@ -7,7 +7,7 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.impl.source.codeStyle.CodeEditUtil import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunctionDefinition, ScPatternDefinition} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText @@ -34,13 +34,11 @@ class AddBracesIntention extends PsiElementBaseIntentionAction { } private def check(project: Project, editor: Editor, element: PsiElement): Option[() => Unit] = { - val containing = ScalaPsiUtil.getParentOfType(element, true, - classOf[ScPatternDefinition], classOf[ScIfStmt], classOf[ScFunctionDefinition], classOf[ScTryBlock], + val classes = Seq(classOf[ScPatternDefinition], classOf[ScIfStmt], classOf[ScFunctionDefinition], classOf[ScTryBlock], classOf[ScFinallyBlock], classOf[ScWhileStmt], classOf[ScDoStmt]) - def isAncestorOfElement(ancestor: PsiElement) = PsiTreeUtil.isContextAncestor(ancestor, element, false) - val expr: Option[ScExpression] = containing match { + val expr: Option[ScExpression] = element.parentOfType(classes).flatMap { case ScPatternDefinition.expr(e) if isAncestorOfElement(e) => Some(e) case ifStmt: ScIfStmt => ifStmt.thenBranch.filter(isAncestorOfElement).orElse(ifStmt.elseBranch.filter(isAncestorOfElement)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/RemoveBracesIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/RemoveBracesIntention.scala index 16616f94cb2..cb2bc5d3bb2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/RemoveBracesIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/RemoveBracesIntention.scala @@ -9,8 +9,8 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil import com.intellij.psi.tree.TokenSet import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.codeInsight.intention.IntentionUtil.CommentsAroundElement +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScCaseClause import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunctionDefinition, ScPatternDefinition} @@ -38,13 +38,12 @@ class RemoveBracesIntention extends PsiElementBaseIntentionAction { } private def check(project: Project, editor: Editor, element: PsiElement): Option[() => Unit] = { - val containing = ScalaPsiUtil.getParentOfType(element, true, - classOf[ScPatternDefinition], classOf[ScIfStmt], classOf[ScFunctionDefinition], classOf[ScTryBlock], + val classes = Seq(classOf[ScPatternDefinition], classOf[ScIfStmt], classOf[ScFunctionDefinition], classOf[ScTryBlock], classOf[ScFinallyBlock], classOf[ScWhileStmt], classOf[ScDoStmt], classOf[ScCaseClause]) def isAncestorOfElement(ancestor: PsiElement) = PsiTreeUtil.isContextAncestor(ancestor, element, false) - val expr: Option[ScExpression] = containing match { + val expr: Option[ScExpression] = element.parentOfType(classes).flatMap { case ScPatternDefinition.expr(e) if isAncestorOfElement(e) => Some(e) case ifStmt: ScIfStmt => ifStmt.thenBranch.filter(isAncestorOfElement).orElse(ifStmt.elseBranch.filter(isAncestorOfElement)) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala index e4accd9836e..0f5c1e0e4bc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/extensions/package.scala @@ -20,7 +20,7 @@ import com.intellij.psi.impl.source.{PostprocessReformattingAspect, PsiFileImpl} import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.stubs.{IStubElementType, StubElement} import com.intellij.psi.tree.{IElementType, TokenSet} -import com.intellij.psi.util.PsiTreeUtil.{getParentOfType, isAncestor} +import com.intellij.psi.util.PsiTreeUtil.{getNonStrictParentOfType, getParentOfType, isAncestor} import com.intellij.util.{ArrayFactory, Processor} import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.scala.extensions.implementation.iterator._ @@ -270,6 +270,12 @@ package object extensions { def parentOfType[E <: PsiElement](clazz: Class[E], strict: Boolean = true): Option[E] = Option(getParentOfType(element, clazz, strict)) + def parentOfType(classes: Seq[Class[_ <: PsiElement]]): Option[PsiElement] = + Option(getParentOfType(element, classes: _*)) + + def nonStrictParentOfType(classes: Seq[Class[_ <: PsiElement]]): Option[PsiElement] = + Option(getNonStrictParentOfType(element, classes: _*)) + def isAncestorOf(otherElement: PsiElement): Boolean = isAncestor(element, otherElement, true) def parents: Iterator[PsiElement] = new ParentsIterator(element) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index de8770fb826..d7a2cce6dd3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -1040,28 +1040,8 @@ object ScalaPsiUtil { /** * For one classOf use PsiTreeUtil.getParenteOfType instead */ - def getParentOfType(element: PsiElement, clazz: Class[_ <: PsiElement]): PsiElement = { - getParentOfType(element, false, clazz) - } - - /** - * For one classOf use PsiTreeUtil.getParenteOfType instead - */ - def getParentOfType(element: PsiElement, classes: Class[_ <: PsiElement]*): PsiElement = { - getParentOfType(element, false, classes: _*) - } - - /** - * For one classOf use PsiTreeUtil.getParenteOfType instead - */ - def getParentOfType(element: PsiElement, strict: Boolean, classes: Class[_ <: PsiElement]*): PsiElement = { - var el: PsiElement = if (!strict) element else { - if (element == null) return null - element.getParent - } - while (el != null && !classes.exists(_.isInstance(el))) el = el.getParent - el - } + def getParentOfType(element: PsiElement, clazz: Class[_ <: PsiElement]): PsiElement = + PsiTreeUtil.getParentOfType(element, clazz, false) @tailrec def getParentWithProperty(element: PsiElement, strict: Boolean, property: PsiElement => Boolean): Option[PsiElement] = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala index f88c325dfc5..b0374b69832 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/inline/ScalaInlineHandler.scala @@ -151,8 +151,10 @@ class ScalaInlineHandler extends InlineHandler { } if (refs.isEmpty) showErrorHint(ScalaBundle.message("cannot.inline.never.used"), inlineTitleSuffix) - else if (!psiNamedElement.isInstanceOf[ScTypeAliasDefinition] && refs.exists(ref => - ScalaPsiUtil.getParentOfType(ref.getElement, classOf[ScStableCodeReferenceElement], classOf[ScStableReferenceElementPattern]) != null)) + else if (!psiNamedElement.isInstanceOf[ScTypeAliasDefinition] && + refs.map(_.getElement) + .flatMap(_.nonStrictParentOfType(Seq(classOf[ScStableCodeReferenceElement], classOf[ScStableReferenceElementPattern]))) + .nonEmpty) showErrorHint(ScalaBundle.message("cannot.inline.stable.reference"), inlineTitleSuffix) else if (!ApplicationManager.getApplication.isUnitTestMode) { val occurences = refs.size match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceField/ScalaIntroduceFieldHandlerBase.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceField/ScalaIntroduceFieldHandlerBase.scala index 188350fb35c..3d6ecd55033 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceField/ScalaIntroduceFieldHandlerBase.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceField/ScalaIntroduceFieldHandlerBase.scala @@ -18,7 +18,6 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScExtendsBloc import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaRefactoringUtil import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaRefactoringUtil._ /** @@ -59,11 +58,10 @@ abstract class ScalaIntroduceFieldHandlerBase extends ScalaRefactoringActionHand } protected def anchorForNewDeclaration(expr: ScExpression, occurrences: Seq[TextRange], aClass: ScTemplateDefinition): PsiElement = { - val commonParent = ScalaRefactoringUtil.commonParent(aClass.getContainingFile, occurrences) val firstOccOffset = occurrences.map(_.getStartOffset).min - val anchor = ScalaRefactoringUtil.statementsAndMembersInClass(aClass).find(_.getTextRange.getEndOffset >= firstOccOffset) + val anchor = statementsAndMembersInClass(aClass).find(_.getTextRange.getEndOffset >= firstOccOffset) anchor.getOrElse { - if (PsiTreeUtil.isAncestor(aClass.extendsBlock.templateBody.orNull, commonParent, false)) null + if (PsiTreeUtil.isAncestor(aClass.extendsBlock.templateBody.orNull, commonParent(aClass.getContainingFile, occurrences), false)) null else { aClass.extendsBlock match { case ScExtendsBlock.EarlyDefinitions(earlyDef) => earlyDef.lastChild.orNull @@ -77,18 +75,20 @@ abstract class ScalaIntroduceFieldHandlerBase extends ScalaRefactoringActionHand object ScalaIntroduceFieldHandlerBase { def canBeInitializedInDeclaration(expr: ScExpression, aClass: ScTemplateDefinition): Boolean = { - val stmtsAndMmbrs = ScalaRefactoringUtil.statementsAndMembersInClass(aClass) + val stmtsAndMmbrs = statementsAndMembersInClass(aClass) expr.withParentsInFile .find(stmtsAndMmbrs.contains(_)) - .forall(ScalaRefactoringUtil.checkForwardReferences(expr, _)) + .forall(checkForwardReferences(expr, _)) } def canBeInitInLocalScope[T <: PsiElement](ifc: IntroduceFieldContext[T], replaceAll: Boolean): Boolean = { val occurrences = if (replaceAll) ifc.occurrences else Seq(ifc.element.getTextRange) - val parExpr: ScExpression = ScalaRefactoringUtil.findParentExpr(ScalaRefactoringUtil.commonParent(ifc.file, occurrences)) - val container = ScalaRefactoringUtil.container(parExpr, ifc.file) - val stmtsAndMmbrs = ScalaRefactoringUtil.statementsAndMembersInClass(ifc.aClass) - val containerIsLocal = container.withParentsInFile.exists(stmtsAndMmbrs.contains(_)) + val parExpr: ScExpression = findParentExpr(commonParent(ifc.file, occurrences)) + val stmtsAndMmbrs = statementsAndMembersInClass(ifc.aClass) + val containerIsLocal = container(parExpr).getOrElse(ifc.file) + .withParentsInFile + .exists(stmtsAndMmbrs.contains(_)) + if (!containerIsLocal) false else { ifc.element match { @@ -100,18 +100,17 @@ object ScalaIntroduceFieldHandlerBase { def anchorForInitializer(occurrences: Seq[TextRange], file: PsiFile): Option[PsiElement] = { var firstRange = occurrences.head - val commonParent = ScalaRefactoringUtil.commonParent(file, occurrences) - val parExpr = ScalaRefactoringUtil.findParentExpr(commonParent) + val parExpr = findParentExpr(commonParent(file, occurrences)) if (parExpr == null) return None - val container: PsiElement = ScalaRefactoringUtil.container(parExpr, file) - val needBraces = !parExpr.isInstanceOf[ScBlock] && ScalaRefactoringUtil.needBraces(parExpr, ScalaRefactoringUtil.nextParent(parExpr, file)) + + val isNotBlock = !parExpr.isInstanceOf[ScBlock] val parent = - if (needBraces) { + if (isNotBlock && needBraces(parExpr, nextParent(parExpr, file))) { firstRange = firstRange.shiftRight(1) parExpr.replaceExpression(createExpressionFromText(s"{${parExpr.getText}}")(file.getManager), removeParenthesis = false) - } else container + } else container(parExpr).getOrElse(file) if (parent == null) None else parent.getChildren.find(_.getTextRange.contains(firstRange)) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceExpressions.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceExpressions.scala index 93bcc088d02..a2a820a43d8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceExpressions.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceExpressions.scala @@ -350,7 +350,7 @@ object IntroduceExpressions { case _ => } replaced - } else container(commonParent, file) + } else container(commonParent).getOrElse(file) } val anchor = parent.getChildren.find(_.getTextRange.contains(firstRange)).getOrElse(parent.getLastChild) if (anchor != null) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/ScalaInplaceVariableIntroducer.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/ScalaInplaceVariableIntroducer.scala index bc0ddc81830..3a3ec99a3e4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/ScalaInplaceVariableIntroducer.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/ScalaInplaceVariableIntroducer.scala @@ -26,6 +26,7 @@ import com.intellij.psi.search.{LocalSearchScope, SearchScope} import com.intellij.psi.util.PsiTreeUtil import com.intellij.refactoring.introduce.inplace.InplaceVariableIntroducer import com.intellij.ui.NonFocusableCheckBox +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScTypedPattern import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScEnumerator, ScExpression} @@ -57,15 +58,17 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, implicit def projectContext: ProjectContext = project + import ScalaInplaceVariableIntroducer._ + private var myVarCheckbox: JCheckBox = _ private var mySpecifyTypeChb: JCheckBox = _ private var myDeclarationStartOffset: Int = 0 - private val newDeclaration = ScalaPsiUtil.getParentOfType(namedElement, classOf[ScEnumerator], classOf[ScDeclaredElementsHolder]) + private val newDeclaration = findDeclaration(namedElement) private var myCheckIdentifierListener: Option[DocumentListener] = None private val myFile: PsiFile = namedElement.getContainingFile private val myBalloonPanel: JPanel = new JPanel() private var nameIsValid: Boolean = true - private val isEnumerator: Boolean = newDeclaration.isInstanceOf[ScEnumerator] + private val isEnumerator: Boolean = newDeclaration.exists(_.isInstanceOf[ScEnumerator]) private val initialName = ScalaNamesUtil.scalaName(namedElement) private val myLabel = new JLabel() @@ -74,10 +77,9 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, private val myChbPanel = new JPanel() private val typePanel = new JPanel() - private val needTypeDefault: Boolean = - ScalaInplaceVariableIntroducer.needsTypeAnnotation(namedElement, expr, forceInferType) + private val needTypeDefault: Boolean = needsTypeAnnotation(namedElement, expr, forceInferType) - setDeclaration(newDeclaration) + newDeclaration.foreach(setDeclaration) private def checkIdentifierListener(): DocumentListener = new DocumentListener { override def documentChanged(e: DocumentEvent): Unit = { @@ -87,10 +89,11 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, else { val input = myCaretRangeMarker.getDocument.getText(range) val numberOfSpaces = input.lastIndexOf(' ') + 1 - val declaration = findDeclaration(range.getStartOffset + numberOfSpaces) - val named: Option[ScNamedElement] = namedElement(declaration) + val maybeDeclaration = findDeclarationAt(range.getStartOffset + numberOfSpaces) + + val named: Option[ScNamedElement] = namedElement(maybeDeclaration) if (named.isDefined) { - setDeclaration(declaration) + maybeDeclaration.foreach(setDeclaration) if (nameIsValid != (named.isDefined && isIdentifier(input.trim, myFile.getLanguage))) { nameIsValid = !nameIsValid } @@ -103,19 +106,17 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, } } - private def namedElement(declaration: PsiElement): Option[ScNamedElement] = declaration match { + private def namedElement(maybeDeclaration: Option[PsiElement]): Option[ScNamedElement] = maybeDeclaration.flatMap { case value: ScValue => value.declaredElements.headOption case variable: ScVariable => variable.declaredElements.headOption case enumerator: ScEnumerator => enumerator.pattern.bindings.headOption case _ => None } - private def findDeclaration(offset: Int): PsiElement = { - val elem = myFile.findElementAt(offset) - ScalaPsiUtil.getParentOfType(elem, classOf[ScEnumerator], classOf[ScDeclaredElementsHolder]) - } + private def findDeclarationAt(offset: Int): Option[PsiElement] = + findDeclaration(myFile.findElementAt(offset)) - private def getDeclaration: PsiElement = findDeclaration(myDeclarationStartOffset) + private def getDeclaration: Option[PsiElement] = findDeclarationAt(myDeclarationStartOffset) private def setDeclaration(declaration: PsiElement): Unit = { myDeclarationStartOffset = declaration.getTextRange.getStartOffset @@ -138,20 +139,15 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, myVarCheckbox.addActionListener((e: ActionEvent) => { val writeAction = new WriteCommandAction[Unit](myProject, getCommandName, getCommandName) { - private def changeValOrVar(asVar: Boolean, declaration: PsiElement): Unit = { - val replacement = - declaration match { - case value: ScValue if asVar => - createVarFromValDeclaration(value) - case variable: ScVariableDefinition if !asVar => - createValFromVarDefinition(variable) - case _ => declaration - } - if (replacement != declaration) setDeclaration(declaration.replace(replacement)) - } - protected def run(result: Result[Unit]): Unit = { - changeValOrVar(myVarCheckbox.isSelected, getDeclaration) + val asVar = myVarCheckbox.isSelected + getDeclaration.collect { + case value: ScValue if asVar => (value, createVarFromValDeclaration(value)) + case variable: ScVariableDefinition if !asVar => (variable, createValFromVarDefinition(variable)) + }.map { + case (declaration, replacement) => declaration.replace(replacement) + }.foreach(setDeclaration) + commitDocument() } } @@ -189,9 +185,8 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, val writeAction = new WriteCommandAction[Unit](myProject, getCommandName, getCommandName) { private def addTypeAnnotation(selectedType: ScType): Unit = { - val declaration = getDeclaration - declaration match { - case _: ScDeclaredElementsHolder | _: ScEnumerator => + getDeclaration.foreach { + case declaration@(_: ScDeclaredElementsHolder | _: ScEnumerator) => val declarationCopy = declaration.copy.asInstanceOf[ScalaPsiElement] val fakeDeclaration = createDeclaration(selectedType, "x", isVariable = false, "", isPresentableText = false) val first = fakeDeclaration.findFirstChildByType(ScalaTokenTypes.tCOLON) @@ -199,7 +194,8 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, val assign = declarationCopy.findFirstChildByType(ScalaTokenTypes.tASSIGN) declarationCopy.addRangeAfter(first, last, assign) assign.delete() - val replaced = getDeclaration.replace(declarationCopy) + + val replaced = declaration.replace(declarationCopy) ScalaPsiUtil.adjustTypes(replaced) setDeclaration(replaced) commitDocument() @@ -208,11 +204,11 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, } private def removeTypeAnnotation(): Unit = { - getDeclaration match { + getDeclaration.foreach { case holder: ScDeclaredElementsHolder => val colon = holder.findFirstChildByType(ScalaTokenTypes.tCOLON) val assign = holder.findFirstChildByType(ScalaTokenTypes.tASSIGN) - implicit val manager = myFile.getManager + implicit val manager: PsiManager = myFile.getManager val whiteSpace = createExpressionFromText("1 + 1").findElementAt(1) val newWhiteSpace = holder.addBefore(whiteSpace, assign) holder.getNode.removeRange(colon.getNode, newWhiteSpace.getNode) @@ -330,11 +326,11 @@ class ScalaInplaceVariableIntroducer(expr: ScExpression, else { myEditor.getCaretModel.moveToOffset(myExprMarker.getEndOffset) } - } else if (getDeclaration != null) { - val declaration = getDeclaration - myEditor.getCaretModel.moveToOffset(declaration.getTextRange.getEndOffset) - } - } else if (getDeclaration != null && !UndoManager.getInstance(myProject).isUndoInProgress) { + } else + getDeclaration.foreach { declaration => + myEditor.getCaretModel.moveToOffset(declaration.getTextRange.getEndOffset) + } + } else if (getDeclaration.isDefined && !UndoManager.getInstance(myProject).isUndoInProgress) { val revertInfo = myEditor.getUserData(ScalaIntroduceVariableHandler.REVERT_INFO) if (revertInfo != null) { extensions.inWriteAction { @@ -410,4 +406,7 @@ object ScalaInplaceVariableIntroducer { else ScalaTypeAnnotationSettings(anchor.getProject).isTypeAnnotationRequiredFor( Declaration(Visibility.Default), Location(anchor), Some(Implementation.Expression(expression))) } else true + + private def findDeclaration(element: PsiElement) = + element.nonStrictParentOfType(Seq(classOf[ScEnumerator], classOf[ScDeclaredElementsHolder])) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala index 0e0ee094af6..0bd9ef0e983 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/inplace/ScalaInplaceRenameHandler.scala @@ -6,12 +6,11 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.project.Project import com.intellij.openapi.ui.popup.JBPopupFactory -import com.intellij.psi.util.PsiUtilBase +import com.intellij.psi.util.PsiUtilBase.getElementAtCaret import com.intellij.psi.{PsiElement, PsiNamedElement} import com.intellij.refactoring.rename.inplace.InplaceRefactoring import com.intellij.refactoring.rename.{PsiElementRenameHandler, RenamePsiElementProcessor} -import org.jetbrains.plugins.scala.extensions.{Both, callbackInTransaction} -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil +import org.jetbrains.plugins.scala.extensions.{Both, PsiElementExt, callbackInTransaction} import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScNewTemplateDefinition import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction @@ -85,13 +84,13 @@ trait ScalaInplaceRenameHandler { showSubstitutePopup(title, positive, ScalaRenameUtil.findSubstituteElement(elementToRename)) } - val atCaret = PsiUtilBase.getElementAtCaret(editor) - val selected = ScalaPsiUtil.getParentOfType(atCaret, classOf[ScReferenceElement], classOf[ScNamedElement]) - val nameId = selected match { + val selected = getElementAtCaret(editor) + .nonStrictParentOfType(Seq(classOf[ScReferenceElement], classOf[ScNamedElement])) + val nameId = selected.collect { case ref: ScReferenceElement => ref.nameId case named: ScNamedElement => named.nameId - case _ => null - } + }.orNull + elementToRename match { case Both(`selected`, fun: ScFunction) if Seq("apply", "unapply", "unapplySeq").contains(fun.name) || fun.isConstructor => specialMethodPopup(fun) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala index 8b8d3f560ec..6254bf6fc46 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala @@ -1079,32 +1079,21 @@ object ScalaRefactoringUtil { } @tailrec - def container(element: PsiElement, file: PsiFile): PsiElement = { - def oneExprBody(fun: ScFunctionDefinition): Boolean = fun.body match { - case Some(_: ScBlock) => false - case Some(_: ScNewTemplateDefinition) => false - case Some(_) => true - case None => false + def container(element: PsiElement): Option[PsiElement] = if (element != null) { + val maybeFunction = element.parentOfType(classOf[ScFunctionDefinition]) + val maybeBody = maybeFunction.flatMap(_.body).filter { + case _: ScBlock | + _: ScNewTemplateDefinition => false + case _ => true } - if (element == null) file - else { - val candidate = ScalaPsiUtil.getParentOfType(element, false, classOf[ScalaFile], classOf[ScBlock], - classOf[ScTemplateBody], classOf[ScCaseClause], classOf[ScEarlyDefinitions]) - - val funDef = getParentOfType(element, classOf[ScFunctionDefinition]) - - val isCaseClausesBlock = candidate match { - case b: ScBlock if b.hasCaseClauses => true - case _ => false - } - - if (funDef != null && isAncestor(candidate, funDef, true) && oneExprBody(funDef)) - funDef.body.get - else if (isCaseClausesBlock) container(candidate.getContext, file) - else candidate + val classes = Seq(classOf[ScalaFile], classOf[ScBlock], classOf[ScTemplateBody], classOf[ScCaseClause], classOf[ScEarlyDefinitions]) + element.nonStrictParentOfType(classes) match { + case Some(candidate) if maybeBody.isDefined && candidate.isAncestorOf(maybeFunction.get) => maybeBody + case Some(block: ScBlock) if block.hasCaseClauses => container(block.getContext) + case maybeCandidate => maybeCandidate } - } + } else None def inSuperConstructor(element: PsiElement, aClass: ScTemplateDefinition): Boolean = { aClass.extendsBlock.templateParents match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ResolveUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ResolveUtils.scala index 2397adaf1c3..d6f99c9ddb6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ResolveUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/ResolveUtils.scala @@ -60,11 +60,11 @@ object ResolveUtils { (kinds contains OBJECT) && isStaticCorrect(c) } case patt: ScBindingPattern => - val parent = getParentOfType(patt, classOf[ScVariable], classOf[ScValue]) - parent match { - case _: ScVariable => kinds contains VAR - case _ => kinds contains VAL + val value = patt.nonStrictParentOfType(Seq(classOf[ScVariable], classOf[ScValue])) match { + case Some(_: ScVariable) => VAR + case _ => VAL } + kinds.contains(value) case patt: ScFieldId => if (patt.getParent /*list of ids*/ .getParent.isInstanceOf[ScVariable]) kinds contains VAR else kinds contains VAL diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceVariable/AbstractIntroduceVariableValidatorTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceVariable/AbstractIntroduceVariableValidatorTestBase.scala index b141d18c05d..a3d89791169 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceVariable/AbstractIntroduceVariableValidatorTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/refactoring/introduceVariable/AbstractIntroduceVariableValidatorTestBase.scala @@ -5,8 +5,8 @@ import com.intellij.openapi.fileEditor.{FileEditorManager, OpenFileDescriptor} import com.intellij.openapi.project.Project import com.intellij.psi.util.PsiTreeUtil.{findCommonParent, getParentOfType} import com.intellij.psi.{PsiElement, PsiFile} +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.actions.ActionTestBase -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScBlock, ScExpression} @@ -96,7 +96,12 @@ object AbstractIntroduceVariableValidatorTestBase { val bound = file.findElementAt(selectionModel.getSelectionEnd - 1) val commonParentOne = findCommonParent(origin, bound) - ScalaPsiUtil.getParentOfType(commonParentOne, length == 1, classOf[ScalaFile], classOf[ScBlock], classOf[ScTemplateBody]) + + val classes = Seq(classOf[ScalaFile], classOf[ScBlock], classOf[ScTemplateBody]) + (length match { + case 1 => commonParentOne.parentOfType(classes) + case _ => commonParentOne.nonStrictParentOfType(classes) + }).orNull } private[this] def getVariableValidator(expression: ScExpression, file: PsiFile) From e6513939b86bac648bcb6865d51e82b17bf8bdec Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 17:39:50 +0300 Subject: [PATCH 109/141] use TC persistent folder for build data if available --- build.sbt | 6 +++--- project/Common.scala | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index a7450b5c442..8f9864bd4c1 100644 --- a/build.sbt +++ b/build.sbt @@ -15,11 +15,11 @@ resolvers in ThisBuild += Resolver.sonatypeRepo("snapshots") ideaBuild in ThisBuild := Versions.ideaVersion -ideaDownloadDirectory in ThisBuild := Path.userHome / ".ScalaPluginIC" / "sdk" +ideaDownloadDirectory in ThisBuild := homePrefix / ".ScalaPluginIC" / "sdk" -testConfigDir in ThisBuild := Path.userHome / ".ScalaPluginIC" / "test-config" +testConfigDir in ThisBuild := homePrefix / ".ScalaPluginIC" / "test-config" -testSystemDir in ThisBuild := Path.userHome / ".ScalaPluginIC" / "test-system" +testSystemDir in ThisBuild := homePrefix / ".ScalaPluginIC" / "test-system" onLoad in Global := ((s: State) => { "updateIdea" :: s}) compose (onLoad in Global).value diff --git a/project/Common.scala b/project/Common.scala index 9d83f477e83..ab37f494aaa 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -44,8 +44,10 @@ object Common { val scalacTests: String = cat("ScalacTests") } + lazy val homePrefix = sys.props.get("tc.idea.prefix").map(new File(_)).getOrElse(Path.userHome) + def ivyHomeDir: File = - Option(System.getProperty("sbt.ivy.home")).fold(Path.userHome / ".ivy2")(file) + Option(System.getProperty("sbt.ivy.home")).fold(homePrefix / ".ivy2")(file) def commonTestSettings(packagedPluginDir: SettingKey[File]): Seq[Setting[_]] = Seq( fork in Test := true, From b4b7015f762558e7099f0c508379d68c16301d3f Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Tue, 31 Oct 2017 15:29:55 +0300 Subject: [PATCH 110/141] ScalaPsiUtil.getParentOfType methods completely eliminated --- .../scala/annotator/ScalaAnnotator.scala | 2 +- .../findUsages/TypeAliasUsagesSearcher.scala | 9 +++--- .../highlighter/AnnotatorHighlighter.scala | 23 ++++++-------- .../completion/filters/other/TypeFilter.scala | 8 +++-- .../templates/selector/AncestorSelector.scala | 6 ++-- .../plugins/scala/lang/psi/ScalaPsiUtil.scala | 6 ---- .../psi/api/base/types/ScTypeElement.scala | 17 ++++------- .../ScStableCodeReferenceElementImpl.scala | 2 +- .../base/types/ScTypeProjectionImpl.scala | 2 +- .../impl/expr/ScReferenceExpressionImpl.scala | 2 +- .../util/ScalaRefactoringUtil.scala | 20 ++++++------- ...MavenDependencyCompletionContributor.scala | 30 +++++++++---------- .../meta/intellij/MetaExpansionsManager.scala | 12 ++++---- .../annotations/MetaAnnotationTestBase.scala | 4 +-- 14 files changed, 62 insertions(+), 81 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index 5c99765a040..fc14ab751d6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -1048,7 +1048,7 @@ abstract class ScalaAnnotator extends Annotator private def checkUnboundUnderscore(under: ScUnderscoreSection, holder: AnnotationHolder) { if (under.getText == "_") { - ScalaPsiUtil.getParentOfType(under, classOf[ScVariableDefinition]) match { + under.parentOfType(classOf[ScVariableDefinition], strict = false).foreach { case varDef @ ScVariableDefinition.expr(_) if varDef.expr.contains(under) => if (varDef.containingClass == null) { val error = ScalaBundle.message("local.variables.must.be.initialized") diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/TypeAliasUsagesSearcher.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/TypeAliasUsagesSearcher.scala index 96fa172f79d..7e9c0bc1c20 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/TypeAliasUsagesSearcher.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/TypeAliasUsagesSearcher.scala @@ -9,7 +9,7 @@ import com.intellij.psi.search.searches.ReferencesSearch import com.intellij.psi.util.PsiTreeUtil import com.intellij.util.Processor import org.jetbrains.annotations.{NotNull, Nullable} -import org.jetbrains.plugins.scala.extensions.inReadAction +import org.jetbrains.plugins.scala.extensions.{PsiElementExt, inReadAction} import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.base.{ScConstructor, ScReferenceElement} import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAliasDefinition @@ -55,12 +55,11 @@ class TypeAliasUsagesSearcher extends QueryExecutorBase[PsiReference, References private class MyProcessor(myTarget: PsiElement, @Nullable prefix: String, mySession: SearchSession) extends RequestResultProcessor(myTarget, prefix) { def processTextOccurrence(element: PsiElement, offsetInElement: Int, consumer: Processor[PsiReference]): Boolean = inReadAction { - ScalaPsiUtil.getParentOfType(element, classOf[ScConstructor]) match { - case cons: ScConstructor if PsiTreeUtil.isAncestor(cons.typeElement, element, false) => + element.parentOfType(classOf[ScConstructor], strict = false) match { + case Some(cons) if PsiTreeUtil.isAncestor(cons.typeElement, element, false) => element match { case resRef: ScReferenceElement => resRef.bind().flatMap(_.parentElement) match { - case Some(`myTarget`) => - consumer.process(resRef) + case Some(`myTarget`) => consumer.process(resRef) case _ => true } case _ => true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/AnnotatorHighlighter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/AnnotatorHighlighter.scala index 66430ddc9c8..65375feef59 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/AnnotatorHighlighter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/AnnotatorHighlighter.scala @@ -1,14 +1,13 @@ package org.jetbrains.plugins.scala package highlighter -import _root_.org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScEarlyDefinitions, ScModifierListOwner} import com.intellij.internal.statistic.UsageTrigger import com.intellij.lang.annotation.AnnotationHolder import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.psi._ -import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes +import org.jetbrains.plugins.scala.lang.psi.ScalaStubBasedElementImpl import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.api.base.{ScConstructor, ScReferenceElement, ScStableCodeReferenceElement} import org.jetbrains.plugins.scala.lang.psi.api.expr._ @@ -17,10 +16,11 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportExpr import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScMember, ScObject, ScTrait} +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScEarlyDefinitions, ScModifierListOwner} import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt, ScalaType} -import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiUtil, ScalaStubBasedElementImpl} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil +import org.jetbrains.plugins.scala.project.ProjectContext import org.jetbrains.plugins.scala.settings.ScalaProjectSettings /** @@ -47,7 +47,7 @@ object AnnotatorHighlighter { } def highlightReferenceElement(refElement: ScReferenceElement, holder: AnnotationHolder) { - implicit val project = refElement.projectContext + implicit val project: ProjectContext = refElement.projectContext def annotateCollectionByType(resolvedType: ScType) { if (ScalaNamesUtil.isOperatorName( @@ -118,12 +118,11 @@ object AnnotatorHighlighter { }, fun.getProject) } - val c = ScalaPsiUtil.getParentOfType(refElement, classOf[ScConstructor]) - - if (c != null && c.getParent.isInstanceOf[ScAnnotationExpr]) return + if (refElement.parentOfType(classOf[ScConstructor], strict = false) + .exists(_.getParent.isInstanceOf[ScAnnotationExpr])) return val resolvedElement = refElement.resolve() - if (PsiTreeUtil.getParentOfType(refElement, classOf[ScImportExpr]) == null && resolvedElement.isInstanceOf[PsiClass]) { + if (refElement.parentOfType(classOf[ScImportExpr]).isEmpty && resolvedElement.isInstanceOf[PsiClass]) { annotateCollection(resolvedElement.asInstanceOf[PsiClass]) } @@ -201,10 +200,7 @@ object AnnotatorHighlighter { case _: ScParameter => annotation.setTextAttributes(DefaultHighlighter.PARAMETER) case x@(_: ScFunctionDefinition | _: ScFunctionDeclaration | _: ScMacroDefinition) => if (SCALA_FACTORY_METHODS_NAMES.contains(x.asInstanceOf[PsiMethod].getName) || x.asInstanceOf[PsiMethod].isConstructor) { - val clazz = PsiTreeUtil.getParentOfType(x, classOf[PsiClass]) - if (clazz != null) { - annotateCollection(clazz) - } + x.parentOfType(classOf[PsiClass]).foreach(annotateCollection) } if (isHighlightableScalaTestKeyword(x.asInstanceOf[ScFunction])) { annotation.setTextAttributes(DefaultHighlighter.SCALATEST_KEYWORD) @@ -232,8 +228,7 @@ object AnnotatorHighlighter { } case x: PsiMethod => if (x.isConstructor) { - val clazz: PsiClass = PsiTreeUtil.getParentOfType(x, classOf[PsiClass]) - if (clazz != null) annotateCollection(clazz) + x.parentOfType(classOf[PsiClass]).foreach(annotateCollection) } if (x.getModifierList != null && x.getModifierList.hasModifierProperty("static")) { annotation.setTextAttributes(DefaultHighlighter.OBJECT_METHOD_CALL) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/filters/other/TypeFilter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/filters/other/TypeFilter.scala index 24434992d54..ff7281b8e80 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/filters/other/TypeFilter.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/filters/other/TypeFilter.scala @@ -5,8 +5,8 @@ package filters.other import com.intellij.psi.filters.ElementFilter import com.intellij.psi.{PsiComment, PsiElement} +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.completion.ScalaCompletionUtil._ -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt @@ -19,8 +19,10 @@ class TypeFilter extends ElementFilter { def isAcceptable(element: Object, context: PsiElement): Boolean = { if (context.isInstanceOf[PsiComment]) return false val leaf = getLeafByOffset(context.getTextRange.getStartOffset, context) - val imp = ScalaPsiUtil.getParentOfType(leaf, classOf[ScImportStmt]) - if (imp != null) return false + + val imp = leaf.parentOfType(classOf[ScImportStmt], strict = false) + if (imp.isDefined) return false + if (leaf != null) { val parent = leaf.getParent parent match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/AncestorSelector.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/AncestorSelector.scala index 7d3f706164b..0fb0f3697a1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/AncestorSelector.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/postfix/templates/selector/AncestorSelector.scala @@ -8,8 +8,8 @@ import com.intellij.openapi.util.Condition import com.intellij.openapi.util.Conditions._ import com.intellij.psi.PsiElement import com.intellij.util.containers.ContainerUtil +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.completion.postfix.templates.selector.SelectorType._ -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression import org.jetbrains.plugins.scala.lang.surroundWith.surrounders.expression.ScalaExpressionSurrounder @@ -24,8 +24,8 @@ class AncestorSelector(val condition: Condition[PsiElement], val selectorType: S } override def getNonFilteredExpressions(context: PsiElement, document: Document, offset: Int): util.List[PsiElement] = { - ScalaPsiUtil.getParentOfType(context, classOf[ScExpression]) match { - case element: ScExpression => + context.parentOfType(classOf[ScExpression], strict = false) match { + case Some(element: ScExpression) => val result = ContainerUtil.newLinkedList[PsiElement](element) var current: PsiElement = element.getParent while (current != null && current.getTextRange != null && current.getTextRange.getEndOffset <= offset && (selectorType match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index d7a2cce6dd3..1d5060c905f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -1037,12 +1037,6 @@ object ScalaPsiUtil { getMethodsForName(clazz, "update") } - /** - * For one classOf use PsiTreeUtil.getParenteOfType instead - */ - def getParentOfType(element: PsiElement, clazz: Class[_ <: PsiElement]): PsiElement = - PsiTreeUtil.getParentOfType(element, clazz, false) - @tailrec def getParentWithProperty(element: PsiElement, strict: Boolean, property: PsiElement => Boolean): Option[PsiElement] = { if (element == null) None diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala index 723744e854c..a512154bbd8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/base/types/ScTypeElement.scala @@ -5,7 +5,7 @@ package api package base package types -import org.jetbrains.plugins.scala.extensions.ifReadAllowed +import org.jetbrains.plugins.scala.extensions.{PsiElementExt, ifReadAllowed} import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScTypeParam import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory._ import org.jetbrains.plugins.scala.lang.psi.types._ @@ -55,17 +55,10 @@ trait ScTypeElement extends ScalaPsiElement with Typeable { * * This in turn is used in the `treeWalkUp` in [[org.jetbrains.plugins.scala.lang.psi.impl.base.ScStableCodeReferenceElementImpl.processQualifier]] */ - private def refreshAnalog() { - ScalaPsiUtil.getParentOfType(this, classOf[ScTypeParam]) match { - case tp: ScTypeParam => - ScalaPsiUtil.getParentOfType(tp, classOf[ScMethodLike]) match { - case ml: ScMethodLike => - ml.effectiveParameterClauses - case _ => - } - case _ => - } - } + private def refreshAnalog(): Unit = + this.parentOfType(classOf[ScTypeParam], strict = false) + .flatMap(_.parentOfType(classOf[ScMethodLike], strict = false)) + .foreach(_.effectiveParameterClauses) @volatile private[this] var _analog: Option[ScTypeElement] = None diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala index 3a51454532a..75ff4926d96 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/ScStableCodeReferenceElementImpl.scala @@ -52,7 +52,7 @@ class ScStableCodeReferenceElementImpl(node: ASTNode) extends ScReferenceElement } def getVariants: Array[Object] = { - val isInImport: Boolean = ScalaPsiUtil.getParentOfType(this, classOf[ScImportStmt]) != null + val isInImport: Boolean = this.parentOfType(classOf[ScImportStmt], strict = false).isDefined doResolve(new CompletionProcessor(getKinds(incomplete = true), this)).flatMap { case res: ScalaResolveResult => val qualifier = res.fromType.getOrElse(Nothing) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala index 6000442b8a3..a4d20f61a80 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/base/types/ScTypeProjectionImpl.scala @@ -45,7 +45,7 @@ class ScTypeProjectionImpl(node: ASTNode) extends ScReferenceElementImpl(node) w doResolve(new ResolveProcessor(getKinds(incomplete), ScTypeProjectionImpl.this, refName)) def getVariants: Array[Object] = { - val isInImport: Boolean = ScalaPsiUtil.getParentOfType(this, classOf[ScImportStmt]) != null + val isInImport: Boolean = this.parentOfType(classOf[ScImportStmt], strict = false).isDefined doResolve(new CompletionProcessor(getKinds(incomplete = true), this)).flatMap { case res: ScalaResolveResult => import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala index 7bed9b22da7..686479c1de0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReferenceExpressionImpl.scala @@ -143,7 +143,7 @@ class ScReferenceExpressionImpl(node: ASTNode) extends ScReferenceElementImpl(no * Important! Do not change types of Object values, this can cause errors due to bad architecture. */ override def getVariants(implicits: Boolean, filterNotNamedVariants: Boolean): Array[Object] = { - val isInImport: Boolean = ScalaPsiUtil.getParentOfType(this, classOf[ScImportStmt]) != null + val isInImport: Boolean = this.parentOfType(classOf[ScImportStmt], strict = false).isDefined getSimpleVariants(implicits, filterNotNamedVariants).flatMap { case res: ScalaResolveResult => diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala index 6254bf6fc46..5ed116330fb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala @@ -880,18 +880,18 @@ object ScalaRefactoringUtil { } def checkCanBeIntroduced(expr: ScExpression): Option[String] = { - ScalaPsiUtil.getParentOfType(expr, classOf[ScConstrBlock]) match { - case block: ScConstrBlock => - for { - selfInv <- block.selfInvocation - args <- selfInv.args - if args.isAncestorOf(expr) - } return Some(ScalaBundle.message("cannot.refactor.arg.in.self.invocation.of.constructor")) - case _ => + val exists1 = expr.parentOfType(classOf[ScConstrBlock], strict = false) + .flatMap(_.selfInvocation) + .flatMap(_.args) + .exists(_.isAncestorOf(expr)) + + if (exists1) { + return Some(ScalaBundle.message("cannot.refactor.arg.in.self.invocation.of.constructor")) } - val guard: ScGuard = getParentOfType(expr, classOf[ScGuard]) - if (guard != null && guard.getParent.isInstanceOf[ScCaseClause]) { + val exists2 = expr.parentOfType(classOf[ScGuard], strict = false) + .exists(_.getParent.isInstanceOf[ScCaseClause]) + if (exists2) { return Some(ScalaBundle.message("refactoring.is.not.supported.in.guard")) } diff --git a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtMavenDependencyCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtMavenDependencyCompletionContributor.scala index 33429cc7bd4..9aa9b0822b4 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtMavenDependencyCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/language/completion/SbtMavenDependencyCompletionContributor.scala @@ -6,9 +6,10 @@ import com.intellij.openapi.project.Project import com.intellij.patterns.PlatformPatterns._ import com.intellij.patterns.StandardPatterns._ import com.intellij.util.ProcessingContext +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.completion.ScalaCompletionContributor import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil -import org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr +import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScInfixExpr, ScReferenceExpression} import org.jetbrains.plugins.scala.lang.psi.impl.base.ScLiteralImpl import org.jetbrains.sbt.language.SbtFileType import org.jetbrains.sbt.resolvers.SbtResolverUtils @@ -96,28 +97,27 @@ class SbtMavenDependencyCompletionContributor extends ScalaCompletionContributor results.stopHere() } - val expr = ScalaPsiUtil.getParentOfType(place, classOf[ScInfixExpr]).asInstanceOf[ScInfixExpr] - if (place.getText == CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED) return val cleanText = place.getText.replaceAll(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED, "").replaceAll("\"", "") - def isValidOp(operation: String) = operation == "%" || operation == "%%" + def isValidOp(expression: ScReferenceExpression) = + expression.getText match { + case "%" | "%%" => true + case _ => false + } - (expr.lOp, expr.operation.getText, expr.rOp) match { - case (_, oper, _) if oper == "+=" || oper == "++=" => // empty completion from scratch + place.parentOfType(classOf[ScInfixExpr], strict = false).foreach { + case ScInfixExpr(_, oper, _) if oper.getText == "+=" || oper.getText == "++=" => // empty completion from scratch completeGroup(cleanText) - case (lop, oper, ScLiteralImpl.string(artifact)) if lop == place.getContext && isValidOp(oper) => - val versionSuffix = if (oper == "%%") s"_${place.scalaLanguageLevelOrDefault.version}" else "" + case ScInfixExpr(lop, oper, ScLiteralImpl.string(artifact)) if lop == place.getContext && isValidOp(oper) => + val versionSuffix = if (oper.getText == "%%") s"_${place.scalaLanguageLevelOrDefault.version}" else "" completeGroup(artifact + versionSuffix) - case (ScLiteralImpl.string(group), oper, rop) if rop == place.getContext && isValidOp(oper) => - if (oper == "%%") - completeArtifact(group, stripVersion = true) - else - completeArtifact(group, stripVersion = false) - case (ScInfixExpr(llop, loper, lrop), oper, rop) - if rop == place.getContext && oper == "%" && isValidOp(loper.getText) => + case ScInfixExpr(ScLiteralImpl.string(group), oper, rop) if rop == place.getContext && isValidOp(oper) => + completeArtifact(group, stripVersion = oper.getText == "%%") + case ScInfixExpr(ScInfixExpr(llop, loper, lrop), oper, rop) + if rop == place.getContext && oper.getText == "%" && isValidOp(loper) => val versionSuffix = if (loper.getText == "%%") s"_${place.scalaLanguageLevelOrDefault.version}" else "" for { ScLiteralImpl.string(group) <- Option(llop) diff --git a/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala b/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala index b3935d73a5a..1088650a337 100644 --- a/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala +++ b/scala/scala-impl/src/scala/meta/intellij/MetaExpansionsManager.scala @@ -13,20 +13,20 @@ import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.{ModuleRootManager, OrderEnumerator} import com.intellij.openapi.vfs.VirtualFile import org.jetbrains.plugins.scala.extensions -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScParameterizedTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScAnnotation import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder -import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTemplateDefinition, ScTypeDefinition} +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTypeDefinition} import org.jetbrains.plugins.scala.macroAnnotations.{CachedInsidePsiElement, ModCount} -import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.{Scala_2_11, Scala_2_12} +import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_12 +import scala.collection.JavaConverters._ import scala.collection.immutable import scala.meta.parsers.Parse import scala.meta.trees.{AbortException, ScalaMetaException, TreeConverter} import scala.meta.{Dialect, Tree} import scala.reflect.internal.util.ScalaClassLoader.URLClassLoader -import scala.collection.JavaConverters._ /** * @author Mikhail Mutcianko @@ -148,9 +148,7 @@ object MetaExpansionsManager { def runMetaAnnotation(annot: ScAnnotation): Either[String, Tree] = { - - val holder: ScAnnotationsHolder = ScalaPsiUtil.getParentOfType(annot, classOf[ScAnnotationsHolder]) - .asInstanceOf[ScAnnotationsHolder] + val holder = annot.parentOfType(classOf[ScAnnotationsHolder], strict = false).orNull @CachedInsidePsiElement(annot, ModCount.getBlockModificationCount) def runMetaAnnotationsImpl(annot: ScAnnotation): Either[String, Tree] = { diff --git a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala index 9b26f1c8a7f..f0972c675f8 100644 --- a/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala +++ b/scala/scala-impl/test/scala/meta/annotations/MetaAnnotationTestBase.scala @@ -20,10 +20,10 @@ import org.jetbrains.plugins.scala.base.DisposableScalaLibraryLoader import org.jetbrains.plugins.scala.base.libraryLoaders.LibraryLoader import org.jetbrains.plugins.scala.debugger.{CompilationCache, ScalaVersion} import org.jetbrains.plugins.scala.extensions.{PsiElementExt, inWriteAction} +import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.statements.ScAnnotationsHolder import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition -import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.project.ModuleExt import org.jetbrains.plugins.scala.project.settings.ScalaCompilerConfiguration import org.jetbrains.plugins.scala.util.TestUtils @@ -131,7 +131,7 @@ abstract class MetaAnnotationTestBase extends JavaCodeInsightFixtureTestCase wit protected def checkExpansionEquals(code: String, expectedExpansion: String): Unit = { import scala.meta.intellij.psiExt._ myFixture.configureByText(s"Usage${getTestName(false)}.scala", code) - val holder = ScalaPsiUtil.getParentOfType(elementAtCaret, classOf[ScAnnotationsHolder]).asInstanceOf[ScAnnotationsHolder] + val holder = elementAtCaret.parentOfType(classOf[ScAnnotationsHolder], strict = false).orNull holder.getMetaExpansion match { case Right(tree) => Assert.assertEquals(expectedExpansion, tree.toString()) case Left(reason) if reason.nonEmpty => Assert.fail(reason) From f723550db6e6d18da1a0acd60c725fe695398f7c Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 1 Nov 2017 14:04:52 +0300 Subject: [PATCH 111/141] parentOfType fixup --- .../src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala index 1d5060c905f..fe66c7f3628 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/ScalaPsiUtil.scala @@ -1404,6 +1404,7 @@ object ScalaPsiUtil { param.parentOfType(classOf[ScFunction]).flatMap { case fun if fun.isSyntheticCopy => Option(fun.containingClass) case fun if fun.isSyntheticApply => getCompanionModule(fun.containingClass) + case _ => None }.collect { case td: ScClass if td.isCase => td }.flatMap(_.constructor).toSeq From c802a570811036f41bddf925b936e7a7aee25403 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Tue, 31 Oct 2017 17:08:22 +0300 Subject: [PATCH 112/141] parentOfType extension method usages --- .../ForwardReferenceInspection.scala | 54 ++++++++++--------- .../ConvertibleToMethodValueInspection.scala | 7 +-- ...orParamsInConstructorPatternSearcher.scala | 5 +- .../ScalaConstructorInsertHandler.scala | 48 +++++++---------- .../findUsages/ScalaUsageTypeProvider.scala | 8 +-- .../lang/parser/ScalaParserDefinition.scala | 9 ++-- .../delete/SafeDeleteProcessorUtil.scala | 3 +- .../IntroduceTypeAlias.scala | 9 ++-- .../ScalaMoveDirectoryWithClassesHelper.scala | 11 ++-- .../refactoring/rename/ScalaRenameUtil.scala | 6 +-- 10 files changed, 72 insertions(+), 88 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/forwardReferenceInspection/ForwardReferenceInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/forwardReferenceInspection/ForwardReferenceInspection.scala index a124a7908c7..d05418ba258 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/forwardReferenceInspection/ForwardReferenceInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/forwardReferenceInspection/ForwardReferenceInspection.scala @@ -3,41 +3,45 @@ package codeInspection.forwardReferenceInspection import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.PsiElement -import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.codeInspection.AbstractInspection -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil +import org.jetbrains.plugins.scala.extensions.PsiElementExt +import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil.nameContext import org.jetbrains.plugins.scala.lang.psi.api.expr.ScReferenceExpression -import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScValue, ScVariable} +import org.jetbrains.plugins.scala.lang.psi.api.statements.ScValueOrVariable import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScMember -import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult /** - * Alefas - */ + * Alefas + */ class ForwardReferenceInspection extends AbstractInspection { + import ForwardReferenceInspection.asValueOrVariable + override protected def actionFor(implicit holder: ProblemsHolder): PartialFunction[PsiElement, Unit] = { case ref: ScReferenceExpression => - val member: ScMember = PsiTreeUtil.getParentOfType(ref, classOf[ScMember]) - if (member != null) { - member.getContext match { - case tb: ScTemplateBody if member.isInstanceOf[ScValue] || member.isInstanceOf[ScVariable] => - ref.bind() match { - case Some(r: ScalaResolveResult) => - ScalaPsiUtil.nameContext(r.getActualElement) match { - case resolved if resolved.isInstanceOf[ScValue] || resolved.isInstanceOf[ScVariable]=> - if (resolved.getParent == tb && !member.hasModifierProperty("lazy") && - !resolved.asInstanceOf[ScMember].hasModifierProperty("lazy") && - resolved.getTextOffset > member.getTextOffset) { - holder.registerProblem(ref, ScalaBundle.message("suspicicious.forward.reference.template.body")) - } - case _ => - } - case _ => - } - case _ => - } + val maybeMember = ref.parentOfType(classOf[ScMember]) + .collect(asValueOrVariable) + .filter(_.getContext.isInstanceOf[ScTemplateBody]) + + val maybeResolved = ref.bind() + .map(_.getActualElement) + .map(nameContext) + .collect(asValueOrVariable) + + val flag = maybeMember.zip(maybeResolved).exists { + case (member, resolved) => resolved.getParent == member.getContext && resolved.getTextOffset > member.getTextOffset + } + + if (flag) { + holder.registerProblem(ref, ScalaBundle.message("suspicicious.forward.reference.template.body")) } } } + +object ForwardReferenceInspection { + + private def asValueOrVariable: PartialFunction[PsiElement, ScValueOrVariable] = { + case v: ScValueOrVariable if !v.hasModifierProperty("lazy") => v + } +} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala index d1b9f1a0f2b..e9ef1dd8c04 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/ConvertibleToMethodValueInspection.scala @@ -4,7 +4,6 @@ package codeInspection.syntacticSimplification import com.intellij.codeInspection.{ProblemHighlightType, ProblemsHolder} import com.intellij.openapi.project.Project import com.intellij.psi._ -import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.codeInspection.collections.MethodRepr import org.jetbrains.plugins.scala.codeInspection.syntacticSimplification.ConvertibleToMethodValueInspection._ import org.jetbrains.plugins.scala.codeInspection.{AbstractFixOnPsiElement, AbstractInspection, InspectionBundle} @@ -41,10 +40,8 @@ class ConvertibleToMethodValueInspection extends AbstractInspection(inspectionId if (allArgsUnderscores(args) && qualOpt.forall(onlyStableValuesUsed)) registerProblem(holder, expr, InspectionBundle.message("convertible.to.method.value.anonymous.hint")) case und: ScUnderscoreSection if und.bindingExpr.isDefined => - val isInParameterOfParameterizedClass = PsiTreeUtil.getParentOfType(und, classOf[ScClassParameter]) match { - case null => false - case cp => cp.containingClass.hasTypeParameters - } + val isInParameterOfParameterizedClass = und.parentOfType(classOf[ScClassParameter]) + .exists(_.containingClass.hasTypeParameters) def mayReplace() = und.bindingExpr.get match { case ResolvesTo(fun) if hasByNameParam(fun) => false case ScReferenceExpression.withQualifier(qual) => onlyStableValuesUsed(qual) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/parameters/ConstructorParamsInConstructorPatternSearcher.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/parameters/ConstructorParamsInConstructorPatternSearcher.scala index 766f09e30df..5b0ef3bc3b0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/parameters/ConstructorParamsInConstructorPatternSearcher.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/findUsages/parameters/ConstructorParamsInConstructorPatternSearcher.scala @@ -5,11 +5,10 @@ package parameters import com.intellij.find.findUsages.{CustomUsageSearcher, FindUsagesOptions} import com.intellij.psi._ import com.intellij.psi.search.searches.ReferencesSearch -import com.intellij.psi.util.PsiTreeUtil import com.intellij.usageView.UsageInfo import com.intellij.usages.{Usage, UsageInfoToUsageConverter} import com.intellij.util.Processor -import org.jetbrains.plugins.scala.extensions.inReadAction +import org.jetbrains.plugins.scala.extensions.{PsiElementExt, inReadAction} import org.jetbrains.plugins.scala.lang.psi.api.base.ScPrimaryConstructor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScBindingPattern, ScConstructorPattern} import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScClassParameter @@ -57,7 +56,7 @@ class ConstructorParamsInConstructorPatternSearcher extends CustomUsageSearcher inReadAction { if (!param.isValid) return None - PsiTreeUtil.getParentOfType(param, classOf[ScPrimaryConstructor]) match { + param.parentOfType(classOf[ScPrimaryConstructor]).flatMap { case pc@ScPrimaryConstructor.ofClass(cls) if cls.isCase => pc.parameters.indexOf(param) match { case -1 => None diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/handlers/ScalaConstructorInsertHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/handlers/ScalaConstructorInsertHandler.scala index 8fe1759e83c..97504a06dce 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/handlers/ScalaConstructorInsertHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/handlers/ScalaConstructorInsertHandler.scala @@ -4,15 +4,14 @@ import com.intellij.codeInsight.AutoPopupController import com.intellij.codeInsight.completion.{CompletionType, InsertHandler, InsertionContext} import com.intellij.codeInsight.lookup.LookupElement import com.intellij.openapi.util.Condition -import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiClass, PsiDocumentManager, PsiFile} import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.completion.lookups.ScalaLookupItem import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement -import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScParameterizedTypeElement, ScSimpleTypeElement, ScTypeElement} +import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScParameterizedTypeElement, ScSimpleTypeElement} import org.jetbrains.plugins.scala.lang.psi.api.expr.ScNewTemplateDefinition -import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.{ScExtendsBlock, ScTemplateBody, ScTemplateParents} +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.{ScExtendsBlock, ScTemplateBody} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createReferenceFromText import org.jetbrains.plugins.scala.overrideImplement.ScalaOIUtil @@ -92,34 +91,25 @@ class ScalaConstructorInsertHandler extends InsertHandler[LookupElement] { PsiDocumentManager.getInstance(context.getProject).commitDocument(document) val file = context.getFile val element = file.findElementAt(endOffset - 1) - val newT = PsiTreeUtil.getParentOfType(element, classOf[ScNewTemplateDefinition]) - if (newT != null) { - newT.extendsBlock.templateParents match { - case Some(tp: ScTemplateParents) => - val elements = tp.typeElements - if (elements.length == 1) { - val element: ScTypeElement = elements.head - val ref: ScStableCodeReferenceElement = element match { - case simple: ScSimpleTypeElement => simple.reference.orNull - case par: ScParameterizedTypeElement => par.typeElement match { - case simple: ScSimpleTypeElement => simple.reference.orNull - case _ => null - } - case _ => null - } - if (ref != null && !isRenamed) { - if (item.prefixCompletion) { - val newRefText = clazz.qualifiedName.split('.').takeRight(2).mkString(".") - val newRef = createReferenceFromText(newRefText)(clazz.getManager) - val replaced = ref.replace(newRef).asInstanceOf[ScStableCodeReferenceElement] - replaced.bindToElement(clazz) - } else { - ref.bindToElement(clazz) - } - } - } + element.parentOfType(classOf[ScNewTemplateDefinition]).foreach { newT => + val maybeRef = newT.extendsBlock.templateParents.toSeq.flatMap(_.typeElements) match { + case Seq(ScSimpleTypeElement(reference)) => reference + case Seq(ScParameterizedTypeElement(ScSimpleTypeElement(reference), _)) => reference + case _ => None + } + + maybeRef match { + case Some(value) if !isRenamed => + val referenceElement = if (item.prefixCompletion) { + val newRefText = clazz.qualifiedName.split('.').takeRight(2).mkString(".") + val newRef = createReferenceFromText(newRefText)(clazz.getManager) + value.replace(newRef).asInstanceOf[ScStableCodeReferenceElement] + } else value + + referenceElement.bindToElement(clazz) case _ => } + ScalaPsiUtil.adjustTypes(newT) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala index 5b8163952d1..761cd14a0a6 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/findUsages/ScalaUsageTypeProvider.scala @@ -64,10 +64,10 @@ object ScalaUsageTypeProvider { def patternUsageType(pattern: ScPattern): UsageType = { def isPatternAncestor(element: PsiElement) = isAncestor(element, pattern, false) - val patterns = getParentOfType(pattern, classOf[ScCatchBlock]) match { - case ScCatchBlock(clauses) => clauses.caseClauses.flatMap(_.pattern) - case _ => Seq.empty - } + val patterns = pattern.parentOfType(classOf[ScCatchBlock]).toSeq.collect { + case ScCatchBlock(clauses) => clauses + }.flatMap(_.caseClauses) + .flatMap(_.pattern) if (patterns.exists(isPatternAncestor)) CLASS_CATCH_CLAUSE_PARAMETER_DECLARATION else pattern match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parser/ScalaParserDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parser/ScalaParserDefinition.scala index 852bef68f2e..3b484071dad 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parser/ScalaParserDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parser/ScalaParserDefinition.scala @@ -6,8 +6,8 @@ import com.intellij.lang.{ASTNode, ParserDefinition} import com.intellij.openapi.project.Project import com.intellij.psi.stubs.PsiFileStub import com.intellij.psi.tree.{IStubFileElementType, TokenSet} -import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{FileViewProvider, PsiElement, PsiFile} +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.lexer.{ScalaLexer, ScalaTokenTypes} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt import org.jetbrains.plugins.scala.lang.psi.impl.ScalaFileImpl @@ -49,10 +49,9 @@ class ScalaParserDefinition extends ScalaParserDefinitionWrapper { } override def spaceExistanceTypeBetweenTokens(leftNode: ASTNode, rightNode: ASTNode): ParserDefinition.SpaceRequirements = { - val importStatement = PsiTreeUtil.getParentOfType(leftNode.getPsi, classOf[ScImportStmt]) - val isNeighbour = Option(importStatement).exists { - _.getTextRange.getEndOffset == rightNode.getTextRange.getStartOffset - } + val isNeighbour = leftNode.getPsi.parentOfType(classOf[ScImportStmt]) + .map(_.getTextRange.getEndOffset) + .contains(rightNode.getTextRange.getStartOffset) import com.intellij.lang.ParserDefinition.SpaceRequirements._ rightNode.getElementType match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/delete/SafeDeleteProcessorUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/delete/SafeDeleteProcessorUtil.scala index 1f4883db345..97dc83ece58 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/delete/SafeDeleteProcessorUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/delete/SafeDeleteProcessorUtil.scala @@ -4,7 +4,6 @@ package refactoring package delete import java.util -import java.util._ import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.util.{Condition, TextRange} @@ -325,7 +324,7 @@ object SafeDeleteProcessorUtil { usages.add(new SafeDeleteFieldWriteReference(assignExpr, psiField)) case _ => val range: TextRange = reference.getRangeInElement - usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(reference.getElement, psiField, range.getStartOffset, range.getEndOffset, false, PsiTreeUtil.getParentOfType(element, classOf[PsiImportStaticStatement]) != null)) + usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(reference.getElement, psiField, range.getStartOffset, range.getEndOffset, false, element.parentOfType(classOf[PsiImportStaticStatement]).isDefined)) } } true diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala index 1598cf5cf86..551e06fc404 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/introduceVariable/IntroduceTypeAlias.scala @@ -18,7 +18,7 @@ import com.intellij.psi._ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil import com.intellij.psi.util.PsiTreeUtil.{findElementOfClassAtRange, getChildOfType, getParentOfType} import org.jetbrains.plugins.scala.ScalaBundle -import org.jetbrains.plugins.scala.extensions.{callbackInTransaction, inWriteAction, startCommand} +import org.jetbrains.plugins.scala.extensions.{PsiElementExt, callbackInTransaction, inWriteAction, startCommand} import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.base.types._ @@ -212,11 +212,8 @@ trait IntroduceTypeAlias { val usualOccurrences = replaceTypeElements(occurrences.getUsualOccurrences, typeName, typeAlias) replaceTypeElements(occurrences.getExtendedOccurrences, typeName, typeAlias) - val className = getParentOfType(parent, classOf[ScObject]) match { - case objectType: ScObject => - objectType.name - case _ => "" - } + val className = parent.parentOfType(classOf[ScObject]) + .map(_.name).getOrElse("") replaceTypeElements(occurrences.getCompanionObjOccurrences, className + "." + typeName, typeAlias) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/move/ScalaMoveDirectoryWithClassesHelper.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/move/ScalaMoveDirectoryWithClassesHelper.scala index c6fae301e54..0e934d9b022 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/move/ScalaMoveDirectoryWithClassesHelper.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/move/ScalaMoveDirectoryWithClassesHelper.scala @@ -12,10 +12,11 @@ import com.intellij.refactoring.move.moveClassesOrPackages.{MoveClassesOrPackage import com.intellij.refactoring.util.MoveRenameUsageInfo import com.intellij.usageView.UsageInfo import com.intellij.util.Function -import org.jetbrains.plugins.scala.extensions.{PsiClassExt, PsiNamedElementExt} +import org.jetbrains.plugins.scala.extensions.{PsiClassExt, PsiElementExt, PsiNamedElementExt} import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject + import scala.collection.JavaConverters._ /** @@ -66,11 +67,9 @@ class ScalaMoveDirectoryWithClassesHelper extends MoveDirectoryWithClassesHelper if (remainsNothing) { ReferencesSearch.search(aPackage, GlobalSearchScope.projectScope(project)).findAll().forEach { reference => - val element: PsiElement = reference.getElement - val importStmt = PsiTreeUtil.getParentOfType(element, classOf[ScImportStmt]) - if (importStmt != null) { - usages.add(ImportStatementToRemoveUsage(importStmt)) - } + reference.getElement.parentOfType(classOf[ScImportStmt]) + .map(ImportStatementToRemoveUsage) + .foreach(usages.add) } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/ScalaRenameUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/ScalaRenameUtil.scala index 3bec6cee22e..caac789bdf4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/ScalaRenameUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/rename/ScalaRenameUtil.scala @@ -6,12 +6,11 @@ import java.util import com.intellij.openapi.editor.RangeMarker import com.intellij.openapi.util.TextRange import com.intellij.psi.search.searches.ReferencesSearch -import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiElement, PsiNamedElement, PsiReference} import com.intellij.refactoring.listeners.RefactoringElementListener import com.intellij.refactoring.rename.RenameUtil import com.intellij.usageView.UsageInfo -import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScReferencePattern import org.jetbrains.plugins.scala.lang.psi.api.base.{ScPrimaryConstructor, ScReferenceElement, ScStableCodeReferenceElement} import org.jetbrains.plugins.scala.lang.psi.api.expr.ScNewTemplateDefinition @@ -20,6 +19,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.fake.FakePsiMethod import org.jetbrains.plugins.scala.lang.psi.light.PsiTypedDefinitionWrapper +import org.jetbrains.plugins.scala.lang.psi.{ScalaPsiElement, ScalaPsiUtil} import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import scala.collection.JavaConverters._ @@ -55,7 +55,7 @@ object ScalaRenameUtil { def replaceImportClassReferences(allReferences: util.Collection[PsiReference]): util.Collection[PsiReference] = { val result = allReferences.asScala.map { case ref: ScStableCodeReferenceElement => - val isInImport = PsiTreeUtil.getParentOfType(ref, classOf[ScImportStmt]) != null + val isInImport = ref.parentOfType(classOf[ScImportStmt]).isDefined if (isInImport && ref.resolve() == null) { val multiResolve = ref.multiResolve(false) if (multiResolve.length > 1 && multiResolve.forall(_.getElement.isInstanceOf[ScTypeDefinition])) { From fb18704ce82446b824a2b874db38ad66a45b4d51 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Wed, 1 Nov 2017 18:13:45 +0300 Subject: [PATCH 113/141] debugger tests fixed #SCL-12826 fixed --- .../debugger/ScalaDebuggerTestCase.scala | 241 +++++++++++------- .../debugger/renderers/RendererTestBase.scala | 61 +++-- .../ScalaCollectionRendererTestBase.scala | 9 +- .../smartStepInto/SmartStepIntoTestBase.scala | 25 +- .../StepOverCaseClausesTestBase.scala | 6 +- 5 files changed, 192 insertions(+), 150 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala index c09736b3a97..6b38e7021db 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaDebuggerTestCase.scala @@ -4,10 +4,15 @@ package debugger import java.io.File import java.util.concurrent.atomic.AtomicReference +import scala.collection.mutable +import scala.concurrent.duration._ +import scala.util.{Failure, Success, Try} + import com.intellij.debugger.DebuggerManagerEx import com.intellij.debugger.engine._ import com.intellij.debugger.engine.evaluation._ import com.intellij.debugger.engine.evaluation.expression.EvaluatorBuilder +import com.intellij.debugger.engine.events.SuspendContextCommandImpl import com.intellij.debugger.impl._ import com.intellij.execution.Executor import com.intellij.execution.application.{ApplicationConfiguration, ApplicationConfigurationType} @@ -18,7 +23,6 @@ import com.intellij.execution.runners.{ExecutionEnvironmentBuilder, ProgramRunne import com.intellij.execution.ui.RunContentDescriptor import com.intellij.openapi.module.Module import com.intellij.openapi.util.{Key, Ref} -import com.intellij.psi.PsiCodeFragment import com.intellij.psi.search.GlobalSearchScope import com.intellij.testFramework.EdtTestUtil import com.intellij.util.concurrency.Semaphore @@ -30,8 +34,6 @@ import org.jetbrains.plugins.scala.debugger.breakpoints.ScalaLineBreakpointType import org.jetbrains.plugins.scala.debugger.evaluation.ScalaCodeFragmentFactory import org.jetbrains.plugins.scala.extensions._ import org.junit.Assert -import scala.collection.mutable -import scala.util.{Failure, Success, Try} /** * User: Alefas @@ -43,12 +45,37 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { private val breakpoints: mutable.Set[(String, Int, Integer)] = mutable.Set.empty - protected def runDebugger(mainClass: String = mainClassName, debug: Boolean = false)(callback: => Unit) { + //safety net against not running tests at all + private var wasAtBreakpoint: Boolean = false + protected def shouldStopAtBreakpointAtLeastOnce(): Boolean = true + + override def setUp() = { + super.setUp() if (needMake) { make() saveChecksums() } - addBreakpoints() + } + + protected def runDebugger(mainClass: String = mainClassName, debug: Boolean = false)(callback: => Unit) { + setupBreakpoints() + val processHandler = runProcess(mainClass, debug) + val debugProcess = getDebugProcess + + try { + callback + } finally { + EdtTestUtil.runInEdtAndWait(() => { + clearXBreakpoints() + debugProcess.stop(true) + processHandler.destroyProcess() + }) + } + + Assert.assertTrue("Stop at breakpoint expected", wasAtBreakpoint || !shouldStopAtBreakpointAtLeastOnce()) + } + + private def runProcess(mainClass: String = mainClassName, debug: Boolean = false): ProcessHandler = { val runner = ProgramRunner.PROGRAM_RUNNER_EP.getExtensions.find { _.getClass == classOf[GenericDebuggerRunner] }.get @@ -63,26 +90,14 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { }, runner) processHandler.set(handler) }) - - - try { - callback - } finally { - - EdtTestUtil.runInEdtAndWait(() => { - clearXBreakpoints() - getDebugProcess.stop(true) - processHandler.get.destroyProcess() - }) - } + processHandler.get } - - protected def runProcess(className: String, - module: Module, - executorClass: Class[_ <: Executor], - listener: ProcessListener, - runner: ProgramRunner[_ <: RunnerSettings]): ProcessHandler = { + private def runProcess(className: String, + module: Module, + executorClass: Class[_ <: Executor], + listener: ProcessListener, + runner: ProgramRunner[_ <: RunnerSettings]): ProcessHandler = { val configuration: ApplicationConfiguration = new ApplicationConfiguration("app", module.getProject, ApplicationConfigurationType.getInstance) configuration.setModule(module) configuration.setMainClassName(className) @@ -103,13 +118,8 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { processHandler.get } - protected def getDebugProcess: DebugProcessImpl = { - getDebugSession.getProcess - } - - protected def getDebugSession: DebuggerSession = { - DebuggerManagerEx.getInstanceEx(getProject).getContext.getDebuggerSession - } + protected def getDebugProcess: DebugProcessImpl = + DebuggerManagerEx.getInstanceEx(getProject).getContext.getDebugProcess protected def resume() { val resumeCommand = getDebugProcess.createResumeCommand(suspendContext) @@ -120,9 +130,12 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { breakpoints += ((fileName, line, lambdaOrdinal)) } - protected def clearBreakpoints(): Unit = breakpoints.clear() + protected def clearBreakpoints(): Unit = { + breakpoints.clear() + clearXBreakpoints() + } - private def addBreakpoints() { + private def setupBreakpoints() { invokeAndWaitInTransaction(getProject) { breakpoints.foreach { case (fileName, line, ordinal) => @@ -149,10 +162,14 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { protected def scalaLineBreakpointType = XBreakpointType.EXTENSION_POINT_NAME.findExtension(classOf[ScalaLineBreakpointType]) - protected def waitForBreakpoint(): SuspendContextImpl = { + protected def waitForBreakpoint(): SuspendContextImpl = { val (suspendContext, processTerminated) = waitForBreakpointInner() - assert(suspendContext != null, "too long process, terminated=" + processTerminated) + val message = + if (processTerminated) "process terminated before breakpoint" + else "too long waiting for breakpoint" + + assert(suspendContext != null, message) suspendContext } @@ -162,75 +179,116 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { } private def waitForBreakpointInner(): (SuspendContextImpl, Boolean) = { - var i = 0 - def processTerminated: Boolean = getDebugProcess.getExecutionResult.getProcessHandler.isProcessTerminated - while (i < 1000 && suspendContext == null && !processTerminated) { - Thread.sleep(10) - i += 1 - } - (suspendContext, processTerminated) - } - - protected def managed[T >: Null](callback: => T): T = { - var result: T = null - def ctx = DebuggerContextUtil.createDebuggerContext(getDebugSession, suspendContext) val semaphore = new Semaphore() semaphore.down() - getDebugProcess.getManagerThread.invokeAndWait(() => { - result = callback - semaphore.up() + + val result = Ref.create[(SuspendContextImpl, Boolean)]((null, false)) + + getDebugProcess.addDebugProcessListener(new DebugProcessAdapterImpl { + override def paused(suspendContext: SuspendContextImpl) = { + wasAtBreakpoint = true + getDebugProcess.removeDebugProcessListener(this) + result.set(suspendContext, false) + semaphore.up() + } + + override def processDetached(process: DebugProcessImpl, closedByUser: Boolean) = { + process.removeDebugProcessListener(this) + result.set(null, true) + semaphore.up() + } }) - def finished = semaphore.waitFor(20000) - assert(finished, "Too long debugger action") - result + + semaphore.waitFor(30000) + + result.get } protected def suspendManager = getDebugProcess.getSuspendManager protected def suspendContext = suspendManager.getPausedContext - protected def evaluationContext() = new EvaluationContextImpl(suspendContext, suspendContext.getFrameProxy, suspendContext.getFrameProxy.thisObject()) + protected def evaluationContext() = managed { + new EvaluationContextImpl(suspendContext, suspendContext.getFrameProxy, suspendContext.getFrameProxy.thisObject()) + } - protected def currentSourcePosition = ContextUtil.getSourcePosition(suspendContext) + protected def currentSourcePosition = managed { + ContextUtil.getSourcePosition(suspendContext) + } protected def evalResult(codeText: String): String = { + val ctx = evaluationContext() + val factory = new ScalaCodeFragmentFactory() + val factoryWrapper = new CodeFragmentFactoryContextWrapper(factory) + val evaluatorBuilder: EvaluatorBuilder = factory.getEvaluatorBuilder + val kind = + if (codeText.contains("\n")) CodeFragmentKind.CODE_BLOCK + else CodeFragmentKind.EXPRESSION + + val contextElement = managed { + ContextUtil.getContextElement(ctx) + } + + val textWithImports = new TextWithImportsImpl(kind, codeText) + val fragment = inReadAction { + val fragment = factoryWrapper.createCodeFragment(textWithImports, contextElement, getProject) + fragment.forceResolveScope(GlobalSearchScope.allScope(getProject)) + DebuggerUtils.checkSyntax(fragment) + fragment + } + + inSuspendContextAction(60.seconds, "Too long evaluate expression: " + codeText) { + val value = Try { + val evaluator = inReadAction { + evaluatorBuilder.build(fragment, currentSourcePosition) + } + evaluator.evaluate(ctx) + } + value match { + case Success(v: VoidValue) => "undefined" + case Success(v) => + DebuggerUtils.getValueAsString(ctx, v) + case Failure(e: EvaluateException) => e.getMessage + case Failure(e: Throwable) => "Other error: " + e.getMessage + } + } + } + + private def waitScheduledAction[T](timeout: Duration, timeoutMsg: String, callback: => T) + (schedule: (=> Unit) => Unit): T = { + val result = Ref.create[T]() val semaphore = new Semaphore() semaphore.down() - val result = - managed[String] { - val ctx: EvaluationContextImpl = evaluationContext() - val factory = new ScalaCodeFragmentFactory() - val kind = if (codeText.contains("\n")) CodeFragmentKind.CODE_BLOCK else CodeFragmentKind.EXPRESSION - val codeFragment: PsiCodeFragment = inReadAction { - val result = new CodeFragmentFactoryContextWrapper(factory). - createCodeFragment(new TextWithImportsImpl(kind, codeText), - ContextUtil.getContextElement(ctx), getProject) - result.forceResolveScope(GlobalSearchScope.allScope(getProject)) - DebuggerUtils.checkSyntax(result) - result - } - val evaluatorBuilder: EvaluatorBuilder = factory.getEvaluatorBuilder - val value = Try { - val evaluator = inReadAction(evaluatorBuilder.build(codeFragment, currentSourcePosition)) - inSuspendContextCommand(ctx) { - evaluator.evaluate(ctx) - } - } - val res = value match { - case Success(v: VoidValue) => "undefined" - case Success(v) => - inSuspendContextCommand(ctx) { - DebuggerUtils.getValueAsString(ctx, v) - } - case Failure(e: EvaluateException) => e.getMessage - case Failure(e: Throwable) => "Other error: " + e.getMessage + schedule { + result.set(callback) + semaphore.up() + } + val finished = semaphore.waitFor(timeout.toMillis) + if (!finished) { + semaphore.up() + } + Assert.assertTrue(timeoutMsg, finished) + result.get + } + + protected def inSuspendContextAction[T](timeout: Duration, timeoutMsg: String)(callback: => T): T = { + val context = suspendContext + val process = getDebugProcess + + waitScheduledAction(timeout, timeoutMsg, callback) { body => + process.getManagerThread.schedule(new SuspendContextCommandImpl(context) { + override def contextAction(suspendContext: SuspendContextImpl): Unit = { + body } - semaphore.up() - res - } - assert(semaphore.waitFor(10000), "Too long evaluate expression: " + codeText) - result + }) + } + } + + protected def managed[T >: Null](callback: => T): T = { + waitScheduledAction(30.seconds, "Too long debugger action", callback) { body => + getDebugProcess.getManagerThread.invoke(() => body) + } } protected def evalEquals(codeText: String, expected: String) { @@ -284,15 +342,6 @@ abstract class ScalaDebuggerTestCase extends ScalaDebuggerTestBase { breakpointLines.foreach(addBreakpoint(_, path)) } - - protected def inSuspendContextCommand[T](ctx: EvaluationContextImpl)(body: => T): T = { - val suspendContext = ctx.getSuspendContext - suspendContext.myInProgress = true - try body - finally { - suspendContext.myInProgress = false - } - } } case class Loc(className: String, methodName: String, line: Int) \ No newline at end of file diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/RendererTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/RendererTestBase.scala index b4f424270ae..76883316b16 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/RendererTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/RendererTestBase.scala @@ -3,16 +3,18 @@ package org.jetbrains.plugins.scala.debugger.renderers import java.util import javax.swing.Icon +import scala.collection.JavaConverters._ +import scala.concurrent.duration.DurationDouble + import com.intellij.debugger.engine.evaluation.{EvaluateException, EvaluationContextImpl} import com.intellij.debugger.ui.impl.ThreadsDebuggerTree -import com.intellij.debugger.ui.impl.watch.{DebuggerTree, LocalVariableDescriptorImpl, NodeDescriptorImpl} -import com.intellij.debugger.ui.tree.render.{ArrayRenderer, ChildrenBuilder, DescriptorLabelListener} +import com.intellij.debugger.ui.impl.watch.{DebuggerTree, NodeDescriptorImpl} import com.intellij.debugger.ui.tree._ +import com.intellij.debugger.ui.tree.render.{ArrayRenderer, ChildrenBuilder, DescriptorLabelListener} import com.intellij.openapi.util.Disposer import com.intellij.ui.SimpleTextAttributes import com.intellij.xdebugger.frame.{XDebuggerTreeNodeHyperlink, XValueChildrenList} import org.jetbrains.plugins.scala.debugger.ScalaDebuggerTestCase -import scala.collection.JavaConverters._ /** * Nikolay.Tropin @@ -26,62 +28,59 @@ abstract class RendererTestBase extends ScalaDebuggerTestCase { Disposer.register(getTestRootDisposable, frameTree) var testVariableChildren: util.List[DebuggerTreeNode] = null - val testVariable = managed[LocalVariableDescriptorImpl] { + val testVariable = inSuspendContextAction(10.seconds, s"Too long rendering of $variableName") { val context = evaluationContext() val testVariable = localVar(frameTree, context, variableName) val renderer = testVariable.getRenderer(getDebugProcess) testVariable.setRenderer(renderer) - inSuspendContextCommand(context) { - testVariable.updateRepresentation(context, DescriptorLabelListener.DUMMY_LISTENER) + testVariable.updateRepresentation(context, DescriptorLabelListener.DUMMY_LISTENER) - val value = testVariable.calcValue(context) + val value = testVariable.calcValue(context) - renderer.buildChildren(value, new ChildrenBuilder { - override def setChildren(children: util.List[DebuggerTreeNode]) {testVariableChildren = children} + renderer.buildChildren(value, new ChildrenBuilder { + override def setChildren(children: util.List[DebuggerTreeNode]) {testVariableChildren = children} - override def getDescriptorManager: NodeDescriptorFactory = frameTree.getNodeFactory + override def getDescriptorManager: NodeDescriptorFactory = frameTree.getNodeFactory - override def getNodeManager: NodeManager = frameTree.getNodeFactory + override def getNodeManager: NodeManager = frameTree.getNodeFactory - override def setRemaining(remaining: Int): Unit = {} + override def setRemaining(remaining: Int): Unit = {} - override def initChildrenArrayRenderer(renderer: ArrayRenderer, arrayLength: Int): Unit = {} + override def initChildrenArrayRenderer(renderer: ArrayRenderer, arrayLength: Int): Unit = {} - override def getParentDescriptor: ValueDescriptor = testVariable + override def getParentDescriptor: ValueDescriptor = testVariable - override def setErrorMessage(errorMessage: String): Unit = {} + override def setErrorMessage(errorMessage: String): Unit = {} - override def setErrorMessage(errorMessage: String, link: XDebuggerTreeNodeHyperlink): Unit = {} + override def setErrorMessage(errorMessage: String, link: XDebuggerTreeNodeHyperlink): Unit = {} - override def addChildren(children: XValueChildrenList, last: Boolean): Unit = {} + override def addChildren(children: XValueChildrenList, last: Boolean): Unit = {} - override def tooManyChildren(remaining: Int): Unit = {} + override def tooManyChildren(remaining: Int): Unit = {} - override def setMessage(message: String, icon: Icon, attributes: SimpleTextAttributes, link: XDebuggerTreeNodeHyperlink): Unit = {} + override def setMessage(message: String, icon: Icon, attributes: SimpleTextAttributes, link: XDebuggerTreeNodeHyperlink): Unit = {} - override def setAlreadySorted(alreadySorted: Boolean): Unit = {} + override def setAlreadySorted(alreadySorted: Boolean): Unit = {} - override def isObsolete: Boolean = false - }, context) - } + override def isObsolete: Boolean = false + }, context) testVariable } - managed{testVariableChildren.asScala map (_.getDescriptor) foreach { - case impl: NodeDescriptorImpl => - val ctx = evaluationContext() - inSuspendContextCommand(ctx) { + inSuspendContextAction(10.seconds, s"Too long updating children nodes of $variableName") { + testVariableChildren.asScala map (_.getDescriptor) foreach { + case impl: NodeDescriptorImpl => impl.updateRepresentation(evaluationContext(), DescriptorLabelListener.DUMMY_LISTENER) - } - case a => println(a) - }} + case a => println(a) + } + } // evalResult(variableName) // - managed { + inSuspendContextAction(10.seconds, s"Too long rendering of $variableName") { (render(testVariable), testVariableChildren.asScala.map(child => render(child.getDescriptor)).toList) } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/ScalaCollectionRendererTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/ScalaCollectionRendererTestBase.scala index dcc78ce8b8d..9cca87b4a09 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/ScalaCollectionRendererTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/renderers/ScalaCollectionRendererTestBase.scala @@ -1,17 +1,10 @@ package org.jetbrains.plugins.scala.debugger.renderers -import java.util - -import com.intellij.debugger.engine.evaluation.{EvaluateException, EvaluationContextImpl} import com.intellij.debugger.settings.NodeRendererSettings -import com.intellij.debugger.ui.impl.ThreadsDebuggerTree -import com.intellij.debugger.ui.impl.watch._ import com.intellij.debugger.ui.tree.render._ -import com.intellij.debugger.ui.tree.{DebuggerTreeNode, NodeDescriptorFactory, NodeManager, ValueDescriptor} -import com.intellij.openapi.util.Disposer -import org.jetbrains.plugins.scala.{DebuggerTests, SlowTests} import org.jetbrains.plugins.scala.debugger._ import org.jetbrains.plugins.scala.debugger.ui.ScalaCollectionRenderer +import org.jetbrains.plugins.scala.{DebuggerTests, SlowTests} import org.junit.experimental.categories.Category /** diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/smartStepInto/SmartStepIntoTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/smartStepInto/SmartStepIntoTestBase.scala index 1267b6d026d..ddeff0c5d1e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/smartStepInto/SmartStepIntoTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/smartStepInto/SmartStepIntoTestBase.scala @@ -37,30 +37,31 @@ class SmartStepIntoTest_212 extends SmartStepIntoTestBase { abstract class SmartStepIntoTestBase extends ScalaDebuggerTestCase { - protected val handler = new ScalaSmartStepIntoHandler - protected var targets: Seq[SmartStepTarget] = null + protected def handler = new ScalaSmartStepIntoHandler - def availableSmartStepTargets(): Seq[SmartStepTarget] = managed { - inReadAction { - handler.findSmartStepTargets(currentSourcePosition).asScala - } - } + def availableSmartStepTargets(): Seq[SmartStepTarget] = + handler.findSmartStepTargets(currentSourcePosition).asScala def checkSmartStepTargets(expected: String*): Unit = { - targets = availableSmartStepTargets() - Assert.assertEquals("Wrong set of smart step targets:", expected, targets.map(_.getPresentation)) + val targets = inReadAction { + availableSmartStepTargets().map(_.getPresentation) + } + Assert.assertEquals("Wrong set of smart step targets:", expected, targets) } def checkSmartStepInto(target: String, source: String, methodName: String, line: Int) = { - if (targets == null) targets = availableSmartStepTargets() - val sst = targets.find(_.getPresentation == target) + val sst = inReadAction { + availableSmartStepTargets().find(_.getPresentation == target) + } Assert.assertTrue(s"Cannot find such target: $target", sst.isDefined) doSmartStepInto(sst.get) checkLocation(source, methodName, line) } private def doSmartStepInto(target: SmartStepTarget): Unit = { - val filter = handler.createMethodFilter(target) + val filter = inReadAction { + handler.createMethodFilter(target) + } val stepIntoCommand = getDebugProcess.createStepIntoCommand(suspendContext, false, filter) getDebugProcess.getManagerThread.invokeAndWait(stepIntoCommand) waitForBreakpoint() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/stepOver/StepOverCaseClausesTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/stepOver/StepOverCaseClausesTestBase.scala index 3ddf139cab0..2de2eef4174 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/stepOver/StepOverCaseClausesTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/stepOver/StepOverCaseClausesTestBase.scala @@ -60,7 +60,7 @@ abstract class StepOverTest extends StepOverTestBase { s""" |object SkipStoreResult { | def main (args: Array[String]){ - | "" + | ""$bp | val z = Seq(1, 2) match { | case Seq(1, _) => | foo() @@ -109,7 +109,7 @@ abstract class StepOverTest extends StepOverTestBase { s""" |object ComplexPattern { | def main (args: Array[String]){ - | "" + | ""$bp | val z = Seq(left(1), left(2)) match { | case Seq(Right("1")) => | foo() @@ -147,7 +147,7 @@ abstract class StepOverTest extends StepOverTestBase { s""" |object NestedMatch { | def main (args: Array[String]){ - | "" + | ""$bp | val z = Seq(left(1), left(2)) match { | case Seq(Left(Seq(Some(1))), x) => x match { | case Left(Seq(None)) => From c6aa3888faf51abb5f0751cd8655916a10d7f2af Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Wed, 1 Nov 2017 18:25:33 +0300 Subject: [PATCH 114/141] debug in anonymous classes inside package objects fixed #SCL-12810 fixed --- .../scala/debugger/ScalaPositionManager.scala | 19 +++++++- .../positionManager/GetAllClassesTest.scala | 46 +++++++++++++++++++ .../PositionManagerTestBase.scala | 16 ++++--- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala index a42f675e133..bad641f4e60 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala @@ -39,7 +39,6 @@ import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager import org.jetbrains.plugins.scala.lang.psi.types.ValueClassType import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil import org.jetbrains.plugins.scala.util.macroDebug.ScalaMacroDebuggingUtil - import scala.annotation.tailrec import scala.collection.JavaConverters._ import scala.collection.mutable @@ -47,6 +46,8 @@ import scala.collection.mutable.ArrayBuffer import scala.reflect.NameTransformer import scala.util.Try +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScPackaging + /** * @author ilyas */ @@ -128,7 +129,10 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag namePatterns ++= Option(namePattern) } } - val packageName: Option[String] = Option(inReadAction(file.asInstanceOf[ScalaFile].getPackageName)) + val packageName: Option[String] = inReadAction { + possiblePositions.headOption + .flatMap(findPackageName) + } val foundWithPattern = if (namePatterns.isEmpty) Nil @@ -242,6 +246,16 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag case _ => false } + private def findPackageName(position: PsiElement): Option[String] = { + def packageWithName(e: PsiElement): Option[String] = e match { + case p: ScPackaging => Some(p.fullPackageName) + case obj: ScObject if obj.isPackageObject => Some(obj.qualifiedName.stripSuffix("package$")) + case _ => None + } + + position.parentsInFile.flatMap(packageWithName).headOption + } + private def filterAllClasses(condition: ReferenceType => Boolean, packageName: Option[String]): Seq[ReferenceType] = { def samePackage(refType: ReferenceType) = { val name = refType.name() @@ -951,6 +965,7 @@ object ScalaPositionManager { private def partsFor(elem: PsiElement): Seq[String] = { elem match { + case o: ScObject if o.isPackageObject => Seq("package$") case td: ScTypeDefinition => Seq(ScalaNamesUtil.toJavaName(td.name)) case newTd: ScNewTemplateDefinition if DebuggerUtil.generatesAnonClass(newTd) => Seq("$anon") case e if ScalaEvaluatorBuilderUtil.isGenerateClass(e) => partsForAnonfun(e) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/GetAllClassesTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/GetAllClassesTest.scala index 752beecb50a..ca45861facd 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/GetAllClassesTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/GetAllClassesTest.scala @@ -41,6 +41,14 @@ abstract class GetAllClassesTest_212_Base extends GetAllClassesTestBase { override def testSimpleTrait(): Unit = { checkGetAllClasses("Test") } + + override def testAnonfunsInPackageObject() = { + checkGetAllClassesInFile("packageObject/package.scala") ( + "packageObject.package$", + "packageObject.package$", + "packageObject.package$" + ) + } } abstract class GetAllClassesTestBase extends PositionManagerTestBase { @@ -313,4 +321,42 @@ abstract class GetAllClassesTestBase extends PositionManagerTestBase { def testPartialFunctionArg(): Unit = { checkGetAllClasses("PartialFunctionArg$", "PartialFunctionArg$$anonfun$main$1", "PartialFunctionArg$$anonfun$main$1") } + + + setupFile("packageObject/package.scala", + s""" + |package object packageObject { + | + | def packageMethod(): Unit = { + | for { + | ${offsetMarker}i <- 1 to 3 + | ${offsetMarker}j <- 1 to 3 + | } { + | if (i < j) + | () + | else { + | ${offsetMarker}println("!") + | } + | } + | } + |} + """.stripMargin) + setupFile("AnonfunsInPackageObject.scala", + s""" + |import packageObject._ + | + |object AnonfunsInPackageObject { + | def main(args: Array[String]): Unit = { + | packageMethod() + | $bp"" + | } + |} + """.stripMargin, hasOffsets = false) + def testAnonfunsInPackageObject(): Unit = { + checkGetAllClassesInFile("packageObject/package.scala")( + "packageObject.package$", + "packageObject.package$$anonfun$packageMethod$1", + "packageObject.package$$anonfun$packageMethod$1$$anonfun$apply$mcVI$sp$1" + ) + } } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/PositionManagerTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/PositionManagerTestBase.scala index 05251ad8633..f65066ac0c4 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/PositionManagerTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/positionManager/PositionManagerTestBase.scala @@ -19,9 +19,8 @@ abstract class PositionManagerTestBase extends ScalaDebuggerTestCase { protected val offsetMarker = "" protected val sourcePositionsOffsets = mutable.HashMap[String, Seq[Int]]() - //fileText should contain object Main with method main - protected def checkGetAllClasses(expectedClassNames: String*) = { - val sourcePositions = sourcePositionsInFile(mainFileName) + protected def checkGetAllClassesInFile(fileName: String)(expectedClassNames: String*): Unit = { + val sourcePositions = sourcePositionsInFile(fileName) runDebugger() { waitForBreakpoint() @@ -31,11 +30,16 @@ abstract class PositionManagerTestBase extends ScalaDebuggerTestCase { posManager.getAllClasses(position) } val classNames = classes.asScala.map(_.name()) - Assert.assertTrue(s"Wrong classes are found at ${position.toString} (found: ${classNames.mkString(", ")}, expected: $className", classNames.contains(className)) + Assert.assertTrue( + s"Wrong classes are found at ${position.toString} (found: ${classNames.mkString(", ")}, expected: $className", + classNames.contains(className) + ) } } } + protected def checkGetAllClasses(expectedClassNames: String*): Unit = checkGetAllClassesInFile(mainFileName)(expectedClassNames: _*) + protected def checkLocationsOfLine(expectedLocations: Set[Loc]*): Unit = { val sourcePositions = sourcePositionsInFile(mainFileName) Assert.assertEquals("Wrong number of expected locations sets: ", sourcePositions.size, expectedLocations.size) @@ -66,7 +70,7 @@ abstract class PositionManagerTestBase extends ScalaDebuggerTestCase { private def toSimpleLocation(location: Location) = Loc(location.declaringType().name(), location.method().name(), location.lineNumber()) - protected def setupFile(fileName: String, fileText: String): Unit = { + protected def setupFile(fileName: String, fileText: String, hasOffsets: Boolean = true): Unit = { val breakpointLine = fileText.lines.indexWhere(_.contains(bp)) var cleanedText = fileText.replace(bp, "").replace("\r", "") val offsets = ArrayBuffer[Int]() @@ -77,7 +81,7 @@ abstract class PositionManagerTestBase extends ScalaDebuggerTestCase { offset = cleanedText.indexOf(offsetMarker) } - assert(offsets.nonEmpty, s"Not specified offset marker in test case. Use $offsetMarker in provided text of the file.") + assert(!hasOffsets || offsets.nonEmpty, s"Not specified offset marker in test case. Use $offsetMarker in provided text of the file.") sourcePositionsOffsets += (fileName -> offsets) addSourceFile(fileName, cleanedText) From e0f3060193fa75681021fb26ba6e498131341bb8 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Wed, 1 Nov 2017 18:44:46 +0300 Subject: [PATCH 115/141] false positive for "Useless expression inspection" fixed #SCL-11087 fixed --- .../plugins/scala/util/SideEffectsUtil.scala | 1 + .../UselessExpressionInspectionTest.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala index 5993f18cddf..23baef7b580 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/util/SideEffectsUtil.scala @@ -74,6 +74,7 @@ object SideEffectsUtil { } val checkBaseExpr = baseExpr match { case _ if hasImplicitConversion(baseExpr) => false + case u: ScUnderscoreSection => false case ResolvesTo(m: PsiMethod) => methodHasNoSideEffects(m, typeOfQual) case ResolvesTo(_: ScSyntheticFunction) => true case ResolvesTo(_: ScTypedDefinition) => diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/controlFlow/UselessExpressionInspectionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/controlFlow/UselessExpressionInspectionTest.scala index 13b784d8a46..07bd3dcc474 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/controlFlow/UselessExpressionInspectionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInspection/controlFlow/UselessExpressionInspectionTest.scala @@ -260,4 +260,18 @@ class UselessExpressionInspectionTest extends ScalaInspectionTestBase { """ checkTextHasNoErrors(text) } + + def testUnderscoreApply(): Unit = { + val text = + """ + |object ToDo { + | var todo: Option[() => Unit] = None + | + | def doIt() = todo.foreach(_ ()) + | def doItToo() = todo.foreach(_.apply()) + | todo.foreach(_()) + |} + """ + checkTextHasNoErrors(text) + } } From c99ebf1702c380aa0bd4bfc289f25efc00de344a Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 18:45:38 +0300 Subject: [PATCH 116/141] insert bare dependency into a list of dependencies instead creating a new setting fix #SCL-12835 --- .../intention/sbt/AddSbtDependencyUtils.scala | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala index cabfb7c3fec..61967f96065 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala @@ -3,6 +3,7 @@ package org.jetbrains.plugins.scala.annotator.intention.sbt import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.project.Project import com.intellij.openapi.util.text.StringUtil +import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiElement, PsiFile} import org.jetbrains.plugins.scala.annotator.intention.sbt.SbtDependenciesVisitor._ import org.jetbrains.plugins.scala.lang.psi.api.expr._ @@ -26,6 +27,8 @@ object AddSbtDependencyUtils { val SBT_SEQ_TYPE = "_root_.scala.collection.Seq" val SBT_SETTING_TYPE = "_root_.sbt.Def.Setting" + private val InfixOpsSet = Set(":=", "+=", "++=") + def getPossiblePlacesToAddFromProjectDefinition(proj: ScPatternDefinition): Seq[PsiElement] = { var res: Seq[PsiElement] = List() @@ -141,19 +144,18 @@ object AddSbtDependencyUtils { } } - def addDependencyToSeq(seqCall: ScMethodCall, info: ArtifactInfo)(implicit project: Project): Option[PsiElement] = - for { - formalSeq <- ScalaPsiElementFactory.createTypeFromText(SBT_SEQ_TYPE, seqCall, seqCall) - formalSetting <- ScalaPsiElementFactory.createTypeFromText(SBT_SETTING_TYPE, seqCall, seqCall) - Typeable(ParameterizedType(designator, typeArguments)) <- Some(seqCall) - if designator.equiv(formalSeq) - Typeable(ParameterizedType(innerDesignator, _)) <- typeArguments.headOption - if innerDesignator.equiv(formalSetting) - } yield { - val addedExpr: ScInfixExpr = generateLibraryDependency(info) - doInSbtWriteCommandAction(seqCall.args.addExpr(addedExpr), seqCall.getContainingFile) - addedExpr + def addDependencyToSeq(seqCall: ScMethodCall, info: ArtifactInfo)(implicit project: Project): Option[PsiElement] = { + def isValid(expr: ScInfixExpr) = InfixOpsSet.contains(expr.operation.refName) + val parentDef = Option(PsiTreeUtil.getParentOfType(seqCall, classOf[ScInfixExpr])) + val addedExpr = parentDef match { + case Some(expr) if isValid(expr) && expr.lOp.textMatches(LIBRARY_DEPENDENCIES) => + generateArtifactPsiExpression(info) + case _ => generateLibraryDependency(info) } + org.slf4j.LoggerFactory + doInSbtWriteCommandAction(seqCall.args.addExpr(addedExpr), seqCall.getContainingFile) + Some(addedExpr) + } def addDependencyToTypedSeq(typedSeq: ScTypedStmt, info: ArtifactInfo)(implicit project: Project): Option[PsiElement] = typedSeq.expr match { From 475c7a8d62f69c8adb38c3313c9379e4f8acfddf Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 19:54:51 +0300 Subject: [PATCH 117/141] handle errors in sbt dependency dialog fix #SCL-12825 --- .../intention/sbt/AddSbtDependencyUtils.scala | 3 +-- .../sbt/ui/SbtPossiblePlacesPanel.scala | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala index 61967f96065..06192f48821 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala @@ -63,7 +63,7 @@ object AddSbtDependencyUtils { if (pat.expr.isEmpty) return - if (pat.expr.get.`type`().get.canonicalText != SBT_PROJECT_TYPE) + if (pat.expr.get.`type`().getOrAny.canonicalText != SBT_PROJECT_TYPE) return res = res ++ Seq(pat) @@ -152,7 +152,6 @@ object AddSbtDependencyUtils { generateArtifactPsiExpression(info) case _ => generateLibraryDependency(info) } - org.slf4j.LoggerFactory doInSbtWriteCommandAction(seqCall.args.addExpr(addedExpr), seqCall.getContainingFile) Some(addedExpr) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index 12566cbdb5e..728cf951bfe 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -68,20 +68,30 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, while (tmpElement.getTextRange != myCurFileLine.element.getTextRange) { tmpElement = tmpElement.getParent } - val dep = AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project).get + val dep = AddSbtDependencyUtils.addDependency(tmpElement, wizard.resultArtifact.get)(project) extensions.inWriteAction { - myCurEditor.getDocument.setText(tmpFile.getText) + val text = dep match { + case Some(_) => tmpFile.getText + case None => "// Could not generate dependency string, please report this issue" + } + myCurEditor.getDocument.setText(text) } myCurEditor.getCaretModel.moveToOffset(myCurFileLine.offset) - val scrollingModel = myCurEditor.getScrollingModel - val oldPos = myCurEditor.offsetToLogicalPosition(myCurFileLine.offset) + val scrollingModel = myCurEditor.getScrollingModel + val oldPos = myCurEditor.offsetToLogicalPosition(myCurFileLine.offset) scrollingModel.scrollTo(new LogicalPosition(math.max(1, oldPos.line - EDITOR_TOP_MARGIN), oldPos.column), ScrollType.CENTER) val attributes = myCurEditor.getColorsScheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) - myCurEditor.getMarkupModel.addRangeHighlighter(dep.getTextRange.getStartOffset, - dep.getTextRange.getEndOffset, + + val (startOffset, endOffset) = dep match { + case Some(elem) => (elem.getTextRange.getStartOffset, elem.getTextRange.getEndOffset) + case None => (0, 0) + } + myCurEditor.getMarkupModel.addRangeHighlighter( + startOffset, + endOffset, HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE From 840dd538e8d636269ac39841357c331d67133363 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 20:15:55 +0300 Subject: [PATCH 118/141] use "%%" operator when adding dependency if possible fix #SCL-12836 --- .../annotator/intention/sbt/AddSbtDependencyUtils.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala index 06192f48821..b11bf48e61d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyUtils.scala @@ -227,8 +227,12 @@ object AddSbtDependencyUtils { private def generateNewLine(implicit ctx: ProjectContext): PsiElement = ScalaPsiElementFactory.createElementFromText("\n") - private def generateArtifactText(info: ArtifactInfo): String = - s""""${info.groupId}" % "${info.artifactId}" % "${info.version}"""" + private def generateArtifactText(info: ArtifactInfo): String = { + if (info.artifactId.matches("^.+_\\d+\\.\\d+$")) + s""""${info.groupId}" %% "${info.artifactId.replaceAll("_\\d+\\.\\d+$", "")}" % "${info.version}"""" + else + s""""${info.groupId}" % "${info.artifactId}" % "${info.version}"""" + } def getRelativePath(elem: PsiElement)(implicit project: ProjectContext): Option[String] = { for { From 70af35c93058da380dc9eb709c67e1a592bead41 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 21:31:13 +0300 Subject: [PATCH 119/141] search imports by enclosing package if no classes were found fix #SCL-12837 --- .../intention/sbt/AddSbtDependencyFix.scala | 28 +++++++++++++------ .../sbt/resolvers/indexes/IvyIndex.scala | 6 ++-- .../sbt/resolvers/indexes/ResolverIndex.scala | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index 18d3cf94325..4104bdeab85 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -11,6 +11,7 @@ import com.intellij.openapi.module.{ModuleManager, ModuleUtilCore} import com.intellij.openapi.progress.{ProgressIndicator, ProgressManager, Task} import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiElement, PsiFile, PsiManager, SmartPsiElementPointer} import org.jetbrains.plugins.scala.annotator.intention.sbt.AddSbtDependencyUtils._ import org.jetbrains.plugins.scala.annotator.intention.sbt.ui.SbtArtifactSearchWizard @@ -21,6 +22,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr import org.jetbrains.plugins.scala.lang.psi.api.statements.ScPatternDefinition +import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportExpr import org.jetbrains.plugins.scala.project.ModuleExt import org.jetbrains.sbt.Sbt import org.jetbrains.sbt.project.SbtProjectSystem @@ -69,11 +71,20 @@ class AddSbtDependencyFix(refElement: SmartPsiElementPointer[ScReferenceElement] import com.intellij.notification.Notifications.Bus def error(msg: String): Unit = Bus.notify(new Notification(getText, getText, msg, NotificationType.ERROR)) def getDeps: Set[ArtifactInfo] = { + def doSearch(name: String): Set[ArtifactInfo] = resolver.getIndex(project) + .map(_.searchArtifactInfo(name)) + .getOrElse(Set.empty) indicator.setText("Searching for artifacts...") val fqName = extensions.inReadAction(getReferenceText) - val artifactInfoSet = resolver.getIndex(project) - .map(_.searchArtifactInfo(fqName)) - .getOrElse(Set.empty) + val artifactInfoSet = if (fqName.endsWith("._")) { // search wildcard imports by containing package + doSearch(fqName.replaceAll("_$", "")) + } else { + doSearch(fqName) match { + case set if set.isEmpty && fqName.contains(".") => // imported name is not a class -> search for enclosing package + doSearch(fqName.substring(0, fqName.lastIndexOf(".") + 1)) + case result => result + } + } extensions.inReadAction(filterByScalaVer(artifactInfoSet)) } @@ -158,12 +169,11 @@ class AddSbtDependencyFix(refElement: SmartPsiElementPointer[ScReferenceElement] proj.getText.contains("\"" + moduleName + "\"") private def getReferenceText: String = { - var result = refElement.getElement - while (result.getParent.isInstanceOf[ScReferenceElement]) { - result = result.getParent.asInstanceOf[ScReferenceElement] - } - - result.getText + val importExpr = PsiTreeUtil.getParentOfType(refElement.getElement, classOf[ScImportExpr]) + if (!importExpr.isSingleWildcard) + s"${importExpr.qualifier.getText}.${refElement.getElement.getText}" // for "import x.y.{foo, bar=>baz}" and so on + else + importExpr.getText } override def getFamilyName = "Add sbt dependencies" diff --git a/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala b/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala index 24620f15b59..3969ab92bd9 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala @@ -212,11 +212,13 @@ class IvyIndex(val root: String, val name: String) extends ResolverIndex { val classExt = ".class" val entries = jarFile.entries().asScala - .filter(e => e.getName.endsWith(classExt) && !e.getName.contains("$")) + .filter(e => (e.getName.endsWith(classExt) && !e.getName.contains("$")) || + e.getName.endsWith("/") || e.getName.endsWith("\\")) entries .map(e => e.getName) - .map(name => name.replaceAll("/", ".").substring(0, name.length - classExt.length)) + .map(name => name.replaceAll("/", ".")) + .map(name => if (name.endsWith(classExt)) name.substring(0, name.length - classExt.length) else name) .toStream } diff --git a/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/ResolverIndex.scala b/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/ResolverIndex.scala index 8073215ba66..8d0863aa45b 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/ResolverIndex.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/ResolverIndex.scala @@ -34,7 +34,7 @@ trait ResolverIndex { object ResolverIndex { val DEFAULT_INDEXES_DIR: File = new File(PathManager.getSystemPath) / "sbt" / "indexes" - val CURRENT_INDEX_VERSION = "3" + val CURRENT_INDEX_VERSION = "5" val NO_TIMESTAMP: Int = -1 val MAVEN_UNAVALIABLE: Int = -2 def getIndexDirectory(root: String) = new File(indexesDir, root.shaDigest) From c0ea69f143e88401295cfa3c01d78d2a3694b371 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 22:44:33 +0300 Subject: [PATCH 120/141] fix imported fqname incorrectly generated #SCL-12837 --- .../scala/annotator/intention/sbt/AddSbtDependencyFix.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index 4104bdeab85..387f085131d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -170,7 +170,7 @@ class AddSbtDependencyFix(refElement: SmartPsiElementPointer[ScReferenceElement] private def getReferenceText: String = { val importExpr = PsiTreeUtil.getParentOfType(refElement.getElement, classOf[ScImportExpr]) - if (!importExpr.isSingleWildcard) + if (refElement.getElement.qualifier.isEmpty) s"${importExpr.qualifier.getText}.${refElement.getElement.getText}" // for "import x.y.{foo, bar=>baz}" and so on else importExpr.getText From e19194bc36b8acba615e0ed75a9429a7b35fe1a4 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 22:55:05 +0300 Subject: [PATCH 121/141] colorize dependency display in a list #SCL-10997 --- .../intention/sbt/ui/SbtArtifactSearchPanel.scala | 4 +++- .../intention/sbt/ui/SbtPossiblePlacesPanel.scala | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala index e3ad9fee0da..e23b11dc177 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtArtifactSearchPanel.scala @@ -45,7 +45,9 @@ class SbtArtifactSearchPanel(wizard: SbtArtifactSearchWizard, artifactInfoSet: S private class DependencyListCellRenderer extends ColoredListCellRenderer[ArtifactInfo] { override def customizeCellRenderer(list: JList[_ <: ArtifactInfo], value: ArtifactInfo, index: Int, selected: Boolean, hasFocus: Boolean): Unit = { setIcon(AllIcons.Modules.Library) - append(s"${value.groupId}:${value.artifactId}:${value.version}") + append(s"${value.groupId}:", SimpleTextAttributes.GRAY_ATTRIBUTES) + append(value.artifactId) + append(s":${value.version}", SimpleTextAttributes.GRAY_ATTRIBUTES) } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala index 728cf951bfe..1aa136ee69e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/ui/SbtPossiblePlacesPanel.scala @@ -115,12 +115,10 @@ class SbtPossiblePlacesPanel(project: Project, wizard: SbtArtifactSearchWizard, private class PlacesCellRenderer extends ColoredListCellRenderer[DependencyPlaceInfo] { override def customizeCellRenderer(list: JList[_ <: DependencyPlaceInfo], info: DependencyPlaceInfo, index: Int, selected: Boolean, hasFocus: Boolean): Unit = { setIcon(org.jetbrains.plugins.scala.icons.Icons.SBT_FILE) - append(info.path + ":", SimpleTextAttributes.REGULAR_ATTRIBUTES) - append(info.line.toString, getGrayAttributes(selected)) + append(info.path + ":") + append(info.line.toString, SimpleTextAttributes.GRAY_ATTRIBUTES) if (info.affectedProjects.nonEmpty) - append(" (" + info.affectedProjects.map(_.toString).mkString(", ") + ")", SimpleTextAttributes.REGULAR_ATTRIBUTES) + append(" (" + info.affectedProjects.map(_.toString).mkString(", ") + ")") } - private def getGrayAttributes(selected: Boolean): SimpleTextAttributes = - if (!selected) SimpleTextAttributes.GRAY_ATTRIBUTES else SimpleTextAttributes.REGULAR_ATTRIBUTES } } \ No newline at end of file From 573821d78b32d38b8df7156d9eeb57cc14a5f4dd Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Wed, 1 Nov 2017 22:59:05 +0300 Subject: [PATCH 122/141] disable add dependency quickfix for shortnames #SCL-10997 --- .../org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index fc14ab751d6..78d76bfd066 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -797,7 +797,6 @@ abstract class ScalaAnnotator extends Annotator annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) annotation.registerFix(ReportHighlightingErrorQuickFix) registerCreateFromUsageFixesFor(refElement, annotation) - annotation.registerFix(new AddSbtDependencyFix(SmartPointerManager.getInstance(refElement.getProject).createSmartPsiElementPointer(refElement))) } } From 8335e959cb2da2af2fc1153913e1aadd3cc0309b Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Thu, 2 Nov 2017 12:11:38 +0300 Subject: [PATCH 123/141] reuse PsiClass search from position manager in runtime type evaluator, + more accurate scope #SCL-12840 fixed --- .../scala/debugger/ScalaPositionManager.scala | 62 ++++---------- .../ScalaRuntimeTypeEvaluator.scala | 80 ++++++++----------- .../evaluation/util/DebuggerUtil.scala | 41 +++++++++- 3 files changed, 88 insertions(+), 95 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala index bad641f4e60..f39d798c96c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaPositionManager.scala @@ -25,7 +25,7 @@ import org.jetbrains.plugins.scala.caches.ScalaShortNamesCacheManager import org.jetbrains.plugins.scala.debugger.ScalaPositionManager._ import org.jetbrains.plugins.scala.debugger.evaluation.ScalaEvaluatorBuilderUtil import org.jetbrains.plugins.scala.debugger.evaluation.evaluator.ScalaCompilingEvaluator -import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil +import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil._ import org.jetbrains.plugins.scala.debugger.filters.ScalaDebuggerSettings import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes @@ -46,6 +46,7 @@ import scala.collection.mutable.ArrayBuffer import scala.reflect.NameTransformer import scala.util.Try +import org.jetbrains.plugins.scala.lang.psi.ElementScope import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScPackaging /** @@ -57,6 +58,8 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag private val outerAndNestedTypePartsPattern = """([^\$]*)(\$.*)?""".r import caches._ + implicit val scope: ElementScope = ElementScope(debugProcess.getProject, debugProcess.getSearchScope) + ScalaPositionManager.cacheInstance(this) @Nullable @@ -116,11 +119,11 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag val sourceImages = onTheLine ++ nonLambdaParent sourceImages.foreach { case null => - case tr: ScTrait if !DebuggerUtil.isLocalClass(tr) => + case tr: ScTrait if !isLocalClass(tr) => val traitImplName = getSpecificNameForDebugger(tr) val simpleName = traitImplName.stripSuffix("$class") Seq(simpleName, traitImplName).foreach(addExactClasses) - case td: ScTypeDefinition if !DebuggerUtil.isLocalClass(td) => + case td: ScTypeDefinition if !isLocalClass(td) => val qName = getSpecificNameForDebugger(td) val delayedBodyName = if (isDelayedInit(td)) Seq(s"$qName$delayedInitBody") else Nil (qName +: delayedBodyName).foreach(addExactClasses) @@ -168,7 +171,7 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag override def createPrepareRequests(requestor: ClassPrepareRequestor, position: SourcePosition): util.List[ClassPrepareRequest] = { def isLocalOrUnderDelayedInit(definition: PsiClass): Boolean = { - DebuggerUtil.isLocalClass(definition) || isDelayedInit(definition) + isLocalClass(definition) || isDelayedInit(definition) } def findEnclosingTypeDefinition: Option[ScTypeDefinition] = { @@ -176,7 +179,7 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag def notLocalEnclosingTypeDefinition(element: PsiElement): Option[ScTypeDefinition] = { PsiTreeUtil.getParentOfType(element, classOf[ScTypeDefinition]) match { case null => None - case td if DebuggerUtil.isLocalClass(td) => notLocalEnclosingTypeDefinition(td.getParent) + case td if isLocalClass(td) => notLocalEnclosingTypeDefinition(td.getParent) case td => Some(td) } } @@ -209,7 +212,7 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag case cl: ScClass if ValueClassType.isValueClass(cl) => //there are no instances of value classes, methods from companion object are used qName.set(getSpecificNameForDebugger(cl) + "$") - case tr: ScTrait if !DebuggerUtil.isLocalClass(tr) => + case tr: ScTrait if !isLocalClass(tr) => //to handle both trait methods encoding qName.set(tr.getQualifiedNameForDebugger + "*") case typeDef: ScTypeDefinition if !isLocalOrUnderDelayedInit(typeDef) => @@ -450,8 +453,8 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag else originalQName.replace(packageSuffix, ".").takeWhile(_ != '$') } def tryToFindClass(name: String) = { - findClassByQualName(name, isScalaObject = false) - .orElse(findClassByQualName(name, isScalaObject = true)) + findClassByQName(name, isScalaObject = false) + .orElse(findClassByQName(name, isScalaObject = true)) } val scriptFile = findScriptFile(refType) @@ -504,7 +507,7 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag private def findElementByReferenceTypeInner(refType: ReferenceType): Option[PsiElement] = { - val byName = findByQualName(refType) orElse findByShortName(refType) + val byName = findPsiClassByQName(refType) orElse findByShortName(refType) if (byName.isDefined) return byName val project = debugProcess.getProject @@ -565,7 +568,7 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag val applySignature = refType.methodsByName("apply").asScala.find(m => !m.isSynthetic).map(_.signature()) if (applySignature.isEmpty) candidates else { - candidates.filter(l => applySignature == DebuggerUtil.lambdaJVMSignature(l)) + candidates.filter(l => applySignature == lambdaJVMSignature(l)) } } @@ -593,38 +596,6 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag filteredWithSignature.headOption } - private def findClassByQualName(qName: String, isScalaObject: Boolean): Option[PsiClass] = { - val project = debugProcess.getProject - - val cacheManager = ScalaShortNamesCacheManager.getInstance(project) - val classes = - if (qName.endsWith(packageSuffix)) - Option(cacheManager.getPackageObjectByName(qName.stripSuffix(packageSuffix), GlobalSearchScope.allScope(project))).toSeq - else - cacheManager.getClassesByFQName(qName.replace(packageSuffix, "."), debugProcess.getSearchScope) - - val clazz = - if (classes.length == 1) classes.headOption - else if (classes.length >= 2) { - if (isScalaObject) classes.find(_.isInstanceOf[ScObject]) - else classes.find(!_.isInstanceOf[ScObject]) - } - else None - clazz.filter(_.isValid) - } - - private def findByQualName(refType: ReferenceType): Option[PsiClass] = { - val originalQName = NameTransformer.decode(refType.name) - val endsWithPackageSuffix = originalQName.endsWith(packageSuffix) - val withoutSuffix = - if (endsWithPackageSuffix) originalQName.stripSuffix(packageSuffix) - else originalQName.stripSuffix("$").stripSuffix("$class") - val withDots = withoutSuffix.replace(packageSuffix, ".").replace('$', '.') - val transformed = if (endsWithPackageSuffix) withDots + packageSuffix else withDots - - findClassByQualName(transformed, originalQName.endsWith("$")) - } - private def findByShortName(refType: ReferenceType): Option[PsiClass] = { val project = debugProcess.getProject @@ -692,7 +663,6 @@ class ScalaPositionManager(val debugProcess: DebugProcess) extends PositionManag object ScalaPositionManager { private val SCRIPT_HOLDER_CLASS_NAME: String = "Main$$anon$1" - private val packageSuffix = ".package$" private val delayedInitBody = "delayedInit$body" private val isCompiledWithIndyLambdasCache = mutable.HashMap[PsiFile, Boolean]() @@ -779,7 +749,7 @@ object ScalaPositionManager { val parentsOnTheLine = element.withParentsInFile.takeWhile(e => e.getTextOffset > startLine).toIndexedSeq val anon = parentsOnTheLine.collectFirst { case e if isLambda(e) => e - case newTd: ScNewTemplateDefinition if DebuggerUtil.generatesAnonClass(newTd) => newTd + case newTd: ScNewTemplateDefinition if generatesAnonClass(newTd) => newTd } val filteredParents = parentsOnTheLine.reverse.filter { case _: ScExpression => true @@ -944,7 +914,7 @@ object ScalaPositionManager { private var compiledWithIndyLambdas = isCompiledWithIndyLambdas(containingFile) private val exactName: Option[String] = { elem match { - case td: ScTypeDefinition if !DebuggerUtil.isLocalClass(td) => + case td: ScTypeDefinition if !isLocalClass(td) => Some(getSpecificNameForDebugger(td)) case _ => None } @@ -967,7 +937,7 @@ object ScalaPositionManager { elem match { case o: ScObject if o.isPackageObject => Seq("package$") case td: ScTypeDefinition => Seq(ScalaNamesUtil.toJavaName(td.name)) - case newTd: ScNewTemplateDefinition if DebuggerUtil.generatesAnonClass(newTd) => Seq("$anon") + case newTd: ScNewTemplateDefinition if generatesAnonClass(newTd) => Seq("$anon") case e if ScalaEvaluatorBuilderUtil.isGenerateClass(e) => partsForAnonfun(e) case _ => Seq.empty } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala index 2dcfada78ee..cf1fb9643af 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala @@ -1,32 +1,28 @@ package org.jetbrains.plugins.scala package debugger.evaluation +import scala.collection.JavaConverters._ + +import com.intellij.debugger.{DebuggerBundle, DebuggerInvocationUtil, EvaluatingComputable} import com.intellij.debugger.codeinsight.RuntimeTypeEvaluator import com.intellij.debugger.engine.ContextUtil import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator import com.intellij.debugger.engine.evaluation.{CodeFragmentKind, EvaluationContextImpl, TextWithImportsImpl} import com.intellij.debugger.impl.DebuggerContextImpl -import com.intellij.debugger.{DebuggerBundle, DebuggerInvocationUtil, EvaluatingComputable} -import com.intellij.openapi.application.{AccessToken, ReadAction} import com.intellij.openapi.editor.Editor import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.psi._ import com.intellij.psi.impl.source.PsiImmediateClassType -import com.intellij.psi.search.GlobalSearchScope -import com.sun.jdi.{ClassType, Type, Value} +import com.sun.jdi.{ClassType, ReferenceType, Type, Value} import org.jetbrains.annotations.Nullable import org.jetbrains.plugins.scala.debugger.evaluation.ScalaRuntimeTypeEvaluator._ import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil -import org.jetbrains.plugins.scala.extensions.inReadAction +import org.jetbrains.plugins.scala.extensions.{IteratorExt, inReadAction} +import org.jetbrains.plugins.scala.lang.psi.ElementScope import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression -import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScModifierListOwner -import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject -import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager import org.jetbrains.plugins.scala.lang.psi.types.ScType -import org.jetbrains.plugins.scala.lang.psi.types.api.ExtractClass -import scala.collection.JavaConverters._ /** * Nikolay.Tropin @@ -37,6 +33,8 @@ abstract class ScalaRuntimeTypeEvaluator(@Nullable editor: Editor, expression: P override def evaluate(evaluationContext: EvaluationContextImpl): PsiType = { val project: Project = evaluationContext.getProject + val process = context.getDebugProcess + if (process == null) return null val evaluator: ExpressionEvaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable[ExpressionEvaluator] { def compute: ExpressionEvaluator = { @@ -48,7 +46,8 @@ abstract class ScalaRuntimeTypeEvaluator(@Nullable editor: Editor, expression: P val value: Value = evaluator.evaluate(evaluationContext) if (value != null) { inReadAction { - Option(getCastableRuntimeType(project, value)).map(new PsiImmediateClassType(_, PsiSubstitutor.EMPTY)).orNull + getCastableRuntimeType(project, value)(ElementScope(project, process.getSearchScope)) + .map(new PsiImmediateClassType(_, PsiSubstitutor.EMPTY)).orNull } } else throw EvaluationException(DebuggerBundle.message("evaluation.error.surrounded.expression.null")) } @@ -58,51 +57,38 @@ object ScalaRuntimeTypeEvaluator { val KEY: Key[ScExpression => ScType] = Key.create("SCALA_RUNTIME_TYPE_EVALUATOR") - def getCastableRuntimeType(project: Project, value: Value): PsiClass = { + private val stdTypeNames = Set("java.lang.Object", "scala.Any", "scala.AnyRef", "scala.AnyVal") + + private def getCastableRuntimeType(project: Project, value: Value)(implicit elementScope: ElementScope): Option[PsiClass] = { val unwrapped = DebuggerUtil.unwrapScalaRuntimeRef(value) val jdiType: Type = unwrapped.asInstanceOf[Value].`type` - var psiClass: PsiClass = findPsiClass(project, jdiType) - if (psiClass != null) { - return psiClass + + findPsiClass(jdiType).orElse { + findBaseClass(jdiType) } + } + + private def findBaseClass(jdiType: Type)(implicit elementScope: ElementScope): Option[PsiClass] = { jdiType match { case classType: ClassType => val superclass: ClassType = classType.superclass - val stdTypeNames = Seq("java.lang.Object", "scala.Any", "scala.AnyRef", "scala.AnyVal") - if (superclass != null && !stdTypeNames.contains(superclass.name)) { - psiClass = findPsiClass(project, superclass) - if (psiClass != null) { - return psiClass - } - } - classType.interfaces.asScala - .map(findPsiClass(project, _)) - .find(_ != null) - .orNull - case _ => null + if (superclass != null && !stdTypeNames.contains(superclass.name)) + findPsiClass(superclass) + else + classType.interfaces.iterator().asScala + .flatMap(findPsiClass(_)) + .headOption + case _ => + None } } - private def findPsiClass(project: Project, jdiType: Type): PsiClass = { - val token: AccessToken = ReadAction.start - try { - ScalaPsiManager.instance(project).getCachedClass(GlobalSearchScope.allScope(project), jdiType.name()).orNull - } - finally { - token.finish() - } - } - - def isSubtypeable(scType: ScType): Boolean = { - scType match { - case ExtractClass(psiClass) => - psiClass match { - case _: ScObject => false - case owner: ScModifierListOwner => !owner.hasFinalModifier - case _ if scType.isInstanceOf[PsiPrimitiveType] => false - case _ => !psiClass.hasModifierProperty(PsiModifier.FINAL) - } - case _ => false + private def findPsiClass(jdiType: Type)(implicit elementScope: ElementScope): Option[PsiClass] = { + jdiType match { + case refType: ReferenceType => + inReadAction(DebuggerUtil.findPsiClassByQName(refType)) + case _ => + None } } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala index 548fa9288b8..51eefd6d553 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/util/DebuggerUtil.scala @@ -14,7 +14,7 @@ import org.jetbrains.plugins.scala.debugger.evaluation.{EvaluationException, Sca import org.jetbrains.plugins.scala.debugger.filters.ScalaDebuggerSettings import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil +import org.jetbrains.plugins.scala.lang.psi.{ElementScope, ScalaPsiUtil} import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScBindingPattern, ScCaseClause} import org.jetbrains.plugins.scala.lang.psi.api.base.{ScMethodLike, ScPrimaryConstructor, ScReferenceElement} import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScAnnotations, ScExpression, ScForStatement, ScNewTemplateDefinition} @@ -28,16 +28,21 @@ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScSubstitutor, ScType, ValueClassType} - import scala.annotation.tailrec import scala.collection.mutable import scala.collection.mutable.ArrayBuffer +import scala.reflect.NameTransformer + +import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.plugins.scala.caches.ScalaShortNamesCacheManager /** * User: Alefas * Date: 19.10.11 */ object DebuggerUtil { + val packageSuffix = ".package$" + class JVMNameBuffer { def append(evaluator: JVMName) { buffer += evaluator @@ -575,4 +580,36 @@ object DebuggerUtil { case _ => elem } } + + def findClassByQName(qName: String, isScalaObject: Boolean)(implicit elementScope: ElementScope): Option[PsiClass] = { + val project = elementScope.project + + val cacheManager = ScalaShortNamesCacheManager.getInstance(project) + val classes = + if (qName.endsWith(packageSuffix)) + Option(cacheManager.getPackageObjectByName(qName.stripSuffix(packageSuffix), elementScope.scope)).toSeq + else + cacheManager.getClassesByFQName(qName.replace(packageSuffix, "."), elementScope.scope) + + val clazz = + if (classes.length == 1) classes.headOption + else if (classes.length >= 2) { + if (isScalaObject) classes.find(_.isInstanceOf[ScObject]) + else classes.find(!_.isInstanceOf[ScObject]) + } + else None + clazz.filter(_.isValid) + } + + def findPsiClassByQName(refType: ReferenceType)(implicit elementScope: ElementScope): Option[PsiClass] = { + val originalQName = NameTransformer.decode(refType.name) + val endsWithPackageSuffix = originalQName.endsWith(packageSuffix) + val withoutSuffix = + if (endsWithPackageSuffix) originalQName.stripSuffix(packageSuffix) + else originalQName.stripSuffix("$").stripSuffix("$class") + val withDots = withoutSuffix.replace(packageSuffix, ".").replace('$', '.') + val transformed = if (endsWithPackageSuffix) withDots + packageSuffix else withDots + + findClassByQName(transformed, originalQName.endsWith("$")) + } } From df08731cc0de02ae8418397136ca77988ac4cf13 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Thu, 2 Nov 2017 12:17:53 +0300 Subject: [PATCH 124/141] possible deadlock in debugger fixed #SCL-12560 fixed --- .../ScalaFrameExtraVariablesProvider.scala | 12 ++++++------ .../evaluation/ScalaRuntimeTypeEvaluator.scala | 14 ++++++-------- .../evaluator/ScalaCompilingEvaluator.scala | 15 ++++++--------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaFrameExtraVariablesProvider.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaFrameExtraVariablesProvider.scala index 4f36f84a410..f167f37f4e8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaFrameExtraVariablesProvider.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/ScalaFrameExtraVariablesProvider.scala @@ -119,13 +119,13 @@ class ScalaFrameExtraVariablesProvider extends FrameExtraVariablesProvider { } } - inReadAction { - srr.getElement match { - case named if generatorNotFromBody(named, place) => tryEvaluate(named.name, place, evaluationContext).isSuccess - case named: PsiNamedElement if notUsedInCurrentClass(named, place) => tryEvaluate(named.name, place, evaluationContext).isSuccess - case _ => true - } + val named = srr.getElement + + if (generatorNotFromBody(named, place) || notUsedInCurrentClass(named, place)) { + val name = inReadAction(named.name) + tryEvaluate(name, place, evaluationContext).isSuccess } + else true } private def isInCatchBlock(cc: ScCaseClause): Boolean = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala index cf1fb9643af..ba60fba9f22 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/ScalaRuntimeTypeEvaluator.scala @@ -3,7 +3,7 @@ package debugger.evaluation import scala.collection.JavaConverters._ -import com.intellij.debugger.{DebuggerBundle, DebuggerInvocationUtil, EvaluatingComputable} +import com.intellij.debugger.DebuggerBundle import com.intellij.debugger.codeinsight.RuntimeTypeEvaluator import com.intellij.debugger.engine.ContextUtil import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator @@ -36,13 +36,11 @@ abstract class ScalaRuntimeTypeEvaluator(@Nullable editor: Editor, expression: P val process = context.getDebugProcess if (process == null) return null - val evaluator: ExpressionEvaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable[ExpressionEvaluator] { - def compute: ExpressionEvaluator = { - val textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, expression.getText) - val codeFragment = new ScalaCodeFragmentFactory().createCodeFragment(textWithImports, expression, project) - ScalaEvaluatorBuilder.build(codeFragment, ContextUtil.getSourcePosition(evaluationContext)) - } - }) + val evaluator: ExpressionEvaluator = inReadAction { + val textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, expression.getText) + val codeFragment = new ScalaCodeFragmentFactory().createCodeFragment(textWithImports, expression, project) + ScalaEvaluatorBuilder.build(codeFragment, ContextUtil.getSourcePosition(evaluationContext)) + } val value: Value = evaluator.evaluate(evaluationContext) if (value != null) { inReadAction { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala index 052121f8e0e..4d4b4db7fc7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/debugger/evaluation/evaluator/ScalaCompilingEvaluator.scala @@ -83,15 +83,12 @@ class ScalaCompilingEvaluator(psiContext: PsiElement, fragment: ScalaCodeFragmen } } - private def callEvaluator(evaluationContext: EvaluationContext): ExpressionEvaluator = { - DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable[ExpressionEvaluator] { - override def compute(): ExpressionEvaluator = { - val callCode = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, generatedClass.callText) - val codeFragment = new ScalaCodeFragmentFactory().createCodeFragment(callCode, generatedClass.getAnchor, project) - ScalaEvaluatorBuilder.build(codeFragment, SourcePosition.createFromElement(generatedClass.getAnchor)) - } - }) - } + private def callEvaluator(evaluationContext: EvaluationContext): ExpressionEvaluator = + inReadAction { + val callCode = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, generatedClass.callText) + val codeFragment = new ScalaCodeFragmentFactory().createCodeFragment(callCode, generatedClass.getAnchor, project) + ScalaEvaluatorBuilder.build(codeFragment, SourcePosition.createFromElement(generatedClass.getAnchor)) + } private def defineClasses(classes: Seq[OutputFileObject], context: EvaluationContext, process: DebugProcess, classLoader: ClassLoaderReference): Unit = { From 945266bec99340b28e3b91e9b1e8e520f44f412c Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Thu, 2 Nov 2017 16:42:20 +0300 Subject: [PATCH 125/141] only show add dep quickfix in import expressions fix #SCL-12843 #SCL-12845 --- .../jetbrains/plugins/scala/annotator/ScalaAnnotator.scala | 5 ++++- .../annotator/intention/sbt/AddSbtDependencyFix.scala | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index 78d76bfd066..300bf53112c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -797,6 +797,8 @@ abstract class ScalaAnnotator extends Annotator annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) annotation.registerFix(ReportHighlightingErrorQuickFix) registerCreateFromUsageFixesFor(refElement, annotation) + if (PsiTreeUtil.getParentOfType(refElement, classOf[ScImportExpr]) != null) + annotation.registerFix(new AddSbtDependencyFix(SmartPointerManager.getInstance(refElement.getProject).createSmartPsiElementPointer(refElement))) } } @@ -866,7 +868,8 @@ abstract class ScalaAnnotator extends Annotator annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) annotation.registerFix(ReportHighlightingErrorQuickFix) registerCreateFromUsageFixesFor(refElement, annotation) - annotation.registerFix(new AddSbtDependencyFix(SmartPointerManager.getInstance(refElement.getProject).createSmartPsiElementPointer(refElement))) + if (PsiTreeUtil.getParentOfType(refElement, classOf[ScImportExpr]) != null) + annotation.registerFix(new AddSbtDependencyFix(SmartPointerManager.getInstance(refElement.getProject).createSmartPsiElementPointer(refElement))) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index 387f085131d..97668a3f059 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -77,7 +77,10 @@ class AddSbtDependencyFix(refElement: SmartPsiElementPointer[ScReferenceElement] indicator.setText("Searching for artifacts...") val fqName = extensions.inReadAction(getReferenceText) val artifactInfoSet = if (fqName.endsWith("._")) { // search wildcard imports by containing package - doSearch(fqName.replaceAll("_$", "")) + doSearch(fqName.replaceAll("_$", "")) match { + case set if set.isEmpty => doSearch(fqName.replaceAll("._$", "")) // not a package, try searching for a class + case result => result + } } else { doSearch(fqName) match { case set if set.isEmpty && fqName.contains(".") => // imported name is not a class -> search for enclosing package @@ -170,7 +173,7 @@ class AddSbtDependencyFix(refElement: SmartPsiElementPointer[ScReferenceElement] private def getReferenceText: String = { val importExpr = PsiTreeUtil.getParentOfType(refElement.getElement, classOf[ScImportExpr]) - if (refElement.getElement.qualifier.isEmpty) + if (importExpr.selectors.size > 1 || importExpr.selectors.exists(_.isAliasedImport)) s"${importExpr.qualifier.getText}.${refElement.getElement.getText}" // for "import x.y.{foo, bar=>baz}" and so on else importExpr.getText From 057c60265ab367be34ae3c98affdcc9e2712af68 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Thu, 2 Nov 2017 16:43:23 +0300 Subject: [PATCH 126/141] improve artifact indexing responsiveness --- .../annotator/intention/sbt/AddSbtDependencyFix.scala | 5 +++++ .../jetbrains/sbt/resolvers/indexes/IvyIndex.scala | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala index 97668a3f059..6df7e42e223 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/intention/sbt/AddSbtDependencyFix.scala @@ -105,6 +105,11 @@ class AddSbtDependencyFix(refElement: SmartPsiElementPointer[ScReferenceElement] indicator.setIndeterminate(true) + resolver.getIndex(project).foreach { + indicator.setText("Updating dependency index...") + _.doUpdate(Some(indicator))(project) + } + val deps = getDeps if (deps.isEmpty) { error("No dependencies found for given import") diff --git a/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala b/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala index 3969ab92bd9..e4e3f468720 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/resolvers/indexes/IvyIndex.scala @@ -33,7 +33,8 @@ class IvyIndex(val root: String, val name: String) extends ResolverIndex { if (artifactToGroupMap.isCorrupted || groupToArtifactMap.isCorrupted || groupArtifactToVersionMap.isCorrupted || - fqNameToGroupArtifactVersionMap.isCorrupted) + fqNameToGroupArtifactVersionMap.isCorrupted || + currentVersion.toInt < CURRENT_INDEX_VERSION.toInt) deleteIndex() } @@ -100,7 +101,7 @@ class IvyIndex(val root: String, val name: String) extends ResolverIndex { fqNameGavMap.getOrElseUpdate(fqName, mutable.Set.empty) ++= artifacts } - val ivyCacheEnumerator = new SbtIvyCacheEnumerator(new File(root)) + val ivyCacheEnumerator = new SbtIvyCacheEnumerator(new File(root), progressIndicator) ivyCacheEnumerator.artifacts.foreach(processArtifact) ivyCacheEnumerator.fqNameToArtifacts.foreach(processFqNames) @@ -194,19 +195,21 @@ class IvyIndex(val root: String, val name: String) extends ResolverIndex { } } - private[indexes] class SbtIvyCacheEnumerator(val cacheDir: File) { + private[indexes] class SbtIvyCacheEnumerator(val cacheDir: File, progressIndicator: Option[ProgressIndicator]) { val fqNameToArtifacts: mutable.Map[String, mutable.Set[ArtifactInfo]] = mutable.Map.empty private val ivyFileFilter = new FileFilter { override def accept(file: File): Boolean = file.name.endsWith(".xml") && - (file.lastModified() > innerTimestamp || currentVersion.toInt < CURRENT_INDEX_VERSION.toInt) + (file.lastModified() > innerTimestamp) } def artifacts: Stream[ArtifactInfo] = listArtifacts(cacheDir) private def fqNamesFromJarFile(file: File): Stream[String] = { + progressIndicator.foreach(_.setText2(file.getAbsolutePath)) + val jarFile = new JarFile(file) val classExt = ".class" From 6ceefa9696bd03d0da74588341854e943f2c221d Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Thu, 2 Nov 2017 21:16:45 +0300 Subject: [PATCH 127/141] don't use acquireShellProcessHandler for adding/removing listeners, it may have unexpected side effects #SCL-12167 --- .../src/org/jetbrains/sbt/shell/SbtProcessManager.scala | 6 ------ .../src/org/jetbrains/sbt/shell/SbtShellRunner.scala | 5 ++--- .../src/org/jetbrains/sbt/shell/communication.scala | 6 ++++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala index cbd43384f07..fb7075a995d 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtProcessManager.scala @@ -187,12 +187,6 @@ class SbtProcessManager(project: Project) extends AbstractProjectComponent(proje pd } - def attachListener(listener: ProcessAdapter): Unit = - acquireShellProcessHandler.addProcessListener(listener) - - def removeListener(listener: ProcessAdapter): Unit = - acquireShellProcessHandler.removeProcessListener(listener) - /** Supply a PrintWriter that writes to the current process. */ def usingWriter[T](f: PrintWriter => T): T = { val writer = new PrintWriter(new OutputStreamWriter(acquireShellProcessHandler.getProcessInput)) diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala index f218b5a98dc..98a06ad8f48 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/SbtShellRunner.scala @@ -94,9 +94,8 @@ class SbtShellRunner(project: Project, consoleTitle: String, debugConnection: Op whenReady = scrollToEnd(), whenWorking = scrollToEnd() ) - val processManager = SbtProcessManager.forProject(project) - processManager.attachListener(shellPromptChanger) - processManager.attachListener(scrollOnStateChange) + myProcessHandler.addProcessListener(shellPromptChanger) + myProcessHandler.addProcessListener(scrollOnStateChange) SbtShellCommunication.forProject(project).initCommunication(myProcessHandler) if (!SbtRunner.isInTest) { diff --git a/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala b/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala index 5ffa02db9a4..e72d977234e 100644 --- a/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala +++ b/scala/scala-impl/src/org/jetbrains/sbt/shell/communication.scala @@ -74,14 +74,16 @@ class SbtShellCommunication(project: Project) extends AbstractProjectComponent(p val (cmd, listener) = next listener.started() - process.attachListener(listener) + + val handler = process.acquireShellProcessHandler + handler.addProcessListener(listener) process.usingWriter { shell => shell.println(cmd) shell.flush() } listener.future.onComplete { _ => - process.removeListener(listener) + handler.removeProcessListener(listener) } } else shellQueueReady.release() } From ae5e5d3dc8747c4e1aceec484ef52f1795d0fdda Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Thu, 2 Nov 2017 22:17:01 +0300 Subject: [PATCH 128/141] missing dependencies for tests #SCL-12167 --- project/dependencies.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index 3b4eb37850d..5f4610d90c0 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -178,10 +178,12 @@ object DependencyGroups { "org.scalaz.stream" % "scalaz-stream_2.11" % "0.6a", "org.specs2" % "specs2_2.10" % "2.4.6", "org.specs2" % "specs2_2.11" % "2.4.15", - "org.specs2" % "specs2-core_2.12" % "4.0.0", "org.specs2" % "specs2-core_2.11" % "3.0.1", + "org.specs2" % "specs2-core_2.12" % "4.0.0", "org.specs2" % "specs2-common_2.11" % "3.0.1", + "org.specs2" % "specs2-common_2.12" % "4.0.0", "org.specs2" % "specs2-matcher_2.11" % "3.0.1", + "org.specs2" % "specs2-matcher_2.12" % "4.0.0", "org.typelevel" % "scodec-bits_2.11" % "1.1.0-SNAPSHOT", "org.typelevel" % "scodec-core_2.11" % "1.7.0-SNAPSHOT", "org.scalatest" % "scalatest_2.10" % "1.9.2", From a99347d688b928e44a7d159939fc2ace5624ee11 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Thu, 2 Nov 2017 22:36:54 +0300 Subject: [PATCH 129/141] do not run UseSbtTestRunTest entirely in edt to avoid deadlock #SCL-12167 --- .../sbt/shell/UseSbtTestRunTest.scala | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index f5016370cd9..22903a43a49 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -9,16 +9,31 @@ import org.jetbrains.plugins.scala.SlowTests import org.jetbrains.plugins.scala.testingSupport.ScalaTestingTestCase import org.jetbrains.plugins.scala.testingSupport.test.{AbstractTestRunConfiguration, TestRunConfigurationForm} import org.junit.experimental.categories.Category - import scala.concurrent.Await import scala.concurrent.duration._ +import com.intellij.testFramework.EdtTestUtil + /** * Created by Roman.Shein on 13.04.2017. */ @Category(Array(classOf[SlowTests])) abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { + override def runInDispatchThread(): Boolean = false + + override def setUp(): Unit = { + EdtTestUtil.runInEdtAndWait { () => + super.setUp() + } + } + + override def tearDown(): Unit = { + EdtTestUtil.runInEdtAndWait { () => + super.tearDown() + } + } + def testScalaTestSimpleTest(): Unit = runSingleTest(ScalaTestingTestCase.getScalaTestTemplateConfig(getProject), "test.scalaTest.SimpleScalaTest", "ScalaTest First test", "scalaTest", List("Marker: ScalaTest first test", "[info] - First test"), @@ -134,14 +149,18 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { val sdk = ProjectRootManager.getInstance(project).getProjectSdk assert(sdk != null, s"project sdk was null in project ${project.getName}") - val executor: Executor = Executor.EXECUTOR_EXTENSION_NAME.findExtension(classOf[DefaultRunExecutor]) - val executionEnvironmentBuilder: ExecutionEnvironmentBuilder = - new ExecutionEnvironmentBuilder(project, executor) - executionEnvironmentBuilder.runProfile(config).buildAndExecute() - runner.getConsoleView.flushDeferredText() + EdtTestUtil.runInEdtAndWait { () => + val executor: Executor = Executor.EXECUTOR_EXTENSION_NAME.findExtension(classOf[DefaultRunExecutor]) + val executionEnvironmentBuilder: ExecutionEnvironmentBuilder = + new ExecutionEnvironmentBuilder(project, executor) + executionEnvironmentBuilder.runProfile(config).buildAndExecute() + runner.getConsoleView.flushDeferredText() + comm.command("exit", showShell = false) + } + val exitCode = Await.result(logger.terminated, 10.minutes) val log = logger.getLog - assert(exitCode != 0, "sbt shell completed with nonzero exit code. Full log:\n$log") + assert(exitCode == 0, s"sbt shell completed with nonzero exit code. Full log:\n$log") expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'. Full log:\n$log")) unexpectedStrings.foreach(str => assert(!log.contains(str), s"sbt shell console contained unexpected string '$str'. Full log:\n$log")) val logSplitted = logLines(log) From bc8af5771cf84a84c3471ce434549c645640a12c Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 1 Nov 2017 14:56:32 +0300 Subject: [PATCH 130/141] ScFunctionDefinition#returnUsages method refactored #SCL-12793 in progress --- .../scala/annotator/FunctionAnnotator.scala | 8 +- .../collections/UnitInMapInspection.scala | 3 +- .../ScalaUselessExpressionInspection.scala | 2 +- .../RemoveRedundantReturnInspection.scala | 5 +- .../ScalaHighlightExitPointsHandler.scala | 4 +- .../ScalaHighlightExprResultHandler.scala | 5 +- .../lang/psi/api/expr/ScExpression.scala | 74 +++++------- .../api/statements/ScFunctionDefinition.scala | 105 ++++++++++++------ .../MakeResultExpressionExplicit.scala | 2 +- .../settings/annotations/Implementation.scala | 2 +- .../impl/ScFunctionDefinitionImplTest.scala | 72 ++++++------ 11 files changed, 145 insertions(+), 137 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala index 0f78d21d32a..3b41d0f95d1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/FunctionAnnotator.scala @@ -64,7 +64,7 @@ trait FunctionAnnotator { for { functionType <- function.returnType - usage <- function.returnUsages() + usage <- function.returnUsages usageType <- typeOf(usage) } { @@ -87,14 +87,14 @@ trait FunctionAnnotator { typeMismatch() } - def needsTypeAnnotation() = { + def needsTypeAnnotation(): Unit = { val message = ScalaBundle.message("function.must.define.type.explicitly", function.name) - val returnTypes = function.returnUsages(withBooleanInfix = false).toSeq.collect { + val returnTypes = function.returnUsages.collect { case retStmt: ScReturnStmt => retStmt.expr.flatMap(_.`type`().toOption).getOrElse(Any) case expr: ScExpression => expr.`type`().getOrAny } val annotation = holder.createErrorAnnotation(usage.asInstanceOf[ScReturnStmt].returnKeyword, message) - annotation.registerFix(new AddReturnTypeFix(function, returnTypes.lub())) + annotation.registerFix(new AddReturnTypeFix(function, returnTypes.toSeq.lub())) } def redundantReturnExpression() = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala index 2926786e39d..5c557cfa8d5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/UnitInMapInspection.scala @@ -4,6 +4,7 @@ import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.codeInspection.{ChangeReferenceNameQuickFix, InspectionBundle} import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression.calculateReturns import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScBlock, ScExpression, ScFunctionExpr} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScEarlyDefinitions import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody @@ -28,7 +29,7 @@ class UnitInMapInspection extends OperationOnCollectionInspection { if (isInBlock) Seq(new ChangeReferenceNameQuickFix(InspectionBundle.message("use.foreach.instead.of.map"), ref, "foreach")) else Seq.empty val Unit = call.projectContext.stdTypes.Unit - val unitTypeReturns = body.calculateReturns().collect { + val unitTypeReturns = calculateReturns(body).collect { case expr@Typeable(ft@FunctionType(Unit, _)) if arg.`type`().getOrAny.equiv(ft) => expr case expr@Typeable(Unit) => expr }.filter(_.getTextLength > 0) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala index 54697452c78..58866108e70 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/controlFlow/ScalaUselessExpressionInspection.scala @@ -64,7 +64,7 @@ class ScalaUselessExpressionInspection extends AbstractInspection("ScalaUselessE } def isInReturnPositionForUnitFunction: Boolean = { Option(PsiTreeUtil.getParentOfType(expr, classOf[ScFunctionDefinition])) match { - case Some(fun) if fun.returnType.exists(_.isUnit) => fun.returnUsages().contains(expr) + case Some(fun) if fun.returnType.exists(_.isUnit) => fun.returnUsages(expr) case _ => false } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/RemoveRedundantReturnInspection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/RemoveRedundantReturnInspection.scala index 035e02a8f4c..2cd06e71798 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/RemoveRedundantReturnInspection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/syntacticSimplification/RemoveRedundantReturnInspection.scala @@ -6,6 +6,7 @@ import com.intellij.codeInspection._ import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.extensions.PsiElementExt +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression.calculateReturns import org.jetbrains.plugins.scala.lang.psi.api.expr.ScReturnStmt import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScFunctionDefinition} @@ -15,12 +16,12 @@ class RemoveRedundantReturnInspection extends AbstractInspection("ScalaRedundant override def actionFor(implicit holder: ProblemsHolder): PartialFunction[PsiElement, Unit] = { case function: ScFunctionDefinition => for (body <- function.body) { - val returns = body.calculateReturns() + val returns = calculateReturns(body) body.depthFirst { !_.isInstanceOf[ScFunction] }.foreach { case r: ScReturnStmt => - if (returns.contains(r)) { + if (returns(r)) { holder.registerProblem(r.returnKeyword, "Return keyword is redundant", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new RemoveReturnKeywordQuickFix(r)) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExitPointsHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExitPointsHandler.scala index bb7bf91e812..0bf35e5e8ee 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExitPointsHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExitPointsHandler.scala @@ -17,8 +17,8 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition class ScalaHighlightExitPointsHandler(fun: ScFunctionDefinition, editor: Editor, file: PsiFile, keyword: PsiElement) extends HighlightUsagesHandlerBase[PsiElement](editor, file) { - def computeUsages(targets: util.List[PsiElement]) { - val usages = fun.returnUsages().toSeq :+ keyword + def computeUsages(targets: util.List[PsiElement]): Unit = { + val usages = fun.returnUsages ++ Set(keyword) usages.map(_.getTextRange).foreach(myReadUsages.add) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExprResultHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExprResultHandler.scala index a461ce9b908..c55ae320085 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExprResultHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/highlighter/usages/ScalaHighlightExprResultHandler.scala @@ -10,12 +10,13 @@ import com.intellij.openapi.editor.Editor import com.intellij.psi.{PsiElement, PsiFile} import com.intellij.util.Consumer import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression.calculateReturns class ScalaHighlightExprResultHandler(expr: ScExpression, editor: Editor, file: PsiFile, keyword: PsiElement) extends HighlightUsagesHandlerBase[PsiElement](editor, file) { - def computeUsages(targets: util.List[PsiElement]) { - val returns = expr.calculateReturns() :+ keyword + def computeUsages(targets: util.List[PsiElement]): Unit = { + val returns = calculateReturns(expr) ++ Set(keyword) returns.map(_.getTextRange).foreach(myReadUsages.add) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala index e1f5d2b6800..f3326e85657 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala @@ -6,19 +6,20 @@ package expr import com.intellij.openapi.progress.ProgressManager import com.intellij.psi._ -import org.jetbrains.plugins.scala.extensions.{ElementText, PsiElementExt, PsiNamedElementExt, StringExt} +import org.jetbrains.plugins.scala.extensions.{PsiElementExt, PsiNamedElementExt, StringExt} import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil.{MethodValue, isAnonymousExpression} import org.jetbrains.plugins.scala.lang.psi.api.InferUtil.{SafeCheckException, extractImplicitParameterType} +import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScCaseClauses import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.base.{ScIntLiteral, ScLiteral} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.ImportUsed import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText import org.jetbrains.plugins.scala.lang.psi.implicits.{ImplicitCollector, ImplicitResolveResult, ScImplicitlyConvertible} +import org.jetbrains.plugins.scala.lang.psi.types._ import org.jetbrains.plugins.scala.lang.psi.types.api._ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType} import org.jetbrains.plugins.scala.lang.psi.types.result._ -import org.jetbrains.plugins.scala.lang.psi.types.{api, _} import org.jetbrains.plugins.scala.lang.resolve.processor.MethodResolveProcessor import org.jetbrains.plugins.scala.lang.resolve.{ScalaResolveResult, StdKinds} import org.jetbrains.plugins.scala.macroAnnotations.{CachedWithRecursionGuard, ModCount} @@ -26,8 +27,6 @@ import org.jetbrains.plugins.scala.project.ProjectPsiElementExt import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_11 import scala.annotation.tailrec -import scala.collection.mutable.ArrayBuffer -import scala.collection.{Seq, Set} /** * @author ilyas, Alexander Podkhalyuzin @@ -158,54 +157,33 @@ trait ScExpression extends ScBlockStatement with PsiAnnotationMemberValue with I else firstName.compareTo(secondName) < 0 } } - - final def calculateReturns(withBooleanInfix: Boolean = false): Seq[PsiElement] = { - val res = new ArrayBuffer[PsiElement] - - def calculateReturns0(el: PsiElement) { - el match { - case tr: ScTryStmt => - calculateReturns0(tr.tryBlock) - tr.catchBlock match { - case Some(ScCatchBlock(caseCl)) => - caseCl.caseClauses.flatMap(_.expr).foreach(calculateReturns0) - case _ => - } - case block: ScBlock => - block.lastExpr match { - case Some(expr) => calculateReturns0(expr) - case _ => res += block - } - case pe: ScParenthesisedExpr => - pe.expr.foreach(calculateReturns0) - case m: ScMatchStmt => - m.getBranches.foreach(calculateReturns0) - case i: ScIfStmt => - i.elseBranch match { - case Some(e) => - calculateReturns0(e) - i.thenBranch match { - case Some(thenBranch) => calculateReturns0(thenBranch) - case _ => - } - case _ => res += i - } - case ScInfixExpr(left, ElementText(op), right) - if withBooleanInfix && (op == "&&" || op == "||") && - left.`type`().exists(_ == api.Boolean) && - right.`type`().exists(_ == api.Boolean) => calculateReturns0(right) - //TODO "!contains" is a quick fix, function needs unit testing to validate its behavior - case _ => if (!res.contains(el)) res += el - } - } - - calculateReturns0(this) - res - } } object ScExpression { + def calculateReturns: ScExpression => Set[ScExpression] = { + case ScTryStmt(tryBlock, maybeCatchBlock, _) => + calculateReturns(tryBlock) ++ + maybeCatchBlock.collect { + case ScCatchBlock(clauses) => clauses + }.toSet[ScCaseClauses] + .flatMap(_.caseClauses) + .flatMap(_.expr) + .flatMap(calculateReturns) + case block: ScBlock => + block.lastExpr + .map(calculateReturns) + .getOrElse(Set(block)) + case ScParenthesisedExpr(innerExpression) => calculateReturns(innerExpression) + case m: ScMatchStmt => + m.getBranches.toSet.flatMap(calculateReturns) + case ScIfStmt(_, maybeThenBranch, Some(elseBranch)) => + calculateReturns(elseBranch) ++ + maybeThenBranch.toSet.flatMap(calculateReturns) + case i: ScIfStmt => Set(i) + case expression => Set(expression) // TODO "!contains" is a quick fix, function needs unit testing to validate its behavior + } + case class ExpressionTypeResult(tr: TypeResult, importsUsed: scala.collection.Set[ImportUsed] = Set.empty, implicitConversion: Option[ScalaResolveResult] = None) { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala index 33db21725c2..02011cb6c96 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala @@ -7,12 +7,15 @@ package statements import com.intellij.psi._ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScConstructorPattern, ScInfixPattern} +import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScCaseClauses, ScConstructorPattern, ScInfixPattern} import org.jetbrains.plugins.scala.lang.psi.api.base.{ScConstructor, ScReferenceElement, ScStableCodeReferenceElement} +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression.calculateReturns import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTypeDefinition} import org.jetbrains.plugins.scala.lang.psi.light.{PsiClassWrapper, StaticTraitScFunctionWrapper} +import org.jetbrains.plugins.scala.lang.psi.types.api.StdTypes +import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} /** @@ -29,10 +32,7 @@ trait ScFunctionDefinition extends ScFunction with ScControlFlowOwner { def removeAssignment() - def returnUsages(withBooleanInfix: Boolean = false): Array[PsiElement] = body.fold(Array.empty[PsiElement])(exp => { - (exp.depthFirst(!_.isInstanceOf[ScFunction]).filter(_.isInstanceOf[ScReturnStmt]) ++ exp.calculateReturns(withBooleanInfix)). - filter(_.getContainingFile == getContainingFile).toArray.distinct - }) + def returnUsages: Set[ScExpression] = innerReturnUsages(calculateReturns) def canBeTailRecursive: Boolean = getParent match { case (_: ScTemplateBody) && Parent(Parent(owner: ScTypeDefinition)) => @@ -52,29 +52,6 @@ trait ScFunctionDefinition extends ScFunction with ScControlFlowOwner { .contains("_root_.scala.annotation.tailrec") def recursiveReferences: Seq[RecursiveReference] = { - val resultExpressions = returnUsages(withBooleanInfix = true) - - @scala.annotation.tailrec - def possiblyTailRecursiveCallFor(elem: PsiElement): PsiElement = elem.getParent match { - case call: ScMethodCall => possiblyTailRecursiveCallFor(call) - case call: ScGenericCall => possiblyTailRecursiveCallFor(call) - case infix: ScInfixExpr if infix.operation == elem => possiblyTailRecursiveCallFor(infix) - case ret: ScReturnStmt => ret - case _ => elem - } - - def expandIf(elem: PsiElement): Seq[PsiElement] = { - elem match { - case i: ScIfStmt if i.elseBranch.isEmpty => - i.thenBranch match { - case Some(thenBranch) => - thenBranch.calculateReturns().flatMap(expandIf) :+ elem - case _ => Seq(elem) - } - case _ => Seq(elem) - } - } - def quickCheck(ref: ScReferenceElement): Boolean = { ref match { case _: ScStableCodeReferenceElement => @@ -96,17 +73,60 @@ trait ScFunctionDefinition extends ScFunction with ScControlFlowOwner { } } - body match { - case Some(b) => - val possiblyRecursiveRefs = b.depthFirst().filterByType[ScReferenceElement].filter(quickCheck).toSeq - val recursiveRefs = possiblyRecursiveRefs.filter(_.isReferenceTo(this)) - if (recursiveRefs.nonEmpty) { - val expressions = resultExpressions.flatMap(expandIf) - recursiveRefs.map(ref => RecursiveReference(ref, expressions.contains(possiblyTailRecursiveCallFor(ref)))) + val recursiveReferences = body.toSeq + .flatMap(_.depthFirst()) + .collect { + case element: ScReferenceElement if quickCheck(element) => element + }.filter(_.isReferenceTo(this)) + + val expressions: Set[PsiElement] = recursiveReferences match { + case Seq() => Set.empty + case _ => + val booleanInstance = StdTypes.instance.Boolean + + def calculateExpandedReturns: ScExpression => Set[ScExpression] = { + case ScInfixExpr(Typeable(`booleanInstance`), ElementText("&&" | "||"), right@Typeable(`booleanInstance`)) => + calculateExpandedReturns(right) + case ScTryStmt(tryBlock, maybeCatchBlock, _) => + calculateExpandedReturns(tryBlock) ++ + maybeCatchBlock.collect { + case ScCatchBlock(clauses) => clauses + }.toSet[ScCaseClauses] + .flatMap(_.caseClauses) + .flatMap(_.expr) + .flatMap(calculateExpandedReturns) + case block: ScBlock => + block.lastExpr + .map(calculateExpandedReturns) + .getOrElse(Set(block)) + case ScParenthesisedExpr(innerExpression) => calculateExpandedReturns(innerExpression) + case m: ScMatchStmt => + m.getBranches.toSet.flatMap(calculateExpandedReturns) + case ScIfStmt(_, maybeThenBranch, Some(elseBranch)) => + calculateExpandedReturns(elseBranch) ++ + maybeThenBranch.toSet.flatMap(calculateExpandedReturns) + case expression => Set(expression) } - else Seq.empty - case _ => Seq.empty + def expandIf(expression: ScExpression): Set[ScExpression] = (expression match { + case ScIfStmt(_, Some(thenBranch), None) => calculateReturns(thenBranch).flatMap(expandIf) + case _ => Set.empty + }) ++ Set(expression) + + innerReturnUsages(calculateExpandedReturns).flatMap(expandIf) + } + + @scala.annotation.tailrec + def possiblyTailRecursiveCallFor(element: PsiElement): PsiElement = element.getParent match { + case call@(_: ScMethodCall | + _: ScGenericCall) => possiblyTailRecursiveCallFor(call) + case infix: ScInfixExpr if infix.operation == element => possiblyTailRecursiveCallFor(infix) + case statement: ScReturnStmt => statement + case _ => element + } + + recursiveReferences.map { reference => + RecursiveReference(reference, expressions(possiblyTailRecursiveCallFor(reference))) } } @@ -124,6 +144,17 @@ trait ScFunctionDefinition extends ScFunction with ScControlFlowOwner { def getStaticTraitFunctionWrapper(cClass: PsiClassWrapper): StaticTraitScFunctionWrapper = { new StaticTraitScFunctionWrapper(this, cClass) } + + private def innerReturnUsages(calculateReturns: ScExpression => Set[ScExpression]): Set[ScExpression] = { + def returnsIn(expression: ScExpression) = + expression.depthFirst(!_.isInstanceOf[ScFunction]).collect { + case statement: ScReturnStmt => statement + } ++ calculateReturns(expression) + + body.toSet + .flatMap(returnsIn) + .filter(_.getContainingFile == getContainingFile) + } } object ScFunctionDefinition { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/declarations/MakeResultExpressionExplicit.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/declarations/MakeResultExpressionExplicit.scala index 297b04adb6a..e0c6a7c6ede 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/declarations/MakeResultExpressionExplicit.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/transformation/declarations/MakeResultExpressionExplicit.scala @@ -13,7 +13,7 @@ import org.jetbrains.plugins.scala.project.ProjectContext class MakeResultExpressionExplicit extends AbstractTransformer { def transformation(implicit project: ProjectContext): PartialFunction[PsiElement, Unit] = { case (e: ScFunctionDefinition) if e.hasExplicitType && !e.hasUnitResultType => - e.returnUsages().foreach { + e.returnUsages.foreach { case _: ScReturnStmt => // skip case it => it.replace(code"return $it") } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/annotations/Implementation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/annotations/Implementation.scala index 52ced091795..5358c7fa674 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/annotations/Implementation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/settings/annotations/Implementation.scala @@ -28,7 +28,7 @@ object Implementation { private class Definition(element: PsiElement) extends Implementation { override def containsReturn: Boolean = element match { - case f: ScFunctionDefinition => f.returnUsages().exists { + case f: ScFunctionDefinition => f.returnUsages.exists { case _: ScReturnStmt => true case _ => false } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/impl/ScFunctionDefinitionImplTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/impl/ScFunctionDefinitionImplTest.scala index 5c31d26bada..fbda4db9df4 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/impl/ScFunctionDefinitionImplTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/psi/impl/ScFunctionDefinitionImplTest.scala @@ -8,66 +8,67 @@ import org.jetbrains.plugins.scala.lang.psi.api.statements.{RecursionType, ScFun import org.junit.Assert._ /** - * Pavel Fatin - */ + * Pavel Fatin + */ class ScFunctionDefinitionImplTest extends SimpleTestCase { - def testNoRecursion() { + + def testNoRecursion(): Unit = { assertRecursionTypeIs("def f(n: Int) = n", NoRecursion) } - def testLinearRecursion() { + def testLinearRecursion(): Unit = { assertRecursionTypeIs("def f(n: Int): Int = 1 + f(n)", OrdinaryRecursion) } - def testTailRecursion() { + def testTailRecursion(): Unit = { assertRecursionTypeIs("def f(n: Int): Int = f(n + 1)", TailRecursion) } - def testTailRecursionWithCurring() { + def testTailRecursionWithCurring(): Unit = { assertRecursionTypeIs("def f(n: Int)(x:Int)(y:Int): Int = f(n + 1)(x)(y)", TailRecursion) } - def testTailRecursionWithTypeParam() { + def testTailRecursionWithTypeParam(): Unit = { assertRecursionTypeIs("def f[A](n: Int): Int = f[A](n + 1)", TailRecursion) } - def testReturn() { + def testReturn(): Unit = { assertRecursionTypeIs("def f(n: Int): Int = return f(n + 1)", TailRecursion) } - def testAndAnd() { + def testAndAnd(): Unit = { assertRecursionTypeIs("def f(n: Int): Boolean = n > 0 && f(n)", TailRecursion) } - def testAndAnd2() { + def testAndAnd2(): Unit = { assertRecursionTypeIs("def f(n: Int): Boolean = f(n) && n > 0", OrdinaryRecursion) } - def testAndAnd3() { + def testAndAnd3(): Unit = { assertRecursionTypeIs("def f(n: Int): Boolean = f(n) && f(n-1)", OrdinaryRecursion) } - def testOrOr() { + def testOrOr(): Unit = { assertRecursionTypeIs("def f(n: Int): Boolean = n > 0 || f(n)", TailRecursion) } - def testOrOr2() { + def testOrOr2(): Unit = { assertRecursionTypeIs("def f(n: Int): Boolean = f(n) || n > 0", OrdinaryRecursion) } - def testOrOr3() { + def testOrOr3(): Unit = { assertRecursionTypeIs("def f(n: Int): Boolean = f(n) || f(n-1)", OrdinaryRecursion) } - def testIf() { + def testIf(): Unit = { assertRecursionTypeIs("def f(n: Int) {if (true) {f(n + 1)}}", TailRecursion) } - def testOtherInfixOperator() { + def testOtherInfixOperator(): Unit = { assertRecursionTypeIs("def f(n: Int): Boolean = n > 0 ** f(n)", OrdinaryRecursion) } - def testDeeperInfixOperator() { + def testDeeperInfixOperator(): Unit = { assertRecursionTypeIs( """ |def f(n: Int): Boolean = @@ -78,31 +79,26 @@ class ScFunctionDefinitionImplTest extends SimpleTestCase { """.stripMargin, TailRecursion) } - def testGetReturnUsages() { - assertUsages( + def testGetReturnUsages(): Unit = { + val code = """ - def f[A](n: Int)(body: => A): Option[A] = { - try - return Some(body) - catch { - case e: Exception if n == 0 => return None - } - f[A](n - 1)(body) - } - """, - "return Some(body)", - "return None", - "f[A](n - 1)(body)") - } - + |def f[A](n: Int)(body: => A): Option[A] = { + | try + | return Some(body) + | catch { + | case e: Exception if n == 0 => return None + | } + | f[A](n - 1)(body) + |} + """.stripMargin - private def assertUsages(@Language("Scala") code: String, expected: String*) { - assertEquals(expected, parse(code).returnUsages().map(_.getText).toSeq) + val actualUsages = parseAsFunction(code).returnUsages + assertEquals(Set("return Some(body)", "return None", "f[A](n - 1)(body)"), actualUsages.map(_.getText)) } - private def assertRecursionTypeIs(@Language("Scala") code: String, expectation: RecursionType) { - assertEquals(expectation, parse(code).recursionType) + private def assertRecursionTypeIs(@Language("Scala") code: String, expected: RecursionType): Unit = { + assertEquals(expected, parseAsFunction(code).recursionType) } - private def parse(@Language("Scala") code: String): ScFunctionDefinition = code.parse[ScFunctionDefinition] + private def parseAsFunction(@Language("Scala") code: String): ScFunctionDefinition = code.parse[ScFunctionDefinition] } \ No newline at end of file From 34f0e10f2bc18e17cc02b731200a5fe96a6cfdcb Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Wed, 1 Nov 2017 18:41:46 +0300 Subject: [PATCH 131/141] ScReturnStmt refactored #SCL-12793 --- .../scala/annotator/ScalaAnnotator.scala | 37 +++----- .../booleans/ExpandBooleanIntention.scala | 86 +++++++++---------- .../lang/psi/api/expr/ScReturnStmt.scala | 18 ++-- .../impl/ScalaControlFlowBuilder.scala | 7 +- .../lang/psi/impl/expr/ScReturnStmtImpl.scala | 18 ++-- .../util/ScalaRefactoringUtil.scala | 6 +- .../booleans/ExpandBooleanIntentionTest.scala | 7 +- 7 files changed, 80 insertions(+), 99 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala index 300bf53112c..47fb773f13b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/ScalaAnnotator.scala @@ -1070,32 +1070,21 @@ abstract class ScalaAnnotator extends Annotator } } - private def checkExplicitTypeForReturnStatement(ret: ScReturnStmt, holder: AnnotationHolder) { - val fun: ScFunction = PsiTreeUtil.getParentOfType(ret, classOf[ScFunction]) - fun match { - case null => - val error = ScalaBundle.message("return.outside.method.definition") - val annotation: Annotation = holder.createErrorAnnotation(ret.returnKeyword, error) - annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) - case _ if !fun.hasAssign || fun.returnType.exists(_ == Unit) => - case _ => fun.returnTypeElement match { - case Some(_: ScTypeElement) => - import org.jetbrains.plugins.scala.lang.psi.types._ - val funType = fun.returnType - funType match { - case Right(tp) if tp equiv Unit => return //nothing to check - case _ => - } + private def checkExplicitTypeForReturnStatement(statement: ScReturnStmt, holder: AnnotationHolder): Unit = { + val function = statement.returnFunction.getOrElse { + val error = ScalaBundle.message("return.outside.method.definition") + val annotation: Annotation = holder.createErrorAnnotation(statement.returnKeyword, error) + annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) + return + } - val importUsed = ret.expr.map { expression => - expression.getTypeAfterImplicitConversion() - }.toSet[ScExpression.ExpressionTypeResult].flatMap { - _.importsUsed - } + function.returnType match { + case Right(tp) if function.hasAssign && !tp.equiv(Unit) => + val importUsed = statement.expr.toSet[ScExpression] + .flatMap(_.getTypeAfterImplicitConversion().importsUsed) - registerUsedImports(ret, importUsed) - case _ => - } + registerUsedImports(statement, importUsed) + case _ => } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/booleans/ExpandBooleanIntention.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/booleans/ExpandBooleanIntention.scala index 7b386757daf..5cfd7c136a7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/booleans/ExpandBooleanIntention.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInsight/intention/booleans/ExpandBooleanIntention.scala @@ -3,65 +3,61 @@ package org.jetbrains.plugins.scala.codeInsight.intention.booleans import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project -import com.intellij.openapi.util.TextRange -import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.{PsiDocumentManager, PsiElement} import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScParenthesisedExpr, ScReturnStmt} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText +import org.jetbrains.plugins.scala.lang.psi.types.result.Typeable +import org.jetbrains.plugins.scala.project.ProjectContext /** - * @author Ksenia.Sautina - * @since 6/29/12 - */ - -object ExpandBooleanIntention { - def familyName = "Expand Boolean" -} - + * @author Ksenia.Sautina + * @since 6/29/12 + */ class ExpandBooleanIntention extends PsiElementBaseIntentionAction { - def getFamilyName: String = ExpandBooleanIntention.familyName - - override def getText: String = "Expand boolean use to 'if else'" - def isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean = { - val returnStmt: ScReturnStmt = PsiTreeUtil.getParentOfType(element, classOf[ScReturnStmt], false) - if (returnStmt == null) return false + import ExpandBooleanIntention._ + + def isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean = + findReturnParent(element).filter { statement => + val range = statement.getTextRange + val offset = editor.getCaretModel.getOffset + range.getStartOffset <= offset && offset <= range.getEndOffset + }.collect { + case ScReturnStmt(Typeable(scType)) => scType.canonicalText + }.contains("Boolean") + + override def invoke(project: Project, editor: Editor, element: PsiElement): Unit = { + val statement = findReturnParent(element).filter(_.isValid) + .getOrElse(return) + + val expressionText = statement match { + case ScReturnStmt(ScParenthesisedExpr(ElementText(text))) => text + case ScReturnStmt(ElementText(text)) => text + case _ => return + } - val range: TextRange = returnStmt.getTextRange - val offset = editor.getCaretModel.getOffset - if (!(range.getStartOffset <= offset && offset <= range.getEndOffset)) return false + val start = statement.getTextRange.getStartOffset - val value = returnStmt.expr.orNull - if (value == null) return false - val valType = value.`type`().getOrElse(null) - if (valType == null) return false - if (valType.canonicalText == "Boolean") return true + inWriteAction { + implicit val context: ProjectContext = project + val replacement = createExpressionFromText(s"if ($expressionText) { return true } else { return false }") + statement.replaceExpression(replacement, removeParenthesis = true) - false + editor.getCaretModel.moveToOffset(start) + PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument) + } } - override def invoke(project: Project, editor: Editor, element: PsiElement) { - val returnStmt: ScReturnStmt = PsiTreeUtil.getParentOfType(element, classOf[ScReturnStmt], false) - if (returnStmt == null || !returnStmt.isValid) return + override def getText: String = "Expand boolean use to 'if else'" - val start = returnStmt.getTextRange.getStartOffset - val expr = new StringBuilder - val value = returnStmt.expr.orNull - if (value == null) return - expr.append("if ") + def getFamilyName: String = FamilyName +} - value match { - case v: ScParenthesisedExpr => expr.append(v.getText) - case _ => expr.append("(").append(value.getText).append(")") - } +object ExpandBooleanIntention { - expr.append("{ return true } else { return false }") + val FamilyName = "Expand Boolean" - inWriteAction { - returnStmt.replaceExpression(createExpressionFromText(expr.toString())(element.getManager), true) - editor.getCaretModel.moveToOffset(start) - PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument) - } - } -} \ No newline at end of file + private def findReturnParent(element: PsiElement): Option[ScReturnStmt] = + element.parentOfType(classOf[ScReturnStmt], strict = false) +} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala index 162900f6657..cc8d52adbb1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala @@ -5,19 +5,25 @@ package api package expr import com.intellij.psi.PsiElement +import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScReturnStmt extends ScExpression { def expr: Option[ScExpression] = findChild(classOf[ScExpression]) def returnKeyword: PsiElement - def returnFunction: Option[ScFunctionDefinition] + def returnFunction: Option[ScFunctionDefinition] = + this.parentOfType(classOf[ScFunctionDefinition]) override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitReturnStatement(this) +} + +object ScReturnStmt { + + def unapply(statement: ScReturnStmt): Option[ScExpression] = statement.expr } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/controlFlow/impl/ScalaControlFlowBuilder.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/controlFlow/impl/ScalaControlFlowBuilder.scala index 305bcc6c776..4a134c61096 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/controlFlow/impl/ScalaControlFlowBuilder.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/controlFlow/impl/ScalaControlFlowBuilder.scala @@ -248,7 +248,6 @@ class ScalaControlFlowBuilder(startInScope: ScalaPsiElement, } override def visitMethodCallExpression(call: ScMethodCall) { - import call.projectContext val matchedParams = call.matchedParameters def isByNameOrFunction(arg: ScExpression) = { val param = matchedParams.toMap.get(arg) @@ -360,10 +359,8 @@ class ScalaControlFlowBuilder(startInScope: ScalaPsiElement, case Some(e) => e != ret case None => false }) - ret.expr match { - case Some(e) => e.accept(this) - case None => - } + ret.expr.foreach(_.accept(this)) + if (isNodeNeeded) startNode(Some(ret)) { _ => addPendingEdge(null, myHead) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala index 680f422ce6f..81297b655d9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala @@ -4,13 +4,11 @@ package psi package impl package expr -import _root_.com.intellij.psi.util.PsiTreeUtil import com.intellij.lang.ASTNode import com.intellij.psi.{PsiElement, PsiElementVisitor} -import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes +import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes.kRETURN import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -19,6 +17,11 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ */ class ScReturnStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScReturnStmt { + + override def returnKeyword: PsiElement = findChildByType(kRETURN) + + protected override def innerType: TypeResult = Right(Nothing) + override def accept(visitor: PsiElementVisitor): Unit = { visitor match { case visitor: ScalaElementVisitor => super.accept(visitor) @@ -27,13 +30,4 @@ class ScReturnStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScR } override def toString: String = "ReturnStatement" - - protected override def innerType: TypeResult = Right(Nothing) - //Failure("Cannot infer type of `return' expression", Some(this)) - - def returnKeyword: PsiElement = findChildByType[PsiElement](ScalaTokenTypes.kRETURN) - - def returnFunction: Option[ScFunctionDefinition] = { - Option(PsiTreeUtil.getParentOfType(this, classOf[ScFunctionDefinition])) - } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala index 5ed116330fb..3cc72dc9533 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/refactoring/util/ScalaRefactoringUtil.scala @@ -665,10 +665,8 @@ object ScalaRefactoringUtil { builder.append(r.refName) case r: ScReturnStmt => builder.append("return ") - r.expr match { - case Some(expression) => builder.append(getShortText(expression)) - case _ => - } + r.expr.map(getShortText) + .foreach(builder.append) case s: ScSuperReference => builder.append(s.getText) case t: ScThisReference => builder.append(t.getText) case t: ScThrowStmt => diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInsight/intentions/booleans/ExpandBooleanIntentionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInsight/intentions/booleans/ExpandBooleanIntentionTest.scala index 1ca4b5676f6..0041af15cfd 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInsight/intentions/booleans/ExpandBooleanIntentionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/codeInsight/intentions/booleans/ExpandBooleanIntentionTest.scala @@ -1,7 +1,8 @@ -package org.jetbrains.plugins.scala.codeInsight.intentions.booleans +package org.jetbrains.plugins.scala.codeInsight +package intentions +package booleans import org.jetbrains.plugins.scala.codeInsight.intention.booleans.ExpandBooleanIntention -import org.jetbrains.plugins.scala.codeInsight.intentions.ScalaIntentionTestBase /** * @author Ksenia.Sautina @@ -9,7 +10,7 @@ import org.jetbrains.plugins.scala.codeInsight.intentions.ScalaIntentionTestBase */ class ExpandBooleanIntentionTest extends ScalaIntentionTestBase { - val familyName = ExpandBooleanIntention.familyName + val familyName = ExpandBooleanIntention.FamilyName def testExpandBoolean() { val text = From 429c10f73832600ea324b0aea03e13858807a186 Mon Sep 17 00:00:00 2001 From: "Nikolay.Tropin" Date: Fri, 3 Nov 2017 13:03:51 +0300 Subject: [PATCH 132/141] one more missing jar added #SCL-12167 --- project/dependencies.scala | 1 + .../Specs2_2_12_4_0_0_Base.scala | 43 +++---------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index 5f4610d90c0..954c890e36d 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -184,6 +184,7 @@ object DependencyGroups { "org.specs2" % "specs2-common_2.12" % "4.0.0", "org.specs2" % "specs2-matcher_2.11" % "3.0.1", "org.specs2" % "specs2-matcher_2.12" % "4.0.0", + "org.specs2" % "specs2-fp_2.12" % "4.0.0", "org.typelevel" % "scodec-bits_2.11" % "1.1.0-SNAPSHOT", "org.typelevel" % "scodec-core_2.11" % "1.7.0-SNAPSHOT", "org.scalatest" % "scalatest_2.10" % "1.9.2", diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala index fc86f888c0f..adbd650092f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/testingSupport/specs2/specs2_2_12_4_0_0/Specs2_2_12_4_0_0_Base.scala @@ -18,58 +18,29 @@ trait Specs2_2_12_4_0_0_Base extends Specs2TestCase { import Specs2_2_12_4_0_0_Base._ implicit val module: Module = getModule - Seq(Specs2CommonLoader(), Specs2CoreLoader(), Specs2MatcherLoader()) + Seq(Specs2CommonLoader(), Specs2CoreLoader(), Specs2MatcherLoader(), Specs2FpLoader()) } } object Specs2_2_12_4_0_0_Base { - abstract class Specs2_3_BaseLoader(implicit module: Module) extends Specs2BaseLoader { + abstract class Specs2_4_BaseLoader(implicit module: Module) extends Specs2BaseLoader { override val version: String = "4.0.0" } - case class Specs2CommonLoader()(implicit val module: Module) extends Specs2_3_BaseLoader { + case class Specs2CommonLoader()(implicit val module: Module) extends Specs2_4_BaseLoader { override val name: String = "specs2-common" } - case class Specs2CoreLoader()(implicit val module: Module) extends Specs2_3_BaseLoader { + case class Specs2CoreLoader()(implicit val module: Module) extends Specs2_4_BaseLoader { override val name: String = "specs2-core" } - case class Specs2MatcherLoader()(implicit val module: Module) extends Specs2_3_BaseLoader { + case class Specs2MatcherLoader()(implicit val module: Module) extends Specs2_4_BaseLoader { override val name: String = "specs2-matcher" } - case class ScalaZEffectLoader()(implicit val module: Module) extends ScalaZBaseLoader { - override val name: String = "scalaz-effect" + case class Specs2FpLoader()(implicit val module: Module) extends Specs2_4_BaseLoader { + override val name: String = "specs2-fp" } - - case class ScalaZStreamLoader()(implicit val module: Module) extends ScalaZBaseLoader { - override val name: String = "scalaz-stream" - override val vendor: String = "org.scalaz.stream" - override val version: String = "0.6a" - } - - case class ShapelessLoader()(implicit val module: Module) extends IvyLibraryLoaderAdapter { - override val name: String = "shapeless" - override val vendor: String = "com.chuusai" - override val version: String = "2.0.0" - override val ivyType: IvyType = Bundles - } - - abstract class SCodecBaseLoader(implicit module: Module) extends IvyLibraryLoaderAdapter { - override val vendor: String = "org.typelevel" - override val ivyType: IvyType = Bundles - } - - case class SCodecCoreLoader()(implicit val module: Module) extends SCodecBaseLoader { - override val name: String = "scodec-core" - override val version: String = "1.7.0-SNAPSHOT" - } - - case class SCodecBitsLoader()(implicit val module: Module) extends SCodecBaseLoader { - override val name: String = "scodec-bits" - override val version: String = "1.1.0-SNAPSHOT" - } - } \ No newline at end of file From 6148e7fae59d03f5730e6cc68f2611c8bd287e0e Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Fri, 3 Nov 2017 13:03:57 +0300 Subject: [PATCH 133/141] pattern matching replaced with a visitor #SCL-12793 --- .../lang/psi/api/expr/ScExpression.scala | 99 ++++++++++++++----- .../api/statements/ScFunctionDefinition.scala | 42 ++++---- .../lang/psi/impl/expr/ScBlockImpl.scala | 5 +- .../psi/impl/expr/ScExpressionImplBase.scala | 24 +++++ .../lang/psi/impl/expr/ScTryBlockImpl.scala | 13 ++- .../lang/psi/impl/expr/ScUnitExprImpl.scala | 7 +- 6 files changed, 125 insertions(+), 65 deletions(-) create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala index f3326e85657..e1347c06614 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala @@ -9,7 +9,6 @@ import com.intellij.psi._ import org.jetbrains.plugins.scala.extensions.{PsiElementExt, PsiNamedElementExt, StringExt} import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil.{MethodValue, isAnonymousExpression} import org.jetbrains.plugins.scala.lang.psi.api.InferUtil.{SafeCheckException, extractImplicitParameterType} -import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScCaseClauses import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.base.{ScIntLiteral, ScLiteral} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.ImportUsed @@ -27,6 +26,7 @@ import org.jetbrains.plugins.scala.project.ProjectPsiElementExt import org.jetbrains.plugins.scala.project.ScalaLanguageLevel.Scala_2_11 import scala.annotation.tailrec +import scala.collection.mutable /** * @author ilyas, Alexander Podkhalyuzin @@ -161,27 +161,71 @@ trait ScExpression extends ScBlockStatement with PsiAnnotationMemberValue with I object ScExpression { - def calculateReturns: ScExpression => Set[ScExpression] = { - case ScTryStmt(tryBlock, maybeCatchBlock, _) => - calculateReturns(tryBlock) ++ - maybeCatchBlock.collect { - case ScCatchBlock(clauses) => clauses - }.toSet[ScCaseClauses] - .flatMap(_.caseClauses) - .flatMap(_.expr) - .flatMap(calculateReturns) - case block: ScBlock => - block.lastExpr - .map(calculateReturns) - .getOrElse(Set(block)) - case ScParenthesisedExpr(innerExpression) => calculateReturns(innerExpression) - case m: ScMatchStmt => - m.getBranches.toSet.flatMap(calculateReturns) - case ScIfStmt(_, maybeThenBranch, Some(elseBranch)) => - calculateReturns(elseBranch) ++ - maybeThenBranch.toSet.flatMap(calculateReturns) - case i: ScIfStmt => Set(i) - case expression => Set(expression) // TODO "!contains" is a quick fix, function needs unit testing to validate its behavior + def calculateReturns(expression: ScExpression): Set[ScExpression] = { + val visitor = new ReturnsVisitor + expression.accept(visitor) + visitor.result + } + + private[api] class ReturnsVisitor extends ScalaElementVisitor { + + private val result_ = mutable.LinkedHashSet.empty[ScExpression] + + def result: Set[ScExpression] = result_.toSet + + override def visitTryExpression(statement: ScTryStmt): Unit = { + acceptVisitor(statement.tryBlock) + + statement.catchBlock.collect { + case ScCatchBlock(clauses) => clauses + }.toSeq + .flatMap(_.caseClauses) + .flatMap(_.expr) + .foreach(acceptVisitor) + } + + override def visitExprInParent(expression: ScParenthesisedExpr): Unit = { + expression.expr match { + case Some(innerExpression) => acceptVisitor(innerExpression) + case _ => super.visitExprInParent(expression) + } + } + + override def visitMatchStatement(statement: ScMatchStmt): Unit = { + statement.getBranches.foreach(acceptVisitor) + } + + override def visitIfStatement(statement: ScIfStmt): Unit = { + statement.elseBranch match { + case Some(elseBranch) => + acceptVisitor(elseBranch) + statement.thenBranch.foreach(acceptVisitor) + case _ => super.visitIfStatement(statement) + } + } + + override def visitReferenceExpression(reference: ScReferenceExpression): Unit = { + visitExpression(reference) + } + + override def visitExpression(expression: ScExpression): Unit = { + val maybeLastExpression = expression match { + case block: ScBlock => block.lastExpr + case _ => None + } + + maybeLastExpression match { + case Some(lastExpression) => + acceptVisitor(lastExpression) + case _ => + super.visitExpression(expression) + result_ += expression + } + } + + protected def acceptVisitor(expression: ScExpression): Unit = { + expression.accept(this) + } } case class ExpressionTypeResult(tr: TypeResult, @@ -196,6 +240,7 @@ object ScExpression { implicit class Ext(val expr: ScExpression) extends AnyVal { private implicit def elementScope: ElementScope = expr.elementScope + private def project = elementScope.projectContext def expectedType(fromUnderscore: Boolean = true): Option[ScType] = @@ -440,8 +485,10 @@ object ScExpression { def isNarrowing(expected: ScType): Option[TypeResult] = { import expr.projectContext - def isByte(v: Long) = v >= scala.Byte.MinValue && v <= scala.Byte.MaxValue - def isChar(v: Long) = v >= scala.Char.MinValue && v <= scala.Char.MaxValue + def isByte(v: Long) = v >= scala.Byte.MinValue && v <= scala.Byte.MaxValue + + def isChar(v: Long) = v >= scala.Char.MinValue && v <= scala.Char.MaxValue + def isShort(v: Long) = v >= scala.Short.MinValue && v <= scala.Short.MaxValue def success(t: ScType) = Some(Right(t)) @@ -458,8 +505,8 @@ object ScExpression { import stdTypes._ expected.removeAbstracts match { - case Char if isChar(intLiteralValue) => success(Char) - case Byte if isByte(intLiteralValue) => success(Byte) + case Char if isChar(intLiteralValue) => success(Char) + case Byte if isByte(intLiteralValue) => success(Byte) case Short if isShort(intLiteralValue) => success(Short) case _ => None } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala index 02011cb6c96..204d699a564 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/statements/ScFunctionDefinition.scala @@ -7,7 +7,7 @@ package statements import com.intellij.psi._ import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScCaseClauses, ScConstructorPattern, ScInfixPattern} +import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScConstructorPattern, ScInfixPattern} import org.jetbrains.plugins.scala.lang.psi.api.base.{ScConstructor, ScReferenceElement, ScStableCodeReferenceElement} import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression.calculateReturns import org.jetbrains.plugins.scala.lang.psi.api.expr._ @@ -82,30 +82,22 @@ trait ScFunctionDefinition extends ScFunction with ScControlFlowOwner { val expressions: Set[PsiElement] = recursiveReferences match { case Seq() => Set.empty case _ => - val booleanInstance = StdTypes.instance.Boolean - - def calculateExpandedReturns: ScExpression => Set[ScExpression] = { - case ScInfixExpr(Typeable(`booleanInstance`), ElementText("&&" | "||"), right@Typeable(`booleanInstance`)) => - calculateExpandedReturns(right) - case ScTryStmt(tryBlock, maybeCatchBlock, _) => - calculateExpandedReturns(tryBlock) ++ - maybeCatchBlock.collect { - case ScCatchBlock(clauses) => clauses - }.toSet[ScCaseClauses] - .flatMap(_.caseClauses) - .flatMap(_.expr) - .flatMap(calculateExpandedReturns) - case block: ScBlock => - block.lastExpr - .map(calculateExpandedReturns) - .getOrElse(Set(block)) - case ScParenthesisedExpr(innerExpression) => calculateExpandedReturns(innerExpression) - case m: ScMatchStmt => - m.getBranches.toSet.flatMap(calculateExpandedReturns) - case ScIfStmt(_, maybeThenBranch, Some(elseBranch)) => - calculateExpandedReturns(elseBranch) ++ - maybeThenBranch.toSet.flatMap(calculateExpandedReturns) - case expression => Set(expression) + def calculateExpandedReturns(expression: ScExpression): Set[ScExpression] = { + val visitor = new ScExpression.ReturnsVisitor { + + private val booleanInstance = StdTypes.instance.Boolean + + override def visitInfixExpression(infix: ScInfixExpr): Unit = { + infix match { + case ScInfixExpr(Typeable(`booleanInstance`), ElementText("&&" | "||"), right@Typeable(`booleanInstance`)) => + acceptVisitor(right) + case _ => super.visitInfixExpression(infix) + } + } + } + + expression.accept(visitor) + visitor.result } def expandIf(expression: ScExpression): Set[ScExpression] = (expression match { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScBlockImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScBlockImpl.scala index 0374922de7c..c733b033fa5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScBlockImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScBlockImpl.scala @@ -5,12 +5,11 @@ package impl package expr import com.intellij.lang.ASTNode -import org.jetbrains.plugins.scala.lang.psi.api.expr._ - +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScBlock /** * @author ilyas */ -class ScBlockImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScBlock { +class ScBlockImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScBlock { override def toString: String = "BlockOfExpressions" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala new file mode 100644 index 00000000000..5f180fdd53c --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala @@ -0,0 +1,24 @@ +package org.jetbrains.plugins.scala +package lang +package psi +package impl +package expr + +import com.intellij.lang.ASTNode +import com.intellij.psi.PsiElementVisitor +import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression + +class ScExpressionImplBase(node: ASTNode) extends ScalaPsiElementImpl(node) with ScExpression { + + override def accept(visitor: PsiElementVisitor): Unit = { + visitor match { + case scalaVisitor: ScalaElementVisitor => accept(scalaVisitor) + case _ => super.accept(visitor) + } + } + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitExpression(this) + } +} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryBlockImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryBlockImpl.scala index 09b51a2677e..5add065e00e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryBlockImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryBlockImpl.scala @@ -5,13 +5,12 @@ package impl package expr import com.intellij.lang.ASTNode -import org.jetbrains.plugins.scala.lang.psi.api.expr._ +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScTryBlock -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - -class ScTryBlockImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryBlock { +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScTryBlockImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScTryBlock { override def toString: String = "TryBlock" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala index 2b2ca97e78b..0065759da03 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnitExprImpl.scala @@ -5,16 +5,15 @@ package impl package expr import com.intellij.lang.ASTNode -import org.jetbrains.plugins.scala.lang.psi.api.expr._ +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScUnitExpr import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author ilyas, Alexander Podkhalyuzin */ +class ScUnitExprImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScUnitExpr { + protected override def innerType: TypeResult = Right(Unit) -class ScUnitExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScUnitExpr { override def toString: String = "UnitExpression" - - protected override def innerType: TypeResult = Right(Unit) } \ No newline at end of file From 5995726582b18abea20faf0c4910cd91d4e2aad6 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 31 Oct 2017 00:56:55 +0100 Subject: [PATCH 134/141] update latest sbt and scala versions --- project/dependencies.scala | 4 ++-- .../org/jetbrains/plugins/scala/debugger/ScalaVersion.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index 954c890e36d..bfab4bcc798 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -29,7 +29,7 @@ object Versions { val latest_2_9 = "2.9.3" val latest_2_10 = "2.10.6" val latest_2_11 = "2.11.11" - val latest_2_12 = "2.12.3" + val latest_2_12 = "2.12.4" val latest: String = latest_2_12 def binaryVersion(v: String): String = @@ -47,7 +47,7 @@ object Versions { val latest_0_12 = "0.12.4" val latest_0_13 = "0.13.16" - val latest_1_0 = "1.0.1" + val latest_1_0 = "1.0.3" val latest: String = latest_1_0 def scalaVersion(v: String): String = diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala index fef698d41bd..52b094a4bf2 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala @@ -38,7 +38,7 @@ case object Scala_2_11_11 extends ScalaVersion { case object Scala_2_12 extends ScalaVersion { override final val major: String = "2.12" - override final val minor: String = "2.12.3" + override final val minor: String = "2.12.4" } trait ScalaSdkOwner { From e8fa054eae22c5f9c61a8c5976d131110d7575f1 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Tue, 31 Oct 2017 00:57:13 +0100 Subject: [PATCH 135/141] reduce timeout for sbt tests --- .../test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index 22903a43a49..13a94ad0e53 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -158,7 +158,7 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { comm.command("exit", showShell = false) } - val exitCode = Await.result(logger.terminated, 10.minutes) + val exitCode = Await.result(logger.terminated, 3.minutes) val log = logger.getLog assert(exitCode == 0, s"sbt shell completed with nonzero exit code. Full log:\n$log") expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'. Full log:\n$log")) From 7364944a0f9629c19f2a4593eb158e318f0b259f Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Thu, 2 Nov 2017 20:31:11 +0100 Subject: [PATCH 136/141] don't use scala version 2.12.4 as project version because of https://github.com/scala/bug/issues/10568 --- project/dependencies.scala | 2 +- .../src/org/jetbrains/plugins/scala/project/Versions.scala | 2 +- .../org/jetbrains/plugins/scala/debugger/ScalaVersion.scala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/project/dependencies.scala b/project/dependencies.scala index bfab4bcc798..972d5945945 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -29,7 +29,7 @@ object Versions { val latest_2_9 = "2.9.3" val latest_2_10 = "2.10.6" val latest_2_11 = "2.11.11" - val latest_2_12 = "2.12.4" + val latest_2_12 = "2.12.3" // don't upgrade to 2.12.4 because it breaks compilation. https://github.com/scala/bug/issues/10568 val latest: String = latest_2_12 def binaryVersion(v: String): String = diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/project/Versions.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/project/Versions.scala index 6f23e5ce819..3a76b9cbc85 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/project/Versions.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/project/Versions.scala @@ -64,7 +64,7 @@ object Versions { val Scala = Entity("http://repo1.maven.org/maven2/org/scala-lang/scala-compiler/", ".+>(\\d+\\.\\d+\\.\\d+)/<.*".r, Version("2.10.0"), - Seq("2.10.6", "2.11.11", "2.12.3")) + Seq("2.10.6", "2.11.11", "2.12.4")) val Sbt013 = Entity("https://dl.bintray.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/", ".+>(\\d+\\.\\d+\\.\\d+)/<.*".r, diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala index 52b094a4bf2..fef698d41bd 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/debugger/ScalaVersion.scala @@ -38,7 +38,7 @@ case object Scala_2_11_11 extends ScalaVersion { case object Scala_2_12 extends ScalaVersion { override final val major: String = "2.12" - override final val minor: String = "2.12.4" + override final val minor: String = "2.12.3" } trait ScalaSdkOwner { From 28ae1ff05b391087f5eba19f0b4def9725729c6c Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Fri, 3 Nov 2017 14:45:58 +0100 Subject: [PATCH 137/141] update sbt module versions in test downloaders and mock sbt libraryLoaders --- build.sbt | 4 +- project/dependencies.scala | 33 +++++++++------ .../test/org/jetbrains/sbt/MockSbt.scala | 41 +++++++++++++++---- 3 files changed, 55 insertions(+), 23 deletions(-) diff --git a/build.sbt b/build.sbt index 8f9864bd4c1..2cf36ec7a15 100644 --- a/build.sbt +++ b/build.sbt @@ -168,7 +168,7 @@ lazy val sbtRuntimeDependencies = ideSkipProject := true ) -lazy val testDownloader = +lazy val testJarsDownloader = newProject("testJarsDownloader", file("target/tools/test-jars-downloader")) .settings( conflictManager := ConflictManager.all, @@ -226,7 +226,7 @@ addCommandAlias("runFastTestsScala", s"testOnly scala.* -- $fastTestOptions") lazy val setUpTestEnvironment = taskKey[Unit]("Set up proper environment for running tests") setUpTestEnvironment in ThisBuild := { - update.in(testDownloader).value + update.in(testJarsDownloader).value } lazy val cleanUpTestEnvironment = taskKey[Unit]("Clean up IDEA test system and config directories") diff --git a/project/dependencies.scala b/project/dependencies.scala index 972d5945945..f202f1fe99a 100644 --- a/project/dependencies.scala +++ b/project/dependencies.scala @@ -3,8 +3,9 @@ import sbt._ object Versions { val scalaVersion: String = Scala.latest_2_12 val scalaBinaryVersion: String = Scala.binary_2_12 + // ATTENTION: when updating sbtVersion also update versions in MockSbt_1_0 val sbtVersion: String = Sbt.latest - val zincVersion = "1.0.0" + val zincVersion = "1.0.3" val ideaVersion = "173.3415.22" val sbtStructureVersion: String = "2017.2" val sbtIdeaShellVersion: String = "2017.2" @@ -50,6 +51,12 @@ object Versions { val latest_1_0 = "1.0.3" val latest: String = latest_1_0 + // these need to be updated to correspond to the versions in sbt/project/Dependencies.scala + // they are required for our tests. TODO: automatically update them based on sbt base version + val latestIo = "1.0.2" + val latestUtil = "1.0.2" + val latestLm = "1.0.3" + def scalaVersion(v: String): String = if (v.startsWith(Sbt.binary_0_12)) Scala.binary_2_9 else if (v.startsWith(Sbt.binary_0_13)) Scala.binary_2_10 @@ -239,17 +246,19 @@ object DependencyGroups { ) val sbt1CrossScala: CrossVersion = CrossVersion.fullMapped(_ => Scala.binary_2_12) - def sbt100Libs(v:String): Seq[ModuleID] = - // these are not cross-versioned - Seq("sbt", "util-interface", "test-agent").map(lib => sbtOrg % lib % v) ++ - // this has separate versioning - Seq(sbtOrg % "compiler-interface" % "1.0.0") ++ - // all of these are published cross-versioned for scala 2.12 - Seq( - "main","logic","collections","util-position","util-relation","actions","completion","io", - "util-control","run","util-logging","task-system","tasks","util-cache", - "testing","util-tracking","main-settings","command","protocol","core-macros", "librarymanagement-core" - ).map(lib => (sbtOrg % lib % v).withCrossVersion(sbt1CrossScala)) +// def sbt100Libs(v:String): Seq[ModuleID] = +// // these are not cross-versioned +// Seq("sbt", "util-interface", "test-agent").map(lib => sbtOrg % lib % v) ++ +// // this has separate versioning +// Seq(sbtOrg % "compiler-interface" % zincVersion) ++ +// // all of these are published cross-versioned for scala 2.12 +// Seq( +// "main","logic","collections","util-position","util-relation","actions","completion","io", +// "util-control","run","util-logging","task-system","tasks","util-cache", +// "testing","util-tracking","main-settings","command","protocol","core-macros", "librarymanagement-core" +// ).map(lib => (sbtOrg % lib % v).withCrossVersion(sbt1CrossScala)) + + def sbt100Libs(v:String): Seq[ModuleID] = Seq(sbtOrg % "sbt" % v) // all the modules are transitive deps // required jars for MockSbt - it adds different versions to test module classpath val mockSbtDownloader: Seq[ModuleID] = { diff --git a/scala/scala-impl/test/org/jetbrains/sbt/MockSbt.scala b/scala/scala-impl/test/org/jetbrains/sbt/MockSbt.scala index 9f9e450ea77..a13cb3ac12d 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/MockSbt.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/MockSbt.scala @@ -6,7 +6,7 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.vfs.VfsUtil import org.jetbrains.plugins.scala.base.libraryLoaders.ScalaLibraryLoader.{ScalaCompilerLoader, ScalaLibraryLoaderAdapter, ScalaReflectLoader, ScalaRuntimeLoader} -import org.jetbrains.plugins.scala.base.libraryLoaders.{IvyLibraryLoader, IvyLibraryLoaderAdapter, LibraryLoader} +import org.jetbrains.plugins.scala.base.libraryLoaders.{IvyLibraryLoader, IvyLibraryLoaderAdapter} import org.jetbrains.plugins.scala.debugger._ import org.jetbrains.sbt.MockSbt._ @@ -54,23 +54,46 @@ trait MockSbt_0_13 extends MockSbtBase { trait MockSbt_1_0 extends MockSbtBase { override implicit val version: ScalaVersion = Scala_2_12 - private val sbt_1_0_modules = Seq("sbt", "util-interface", "test-agent") + // https://github.com/sbt/sbt/blob/1.x/project/Dependencies.scala + // update them when updating versions.sbtVersion + // TODO find a way to automatically get the dependencies via transitive deps from org.scala-sbt:sbt artifact + private val ioVersion = "1.0.2" + private val utilVersion = "1.0.2" + private val lmVersion = "1.0.3" + private val zincVersion = "1.0.3" + + private val sbt_1_0_modules = Seq("sbt", "test-agent") + + private val util_cross = Seq("util-cache","util-control","util-logging","util-position","util-relation","util-tracking") + private val lm_cross = Seq("librarymanagement-core","librarymanagement-ivy") private val sbt_1_0_modules_cross = Seq( - "main","logic","collections","util-position","util-relation","actions","completion","io", - "util-control","run","util-logging","task-system","tasks","util-cache", - "testing","util-tracking","main-settings","command","protocol","core-macros", "librarymanagement-core") + "main","logic","collections","actions","completion", + "run","task-system","tasks","testing","main-settings", + "command","protocol","core-macros") - private def sbt_1_0_compiler_interface(implicit module: Module) = new SbtBaseLoader() { + private def compilerInterfaceLoader(implicit module: Module) = new SbtBaseLoader() { override val name: String = "compiler-interface" - override val version = "1.0.0" + override val version: String = zincVersion + } + + private def utilInterfaceLoader = new SbtBaseLoader() { + override val name: String = "util-interface" + override val version: String = utilVersion + } + + private def ioLoader = new SbtBaseLoader_Cross() { + override val name: String = "io" + override val version: String = ioVersion } override protected def librariesLoaders: Seq[IvyLibraryLoader] = scalaLoaders ++ sbt_1_0_modules.map(sbtLoader) ++ - sbt_1_0_modules_cross.map(sbtLoader_cross) :+ - sbt_1_0_compiler_interface + sbt_1_0_modules_cross.map(sbtLoader_cross) ++ + util_cross.map(sbtLoader_cross(_)(utilVersion,module)) ++ + lm_cross.map(sbtLoader_cross(_)(lmVersion,module)) ++ + Seq(compilerInterfaceLoader, ioLoader, utilInterfaceLoader) } private[sbt] object MockSbt { From 7bd75810e41b22d4fd3a4da42cc74f68013ff303 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Sun, 5 Nov 2017 14:10:37 +0100 Subject: [PATCH 138/141] contortions to wait for the sbt shell test process to end. #SCL-12167 --- .../sbt/shell/UseSbtTestRunTest.scala | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala index 13a94ad0e53..cc34496a89b 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/UseSbtTestRunTest.scala @@ -2,16 +2,18 @@ package org.jetbrains.sbt.shell import com.intellij.execution.Executor import com.intellij.execution.executors.DefaultRunExecutor -import com.intellij.execution.runners.ExecutionEnvironmentBuilder +import com.intellij.execution.process.{ProcessAdapter, ProcessEvent} +import com.intellij.execution.runners.{ExecutionEnvironmentBuilder, ProgramRunner} +import com.intellij.execution.ui.RunContentDescriptor import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.roots.ProjectRootManager import org.jetbrains.plugins.scala.SlowTests import org.jetbrains.plugins.scala.testingSupport.ScalaTestingTestCase import org.jetbrains.plugins.scala.testingSupport.test.{AbstractTestRunConfiguration, TestRunConfigurationForm} import org.junit.experimental.categories.Category -import scala.concurrent.Await -import scala.concurrent.duration._ +import scala.concurrent.{Await, Promise} +import scala.concurrent.duration._ import com.intellij.testFramework.EdtTestUtil /** @@ -149,16 +151,36 @@ abstract class UseSbtTestRunTest extends SbtProjectPlatformTestCase { val sdk = ProjectRootManager.getInstance(project).getProjectSdk assert(sdk != null, s"project sdk was null in project ${project.getName}") + val runComplete = Promise[Int] + EdtTestUtil.runInEdtAndWait { () => val executor: Executor = Executor.EXECUTOR_EXTENSION_NAME.findExtension(classOf[DefaultRunExecutor]) val executionEnvironmentBuilder: ExecutionEnvironmentBuilder = new ExecutionEnvironmentBuilder(project, executor) - executionEnvironmentBuilder.runProfile(config).buildAndExecute() + + // we need this whole setup to get the SbtProcessHandlerWrapper that the run config uses + // rather than the sbt shell process handler since it isn't terminated by the time the test run completes + val executionEnvironment = executionEnvironmentBuilder + .runProfile(config) + .build() + + val runCompleteListener = new ProcessAdapter { + override def processTerminated(event: ProcessEvent): Unit = + if (!runComplete.isCompleted) + runComplete.success(event.getExitCode) + } + + val callback = new ProgramRunner.Callback { + override def processStarted(descriptor: RunContentDescriptor): Unit = { + descriptor.getProcessHandler.addProcessListener(runCompleteListener) + } + } + + executionEnvironment.getRunner.execute(executionEnvironment, callback) runner.getConsoleView.flushDeferredText() - comm.command("exit", showShell = false) } - val exitCode = Await.result(logger.terminated, 3.minutes) + val exitCode = Await.result(runComplete.future, 3.minutes) val log = logger.getLog assert(exitCode == 0, s"sbt shell completed with nonzero exit code. Full log:\n$log") expectedStrings.foreach(str => assert(log.contains(str), s"sbt shell console did not contain expected string '$str'. Full log:\n$log")) From 058badfd65304053a54c7ceecde3a63d2476d51c Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Sat, 4 Nov 2017 15:47:47 +0300 Subject: [PATCH 139/141] ScExpressionImplBase inheritors --- .../lang/psi/api/expr/ScAssignStmt.scala | 29 ++++---- .../lang/psi/api/expr/ScCatchBlock.scala | 16 +++-- .../lang/psi/api/expr/ScConstrBlock.scala | 14 ++-- .../scala/lang/psi/api/expr/ScDoStmt.scala | 36 +++++----- .../lang/psi/api/expr/ScExpression.scala | 4 ++ .../lang/psi/api/expr/ScFinallyBlock.scala | 9 ++- .../lang/psi/api/expr/ScForStatement.scala | 28 +++++--- .../lang/psi/api/expr/ScFunctionExpr.scala | 9 +-- .../scala/lang/psi/api/expr/ScGenerator.scala | 19 +++-- .../lang/psi/api/expr/ScGenericCall.scala | 15 ++-- .../scala/lang/psi/api/expr/ScGuard.scala | 4 +- .../scala/lang/psi/api/expr/ScIfStmt.scala | 27 ++++--- .../scala/lang/psi/api/expr/ScInfixExpr.scala | 14 ++-- .../scala/lang/psi/api/expr/ScMatchStmt.scala | 18 ++--- .../lang/psi/api/expr/ScMethodCall.scala | 23 +++--- .../psi/api/expr/ScParenthesisedExpr.scala | 14 ++-- .../lang/psi/api/expr/ScPostfixExpr.scala | 19 +++-- .../lang/psi/api/expr/ScPrefixExpr.scala | 17 +++-- .../lang/psi/api/expr/ScReturnStmt.scala | 4 +- .../lang/psi/api/expr/ScSelfInvocation.scala | 13 ++-- .../lang/psi/api/expr/ScSuperReference.scala | 21 +++--- .../lang/psi/api/expr/ScThisReference.scala | 19 +++-- .../scala/lang/psi/api/expr/ScThrowStmt.scala | 8 +-- .../scala/lang/psi/api/expr/ScTryStmt.scala | 14 ++-- .../scala/lang/psi/api/expr/ScTuple.scala | 16 +++-- .../scala/lang/psi/api/expr/ScTypedStmt.scala | 15 ++-- .../psi/api/expr/ScUnderscoreSection.scala | 6 +- .../scala/lang/psi/api/expr/ScWhileStmt.scala | 16 ++--- .../lang/psi/impl/expr/ScAssignStmtImpl.scala | 21 ++---- .../lang/psi/impl/expr/ScCatchBlockImpl.scala | 22 ++---- .../psi/impl/expr/ScConstrBlockImpl.scala | 20 ++---- .../lang/psi/impl/expr/ScConstrExprImpl.scala | 10 +-- .../lang/psi/impl/expr/ScDoStmtImpl.scala | 28 ++------ .../psi/impl/expr/ScExpressionImplBase.scala | 12 +--- .../psi/impl/expr/ScFinallyBlockImpl.scala | 13 ++-- .../psi/impl/expr/ScForStatementImpl.scala | 70 +++++++++---------- .../psi/impl/expr/ScFunctionExprImpl.scala | 20 ++---- .../lang/psi/impl/expr/ScGeneratorImpl.scala | 28 +++----- .../psi/impl/expr/ScGenericCallImpl.scala | 60 +++++++--------- .../lang/psi/impl/expr/ScGuardImpl.scala | 6 +- .../lang/psi/impl/expr/ScIfStmtImpl.scala | 28 +++----- .../lang/psi/impl/expr/ScInfixExprImpl.scala | 25 ++----- .../lang/psi/impl/expr/ScMatchStmtImpl.scala | 21 ++---- .../lang/psi/impl/expr/ScMethodCallImpl.scala | 19 ++--- .../impl/expr/ScParenthesisedExprImpl.scala | 26 ++----- .../psi/impl/expr/ScPostfixExprImpl.scala | 26 ++----- .../lang/psi/impl/expr/ScPrefixExprImpl.scala | 25 ++----- .../lang/psi/impl/expr/ScReturnStmtImpl.scala | 17 ++--- .../psi/impl/expr/ScSelfInvocationImpl.scala | 35 ++++------ .../psi/impl/expr/ScSuperReferenceImpl.scala | 61 ++++++---------- .../psi/impl/expr/ScThisReferenceImpl.scala | 23 ++---- .../lang/psi/impl/expr/ScThrowStmtImpl.scala | 20 ++---- .../lang/psi/impl/expr/ScTryStmtImpl.scala | 15 +--- .../lang/psi/impl/expr/ScTupleImpl.scala | 16 +---- .../lang/psi/impl/expr/ScTypedStmtImpl.scala | 16 +---- .../impl/expr/ScUnderscoreSectionImpl.scala | 18 +---- .../lang/psi/impl/expr/ScWhileStmtImpl.scala | 21 ++---- 57 files changed, 478 insertions(+), 691 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAssignStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAssignStmt.scala index 21d28cba5a4..f8559792c20 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAssignStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScAssignStmt.scala @@ -7,14 +7,12 @@ package expr import com.intellij.psi.{PsiElement, PsiField} import org.jetbrains.plugins.scala.lang.psi.api.statements.ScVariable import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScClassParameter +import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult import org.jetbrains.plugins.scala.lang.resolve.processor.DynamicResolveProcessor -import org.jetbrains.plugins.scala.lang.resolve.{ResolvableReferenceExpression, ScalaResolveResult} - /** - * @author Alexander Podkhalyuzin - */ - + * @author Alexander Podkhalyuzin + */ trait ScAssignStmt extends ScExpression { def getLExpression: ScExpression = findChildByClassScala(classOf[ScExpression]) @@ -25,15 +23,11 @@ trait ScAssignStmt extends ScExpression { def assignName: Option[String] = { getLExpression match { - case ref: ScReferenceExpression if ref.qualifier == None => Some(ref.getText) + case ref: ScReferenceExpression if ref.qualifier.isEmpty => Some(ref.getText) case _ => None } } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitAssignmentStatement(this) - } - def isNamedParameter: Boolean = { getLExpression match { case expr: ScReferenceExpression => @@ -48,16 +42,17 @@ trait ScAssignStmt extends ScExpression { def mirrorMethodCall: Option[ScMethodCall] /** - * Has sense only in case if left token resolves to parameterless function - * @return parameterless function setter, or None otherwise - */ + * Has sense only in case if left token resolves to parameterless function + * + * @return parameterless function setter, or None otherwise + */ def resolveAssignment: Option[ScalaResolveResult] def shapeResolveAssignment: Option[ScalaResolveResult] /** - * @return element to which equals sign should navigate - */ + * @return element to which equals sign should navigate + */ def assignNavigationElement: PsiElement = { getLExpression match { case methodCall: ScMethodCall => @@ -105,6 +100,10 @@ trait ScAssignStmt extends ScExpression { } false } + + override def accept(visitor: ScalaElementVisitor) { + visitor.visitAssignmentStatement(this) + } } object NamedAssignStmt { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScCatchBlock.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScCatchBlock.scala index f1668c1e437..f5ff08b27f2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScCatchBlock.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScCatchBlock.scala @@ -9,13 +9,19 @@ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScCaseClauses /** - * Author: Alexander Podkhalyuzin - * Date: 06.03.2008 - */ + * Author: Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScCatchBlock extends ScalaPsiElement { def expression: Option[ScExpression] = findChild(classOf[ScExpression]) - def getLeftParenthesis : Option[PsiElement] - def getRightParenthesis : Option[PsiElement] + + def getLeftParenthesis: Option[PsiElement] + + def getRightParenthesis: Option[PsiElement] + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitCatchBlock(this) + } } object ScCatchBlock { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScConstrBlock.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScConstrBlock.scala index d20ff2e7be6..3f29df65cdc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScConstrBlock.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScConstrBlock.scala @@ -1,13 +1,17 @@ - package org.jetbrains.plugins.scala +package org.jetbrains.plugins.scala package lang package psi package api package expr - /** -* @author Alexander.Podkhalyuzin -*/ - +/** + * @author Alexander.Podkhalyuzin + */ trait ScConstrBlock extends ScBlockExpr { + def selfInvocation: Option[ScSelfInvocation] = findChild(classOf[ScSelfInvocation]) + + override def accept(visitor: ScalaElementVisitor) { + visitor.visitConstrBlock(this) + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScDoStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScDoStmt.scala index 131cedc3877..0f5145eaef7 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScDoStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScDoStmt.scala @@ -4,28 +4,30 @@ package psi package api package expr -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScDoStmt extends ScExpression { def condition: Option[ScExpression] - - /** - * retrun loop expression of do statement - * @return body of do statement - */ - def getExprBody: Option[ScExpression] - /** - * return does do statement has loop expression - * @return has loop expression - */ - def hasExprBody: Boolean + /** + * retrun loop expression of do statement + * + * @return body of do statement + */ + def getExprBody: Option[ScExpression] + /** + * return does do statement has loop expression + * + * @return has loop expression + */ + def hasExprBody: Boolean = getExprBody.isDefined - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitDoStatement(this) + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitDoStatement(this) + } } object ScDoStmt { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala index e1347c06614..ad70efdfa5f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScExpression.scala @@ -157,6 +157,10 @@ trait ScExpression extends ScBlockStatement with PsiAnnotationMemberValue with I else firstName.compareTo(secondName) < 0 } } + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitExpression(this) + } } object ScExpression { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFinallyBlock.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFinallyBlock.scala index 53e20d8e019..81edfd557d9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFinallyBlock.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFinallyBlock.scala @@ -4,11 +4,10 @@ package psi package api package expr -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScFinallyBlock extends ScalaPsiElement { def expression: Option[ScExpression] = findChild(classOf[ScExpression]) } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScForStatement.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScForStatement.scala index 32c96875e06..c95cd088af3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScForStatement.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScForStatement.scala @@ -7,26 +7,34 @@ package expr import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScForStatement extends ScExpression { def getDesugarizedExpr: Option[ScExpression] /** - * @param forDisplay true if the desugaring is intended for DesugarForIntention, - * false if it is intented for the type system. + * @param forDisplay true if the desugaring is intended for DesugarForIntention, + * false if it is intented for the type system. */ def getDesugarizedExprText(forDisplay: Boolean): Option[String] + def isYield: Boolean + def enumerators: Option[ScEnumerators] + def patterns: Seq[ScPattern] + def body: Option[ScExpression] = findChild(classOf[ScExpression]) - def getLeftParenthesis : Option[PsiElement] - def getRightParenthesis : Option[PsiElement] - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitForExpression(this) + + def getLeftParenthesis: Option[PsiElement] + + def getRightParenthesis: Option[PsiElement] + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitForExpression(this) + } } object ScForStatement { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFunctionExpr.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFunctionExpr.scala index 1460733ae0e..e0766c153fb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFunctionExpr.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScFunctionExpr.scala @@ -7,9 +7,8 @@ package expr import org.jetbrains.plugins.scala.lang.psi.api.statements.params._ /** -* @author Alexander Podkhalyuzin, ilyas -*/ - + * @author Alexander Podkhalyuzin, ilyas + */ trait ScFunctionExpr extends ScExpression with ScControlFlowOwner { def parameters: Seq[ScParameter] @@ -18,7 +17,9 @@ trait ScFunctionExpr extends ScExpression with ScControlFlowOwner { def result: Option[ScExpression] - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitFunctionExpression(this) + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitFunctionExpression(this) + } } object ScFunctionExpr { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenerator.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenerator.scala index 051252890da..52cd9e6533d 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenerator.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenerator.scala @@ -7,20 +7,19 @@ package expr import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes - -/** -* @author Alexander Podkhalyuzin -* Date: 07.03.2008 -*/ - -trait ScGenerator extends ScalaPsiElement with ScPatterned{ +/** + * @author Alexander Podkhalyuzin + * Date: 07.03.2008 + */ +trait ScGenerator extends ScalaPsiElement with ScPatterned { def guard: ScGuard def rvalue: ScExpression - def valKeyword: Option[PsiElement] = { + def valKeyword: Option[PsiElement] = Option(getNode.findChildByType(ScalaTokenTypes.kVAL)).map(_.getPsi) - } - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitGenerator(this) + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitGenerator(this) + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala index 4080c2d9520..e042c6d208c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGenericCall.scala @@ -8,18 +8,17 @@ import com.intellij.psi.ResolveResult import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScTypeArgs, ScTypeElement} import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScGenericCall extends ScExpression { def referencedExpr: ScExpression = findChildByClassScala(classOf[ScExpression]) def typeArgs: Option[ScTypeArgs] = findChild(classOf[ScTypeArgs]) - def arguments : Seq[ScTypeElement] = (for (t <- typeArgs) yield t.typeArgs) match { + def arguments: Seq[ScTypeElement] = (for (t <- typeArgs) yield t.typeArgs) match { case Some(x) => x case _ => Nil } @@ -33,6 +32,10 @@ trait ScGenericCall extends ScExpression { def multiType: Array[TypeResult] def multiResolve: Option[Array[ResolveResult]] + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitGenericCallExpression(this) + } } object ScGenericCall { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGuard.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGuard.scala index 434bffccd17..ed68c284b5c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGuard.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScGuard.scala @@ -5,8 +5,8 @@ package api package expr /** - * @author Alexander Podkhalyuzin - */ + * @author Alexander Podkhalyuzin + */ trait ScGuard extends ScalaPsiElement { def expr: Option[ScExpression] diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScIfStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScIfStmt.scala index 2ca3da26c9d..66027cfd6cb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScIfStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScIfStmt.scala @@ -6,19 +6,24 @@ package expr import com.intellij.psi.PsiElement - -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScIfStmt extends ScExpression { def condition: Option[ScExpression] - def thenBranch : Option[ScExpression] - def elseBranch : Option[ScExpression] - def getLeftParenthesis : Option[PsiElement] - def getRightParenthesis : Option[PsiElement] - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitIfStatement(this) + + def thenBranch: Option[ScExpression] + + def elseBranch: Option[ScExpression] + + def getLeftParenthesis: Option[PsiElement] + + def getRightParenthesis: Option[PsiElement] + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitIfStatement(this) + } } object ScIfStmt { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScInfixExpr.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScInfixExpr.scala index 0e063d3e081..731b4899782 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScInfixExpr.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScInfixExpr.scala @@ -10,17 +10,17 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeArgs import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil /** -* @author Alexander Podkhalyuzin -*/ - + * @author Alexander Podkhalyuzin + */ trait ScInfixExpr extends ScExpression with ScSugarCallExpr { + def lOp: ScExpression = findChildrenByClassScala(classOf[ScExpression]).apply(0) - def operation : ScReferenceExpression = { + def operation: ScReferenceExpression = { val children = findChildrenByClassScala(classOf[ScExpression]) if (children.length < 2) throw new RuntimeException("Wrong infix expression: " + getText) children.apply(1) match { - case re : ScReferenceExpression => re + case re: ScReferenceExpression => re case _ => throw new RuntimeException("Wrong infix expression: " + getText) } } @@ -53,6 +53,10 @@ trait ScInfixExpr extends ScExpression with ScSugarCallExpr { def getInvokedExpr: ScExpression = operation def argsElement: PsiElement = getArgExpr + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitInfixExpression(this) + } } object ScInfixExpr { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMatchStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMatchStmt.scala index 902afc0e01a..a54f0a90e94 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMatchStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMatchStmt.scala @@ -8,19 +8,19 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.{ScCaseClause, ScC import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createExpressionFromText /** - * @author Alexander Podkhalyuzin, ilyas - */ - + * @author Alexander Podkhalyuzin, ilyas + */ trait ScMatchStmt extends ScExpression { def expr: Option[ScExpression] = findChild(classOf[ScExpression]) def getBranches: Seq[ScExpression] = getCaseClauses match { case null => Seq.empty case c => c.caseClauses.map { - (clause: ScCaseClause) => clause.expr match { - case Some(expr) => expr - case None => createExpressionFromText("{}") - } + (clause: ScCaseClause) => + clause.expr match { + case Some(expr) => expr + case None => createExpressionFromText("{}") + } } } @@ -32,7 +32,9 @@ trait ScMatchStmt extends ScExpression { else cc.caseClauses } - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitMatchStatement(this) + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitMatchStatement(this) + } } object ScMatchStmt { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMethodCall.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMethodCall.scala index b1839a08188..95e038119b8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMethodCall.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScMethodCall.scala @@ -6,11 +6,10 @@ package expr import com.intellij.psi.PsiElement -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScMethodCall extends ScExpression with MethodInvocation { def deepestInvokedExpr: ScExpression = { getEffectiveInvokedExpr match { @@ -22,12 +21,8 @@ trait ScMethodCall extends ScExpression with MethodInvocation { def args: ScArgumentExprList = findChildByClassScala(classOf[ScArgumentExprList]) - override def accept(visitor: ScalaElementVisitor) { - visitor.visitMethodCallExpression(this) - } - override def isUpdateCall: Boolean = getContext.isInstanceOf[ScAssignStmt] && - getContext.asInstanceOf[ScAssignStmt].getLExpression == this + getContext.asInstanceOf[ScAssignStmt].getLExpression == this def updateExpression(): Option[ScExpression] = { getContext match { @@ -39,9 +34,13 @@ trait ScMethodCall extends ScExpression with MethodInvocation { def argsElement: PsiElement = args /** - * If named parameters enabled for this method even if it is from java; needed for Play 2 support - */ + * If named parameters enabled for this method even if it is from java; needed for Play 2 support + */ def isNamedParametersEnabledEverywhere: Boolean = false + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitMethodCallExpression(this) + } } object ScMethodCall { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScParenthesisedExpr.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScParenthesisedExpr.scala index 5c5ac9ed266..8d980fc983a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScParenthesisedExpr.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScParenthesisedExpr.scala @@ -4,13 +4,17 @@ package psi package api package expr -/** -* @author Alexander Podkhalyuzin -* Date: 07.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 07.03.2008 + */ trait ScParenthesisedExpr extends ScInfixArgumentExpression { + def expr: Option[ScExpression] = findChild(classOf[ScExpression]) + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitExprInParent(this) + } } object ScParenthesisedExpr { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPostfixExpr.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPostfixExpr.scala index f5c4fca20d0..55b5e388c3b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPostfixExpr.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPostfixExpr.scala @@ -4,20 +4,25 @@ package psi package api package expr -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScPostfixExpr extends ScExpression with ScSugarCallExpr { + def operand: ScExpression = findChildrenByClassScala(classOf[ScExpression]).apply(0) - def operation : ScReferenceExpression = findChildrenByClassScala(classOf[ScExpression]).apply(1) match { - case re : ScReferenceExpression => re + + def operation: ScReferenceExpression = findChildrenByClassScala(classOf[ScExpression]).apply(1) match { + case re: ScReferenceExpression => re case _ => throw new UnsupportedOperationException("Postfix Expr Operation is not reference expression: " + this.getText) } def getBaseExpr: ScExpression = operand + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitPostfixExpression(this) + } } object ScPostfixExpr { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPrefixExpr.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPrefixExpr.scala index 74a3853a110..ef75dc6297f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPrefixExpr.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScPrefixExpr.scala @@ -6,16 +6,15 @@ package expr import com.intellij.psi.PsiElement -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScPrefixExpr extends ScExpression with ScSugarCallExpr { def operand: ScExpression = findChildrenByClassScala(classOf[ScExpression]).apply(1) - def operation : ScReferenceExpression = findChildrenByClassScala(classOf[ScExpression]).apply(0) match { - case re : ScReferenceExpression => re + def operation: ScReferenceExpression = findChildrenByClassScala(classOf[ScExpression]).apply(0) match { + case re: ScReferenceExpression => re case _ => throw new UnsupportedOperationException("Prefix Expr Operation is not reference expression: " + this.getText) } @@ -23,6 +22,10 @@ trait ScPrefixExpr extends ScExpression with ScSugarCallExpr { def argsElement: PsiElement = operation def getBaseExpr: ScExpression = operand + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitPrefixExpression(this) + } } object ScPrefixExpr { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala index cc8d52adbb1..d8b5f142ea4 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScReturnStmt.scala @@ -20,7 +20,9 @@ trait ScReturnStmt extends ScExpression { def returnFunction: Option[ScFunctionDefinition] = this.parentOfType(classOf[ScFunctionDefinition]) - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitReturnStatement(this) + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitReturnStatement(this) + } } object ScReturnStmt { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala index 3fed27555e7..17049c09fc9 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSelfInvocation.scala @@ -7,11 +7,10 @@ package expr import com.intellij.psi.{PsiElement, PsiReference} import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult -/** -* @author Alexander Podkhalyuzin -* Date: 22.02.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 22.02.2008 + */ trait ScSelfInvocation extends ScalaPsiElement with PsiReference { def args: Option[ScArgumentExprList] = findChild(classOf[ScArgumentExprList]) @@ -26,4 +25,8 @@ trait ScSelfInvocation extends ScalaPsiElement with PsiReference { def multiType(i: Int): Seq[TypeResult] def thisElement: PsiElement = getFirstChild + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitSelfInvocation(this) + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSuperReference.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSuperReference.scala index 2e212459ab4..806d6bf9cdc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSuperReference.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScSuperReference.scala @@ -9,24 +9,27 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.{ScPathElement, ScStableCod import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition /** -* @author Alexander Podkhalyuzin -* Date: 14.03.2008 -*/ - + * @author Alexander Podkhalyuzin + * Date: 14.03.2008 + */ trait ScSuperReference extends ScExpression with ScPathElement { /** - * @return is reference in decompiled file from Self type class - */ + * @return is reference in decompiled file from Self type class + */ def isHardCoded: Boolean //type of M for super[M] - def staticSuper : Option[ScType] - + def staticSuper: Option[ScType] + //name of super type as written in code def staticSuperName: String //for A.super or simply super - def drvTemplate : Option[ScTemplateDefinition] + def drvTemplate: Option[ScTemplateDefinition] def reference: Option[ScStableCodeReferenceElement] = findChild(classOf[ScStableCodeReferenceElement]) + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitSuperReference(this) + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThisReference.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThisReference.scala index c276526fd4b..c9a526449c5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThisReference.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThisReference.scala @@ -7,13 +7,18 @@ package expr import org.jetbrains.plugins.scala.lang.psi.api.base.{ScPathElement, ScStableCodeReferenceElement} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScThisReference extends ScExpression with ScPathElement { - def reference: Option[ScStableCodeReferenceElement] = findChild(classOf[ScStableCodeReferenceElement]) - def refTemplate : Option[ScTemplateDefinition] + def reference: Option[ScStableCodeReferenceElement] = + findChild(classOf[ScStableCodeReferenceElement]) + + def refTemplate: Option[ScTemplateDefinition] + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitThisReference(this) + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThrowStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThrowStmt.scala index f99fec1d403..3ae8316f7b3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThrowStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScThrowStmt.scala @@ -4,13 +4,13 @@ package psi package api package expr - /** * @author Alexander Podkhalyuzin */ - trait ScThrowStmt extends ScExpression { - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitThrowExpression(this) + def body: Option[ScExpression] = findChild(classOf[ScExpression]) - def body: Option[ScExpression] + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitThrowExpression(this) + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTryStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTryStmt.scala index 6d590bff05f..023cf4e2a47 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTryStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTryStmt.scala @@ -4,17 +4,19 @@ package psi package api package expr - -/** -* @author Alexander Podkhalyuzin -*/ - +/** + * @author Alexander Podkhalyuzin + */ trait ScTryStmt extends ScExpression { def tryBlock: ScTryBlock = findChildByClassScala(classOf[ScTryBlock]) + def catchBlock: Option[ScCatchBlock] = findChild(classOf[ScCatchBlock]) + def finallyBlock: Option[ScFinallyBlock] = findChild(classOf[ScFinallyBlock]) - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitTryExpression(this) + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitTryExpression(this) + } } object ScTryStmt { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTuple.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTuple.scala index 700cd83abb4..aac4fa095a5 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTuple.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTuple.scala @@ -4,13 +4,17 @@ package psi package api package expr -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScTuple extends ScInfixArgumentExpression { - def exprs : Seq[ScExpression] = findChildrenByClassScala(classOf[ScExpression]).toSeq + def exprs: Seq[ScExpression] = findChildrenByClassScala(classOf[ScExpression]).toSeq + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitTupleExpr(this) + } + } object ScTuple { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTypedStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTypedStmt.scala index 84938589dbe..29dc5f42859 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTypedStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScTypedStmt.scala @@ -6,13 +6,18 @@ package expr import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScSequenceArg, ScTypeElement} -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ trait ScTypedStmt extends ScExpression { def expr: ScExpression = findChildByClassScala(classOf[ScExpression]) + def typeElement: Option[ScTypeElement] = findChild(classOf[ScTypeElement]) + def isSequenceArg: Boolean = getLastChild.isInstanceOf[ScSequenceArg] + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitTypedStmt(this) + } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScUnderscoreSection.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScUnderscoreSection.scala index 86ea562e86b..9a002d6be0a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScUnderscoreSection.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScUnderscoreSection.scala @@ -10,13 +10,11 @@ import org.jetbrains.plugins.scala.lang.psi.api.base.ScConstructor import org.jetbrains.plugins.scala.lang.psi.api.expr.ScUnderScoreSectionUtil.isUnderscore import scala.annotation.tailrec -import scala.collection.mutable.ListBuffer /** * @author Alexander Podkhalyuzin * Date: 06.03.2008 */ - trait ScUnderscoreSection extends ScExpression { def bindingExpr: Option[ScExpression] = { findChildByClassScala(classOf[ScExpression]) match { @@ -89,6 +87,10 @@ trait ScUnderscoreSection extends ScExpression { case _ => go(removeParentheses(this)) } } + + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitUnderscoreExpression(this) + } } object ScUnderScoreSectionUtil { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScWhileStmt.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScWhileStmt.scala index 1d1cffc0a04..f9a4be1e2a8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScWhileStmt.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/api/expr/ScWhileStmt.scala @@ -6,21 +6,21 @@ package expr import com.intellij.psi.PsiElement - -/** -* @author Alexander Podkhalyuzin -*/ - +/** + * @author Alexander Podkhalyuzin + */ trait ScWhileStmt extends ScExpression { def condition: Option[ScExpression] def body: Option[ScExpression] - def getLeftParenthesis : Option[PsiElement] + def getLeftParenthesis: Option[PsiElement] - def getRightParenthesis : Option[PsiElement] + def getRightParenthesis: Option[PsiElement] - override def accept(visitor: ScalaElementVisitor): Unit = visitor.visitWhileStatement(this) + override def accept(visitor: ScalaElementVisitor): Unit = { + visitor.visitWhileStatement(this) + } } object ScWhileStmt { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala index d5615dc0379..8ce6f302781 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScAssignStmtImpl.scala @@ -5,8 +5,7 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.{PsiElementVisitor, PsiField, ResolveState} -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor +import com.intellij.psi.{PsiField, ResolveState} import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScClassParameter import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScVariable} @@ -19,12 +18,9 @@ import org.jetbrains.plugins.scala.lang.resolve.{ScalaResolveResult, StdKinds} import org.jetbrains.plugins.scala.macroAnnotations.{Cached, ModCount} /** - * @author Alexander Podkhalyuzin - */ - -class ScAssignStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScAssignStmt { - override def toString: String = "AssignStatement" - + * @author Alexander Podkhalyuzin + */ +class ScAssignStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScAssignStmt { protected override def innerType: TypeResult = { getLExpression match { case call: ScMethodCall => call.`type`() @@ -40,13 +36,6 @@ class ScAssignStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScA } } - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - @Cached(ModCount.getBlockModificationCount, this) def resolveAssignment: Option[ScalaResolveResult] = resolveAssignmentInner(shapeResolve = false) @@ -113,4 +102,6 @@ class ScAssignStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScA case _ => None } } + + override def toString: String = "AssignStatement" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScCatchBlockImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScCatchBlockImpl.scala index 7ed31b164e4..07d3eec4627 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScCatchBlockImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScCatchBlockImpl.scala @@ -5,37 +5,25 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.{PsiElement, PsiElementVisitor} +import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ /** * Author: Alexander Podkhalyuzin * Date: 06.03.2008 */ -class ScCatchBlockImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScCatchBlock { - override def toString: String = "CatchBlock" - - override def accept(visitor: ScalaElementVisitor) { - visitor.visitCatchBlock(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case s: ScalaElementVisitor => s.visitCatchBlock(this) - case _ => super.accept(visitor) - } - } +class ScCatchBlockImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScCatchBlock { def getLeftParenthesis: Option[PsiElement] = { val leftParenthesis = findChildByType[PsiElement](ScalaTokenTypes.tLPARENTHESIS) - if (leftParenthesis == null) None else Some(leftParenthesis) + Option(leftParenthesis) } def getRightParenthesis: Option[PsiElement] = { val rightParenthesis = findChildByType[PsiElement](ScalaTokenTypes.tRPARENTHESIS) - if (rightParenthesis == null) None else Some(rightParenthesis) + Option(rightParenthesis) } + override def toString: String = "CatchBlock" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrBlockImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrBlockImpl.scala index e0b7007ecdf..09297294dfb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrBlockImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrBlockImpl.scala @@ -5,29 +5,17 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.{PsiElement, PsiElementVisitor} -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor +import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.expr._ /** * @author Alexander.Podkhalyuzin */ - -class ScConstrBlockImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScConstrBlock { - override def toString: String = "ConstructorBlock" - - override def accept(visitor: ScalaElementVisitor) { - visitor.visitConstrBlock(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case s: ScalaElementVisitor => s.visitConstrBlock(this) - case _ => super.accept(visitor) - } - } +class ScConstrBlockImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScConstrBlock { override def createMirror(text: String): PsiElement = { ScalaPsiElementFactory.createConstructorBodyWithContextFromText(text, getContext, this) } + + override def toString: String = "ConstructorBlock" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrExprImpl.scala index 0eabc89b71a..1ff53255ea0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScConstrExprImpl.scala @@ -7,12 +7,12 @@ package expr import com.intellij.lang.ASTNode import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.expr.ScConstrExpr -/** -* @author Alexander Podkhalyuzin -* Date: 22.02.2008 -*/ -class ScConstrExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScConstrExpr { +/** + * @author Alexander Podkhalyuzin + * Date: 22.02.2008 + */ +class ScConstrExprImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScConstrExpr { override def createMirror(text: String): PsiElement = { ScalaPsiElementFactory.createConstructorBodyWithContextFromText(text, getContext, this) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScDoStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScDoStmtImpl.scala index 7f9ad288cee..623183e5fcd 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScDoStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScDoStmtImpl.scala @@ -8,35 +8,21 @@ import com.intellij.lang.ASTNode import com.intellij.psi._ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - -class ScDoStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScDoStmt { - override def toString: String = "DoStatement" +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScDoStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScDoStmt { def getExprBody: Option[ScExpression] = findChild(classOf[ScExpression]) - def hasExprBody: Boolean = { - getExprBody match { - case None => false - case Some(_) => true - } - } def condition: Option[ScExpression] = { val rpar = findChildByType[PsiElement](ScalaTokenTypes.tLPARENTHESIS) val c = if (rpar != null) PsiTreeUtil.getNextSiblingOfType(rpar, classOf[ScExpression]) else null - if (c == null) None else Some(c) + Option(c) } - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } + override def toString: String = "DoStatement" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala index 5f180fdd53c..d6fdf79e5db 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScExpressionImplBase.scala @@ -6,19 +6,11 @@ package expr import com.intellij.lang.ASTNode import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression class ScExpressionImplBase(node: ASTNode) extends ScalaPsiElementImpl(node) with ScExpression { - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case scalaVisitor: ScalaElementVisitor => accept(scalaVisitor) - case _ => super.accept(visitor) - } - } - - override def accept(visitor: ScalaElementVisitor): Unit = { - visitor.visitExpression(this) + override final def accept(visitor: PsiElementVisitor): Unit = { + super.accept(visitor) } } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFinallyBlockImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFinallyBlockImpl.scala index 80942685f2c..745fbcc0078 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFinallyBlockImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFinallyBlockImpl.scala @@ -5,13 +5,12 @@ package impl package expr import com.intellij.lang.ASTNode -import org.jetbrains.plugins.scala.lang.psi.api.expr._ +import org.jetbrains.plugins.scala.lang.psi.api.expr.ScFinallyBlock -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - -class ScFinallyBlockImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScFinallyBlock { +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScFinallyBlockImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScFinallyBlock { override def toString: String = "FinallyBlock" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala index d32abe86923..0e88db9fc02 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScForStatementImpl.scala @@ -10,7 +10,6 @@ import com.intellij.psi._ import com.intellij.psi.scope._ import org.jetbrains.plugins.scala.extensions.PsiElementExt import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._ import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -22,19 +21,10 @@ import scala.annotation.tailrec import scala.collection.mutable /** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - -class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScForStatement { - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - - override def toString: String = "ForStatement" + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScForStatementImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScForStatement { def isYield: Boolean = findChildByType[PsiElement](ScalaTokenTypes.kYIELD) != null @@ -44,9 +34,9 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S def patterns: Seq[ScPattern] = enumerators.toSeq.flatMap(_.patterns) override def processDeclarations(processor: PsiScopeProcessor, - state: ResolveState, - lastParent: PsiElement, - place: PsiElement): Boolean = { + state: ResolveState, + lastParent: PsiElement, + place: PsiElement): Boolean = { val enumerators: ScEnumerators = this.enumerators match { case None => return true case Some(x) => x @@ -54,7 +44,7 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S if (lastParent == enumerators) return true enumerators.processDeclarations(processor, state, null, place) } - + protected def bodyToText(expr: ScExpression) = expr.getText @tailrec @@ -73,7 +63,9 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S val copyOf = this.copy().asInstanceOf[ScForStatement] val underscores = ScUnderScoreSectionUtil.underscores(copyOf) val length = underscores.length + def name(i: Int): String = s"forAnonParam$$$i" + underscores.zipWithIndex.foreach { case (underscore, index) => val referenceExpression = ScalaPsiElementFactory.createReferenceExpressionFromText(name(index)) @@ -101,7 +93,7 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S val gen = gens.head if (gen.rvalue == null) return None exprText.append("(").append(gen.rvalue.getText).append(")").append(".").append(if (isYield) "map" else "foreach") - .append(" { case ") + .append(" { case ") gen.pattern.desugarizedPatternIndex = exprText.length exprText.append(gen.pattern.getText).append(s" $arrow ") body match { @@ -123,26 +115,26 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S val tp = gen.rvalue.`type`().getOrAny val processor = new ImplicitCompletionProcessor(StdKinds.methodRef, this) { - override def execute(element: PsiElement, state: ResolveState): Boolean = { - super.execute(element, state) - if (!levelSet.isEmpty) { - filterFound = true - false - } else true - } + override def execute(element: PsiElement, state: ResolveState): Boolean = { + super.execute(element, state) + if (!levelSet.isEmpty) { + filterFound = true + false + } else true + } override protected val forName = Some("withFilter") - } + } processor.processType(tp, this) if (!filterFound) filterText = "filter" exprText.append(gen.pattern.getText). - append(" <- ((").append(gen.rvalue.getText).append(s").$filterText { case "). - append(gen.pattern.bindings.map(b => b.name).mkString("(", ", ", ")")).append(s" $arrow ") - if (forDisplay) { - exprText.append(guard.expr.map(_.getText).getOrElse("true")) - } else { - exprText.append(guard.expr.map(_.getText).getOrElse("true")).append(";true") - } + append(" <- ((").append(gen.rvalue.getText).append(s").$filterText { case "). + append(gen.pattern.bindings.map(b => b.name).mkString("(", ", ", ")")).append(s" $arrow ") + if (forDisplay) { + exprText.append(guard.expr.map(_.getText).getOrElse("true")) + } else { + exprText.append(guard.expr.map(_.getText).getOrElse("true")).append(";true") + } exprText.append("})") next = nextEnumerator(next) @@ -164,7 +156,7 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S } case _: ScGenerator => exprText.append("(").append(gen.rvalue.getText).append(")").append("."). - append(if (isYield) "flatMap " else "foreach ").append("{ case ") + append(if (isYield) "flatMap " else "foreach ").append("{ case ") gen.pattern.desugarizedPatternIndex = exprText.length exprText.append(gen.pattern.getText).append(s" $arrow ").append("for {") while (next != null) { @@ -196,9 +188,9 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S } exprText.append(") <- (for (").append(freshName1).append("@(").append(gen.pattern.getText).append(") <- "). - append(gen.rvalue.getText).append(") yield {val ").append(freshName2).append("@("). - append(enum.pattern.getText).append(") = ").append(enum.rvalue.getText). - append("; (").append(freshName2).append(", ").append(freshName1).append(")})") + append(gen.rvalue.getText).append(") yield {val ").append(freshName2).append("@("). + append(enum.pattern.getText).append(") = ").append(enum.rvalue.getText). + append("; (").append(freshName2).append(", ").append(freshName1).append(")})") next = nextEnumerator(next) if (next != null) exprText.append(" ; ") while (next != null) { @@ -283,6 +275,7 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S } } } + if ((enums.isEmpty && guards.isEmpty && gens.length == 1) || gens.isEmpty || res.isEmpty) res else { val expr = res.get @@ -359,4 +352,5 @@ class ScForStatementImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S def getRightParenthesis = Option(findChildByType[PsiElement](ScalaTokenTypes.tRPARENTHESIS)) + override def toString: String = "ForStatement" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala index d3e175a081a..6e0ecf0d7a2 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScFunctionExprImpl.scala @@ -7,7 +7,6 @@ package expr import com.intellij.lang.ASTNode import com.intellij.psi._ import com.intellij.psi.scope._ -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScParameter, ScParameters} import org.jetbrains.plugins.scala.lang.psi.types.api @@ -15,18 +14,9 @@ import org.jetbrains.plugins.scala.lang.psi.types.api.FunctionType import org.jetbrains.plugins.scala.lang.psi.types.result._ /** - * @author Alexander Podkhalyuzin - */ - -class ScFunctionExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScFunctionExpr { - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - - override def toString: String = "FunctionExpression" + * @author Alexander Podkhalyuzin + */ +class ScFunctionExprImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScFunctionExpr { def parameters: Seq[ScParameter] = params.params @@ -40,7 +30,7 @@ class ScFunctionExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S place: PsiElement): Boolean = { result match { case Some(x) if x == lastParent || (lastParent.isInstanceOf[ScalaPsiElement] && - x == lastParent.asInstanceOf[ScalaPsiElement].getDeepSameElementInContext)=> + x == lastParent.asInstanceOf[ScalaPsiElement].getDeepSameElementInContext) => for (p <- parameters) { if (!processor.execute(p, state)) return false } @@ -57,4 +47,6 @@ class ScFunctionExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with S } override def controlFlowScope: Option[ScalaPsiElement] = result + + override def toString: String = "FunctionExpression" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGeneratorImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGeneratorImpl.scala index c346c1fb25b..83cae028cbc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGeneratorImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGeneratorImpl.scala @@ -5,31 +5,19 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi._ -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScPattern -import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScExpression, _} - - -/** -* @author Alexander Podkhalyuzin -* Date: 07.03.2008 -*/ - -class ScGeneratorImpl(node: ASTNode) extends ScalaPsiElementImpl (node) with ScGenerator { - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - - override def toString: String = "Generator" +import org.jetbrains.plugins.scala.lang.psi.api.expr._ +/** + * @author Alexander Podkhalyuzin + * Date: 07.03.2008 + */ +class ScGeneratorImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScGenerator { def pattern: ScPattern = findChildByClass(classOf[ScPattern]) def guard: ScGuard = findChildByClass(classOf[ScGuard]) def rvalue: ScExpression = findChildByClass(classOf[ScExpression]) - + + override def toString: String = "Generator" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala index 0e604ecb73b..4e7d3b0353c 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGenericCallImpl.scala @@ -7,7 +7,6 @@ package expr import com.intellij.lang.ASTNode import com.intellij.psi._ import org.jetbrains.plugins.scala.extensions.PsiElementExt -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.types.ScTypeElement import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFun, ScFunction} @@ -20,40 +19,41 @@ import org.jetbrains.plugins.scala.lang.resolve.processor._ import org.jetbrains.plugins.scala.lang.resolve.{ResolveUtils, ScalaResolveResult} /** - * @author Alexander Podkhalyuzin - * Date: 06.03.2008 - */ - -class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScGenericCall { - override def toString: String = "GenericCall" - - + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScGenericCallImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScGenericCall { /** - * Utility method to get generics for apply methods of concrecte class. - */ + * Utility method to get generics for apply methods of concrecte class. + */ private def processType(tp: ScType, isShape: Boolean): ScType = { - val curr = getContext match {case call: ScMethodCall => call case _ => this} + val curr = getContext match { + case call: ScMethodCall => call + case _ => this + } val isUpdate = curr.getContext.isInstanceOf[ScAssignStmt] && - curr.getContext.asInstanceOf[ScAssignStmt].getLExpression == curr + curr.getContext.asInstanceOf[ScAssignStmt].getLExpression == curr val methodName = if (isUpdate) "update" else "apply" val args: List[Seq[ScExpression]] = if (curr == this && !isUpdate) List.empty else { - (curr match {case call: ScMethodCall => call.args.exprs - case _ => Seq.empty[ScExpression]}) ++ ( - if (isUpdate) curr.getContext.asInstanceOf[ScAssignStmt].getRExpression match { - case Some(x) => Seq[ScExpression](x) - case None => - Seq[ScExpression](createExpressionFromText("{val x: Nothing = null; x}")) - //we can't to not add something => add Nothing expression - } - else Seq.empty) :: Nil + (curr match { + case call: ScMethodCall => call.args.exprs + case _ => Seq.empty[ScExpression] + }) ++ ( + if (isUpdate) curr.getContext.asInstanceOf[ScAssignStmt].getRExpression match { + case Some(x) => Seq[ScExpression](x) + case None => + Seq[ScExpression](createExpressionFromText("{val x: Nothing = null; x}")) + //we can't to not add something => add Nothing expression + } + else Seq.empty) :: Nil } val typeArgs: Seq[ScTypeElement] = this.arguments import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression._ val processor = new MethodResolveProcessor(referencedExpr, methodName, args, typeArgs, - Seq.empty /* todo: ? */, isShapeResolve = isShape, enableTupling = true) + Seq.empty /* todo: ? */ , isShapeResolve = isShape, enableTupling = true) processor.processType(tp, referencedExpr, ResolveState.initial) val candidates = processor.candidates if (candidates.length != 1) Nothing @@ -70,6 +70,7 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } + private def convertReferencedType(typeResult: TypeResult): TypeResult = { var refType = typeResult.getOrElse(return typeResult) if (!refType.isInstanceOf[ScTypePolymorphicType]) refType = processType(refType, isShape = false) @@ -81,7 +82,6 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } - private def shapeType(typeResult: TypeResult): TypeResult = { var refType = typeResult.getOrElse(return typeResult) if (!refType.isInstanceOf[ScTypePolymorphicType]) refType = processType(refType, isShape = true) @@ -93,6 +93,7 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } + protected override def innerType: TypeResult = { val typeResult = referencedExpr.getNonValueType() convertReferencedType(typeResult) @@ -136,14 +137,5 @@ class ScGenericCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc } } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitGenericCallExpression(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitGenericCallExpression(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "GenericCall" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGuardImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGuardImpl.scala index c87702b34aa..1eeac5a6d37 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGuardImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScGuardImpl.scala @@ -9,9 +9,9 @@ import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -/** -* @author Alexander Podkhalyuzin -*/ +/** + * @author Alexander Podkhalyuzin + */ class ScGuardImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScGuard { override def accept(visitor: PsiElementVisitor): Unit = { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala index 3089471e735..fd2012c693f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScIfStmtImpl.scala @@ -5,29 +5,19 @@ package impl package expr import com.intellij.lang.ASTNode +import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil -import com.intellij.psi.{PsiElement, PsiElementVisitor} import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.ScTypeExt import org.jetbrains.plugins.scala.lang.psi.types.api.Unit import org.jetbrains.plugins.scala.lang.psi.types.result._ /** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - -class ScIfStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScIfStmt { - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - - override def toString: String = "IfStatement" + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScIfStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScIfStmt { def condition: Option[ScExpression] = { val rpar = findChildByType[PsiElement](ScalaTokenTypes.tRPARENTHESIS) @@ -42,11 +32,11 @@ class ScIfStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScIfStm else getLastChild match { case expression: ScExpression => expression case _ => PsiTreeUtil.getPrevSiblingOfType(getLastChild, classOf[ScExpression]) - } + } if (t == null) None else condition match { - case None => Some(t) + case None => Some(t) case Some(c) if c != t => Some(t) - case _ => None + case _ => None } } @@ -76,4 +66,6 @@ class ScIfStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScIfStm case _ => Failure(ScalaBundle.message("nothing.to.type")) } } + + override def toString: String = "IfStatement" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala index 91cfa79e938..395c1943e05 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScInfixExprImpl.scala @@ -5,21 +5,15 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor import org.jetbrains.plugins.scala.extensions._ -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.result.TypeResult -import scala.collection.Seq - /** - * @author Alexander Podkhalyuzin - * Date: 06.03.2008 - */ - -class ScInfixExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScInfixExpr { - override def toString: String = "InfixExpression" + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScInfixExprImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScInfixExpr { override def argumentExpressions: Seq[ScExpression] = { if (isRightAssoc) Seq(lOp) @@ -48,14 +42,5 @@ class ScInfixExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScIn } } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitInfixExpression(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitInfixExpression(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "InfixExpression" } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala index 54c92b369c4..0128a6476cb 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMatchStmtImpl.scala @@ -5,31 +5,22 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} /** - * @author Alexander Podkhalyuzin - * Date: 06.03.2008 - */ - -class ScMatchStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScMatchStmt { - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - - override def toString: String = "MatchStatement" + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScMatchStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScMatchStmt { protected override def innerType: TypeResult = { val branchesTypes = getBranches.map(_.`type`().getOrNothing) val branchesLub = branchesTypes.foldLeft(Nothing: ScType)(_.lub(_)) Right(branchesLub) } + + override def toString: String = "MatchStatement" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMethodCallImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMethodCallImpl.scala index 142c99f7e88..d1fd83bb739 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMethodCallImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScMethodCallImpl.scala @@ -5,18 +5,14 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ -import scala.collection.Seq - /** - * @author Alexander Podkhalyuzin - * Date: 06.03.2008 - */ + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScMethodCallImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScMethodCall { -class ScMethodCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScMethodCall { def getInvokedExpr: ScExpression = findChildByClassScala(classOf[ScExpression]) def argumentExpressions: Seq[ScExpression] = if (args != null) args.exprs else Nil @@ -35,12 +31,5 @@ class ScMethodCallImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScM } } - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - override def toString: String = "MethodCall" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala index b658150b39a..fd89bc407f8 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScParenthesisedExprImpl.scala @@ -5,19 +5,15 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.result._ /** -* @author Alexander Podkhalyuzin -* Date: 07.03.2008 -* Time: 9:24:19 -*/ - -class ScParenthesisedExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScParenthesisedExpr { - override def toString: String = "ExpressionInParenthesis" + * @author Alexander Podkhalyuzin + * Date: 07.03.2008 + * Time: 9:24:19 + */ +class ScParenthesisedExprImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScParenthesisedExpr { protected override def innerType: TypeResult = { expr match { @@ -28,15 +24,5 @@ class ScParenthesisedExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w } } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitExprInParent(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitExprInParent(this) - case _ => super.accept(visitor) - } - } - + override def toString: String = "ExpressionInParenthesis" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPostfixExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPostfixExprImpl.scala index 3ca6c506f49..eb9dc2451bc 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPostfixExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPostfixExprImpl.scala @@ -5,19 +5,16 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.{PsiElement, PsiElementVisitor} -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor +import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.psi.api.expr._ import scala.collection.Seq -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - -class ScPostfixExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScPostfixExpr { - override def toString: String = "PostfixExpression" +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScPostfixExprImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScPostfixExpr { def argumentExpressions: Seq[ScExpression] = Seq.empty @@ -25,14 +22,5 @@ class ScPostfixExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with Sc def argsElement: PsiElement = operation - override def accept(visitor: ScalaElementVisitor) { - visitor.visitPostfixExpression(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitPostfixExpression(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "PostfixExpression" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPrefixExprImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPrefixExprImpl.scala index 027d66b0a16..415001d5a2e 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPrefixExprImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScPrefixExprImpl.scala @@ -5,32 +5,19 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import scala.collection.Seq -/** -* @author Alexander Podkhalyuzin -* Date: 06.03.2008 -*/ - -class ScPrefixExprImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScPrefixExpr { - override def toString: String = "PrefixExpression" +/** + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScPrefixExprImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScPrefixExpr { def argumentExpressions: Seq[ScExpression] = Seq.empty def getInvokedExpr: ScExpression = operation - override def accept(visitor: ScalaElementVisitor) { - visitor.visitPrefixExpression(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitPrefixExpression(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "PrefixExpression" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala index 81297b655d9..f4f999512d1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScReturnStmtImpl.scala @@ -5,29 +5,20 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.{PsiElement, PsiElementVisitor} +import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes.kRETURN -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.result._ /** - * @author Alexander Podkhalyuzin - */ - -class ScReturnStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScReturnStmt { + * @author Alexander Podkhalyuzin + */ +class ScReturnStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScReturnStmt { override def returnKeyword: PsiElement = findChildByType(kRETURN) protected override def innerType: TypeResult = Right(Nothing) - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - override def toString: String = "ReturnStatement" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala index fd6bdc2d530..59878b8eed1 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSelfInvocationImpl.scala @@ -8,7 +8,6 @@ import com.intellij.lang.ASTNode import com.intellij.openapi.util.TextRange import com.intellij.psi._ import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.{ScMethodLike, ScMethodLikeExt} import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction @@ -25,19 +24,18 @@ import org.jetbrains.plugins.scala.lang.resolve.processor.MethodResolveProcessor import scala.collection.Seq /** -* @author Alexander Podkhalyuzin -* Date: 22.02.2008 -*/ -class ScSelfInvocationImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScSelfInvocation { - override def toString: String = "SelfInvocation" + * @author Alexander Podkhalyuzin + * Date: 22.02.2008 + */ +class ScSelfInvocationImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScSelfInvocation { def bind: Option[PsiElement] = bindInternal(shapeResolve = false) - private def bindInternal(shapeResolve: Boolean): Option[PsiElement] = { - val seq = bindMultiInternal(shapeResolve) - if (seq.length == 1) Some(seq(0)) - else None - } + private def bindInternal(shapeResolve: Boolean): Option[PsiElement] = + bindMultiInternal(shapeResolve) match { + case Seq(head) => Some(head) + case _ => None + } private def bindMultiInternal(shapeResolve: Boolean): Seq[PsiElement] = { val psiClass = PsiTreeUtil.getContextOfType(this, classOf[PsiClass]) @@ -51,7 +49,7 @@ class ScSelfInvocationImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with case None => Seq.empty } val proc = new MethodResolveProcessor(this, "this", List(expressions), Seq.empty, - Seq.empty /*todo: ? */, StdKinds.methodsOnly, constructorResolve = true, isShapeResolve = shapeResolve, + Seq.empty /*todo: ? */ , StdKinds.methodsOnly, constructorResolve = true, isShapeResolve = shapeResolve, enableTupling = true, selfConstructorResolve = true) for (constr <- clazz.secondaryConstructors.filter(_ != method) if constr != method) { proc.execute(constr, ResolveState.initial) @@ -91,16 +89,7 @@ class ScSelfInvocationImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with bindMultiInternal(shapeResolve = false).map(pe => workWithBindInternal(Some(pe), i)) } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitSelfInvocation(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case s: ScalaElementVisitor => s.visitSelfInvocation(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "SelfInvocation" override def handleElementRename(newElementName: String): PsiElement = this @@ -120,6 +109,6 @@ class ScSelfInvocationImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with override def getRangeInElement: TextRange = { val start = this.getTextRange.getStartOffset - Option(thisElement).getOrElse(this).getTextRange.shiftRight(- start) + Option(thisElement).getOrElse(this).getTextRange.shiftRight(-start) } } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala index 64db55ee804..f730bc34f42 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScSuperReferenceImpl.scala @@ -11,25 +11,20 @@ import com.intellij.psi.util.PsiTreeUtil import com.intellij.util.IncorrectOperationException import org.jetbrains.plugins.scala.extensions._ import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes +import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScExtendsBlock import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScObject, ScTemplateDefinition, ScTypeDefinition} -import org.jetbrains.plugins.scala.lang.psi.api.{ScalaElementVisitor, ScalaFile} import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory.createIdentifier import org.jetbrains.plugins.scala.lang.psi.types.result._ import org.jetbrains.plugins.scala.lang.psi.types.{ScType, ScTypeExt} import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult -import _root_.scala.collection.mutable.ArrayBuffer - /** -* @author Alexander Podkhalyuzin -* Date: 14.03.2008 -*/ - -class ScSuperReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScSuperReference { - override def toString = "SuperReference" - + * @author Alexander Podkhalyuzin + * Date: 14.03.2008 + */ +class ScSuperReferenceImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScSuperReference { def isHardCoded: Boolean = { val id = findChildByType[PsiElement](ScalaTokenTypes.tIDENTIFIER) if (id == null) false else { @@ -59,16 +54,15 @@ class ScSuperReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with } } - - def drvTemplate: Option[ScTemplateDefinition] = reference match { case Some(q) => q.bind() match { - case Some(ScalaResolveResult(td : ScTypeDefinition, _)) => Some(td) + case Some(ScalaResolveResult(td: ScTypeDefinition, _)) => Some(td) case _ => None } case None => ScalaPsiUtil.drvTemplate(this) } + def staticSuper: Option[ScType] = { val id = findChildByType[PsiElement](ScalaTokenTypes.tIDENTIFIER) if (id == null) None else findSuper(id) @@ -80,27 +74,31 @@ class ScSuperReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with val id = findChildByType[PsiElement](ScalaTokenTypes.tIDENTIFIER) if (id == null) null else new PsiReference { def getElement: ScSuperReferenceImpl = ScSuperReferenceImpl.this + def getRangeInElement: TextRange = new TextRange(0, id.getTextLength).shiftRight(id.getStartOffsetInParent) + def getCanonicalText: String = resolve match { - case c : PsiClass => c.qualifiedName + case c: PsiClass => c.qualifiedName case _ => null } + def isSoft: Boolean = false def handleElementRename(newElementName: String): ScSuperReferenceImpl = doRename(newElementName) - def bindToElement(e : PsiElement): ScSuperReferenceImpl = e match { - case c : PsiClass => doRename(c.name) + + def bindToElement(e: PsiElement): ScSuperReferenceImpl = e match { + case c: PsiClass => doRename(c.name) case _ => throw new IncorrectOperationException("cannot bind to anything but class") } - private def doRename(newName : String) = { + private def doRename(newName: String) = { val parent = id.getNode.getTreeParent parent.replaceChild(id.getNode, createIdentifier(newName)) ScSuperReferenceImpl.this } def isReferenceTo(element: PsiElement): Boolean = element match { - case c : PsiClass => c.name == id.getText && resolve == c + case c: PsiClass => c.name == id.getText && resolve == c case _ => false } @@ -109,11 +107,12 @@ class ScSuperReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with findSuper(id) match { case Some(t) => t.extractClass match { case Some(c) => c - case None => null + case None => null } - case _ => null + case _ => null } } + ScalaPsiUtil.fileContext(id) match { case file: ScalaFile if file.isCompiled => val next = id.getNode.getTreeNext @@ -132,19 +131,14 @@ class ScSuperReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with } def getVariants: Array[Object] = superTypes match { - case None => Array[Object]() + case None => Array.emptyObjectArray case Some(supers) => - val buff = new ArrayBuffer[Object] - supers.foreach { t => t.extractClass match { - case Some(c) => buff += c - case None => - }} - buff.toArray + supers.flatMap(_.extractClass).toArray } } } - def findSuper(id : PsiElement) : Option[ScType] = superTypes match { + def findSuper(id: PsiElement): Option[ScType] = superTypes match { case None => None case Some(types) => val name = id.getText @@ -171,14 +165,5 @@ class ScSuperReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with protected override def innerType = Failure("Cannot infer type of `super' expression") - override def accept(visitor: ScalaElementVisitor) { - visitor.visitSuperReference(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitSuperReference(this) - case _ => super.accept(visitor) - } - } + override def toString = "SuperReference" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala index 9144a8406ff..b2d637ebc04 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThisReferenceImpl.scala @@ -5,9 +5,7 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition} @@ -17,12 +15,10 @@ import org.jetbrains.plugins.scala.lang.psi.types.api.designator.{DesignatorOwne import org.jetbrains.plugins.scala.lang.psi.types.result._ /** - * @author Alexander Podkhalyuzin - * Date: 06.03.2008 - */ - -class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScThisReference { - override def toString: String = "ThisReference" + * @author Alexander Podkhalyuzin + * Date: 06.03.2008 + */ +class ScThisReferenceImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScThisReference { protected override def innerType: TypeResult = { import scala.meta.intellij.psiExt.TemplateDefExt @@ -43,16 +39,7 @@ class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with if (encl != null) Some(PsiTreeUtil.getContextOfType(encl, false, classOf[ScTemplateDefinition])) else None } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitThisReference(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitThisReference(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "ThisReference" } object ScThisReferenceImpl { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala index 9f5a9869d8e..4b8a3bb3e06 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScThrowStmtImpl.scala @@ -5,27 +5,15 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api.Nothing import org.jetbrains.plugins.scala.lang.psi.types.result._ /** -* @author Alexander Podkhalyuzin, ilyas -*/ - -class ScThrowStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScThrowStmt { - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - - override def toString: String = "ThrowStatement" - + * @author Alexander Podkhalyuzin, ilyas + */ +class ScThrowStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScThrowStmt { protected override def innerType: TypeResult = Right(Nothing) - def body: Option[ScExpression] = findChild(classOf[ScExpression]) + override def toString: String = "ThrowStatement" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala index 835ca572b65..dac96f14afa 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTryStmtImpl.scala @@ -5,8 +5,6 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.types.api.designator.ScDesignatorType @@ -19,16 +17,7 @@ import org.jetbrains.plugins.scala.project.ProjectContext /** * @author Alexander Podkhalyuzin */ - -class ScTryStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryStmt { - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } - - override def toString: String = "TryStatement" +class ScTryStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScTryStmt { import ScTryStmtImpl._ @@ -52,6 +41,8 @@ class ScTryStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTryS case _ => Right(tryBlockType) } } + + override def toString: String = "TryStatement" } object ScTryStmtImpl { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala index c28e1f5c779..8d66e8cd246 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTupleImpl.scala @@ -5,8 +5,6 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api.{TupleType, Unit} import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -14,8 +12,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ /** * @author ilyas, Alexander Podkhalyuzin */ -class ScTupleImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTuple { - override def toString: String = "Tuple" +class ScTupleImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScTuple { protected override def innerType: TypeResult = { val result = exprs.map(_.`type`().getOrAny) match { @@ -25,14 +22,5 @@ class ScTupleImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTuple Right(result) } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitTupleExpr(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitTupleExpr(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "Tuple" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala index 4c36960929e..175cbaf21fe 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScTypedStmtImpl.scala @@ -5,8 +5,6 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.result._ @@ -15,8 +13,7 @@ import org.jetbrains.plugins.scala.lang.psi.types.result._ * Date: 06.03.2008 */ -class ScTypedStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTypedStmt { - override def toString: String = "TypedStatement" +class ScTypedStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScTypedStmt { protected override def innerType: TypeResult = { typeElement match { @@ -26,14 +23,5 @@ class ScTypedStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScTy } } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitTypedStmt(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitTypedStmt(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "TypedStatement" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala index 1a46ace4d83..6c130805ae0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScUnderscoreSectionImpl.scala @@ -5,9 +5,8 @@ package impl package expr import com.intellij.lang.ASTNode -import com.intellij.psi.{PsiElement, PsiElementVisitor} +import com.intellij.psi.PsiElement import org.jetbrains.plugins.scala.extensions.PsiElementExt -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScClassParameter, ScParameter} @@ -22,9 +21,7 @@ import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult * @author Alexander Podkhalyuzin, ilyas */ -class ScUnderscoreSectionImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScUnderscoreSection { - override def toString: String = "UnderscoreSection" - +class ScUnderscoreSectionImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScUnderscoreSection { protected override def innerType: TypeResult = { bindingExpr match { case Some(ref: ScReferenceExpression) => @@ -116,14 +113,5 @@ class ScUnderscoreSectionImpl(node: ASTNode) extends ScalaPsiElementImpl(node) w } } - override def accept(visitor: ScalaElementVisitor) { - visitor.visitUnderscoreExpression(this) - } - - override def accept(visitor: PsiElementVisitor) { - visitor match { - case visitor: ScalaElementVisitor => visitor.visitUnderscoreExpression(this) - case _ => super.accept(visitor) - } - } + override def toString: String = "UnderscoreSection" } \ No newline at end of file diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala index 453b416f84c..8fd5b678e89 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/psi/impl/expr/ScWhileStmtImpl.scala @@ -5,26 +5,18 @@ package impl package expr import com.intellij.lang.ASTNode +import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil -import com.intellij.psi.{PsiElement, PsiElementVisitor} import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -import org.jetbrains.plugins.scala.lang.psi.api.ScalaElementVisitor import org.jetbrains.plugins.scala.lang.psi.api.expr._ import org.jetbrains.plugins.scala.lang.psi.types.api /** -* @author Alexander.Podkhalyuzin -*/ - -class ScWhileStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScWhileStmt { - override def accept(visitor: PsiElementVisitor): Unit = { - visitor match { - case visitor: ScalaElementVisitor => super.accept(visitor) - case _ => super.accept(visitor) - } - } + * @author Alexander.Podkhalyuzin + */ +class ScWhileStmtImpl(node: ASTNode) extends ScExpressionImplBase(node) with ScWhileStmt { - override def toString: String = "WhileStatement" + protected override def innerType = Right(api.Unit) def condition: Option[ScExpression] = { val rpar = findChildByType[PsiElement](ScalaTokenTypes.tRPARENTHESIS) @@ -48,6 +40,5 @@ class ScWhileStmtImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScWh Option(rightParenthesis) } - - protected override def innerType = Right(api.Unit) + override def toString: String = "WhileStatement" } \ No newline at end of file From cb18bb731b01f562612ade0ce2df44d3a605fed5 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Sun, 5 Nov 2017 20:19:09 +0100 Subject: [PATCH 140/141] more informative assertion failures in SettingQueryHandlerTest --- .../sbt/shell/SettingQueryHandlerTest.scala | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/sbt/shell/SettingQueryHandlerTest.scala b/scala/scala-impl/test/org/jetbrains/sbt/shell/SettingQueryHandlerTest.scala index 827312576be..1a11b85de94 100644 --- a/scala/scala-impl/test/org/jetbrains/sbt/shell/SettingQueryHandlerTest.scala +++ b/scala/scala-impl/test/org/jetbrains/sbt/shell/SettingQueryHandlerTest.scala @@ -62,8 +62,9 @@ abstract class SettingQueryHandlerTest extends SbtProjectPlatformTestCase { comm.command(commandBefore, showShell = false).flatMap { _ => handler.getSettingValue() }, Duration(timeoutSeconds, TimeUnit.SECONDS)) runner.getConsoleView.flushDeferredText() - assert(res == expectedValue, s"Invalid value read by SettingQueryHandler: '$expectedValue' expected, but '$res' found") - assert(!logger.getLog.contains(SbtProjectPlatformTestCase.errorPrefix)) + val log = logger.getLog + assert(res == expectedValue, s"Invalid value read by SettingQueryHandler: '$expectedValue' expected, but '$res' found. Full log:\n$log") + assert(!logger.getLog.contains(SbtProjectPlatformTestCase.errorPrefix), s"log contained errors. Full log:\n $log") } protected def doTestSetSetting(settingName: String, expectedValue: String, timeoutSeconds: Int, @@ -74,8 +75,9 @@ abstract class SettingQueryHandlerTest extends SbtProjectPlatformTestCase { val res = Await.result(setHandler.setSettingValue(expectedValue).flatMap { _ => handler.getSettingValue() }, Duration(timeoutSeconds, "second")) runner.getConsoleView.flushDeferredText() - assert(res == expectedValue, s"Invalid value read by SettingQueryHandler: '$expectedValue' expected, but '$res' found") - assert(!logger.getLog.contains(SbtProjectPlatformTestCase.errorPrefix)) + val log = logger.getLog + assert(res == expectedValue, s"Invalid value read by SettingQueryHandler: '$expectedValue' expected, but '$res' found. Full log:\n$log") + assert(!logger.getLog.contains(SbtProjectPlatformTestCase.errorPrefix), s"log contained errors. Full log:\n $log") } protected def doTestAddToSetting(settingName: String, setCommand: String, addValue: String, expectedValue: String, @@ -90,11 +92,12 @@ abstract class SettingQueryHandlerTest extends SbtProjectPlatformTestCase { _ => handler.getSettingValue() }, Duration(timeoutSeconds, "second")).trim runner.getConsoleView.flushDeferredText() - assert(res == expectedValue, s"Invalid value read by SettingQueryHandler: '$expectedValue' expected, but '$res' found") - assert(!logger.getLog.contains(SbtProjectPlatformTestCase.errorPrefix)) + val log = logger.getLog + assert(res == expectedValue, s"Invalid value read by SettingQueryHandler: '$expectedValue' expected, but '$res' found. Full log:\n$log") + assert(!logger.getLog.contains(SbtProjectPlatformTestCase.errorPrefix), s"log contained errors. Full log:\n $log") } protected def getScalaTestProjectUri: String = "file:" + getBasePath.replace("\\", "/") + "/" + getPath + "/" protected val timeout = 60 -} \ No newline at end of file +} From 63d2fd9ef8733e65e4adb7155f8cdaa070970059 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Sun, 5 Nov 2017 22:11:31 +0100 Subject: [PATCH 141/141] probably hopeless attempt to fix leaking library loaders --- ...ghtPlatformCodeInsightTestCaseAdapter.java | 25 ++++++++++--------- .../scala/failed/resolve/Postgres.scala | 4 +-- .../scala/failed/resolve/ScalazTest.scala | 4 +-- .../failed/typeInference/ScalaZTest.scala | 4 +-- .../Specs2ToScalaCheckImplicitTest.scala | 4 +-- .../adjustTypes/tests/AdjustTypesTests.scala | 4 +-- .../scala/lang/macros/MonocleLensesTest.scala | 4 +-- .../generated/TypeInferenceCatsTest.scala | 4 +-- .../generated/TypeInferenceScalazTest.scala | 4 +-- .../generated/TypeInferenceSlickTest.scala | 4 +-- .../generated/TypeInferenceSprayTest.scala | 4 +-- .../scala/meta/ScalaMetaLibrariesOwner.scala | 2 +- .../QuasiQuoteTypeInferenceTestBase.scala | 4 +-- 13 files changed, 36 insertions(+), 35 deletions(-) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java index 6235681fea4..56f741d124f 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightPlatformCodeInsightTestCaseAdapter.java @@ -24,11 +24,12 @@ import org.jetbrains.plugins.scala.debugger.Scala_2_10$; import org.jetbrains.plugins.scala.util.TestUtils; import scala.collection.Seq; +import scala.collection.immutable.Vector$; +import scala.collection.mutable.Buffer; +import scala.collection.mutable.Buffer$; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; /** * @author Alexander Podkhalyuzin @@ -71,21 +72,21 @@ public Module module() { @Override public Seq librariesLoaders() { - return scala.collection.JavaConverters.asScalaBuffer(librariesLoadersAdapter()); - } - - private List librariesLoadersAdapter() { Module module = module(); + ArrayList back = new ArrayList<>(); - ArrayList result = new ArrayList(); - result.add(new ScalaLibraryLoader(isIncludeReflectLibrary(), module)); + ScalaLibraryLoader scalaLoader = new ScalaLibraryLoader(isIncludeReflectLibrary(), module); + back.add(scalaLoader); String path = rootPath(); if (path != null) { - result.add(new SourcesLoader(path, module)); + back.add(new SourcesLoader(path, module)); } - result.addAll(Arrays.asList(additionalLibraries())); + Buffer result = scala.collection.JavaConverters.asScalaBuffer(back); + Seq addLibs = additionalLibraries(); + //noinspection unchecked (because variance) + result.$plus$plus$eq(addLibs); return result; } @@ -120,8 +121,8 @@ protected boolean isIncludeReflectLibrary() { return false; } - protected ThirdPartyLibraryLoader[] additionalLibraries() { - return EMPTY_LOADERS_ARRAY; + protected Seq additionalLibraries() { + return Vector$.MODULE$.empty(); } protected VirtualFile getVFileAdapter() { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/Postgres.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/Postgres.scala index 4b426a675b2..abbe6e5e323 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/Postgres.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/Postgres.scala @@ -12,8 +12,8 @@ import org.junit.experimental.categories.Category @Category(Array(classOf[PerfCycleTests])) class Postgres extends FailedResolveTest("postgresql") { - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(PostgresLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(PostgresLoader()(module)) def testSCL8556(): Unit = doTest() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/ScalazTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/ScalazTest.scala index 7c4e6f87127..807fb0784cc 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/ScalazTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/resolve/ScalazTest.scala @@ -11,8 +11,8 @@ import org.junit.experimental.categories.Category @Category(Array(classOf[PerfCycleTests])) class ScalazTest extends FailedResolveTest("scalaz") { - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(ScalaZCoreLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(ScalaZCoreLoader()(module)) def testSCL7213(): Unit = doTest() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/ScalaZTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/ScalaZTest.scala index 2f3d5412332..960444e41ca 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/ScalaZTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/ScalaZTest.scala @@ -12,8 +12,8 @@ import org.junit.experimental.categories.Category @Category(Array(classOf[PerfCycleTests])) class ScalaZTest extends TypeInferenceTestBase { - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(ScalaZCoreLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(ScalaZCoreLoader()(module)) def testSCL5706(): Unit = { doTest( diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/Specs2ToScalaCheckImplicitTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/Specs2ToScalaCheckImplicitTest.scala index 554822c3c1d..81462e258b9 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/Specs2ToScalaCheckImplicitTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/failed/typeInference/Specs2ToScalaCheckImplicitTest.scala @@ -11,8 +11,8 @@ import org.junit.experimental.categories.Category @Category(Array(classOf[PerfCycleTests])) class Specs2ToScalaCheckImplicitTest extends TypeInferenceTestBase { - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(Specs2Loader("2.4.15")(module), ScalaZCoreLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(Specs2Loader("2.4.15")(module), ScalaZCoreLoader()(module)) def testSCL8864(): Unit = doTest { s"""object Main extends App { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala index 4526de7b1d8..e133ec813c8 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/adjustTypes/tests/AdjustTypesTests.scala @@ -43,8 +43,8 @@ class AdjustTypesTests extends AdjustTypesTestBase { class AdjustCatsTypeTest extends AdjustTypesTestBase { - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(CatsLoader()(module)) + override protected def additionalLibraries(): Seq[CatsLoader] = + Seq(CatsLoader()(module)) def testSCL10006(): Unit = doTest() } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala index 1b939b751d3..2fa406e5b37 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/macros/MonocleLensesTest.scala @@ -19,11 +19,11 @@ class MonocleLensesTest extends ScalaLightPlatformCodeInsightTestCaseAdapter { override implicit val version: ScalaVersion = Scala_2_12 - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = { + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = { import MonocleLensesTest._ implicit val module: Module = getModuleAdapter - Array(MonocleCoreLoader(), MonocleMacroLoader(), MonocleGeneric()) + Seq(MonocleCoreLoader(), MonocleMacroLoader(), MonocleGeneric()) } protected def folderPath: String = TestUtils.getTestDataPath diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceCatsTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceCatsTest.scala index 6518dca5e31..f9ccc050489 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceCatsTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceCatsTest.scala @@ -11,8 +11,8 @@ import org.junit.experimental.categories.Category @Category(Array(classOf[SlowTests])) class TypeInferenceCatsTest extends TypeInferenceTestBase { - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(CatsLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(CatsLoader()(module)) override protected def folderPath: String = super.folderPath + "cats/" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceScalazTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceScalazTest.scala index 8d538486661..d92bb151c07 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceScalazTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceScalazTest.scala @@ -14,8 +14,8 @@ class TypeInferenceScalazTest extends TypeInferenceTestBase { //This class was generated by build script, please don't change this override def folderPath: String = super.folderPath + "scalaz/" - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(ScalaZCoreLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(ScalaZCoreLoader()(module)) def testSCL3819() { doTest() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSlickTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSlickTest.scala index 75ca651d966..ed9d69ed33e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSlickTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSlickTest.scala @@ -14,8 +14,8 @@ class TypeInferenceSlickTest extends TypeInferenceTestBase { //This class was generated by build script, please don't change this override def folderPath: String = super.folderPath + "slick/" - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(SlickLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(SlickLoader()(module)) def testSCL9261(): Unit = doTest() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSprayTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSprayTest.scala index d77345e1a2b..e7740755f0a 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSprayTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/generated/TypeInferenceSprayTest.scala @@ -13,8 +13,8 @@ class TypeInferenceSprayTest extends TypeInferenceTestBase { //This class was generated by build script, please don't change this override def folderPath: String = super.folderPath + "spray/" - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - Array(SprayLoader()(module)) + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + Seq(SprayLoader()(module)) def testSCL8274(): Unit = doTest() } diff --git a/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala b/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala index 721bc76233a..e1d8a3cb2b2 100644 --- a/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala +++ b/scala/scala-impl/test/scala/meta/ScalaMetaLibrariesOwner.scala @@ -10,7 +10,7 @@ trait ScalaMetaLibrariesOwner extends ScalaSdkOwner { import ScalaMetaLibrariesOwner._ - protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = Array( + protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = Seq( MetaCommonLoader(), MetaDialectsLoader(), MetaInlineLoader(), diff --git a/scala/scala-impl/test/scala/meta/quasiquotes/QuasiQuoteTypeInferenceTestBase.scala b/scala/scala-impl/test/scala/meta/quasiquotes/QuasiQuoteTypeInferenceTestBase.scala index 6a2134c20a3..5d10a4a3e76 100644 --- a/scala/scala-impl/test/scala/meta/quasiquotes/QuasiQuoteTypeInferenceTestBase.scala +++ b/scala/scala-impl/test/scala/meta/quasiquotes/QuasiQuoteTypeInferenceTestBase.scala @@ -7,8 +7,8 @@ import scala.meta.ScalaMetaLibrariesOwner abstract class QuasiQuoteTypeInferenceTestBase extends TypeInferenceTestBase with ScalaMetaLibrariesOwner { - override protected def additionalLibraries(): Array[ThirdPartyLibraryLoader] = - super.additionalLibraries() + override protected def additionalLibraries(): Seq[ThirdPartyLibraryLoader] = + super[ScalaMetaLibrariesOwner].additionalLibraries() override protected def doTest(fileText: String): Unit = super.doTest(