From 7c4a4c8f14a8a2829c06e326ff3d7f74f2555de6 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 11 Jul 2013 15:08:07 +0200 Subject: [PATCH] remove long deprecated FileCopyPatcher API --- .../CompletionInitializationContext.java | 14 ++---- .../completion/DummyIdentifierPatcher.java | 45 ------------------- .../completion/FileCopyPatcher.java | 45 ------------------- .../completion/CodeCompletionHandlerBase.java | 12 +++-- 4 files changed, 13 insertions(+), 103 deletions(-) delete mode 100644 platform/lang-api/src/com/intellij/codeInsight/completion/DummyIdentifierPatcher.java delete mode 100644 platform/lang-api/src/com/intellij/codeInsight/completion/FileCopyPatcher.java diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionInitializationContext.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionInitializationContext.java index c034fe1c47f9..c8dec2cb8efd 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionInitializationContext.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionInitializationContext.java @@ -41,7 +41,7 @@ public class CompletionInitializationContext { private final PsiFile myFile; private final CompletionType myCompletionType; private final OffsetMap myOffsetMap; - private FileCopyPatcher myFileCopyPatcher = new DummyIdentifierPatcher(DUMMY_IDENTIFIER); + private String myDummyIdentifier = DUMMY_IDENTIFIER; public CompletionInitializationContext(final Editor editor, final PsiFile file, final CompletionType completionType) { myEditor = editor; @@ -69,12 +69,7 @@ public class CompletionInitializationContext { } public void setDummyIdentifier(@NotNull String dummyIdentifier) { - setFileCopyPatcher(new DummyIdentifierPatcher(dummyIdentifier)); - } - - @Deprecated - public void setFileCopyPatcher(@NotNull final FileCopyPatcher fileCopyPatcher) { - myFileCopyPatcher = fileCopyPatcher; + myDummyIdentifier = dummyIdentifier; } @NotNull @@ -82,9 +77,8 @@ public class CompletionInitializationContext { return PsiUtilBase.getLanguageInEditor(getEditor(), getProject()); } - @NotNull - public FileCopyPatcher getFileCopyPatcher() { - return myFileCopyPatcher; + public String getDummyIdentifier() { + return myDummyIdentifier; } @NotNull diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/DummyIdentifierPatcher.java b/platform/lang-api/src/com/intellij/codeInsight/completion/DummyIdentifierPatcher.java deleted file mode 100644 index 950e7484a200..000000000000 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/DummyIdentifierPatcher.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInsight.completion; - -import com.intellij.openapi.util.text.StringUtil; -import org.jetbrains.annotations.NotNull; -import com.intellij.openapi.editor.Document; -import com.intellij.psi.PsiFile; - -/** - * @author peter - */ -public class DummyIdentifierPatcher extends FileCopyPatcher { - private final String myDummyIdentifier; - - public DummyIdentifierPatcher(final String dummyIdentifier) { - myDummyIdentifier = dummyIdentifier; - } - - @Override - public void patchFileCopy(@NotNull final PsiFile fileCopy, @NotNull final Document document, @NotNull final OffsetMap map) { - if (StringUtil.isEmpty(myDummyIdentifier)) return; - int startOffset = map.getOffset(CompletionInitializationContext.START_OFFSET); - int endOffset = map.getOffset(CompletionInitializationContext.SELECTION_END_OFFSET); - document.replaceString(startOffset, endOffset, myDummyIdentifier); - } - - @Override - public String toString() { - return "Insert \"" + myDummyIdentifier + "\""; - } -} diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/FileCopyPatcher.java b/platform/lang-api/src/com/intellij/codeInsight/completion/FileCopyPatcher.java deleted file mode 100644 index 2ce82121b180..000000000000 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/FileCopyPatcher.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInsight.completion; - -import com.intellij.openapi.editor.Document; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; - -/** - * @author peter - */ -public abstract class FileCopyPatcher { - - /** - * On completion, a file copy is created and this method is invoked on corresponding document. This is usually - * done to ensure that there is some non-whitespace text at caret position, for example, to find reference at - * that offset and ask for its {@link com.intellij.psi.PsiReference#getVariants()}. In - * {@link com.intellij.codeInsight.completion.CompletionContributor} it will also be easier to determine which - * variants to suggest at current position. - * - * Default implementation is {@link com.intellij.codeInsight.completion.DummyIdentifierPatcher} which - * inserts {@link com.intellij.codeInsight.completion.CompletionInitializationContext#DUMMY_IDENTIFIER} - * to the document replacing editor selection (see {@link CompletionInitializationContext#START_OFFSET} and - * {@link CompletionInitializationContext#SELECTION_END_OFFSET}). - * - * @param fileCopy - * @param document - * @param map {@link com.intellij.codeInsight.completion.CompletionInitializationContext#START_OFFSET} should be valid after return - */ - public abstract void patchFileCopy(@NotNull final PsiFile fileCopy, @NotNull Document document, @NotNull OffsetMap map); - -} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 40645719d59b..24aa0f2a70d1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -51,6 +51,7 @@ import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.*; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; @@ -199,8 +200,8 @@ public class CodeCompletionHandlerBase { CompletionContributor dummyIdentifierChanger; @Override - public void setFileCopyPatcher(@NotNull FileCopyPatcher fileCopyPatcher) { - super.setFileCopyPatcher(fileCopyPatcher); + public void setDummyIdentifier(@NotNull String dummyIdentifier) { + super.setDummyIdentifier(dummyIdentifier); if (dummyIdentifierChanger != null) { LOG.error("Changing the dummy identifier twice, already changed by " + dummyIdentifierChanger); @@ -546,7 +547,12 @@ public class CodeCompletionHandlerBase { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - initContext.getFileCopyPatcher().patchFileCopy(hostCopy[0], copyDocument, hostMap); + String dummyIdentifier = initContext.getDummyIdentifier(); + if (StringUtil.isEmpty(dummyIdentifier)) return; + + int startOffset = hostMap.getOffset(CompletionInitializationContext.START_OFFSET); + int endOffset = hostMap.getOffset(CompletionInitializationContext.SELECTION_END_OFFSET); + copyDocument.replaceString(startOffset, endOffset, dummyIdentifier); } }); }