by default execute typed handler when finishing completion by a character

This commit is contained in:
peter
2011-03-08 18:00:36 +01:00
parent f15136acf2
commit 24b5e9a888
12 changed files with 34 additions and 25 deletions
@@ -87,13 +87,15 @@ public class JavaAwareCompletionData extends CompletionData{
ret.setInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
if (context.shouldAddCompletionChar()) {
return;
}
TailType type = analyzeItem(item.getObject(), context.getFile().findElementAt(context.getStartOffset()));
if (type == TailType.NONE) {
type = tailType;
}
//new DefaultInsertHandler().handleInsert(context, item);
if (type != TailType.NONE) {
context.setAddCompletionChar(false);
type.processTail(context.getEditor(), context.getTailOffset());
}
}
@@ -44,10 +44,6 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
public void handleInsert(final InsertionContext context, final JavaPsiClassReferenceElement item) {
final char c = context.getCompletionChar();
if (c != '.' && c != ' ' && c != '#') {
context.setAddCompletionChar(false);
}
int offset = context.getTailOffset() - 1;
final PsiFile file = context.getFile();
if (PsiTreeUtil.findElementOfClassAtOffset(file, offset, PsiImportStatementBase.class, false) != null) {
@@ -842,8 +842,9 @@ public class JavaCompletionUtil {
final boolean hasTail = tailType != TailType.NONE && tailType != TailType.UNKNOWN;
final boolean smart = completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR;
final boolean addCompletionChar = context.shouldAddCompletionChar();
context.setAddCompletionChar(false);
if (completionChar == '(' || completionChar == '.' || completionChar == ',' || completionChar == ';') {
context.setAddCompletionChar(false);
}
final boolean needRightParenth = forceClosingParenthesis || !smart && (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET || hasTail);
if (hasTail) {
@@ -863,7 +864,7 @@ public class JavaCompletionUtil {
AutoPopupController.getInstance(file.getProject()).autoPopupParameterInfo(editor, overloadsMatter ? null : (PsiElement)item.getObject());
}
if (smart || needRightParenth && addCompletionChar) {
if (smart || needRightParenth) {
TailType toInsert = tailType;
LookupItem lookupItem = item.as(LookupItem.CLASS_CONDITION_KEY);
if (lookupItem == null || lookupItem.getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailType.UNKNOWN) {
@@ -877,7 +878,7 @@ public class JavaCompletionUtil {
}
toInsert.processTail(editor, context.getTailOffset());
if (context.getCompletionChar() == '.') {
if (completionChar == '.') {
AutoPopupController.getInstance(file.getProject()).autoPopupMemberLookup(context.getEditor(), null);
}
}
@@ -123,6 +123,7 @@ public class JavaMethodCallElement extends LookupItem<PsiMethod> implements Type
final PsiType type = method.getReturnType();
if (context.getCompletionChar() == '!' && type != null && PsiType.BOOLEAN.isAssignableFrom(type)) {
context.setAddCompletionChar(false);
context.commitDocument();
final int offset = context.getOffset(refStart);
final PsiMethodCallExpression methodCall = PsiTreeUtil.findElementOfClassAtOffset(file, offset, PsiMethodCallExpression.class, false);
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.TailType;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.codeInsight.lookup.TailTypeDecorator;
@@ -52,10 +53,12 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
}
protected TailType computeTailType(InsertionContext context) {
final TailType defType = LookupItem.getDefaultTailType(context.getCompletionChar());
if (defType != null) {
context.setAddCompletionChar(false);
return defType;
if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
return TailType.SMART_COMPLETION;
}
if (LookupItem.getDefaultTailType(context.getCompletionChar()) != null) {
return null;
}
LookupElement delegate = getDelegate();
@@ -3,7 +3,7 @@ class Foo {
{
String abc;
String abcdef;
abc <caret>d
abc <caret> d
}
}