Skip to content

Commit

Permalink
Merged branch idea243.release into idea243.x
Browse files Browse the repository at this point in the history
  • Loading branch information
builduser committed Jan 8, 2025
2 parents 723b876 + 67dbcad commit 18d8f9b
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ private object CompilerMessages {
def isUnusedImport(description: String): Boolean =
description.trim.equalsIgnoreCase("unused import")

def isNeedsToBeAbstract(description: String): Boolean =
description.contains("needs to be abstract")

def isNoWarningsCanBeIncurred(description: String): Boolean =
description.trim.equalsIgnoreCase("No warnings can be incurred under -Werror (or -Xfatal-warnings)")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package org.jetbrains.plugins.scala.compiler.highlighting
import com.intellij.codeInsight.daemon.impl.{ErrorStripeUpdateManager, HighlightInfo, HighlightInfoType, UpdateHighlightersUtil}
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.modcommand.ModCommandAction
import com.intellij.openapi.application.{ModalityState, ReadAction}
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.{Document, Editor, EditorFactory}
import com.intellij.openapi.fileEditor.{FileDocumentManager, FileEditorManager}
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.project.{DumbService, Project}
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.vfs.{VirtualFile, VirtualFileManager}
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.problems.WolfTheProblemSolver
import com.intellij.psi._
import com.intellij.psi.util.PsiTreeUtil
Expand All @@ -20,26 +21,25 @@ import com.intellij.xml.util.XmlStringUtil
import org.jetbrains.annotations.{Nls, Nullable}
import org.jetbrains.jps.incremental.scala.Client.PosInfo
import org.jetbrains.plugins.scala.annotator.UnresolvedReferenceFixProvider
import org.jetbrains.plugins.scala.annotator.element.ScTemplateDefinitionAnnotator
import org.jetbrains.plugins.scala.caches.ModTracker.anyScalaPsiChange
import org.jetbrains.plugins.scala.codeInsight.implicits.ImplicitHints
import org.jetbrains.plugins.scala.codeInspection.ScalaInspectionBundle
import org.jetbrains.plugins.scala.codeInspection.declarationRedundancy.ScalaOptimizeImportsFix
import org.jetbrains.plugins.scala.compiler.diagnostics.Action
import org.jetbrains.plugins.scala.compiler.highlighting.ExternalHighlighting.RangeInfo
import org.jetbrains.plugins.scala.editor.DocumentExt
import org.jetbrains.plugins.scala.extensions.{IteratorExt, ObjectExt, PsiElementExt, executeOnPooledThread, invokeLater}
import org.jetbrains.plugins.scala.extensions.{ObjectExt, Parent, PsiElementExt, executeOnPooledThread, invokeLater}
import org.jetbrains.plugins.scala.lang.psi.api.base.{ScReference, ScStableCodeReference}
import org.jetbrains.plugins.scala.lang.psi.api.expr.ScMethodCall
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.ImportUsed
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.ImportUsed.UnusedImportReportedByCompilerKey
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.{ScImportExpr, ScImportOrExportStmt, ScImportSelector}
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTemplateDefinition
import org.jetbrains.plugins.scala.lang.psi.impl.{CompilerType, ScalaPsiManager}
import org.jetbrains.plugins.scala.settings.{ProblemSolverUtils, ScalaHighlightingMode, ScalaProjectSettings}
import org.jetbrains.plugins.scala.util.{CanonicalPath, CompilationId, DocumentVersion}
import org.jetbrains.plugins.scala.util.CompilationId

import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.nio.file.Path
import java.util.Collections
import java.util.concurrent.Callable
import java.util.function.Consumer
Expand Down Expand Up @@ -263,6 +263,20 @@ private final class ExternalHighlightersService(project: Project) { self =>
highlightInfoBuilder(document, HighlightInfoType.UNUSED_SYMBOL, unusedImportRange, ScalaInspectionBundle.message("unused.import.statement"), Nil)
.registerFix(new ScalaOptimizeImportsFix, null, null, unusedImportRange, null)
} else standardBuilder
} else if (highlighting.diagnostics.isEmpty && CompilerMessages.isNeedsToBeAbstract(description)) {
psiFile.findElementAt(highlightRange.getStartOffset) match {
case Parent(td: ScTemplateDefinition) =>
val fixes = ScTemplateDefinitionAnnotator.needsToBeAbstractFixes(td)
fixes.foldLeft(standardBuilder) {
case (builder, fix: ModCommandAction) =>
//noinspection ApiStatus
builder.registerFix(fix, null, null, highlightRange, null)
case (builder, fix: IntentionAction) =>
builder.registerFix(fix, null, null, highlightRange, null)
case (builder, _) => builder
}
case _ => standardBuilder
}
} else standardBuilder

