mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tailOffset degraded in class name completion (EA-24778)
This commit is contained in:
+1
-1
@@ -53,7 +53,7 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
|
||||
insertParentheses(context, delegate, delegate.getObject(), withTail && isAbstract);
|
||||
|
||||
DefaultInsertHandler.addImportForItem(context.getFile(), context.getStartOffset(), delegate);
|
||||
DefaultInsertHandler.addImportForItem(context, delegate);
|
||||
|
||||
|
||||
if (withTail) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
@@ -116,7 +117,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
}
|
||||
}
|
||||
}
|
||||
addImportForItem(file, context.getStartOffset(), item);
|
||||
addImportForItem(context, item);
|
||||
if (context.getTailOffset() < 0) { //hack, hack, hack. ideally the tail offset just should survive after the importing stuff
|
||||
context.setTailOffset(context.getEditor().getCaretModel().getOffset());
|
||||
}
|
||||
@@ -241,9 +242,11 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
JavaCompletionUtil.initOffsets(file, file.getProject(), offsetMap);
|
||||
}
|
||||
|
||||
public static void addImportForItem(PsiFile file, int startOffset, LookupElement item) throws IncorrectOperationException {
|
||||
PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
|
||||
public static void addImportForItem(InsertionContext context, LookupElement item) throws IncorrectOperationException {
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||
|
||||
int startOffset = context.getStartOffset();
|
||||
PsiFile file = context.getFile();
|
||||
Object o = item.getObject();
|
||||
if (o instanceof PsiClass){
|
||||
PsiClass aClass = (PsiClass)o;
|
||||
@@ -252,8 +255,11 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
int length = lookupString.length();
|
||||
final int i = lookupString.indexOf('<');
|
||||
if (i >= 0) length = i;
|
||||
RangeMarker savedTail = context.getDocument().createRangeMarker(context.getTailOffset(), context.getTailOffset());
|
||||
final int newOffset = addImportForClass(file, startOffset, startOffset + length, aClass);
|
||||
JavaCompletionUtil.shortenReference(file, newOffset);
|
||||
assert savedTail.isValid();
|
||||
context.setTailOffset(savedTail.getStartOffset());
|
||||
}
|
||||
else if (o instanceof PsiType){
|
||||
PsiType type = ((PsiType)o).getDeepComponentType();
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
|
||||
LOG.assertTrue(context.getTailOffset() >= 0);
|
||||
String docText = context.getDocument().getText();
|
||||
DefaultInsertHandler.addImportForItem(context.getFile(), context.getStartOffset(), item);
|
||||
DefaultInsertHandler.addImportForItem(context, item);
|
||||
if (context.getTailOffset() < 0) {
|
||||
if (ApplicationManagerEx.getApplicationEx().isInternal()) {
|
||||
LOG.error("Tail offset degraded: " + context.getStartOffset() + "; " + docText);
|
||||
|
||||
@@ -37,7 +37,7 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
|
||||
@Override
|
||||
public void handleInsert(InsertionContext context) {
|
||||
DefaultInsertHandler.addImportForItem(context.getFile(), context.getStartOffset(), this);
|
||||
DefaultInsertHandler.addImportForItem(context, this);
|
||||
super.handleInsert(context);
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
public class Bar {
|
||||
{
|
||||
if (2 != InpStrRea<caret>Aaa) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class Bar {
|
||||
{
|
||||
if (2 != InputStreamReader<caret>Aaa) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -842,6 +842,12 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
assertStringItems("myField1", "myField2");
|
||||
}
|
||||
|
||||
public void testClassNameInsideIdentifierInIf() throws Throwable {
|
||||
configure()
|
||||
type '\n'
|
||||
checkResult()
|
||||
}
|
||||
|
||||
public void testSuggestMembersOfStaticallyImportedClasses() throws Exception {
|
||||
myFixture.addClass("""package foo;
|
||||
public class Foo {
|
||||
|
||||
Reference in New Issue
Block a user