Skip to content

Commit

Permalink
Cleanup in ImportCompletionProposal
Browse files Browse the repository at this point in the history
The superclass BasicCompletionProposal already provides all necessary
behavior.
  • Loading branch information
kiritsuku committed Oct 4, 2014
1 parent 28660c9 commit b6e85fd
Showing 1 changed file with 13 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package org.scalaide.core.internal.quickfix

import scala.tools.refactoring.implementations.AddImportStatement
import org.scalaide.util.internal.eclipse.TextEditUtils

import org.eclipse.jdt.ui.ISharedImages
import org.eclipse.jdt.ui.JavaUI
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.TextUtilities
import org.eclipse.jface.text.contentassist.IContextInformation
import org.eclipse.swt.graphics.Image
import org.eclipse.swt.graphics.Point
import org.scalaide.core.compiler.IScalaPresentationCompiler.Implicits._
import org.scalaide.core.completion.RelevanceValues
import org.scalaide.core.quickassist.BasicCompletionProposal
import org.scalaide.logging.HasLogger
import org.scalaide.util.eclipse.EditorUtils
import org.scalaide.core.compiler.IScalaPresentationCompiler.Implicits._

case class ImportCompletionProposal(val importName: String) extends IJavaCompletionProposal with HasLogger {
import org.scalaide.util.internal.eclipse.TextEditUtils

def getRelevance() = RelevanceValues.ImportCompletionProposal
case class ImportCompletionProposal(val importName: String)
extends BasicCompletionProposal(
relevance = RelevanceValues.ImportCompletionProposal,
displayString = s"Import $importName",
image = JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_IMPDECL))
with HasLogger {

/**
* Inserts the proposed completion into the given document.
*
* @param document the document into which to insert the proposed completion
*/
def apply(document: IDocument) {
override def apply(document: IDocument): Unit = {
// First, try to insert with an AST transformation, if that fails, use the (old) method
try {
applyByASTTransformation(document)
Expand All @@ -41,7 +42,7 @@ case class ImportCompletionProposal(val importName: String) extends IJavaComplet
*
* @param document the document into which to insert the proposed completion
*/
private def applyByASTTransformation(document: IDocument) {
private def applyByASTTransformation(document: IDocument): Unit = {

EditorUtils.withScalaFileAndSelection { (scalaSourceFile, textSelection) =>

Expand Down Expand Up @@ -72,7 +73,7 @@ case class ImportCompletionProposal(val importName: String) extends IJavaComplet
*
* @param document the document into which to insert the proposed completion
*/
private def applyByTextTransformation(document: IDocument) {
private def applyByTextTransformation(document: IDocument): Unit = {
val lineDelimiter = TextUtilities.getDefaultLineDelimiter(document)

// Find the package declaration
Expand Down Expand Up @@ -111,61 +112,4 @@ case class ImportCompletionProposal(val importName: String) extends IJavaComplet
// Insert the import as the third line in the file... RISKY AS HELL :D
document.replace(insertIndex, 0, preInsert + "import " + importName + lineDelimiter);
}

/**
* Returns the new selection after the proposal has been applied to
* the given document in absolute document coordinates. If it returns
* <code>null</code>, no new selection is set.
*
* A document change can trigger other document changes, which have
* to be taken into account when calculating the new selection. Typically,
* this would be done by installing a document listener or by using a
* document position during {@link #apply(IDocument)}.
*
* @param document the document into which the proposed completion has been inserted
* @return the new selection in absolute document coordinates
*/
def getSelection(document: IDocument): Point = null


/**
* Returns optional additional information about the proposal. The additional information will
* be presented to assist the user in deciding if the selected proposal is the desired choice.
* <p>
* If {@link ICompletionProposalExtension5} is implemented, this method should not be called any
* longer. This method may be deprecated in a future release.
* </p>
*
* @return the additional information or <code>null</code>
*/
def getAdditionalProposalInfo(): String = null


/**
* Returns the string to be displayed in the list of completion proposals.
*
* @return the string to be displayed
*
* @see ICompletionProposalExtension6#getStyledDisplayString()
*/
def getDisplayString(): String = s"Import $importName"


/**
* Returns the image to be displayed in the list of completion proposals.
* The image would typically be shown to the left of the display string.
*
* @return the image to be shown or <code>null</code> if no image is desired
*/
def getImage(): Image = JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_IMPDECL)


/**
* Returns optional context information associated with this proposal.
* The context information will automatically be shown if the proposal
* has been applied.
*
* @return the context information for this proposal or <code>null</code>
*/
def getContextInformation(): IContextInformation = null
}

0 comments on commit b6e85fd

Please sign in to comment.