val fixes = findUnresolvedReferenceFixes(psiFile, highlightRange, highlighting.highlightType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,6 @@ class ScalaCompilerHighlightingTest_2_13 extends ScalaCompilerHighlightingTestBa
runTestFunctionLiteral(50)
}

private def runTestErrorHighlighting(): Unit = runTestCase(
fileName = "AbstractMethodInClassError.scala",
content =
"""
|class AbstractMethodInClassError {
| def method: Int
|}
|""".stripMargin,
expectedResult = expectedResult(ExpectedHighlighting(
severity = HighlightSeverity.ERROR,
range = Some(TextRange.create(7, 33)),
quickFixDescriptions = Seq.empty,
msgPrefix = "class AbstractMethodInClassError needs to be abstract"
))
)

def testErrorHighlighting(): Unit = runTestErrorHighlighting()

def testErrorHighlighting_UseCompilerRangesDisabled(): Unit = withUseCompilerRangesDisabled {
runTestErrorHighlighting()
}

private def runTestWrongReturnType(startOffset: Int): Unit = runTestCase(
fileName = "WrongReturnType.scala",
content =
Expand Down Expand Up @@ -354,28 +332,6 @@ abstract class ScalaCompilerHighlightingTest_3 extends ScalaCompilerHighlighting
runTestFunctionLiteral()
}

private def runTestErrorHighlighting(): Unit = runTestCase(
fileName = "AbstractMethodInClassError.scala",
content =
"""
|class AbstractMethodInClassError {
| def method: Int
|}
|""".stripMargin,
expectedResult = expectedResult(ExpectedHighlighting(
severity = HighlightSeverity.ERROR,
range = Some(TextRange.create(7, 33)),
quickFixDescriptions = Seq.empty,
msgPrefix = "class AbstractMethodInClassError needs to be abstract"
))
)

def testErrorHighlighting(): Unit = runTestErrorHighlighting()

def testErrorHighlighting_UseCompilerRangesDisabled(): Unit = withUseCompilerRangesDisabled {
runTestErrorHighlighting()
}

private def runTestWrongReturnType(startOffset: Int): Unit = runTestCase(
fileName = "WrongReturnType.scala",
content =
Expand Down Expand Up @@ -423,6 +379,30 @@ abstract class ScalaCompilerHighlightingTest_3 extends ScalaCompilerHighlighting
def testCompilationWithParserError_UseCompilerRangesDisabled(): Unit = withUseCompilerRangesDisabled {
runTestCompilationWithParserError()
}

// SCL-19751
private def runTestNotImplementedMembers(): Unit = runTestCase(
fileName = "NotImplementedMembers.scala",
content =
"""
|trait Something(x: Int):
| def implementMe: Unit
|
|class X extends Something(10)
|""".stripMargin,
expectedResult = expectedResult(ExpectedHighlighting(
severity = HighlightSeverity.ERROR,
range = Some(TextRange.create(57, 58)),
quickFixDescriptions = Seq("Make 'X' abstract", "Implement members"),
msgPrefix = "class X needs to be abstract, since def implementMe: Unit in trait Something is not defined"
))
)

def testNotImplementedMembers(): Unit = runTestNotImplementedMembers()

def testNotImplementedMembers_UseCompilerRangesDisabled(): Unit = withUseCompilerRangesDisabled {
runTestNotImplementedMembers()
}
}

