mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
tab completion shoulnd't overwrite new class'es argument list
This commit is contained in:
@@ -55,6 +55,16 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
return TailType.NONE;
|
||||
}
|
||||
};
|
||||
public static final DefaultInsertHandler NO_TAIL_PARENS_HANDLER = new DefaultInsertHandler(){
|
||||
@Override
|
||||
protected TailType getTailType(char completionChar) {
|
||||
return TailType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeEndOfIdentifier(boolean needParenth) {
|
||||
}
|
||||
};
|
||||
|
||||
public void handleInsert(final InsertionContext context, LookupElement item) {
|
||||
super.handleInsert(context, item);
|
||||
@@ -80,10 +90,12 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
final boolean needLeftParenth = isToInsertParenth();
|
||||
final boolean hasParams = needLeftParenth && hasParams();
|
||||
|
||||
if (CompletionUtil.isOverwrite(item, completionChar))
|
||||
if (CompletionUtil.isOverwrite(item, completionChar)) {
|
||||
removeEndOfIdentifier(needLeftParenth && hasParams);
|
||||
else if(myContext.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET) != myContext.getSelectionEndOffset())
|
||||
}
|
||||
else if(myContext.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET) != myContext.getSelectionEndOffset()) {
|
||||
JavaCompletionUtil.resetParensInfo(context.getOffsetMap());
|
||||
}
|
||||
|
||||
handleParenses(hasParams, needLeftParenth, tailType);
|
||||
handleBrackets();
|
||||
@@ -253,7 +265,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isToInsertParenth(){
|
||||
protected boolean isToInsertParenth(){
|
||||
return insertingAnnotationWithParameters();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class JavaPsiClassReferenceElement extends LookupItem<Object> {
|
||||
public static final InsertHandler<JavaPsiClassReferenceElement> JAVA_CLASS_INSERT_HANDLER = new InsertHandler<JavaPsiClassReferenceElement>() {
|
||||
public void handleInsert(final InsertionContext context, final JavaPsiClassReferenceElement item) {
|
||||
if (completingRawConstructor(context, item)) {
|
||||
DefaultInsertHandler.NO_TAIL_HANDLER.handleInsert(context, item);
|
||||
DefaultInsertHandler.NO_TAIL_PARENS_HANDLER.handleInsert(context, item);
|
||||
ConstructorInsertHandler.insertParentheses(context, item, item.getObject());
|
||||
} else {
|
||||
new DefaultInsertHandler().handleInsert(context, item);
|
||||
|
||||
@@ -174,7 +174,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
JavaCompletionUtil.setShowFQN((LookupItem)item);
|
||||
} else {
|
||||
}
|
||||
((LookupItem) item).setInsertHandler(DefaultInsertHandler.NO_TAIL_HANDLER);
|
||||
((LookupItem) item).setInsertHandler(DefaultInsertHandler.NO_TAIL_PARENS_HANDLER);
|
||||
result.addElement(decorate(LookupElementDecorator.withInsertHandler((LookupItem)item, ConstructorInsertHandler.INSTANCE), infos));
|
||||
}
|
||||
}
|
||||
@@ -578,7 +578,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
item.setAttribute(LookupItem.INDICATE_ANONYMOUS, "");
|
||||
}
|
||||
|
||||
item.setInsertHandler(DefaultInsertHandler.NO_TAIL_HANDLER);
|
||||
item.setInsertHandler(DefaultInsertHandler.NO_TAIL_PARENS_HANDLER);
|
||||
result.addElement(decorate(type instanceof PsiClassType ? LookupElementDecorator.withInsertHandler(item, ConstructorInsertHandler.INSTANCE) : item, infos));
|
||||
}
|
||||
|
||||
@@ -621,13 +621,19 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
PsiElement element = file.findElementAt(context.getStartOffset());
|
||||
if (element instanceof PsiIdentifier) {
|
||||
element = element.getParent();
|
||||
while (element instanceof PsiJavaCodeReferenceElement || element instanceof PsiMethodCallExpression ||
|
||||
while (element instanceof PsiJavaCodeReferenceElement || element instanceof PsiCall ||
|
||||
element instanceof PsiThisExpression || element instanceof PsiSuperExpression ||
|
||||
element instanceof PsiTypeElement ||
|
||||
element instanceof PsiClassObjectAccessExpression) {
|
||||
int newEnd = element.getTextRange().getEndOffset();
|
||||
if (element instanceof PsiMethodCallExpression) {
|
||||
newEnd = ((PsiMethodCallExpression)element).getMethodExpression().getElement().getTextRange().getEndOffset();
|
||||
newEnd = ((PsiMethodCallExpression)element).getMethodExpression().getTextRange().getEndOffset();
|
||||
}
|
||||
else if (element instanceof PsiNewExpression) {
|
||||
final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)element).getClassReference();
|
||||
if (classReference != null) {
|
||||
newEnd = classReference.getTextRange().getEndOffset();
|
||||
}
|
||||
}
|
||||
context.getOffsetMap().addOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET, newEnd);
|
||||
element = element.getParent();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
public class Main {
|
||||
|
||||
public void main(String[] args) {
|
||||
Aaaa a = new Bbbb(<caret>2);
|
||||
}
|
||||
|
||||
class Aaaa {
|
||||
int aaa;
|
||||
|
||||
Aaaa(int aaa) {
|
||||
this.aaa = aaa;
|
||||
}
|
||||
}
|
||||
|
||||
class Bbbb extends Aaaa{
|
||||
Bbbb(int aaa) {
|
||||
super(aaa);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
public class Main {
|
||||
|
||||
public void main(String[] args) {
|
||||
Aaaa a = new B<caret>Aaaa(2);
|
||||
}
|
||||
|
||||
class Aaaa {
|
||||
int aaa;
|
||||
|
||||
Aaaa(int aaa) {
|
||||
this.aaa = aaa;
|
||||
}
|
||||
}
|
||||
|
||||
class Bbbb extends Aaaa{
|
||||
Bbbb(int aaa) {
|
||||
super(aaa);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -996,6 +996,12 @@ public class SmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
checkResultByTestName();
|
||||
}
|
||||
|
||||
public void testTabAfterNew() throws Exception {
|
||||
configureByTestName();
|
||||
select('\t');
|
||||
checkResultByTestName();
|
||||
}
|
||||
|
||||
private void doTest(boolean performAction, boolean selectItem) throws Exception {
|
||||
configureByTestName();
|
||||
if (performAction) {
|
||||
|
||||
Reference in New Issue
Block a user