mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
less error-prone CompletionConfidence API
This commit is contained in:
@@ -15,14 +15,16 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class AlwaysFocusLookup extends CompletionConfidence {
|
||||
@NotNull
|
||||
@Override
|
||||
public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
return true;
|
||||
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
return ThreeState.YES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -25,11 +26,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public abstract class CompletionConfidence {
|
||||
|
||||
@Nullable
|
||||
public abstract Boolean shouldFocusLookup(@NotNull CompletionParameters parameters);
|
||||
@NotNull
|
||||
public abstract ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters);
|
||||
|
||||
@Nullable
|
||||
public Boolean shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
|
||||
return null;
|
||||
@NotNull
|
||||
public ThreeState shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,19 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class UnfocusedComments extends CompletionConfidence {
|
||||
@NotNull
|
||||
@Override
|
||||
public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
if (PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiComment.class) != null) {
|
||||
return false;
|
||||
return ThreeState.NO;
|
||||
}
|
||||
return null;
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -17,27 +17,29 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class UnfocusedNameIdentifier extends CompletionConfidence {
|
||||
@NotNull
|
||||
@Override
|
||||
public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
final PsiElement position = parameters.getPosition();
|
||||
final PsiElement parent = position.getParent();
|
||||
if (parent instanceof PsiNameIdentifierOwner) {
|
||||
final PsiElement nameIdentifier = ((PsiNameIdentifierOwner)parent).getNameIdentifier();
|
||||
if (nameIdentifier == position) {
|
||||
return false;
|
||||
return ThreeState.NO;
|
||||
}
|
||||
|
||||
if (nameIdentifier != null && position.getTextRange().equals(nameIdentifier.getTextRange())) {
|
||||
//sometimes name identifiers are non-physical (e.g. Groovy)
|
||||
return false;
|
||||
return ThreeState.NO;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -68,6 +68,7 @@ import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.reference.SoftReference;
|
||||
import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ThreeState;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -207,8 +208,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
Language language = elementAt != null ? PsiUtilBase.findLanguageFromElement(elementAt):psiFile.getLanguage();
|
||||
|
||||
for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
|
||||
final Boolean result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset); // TODO: Peter Lazy API
|
||||
if (result == Boolean.TRUE) return;
|
||||
final ThreeState result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset); // TODO: Peter Lazy API
|
||||
if (result == ThreeState.YES) return;
|
||||
if (result == ThreeState.NO) break;
|
||||
}
|
||||
} else {
|
||||
CommandProcessor.getInstance().executeCommand(project, initCmd, null, null);
|
||||
@@ -224,9 +226,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
|
||||
final Language language = PsiUtilBase.getLanguageAtOffset(parameters.getPosition().getContainingFile(), parameters.getOffset());
|
||||
for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
|
||||
final Boolean result = confidence.shouldFocusLookup(parameters);
|
||||
if (result != null) {
|
||||
return result;
|
||||
final ThreeState result = confidence.shouldFocusLookup(parameters);
|
||||
if (result != ThreeState.UNSURE) {
|
||||
return result == ThreeState.YES;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
+7
-5
@@ -15,6 +15,7 @@ package org.jetbrains.plugins.groovy.lang.completion;
|
||||
import com.intellij.codeInsight.completion.CompletionConfidence;
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
@@ -23,19 +24,20 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrRefere
|
||||
* @author peter
|
||||
*/
|
||||
public class GroovyCompletionConfidence extends CompletionConfidence {
|
||||
@NotNull
|
||||
@Override
|
||||
public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
final PsiElement position = parameters.getPosition();
|
||||
if (position.getParent() instanceof GrReferenceExpression) {
|
||||
final GrExpression expression = ((GrReferenceExpression)position.getParent()).getQualifierExpression();
|
||||
if (expression == null) {
|
||||
return true;
|
||||
return ThreeState.YES;
|
||||
}
|
||||
if (expression.getType() == null) {
|
||||
return false;
|
||||
return ThreeState.NO;
|
||||
}
|
||||
return true;
|
||||
return ThreeState.YES;
|
||||
}
|
||||
return null;
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -3,21 +3,23 @@ package com.intellij.codeInsight.completion;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.xml.XmlTokenType;
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class XmlNameCompletionConfidence extends CompletionConfidence{
|
||||
@NotNull
|
||||
@Override
|
||||
public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
final ASTNode node = parameters.getPosition().getNode();
|
||||
if (node == null) return null;
|
||||
if (node == null) return ThreeState.UNSURE;
|
||||
|
||||
final IElementType elementType = node.getElementType();
|
||||
if (elementType == XmlTokenType.XML_NAME || elementType == XmlTokenType.XML_TAG_NAME) {
|
||||
return true;
|
||||
return ThreeState.YES;
|
||||
}
|
||||
return null;
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user