mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 15:15:45 +07:00
remove long deprecated FileCopyPatcher API
This commit is contained in:
+4
-10
@@ -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
|
||||
|
||||
@@ -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 + "\"";
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
+9
-3
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user