trait ScalaCompilerHighlightingCommonScala2Scala3Test {
Expand Down Expand Up @@ -452,4 +432,26 @@ trait ScalaCompilerHighlightingCommonScala2Scala3Test {
def testWarningHighlighting_UseCompilerRangesDisabled(): Unit = withUseCompilerRangesDisabled {
runTestWarningHighlighting(Seq.empty)
}

protected def runTestAbstractMethodInClass(): Unit = runTestCase(
fileName = "AbstractMethodInClassError.scala",
content =
"""
|class AbstractMethodInClassError {
| def method: Int
|}
|""".stripMargin,
expectedResult = expectedResult(ExpectedHighlighting(
severity = HighlightSeverity.ERROR,
range = Some(TextRange.create(7, 33)),
quickFixDescriptions = Seq("Make 'AbstractMethodInClassError' abstract"),
msgPrefix = "class AbstractMethodInClassError needs to be abstract"
))
)

def testAbstractMethodInClass(): Unit = runTestAbstractMethodInClass()

def testAbstractMethodInClass_UseCompilerRangesDisabled(): Unit = withUseCompilerRangesDisabled {
runTestAbstractMethodInClass()
}
}
7 changes: 0 additions & 7 deletions scala/scala-impl/resources/META-INF/scala-plugin-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -894,13 +894,6 @@
<className>org.jetbrains.plugins.scala.editor.documentationProvider.actions.CreateScalaDocStubIntentionAction</className>
</intentionAction>

<intentionAction>
<language>Scala</language>
<categoryKey>intention.category.scala</categoryKey>
<bundleName>messages.ScalaCodeInsightBundle</bundleName>
<className>org.jetbrains.plugins.scala.codeInspection.notImplementedCode.NotImplementedMembersAction</className>
</intentionAction>

<intentionAction>
<language>Scala</language>
<categoryKey>intention.category.scala</categoryKey>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.plugins.scala.annotator.element

import com.intellij.codeInsight.intention.CommonIntentionAction
import com.intellij.openapi.util.TextRange
import com.intellij.psi.{PsiClass, PsiMethod, PsiModifier, PsiModifierList}
import org.jetbrains.annotations.Nls
Expand Down Expand Up @@ -445,18 +446,7 @@ object ScTemplateDefinitionAnnotator extends ElementAnnotator[ScTemplateDefiniti
)
)
}.foreach { message =>
val nameId = element.nameId
val fixes = {
val maybeModifierFix = element match {
case cls: ScClass => Some(new ModifierQuickFix.Add(cls, nameId, ScalaModifier.Abstract))
case _ => None
}

val maybeImplementFix =
Option.when(ScalaOIUtil.getMembersToImplement(element).nonEmpty)(new ImplementMembersQuickFix(element))

maybeModifierFix ++ maybeImplementFix
}
val fixes = needsToBeAbstractFixes(element)
holder.createErrorAnnotation(highlightRange(element), message.nls, fixes)
}
}
Expand Down Expand Up @@ -512,6 +502,19 @@ object ScTemplateDefinitionAnnotator extends ElementAnnotator[ScTemplateDefiniti
ScalaBundle.message("object.creation.impossible.since", reasons)
}

def needsToBeAbstractFixes(element: ScTemplateDefinition): Iterable[CommonIntentionAction] = {
val nameId = element.nameId
val maybeModifierFix = element match {
case cls: ScClass => Some(new ModifierQuickFix.Add(cls, nameId, ScalaModifier.Abstract))
case _ => None
}

val maybeImplementFix =
Option.when(ScalaOIUtil.getMembersToImplement(element).nonEmpty)(new ImplementMembersQuickFix(element))

maybeModifierFix ++ maybeImplementFix
}

private def highlightRange(definition: ScTemplateDefinition): TextRange =
TextRange.create(getHighlightingStartOffset(definition), getHighlightingEndOffset(definition))

Expand Down

This file was deleted.

0 comments on commit 18d8f9b

Please sign in to comment.