本文整理汇总了Java中com.intellij.codeInsight.completion.util.ParenthesesInsertHandler类的典型用法代码示例。如果您正苦于以下问题:Java ParenthesesInsertHandler类的具体用法?Java ParenthesesInsertHandler怎么用?Java ParenthesesInsertHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParenthesesInsertHandler类属于com.intellij.codeInsight.completion.util包,在下文中一共展示了ParenthesesInsertHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addLookupElement
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
private void addLookupElement(List<LookupElement> lookupElements, PsiElement el) {
if (!el.isValid()) return;
LookupElementBuilder builder;
if (el instanceof DictionaryComponent) {
DictionaryComponent dc = (DictionaryComponent) el;
String dName = dc.getDictionary().getName();
builder = LookupElementBuilder.createWithIcon(dc).appendTailText(" " + dName, true);
} else if (el instanceof AppleScriptComponent) {
builder = LookupElementBuilder.createWithIcon((AppleScriptComponent) el);
if (el instanceof AppleScriptHandlerPositionalParametersDefinition) {
AppleScriptHandlerPositionalParametersDefinition handlerCall = (AppleScriptHandlerPositionalParametersDefinition) el;
builder = builder.withInsertHandler(handlerCall.getFormalParameterList() != null ?
ParenthesesInsertHandler.WITH_PARAMETERS : ParenthesesInsertHandler.NO_PARAMETERS);
}
} else {
builder = LookupElementBuilder.create(el);
}
AppleScriptComponentType componentType = AppleScriptComponentType.typeOf(el);
String typeText = componentType != null ? componentType.toString().toLowerCase() : null;
builder = builder.withTypeText(typeText, null, true);
lookupElements.add(builder);
}
示例2: fillLookupElementsList
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
@Override
void fillLookupElementsList(@NotNull List<LookupElement> list) {
LookupElement getterLookupElement =
LookupElementBuilder.create(getGetterName())
.withTypeText(getDefinitionClass().getName())
.withTailText("(self)")
.withInsertHandler(ParenthesesInsertHandler.NO_PARAMETERS)
.withIcon(PlatformIcons.METHOD_ICON);
list.add(getterLookupElement);
if (getSetterName() != null) {
LookupElement setterLookupElement =
LookupElementBuilder.create(getSetterName())
.withTypeText(getDefinitionClass().getName())
.withTailText("(self, value)")
.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS)
.withIcon(PlatformIcons.METHOD_ICON);
list.add(setterLookupElement);
}
}
示例3: completeAnnotations
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
private boolean completeAnnotations(@NotNull CompletionResultSet result, PsiFile file, PsiElement completionElement) {
final JSGraphQLEndpointFieldDefinition field = PsiTreeUtil.getNextSiblingOfType(completionElement, JSGraphQLEndpointFieldDefinition.class);
final JSGraphQLEndpointProperty property = PsiTreeUtil.getNextSiblingOfType(completionElement, JSGraphQLEndpointProperty.class);
final JSGraphQLEndpointAnnotation nextAnnotation = PsiTreeUtil.getNextSiblingOfType(completionElement, JSGraphQLEndpointAnnotation.class);
final boolean afterAtAnnotation = completionElement.getNode().getElementType() == JSGraphQLEndpointTokenTypes.AT_ANNOTATION;
if (afterAtAnnotation || field != null || nextAnnotation != null || property != null) {
final JSGraphQLConfigurationProvider configurationProvider = JSGraphQLConfigurationProvider.getService(file.getProject());
for (JSGraphQLSchemaEndpointAnnotation endpointAnnotation : configurationProvider.getEndpointAnnotations()) {
String completion = endpointAnnotation.name;
if (!afterAtAnnotation) {
completion = "@" + completion;
}
LookupElementBuilder element = LookupElementBuilder.create(completion).withIcon(JSGraphQLIcons.Schema.Attribute);
if(endpointAnnotation.arguments != null && endpointAnnotation.arguments.size() > 0) {
element = element.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS);
}
result.addElement(element);
}
return true;
}
return false;
}
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:23,代码来源:JSGraphQLEndpointCompletionContributor.java
示例4: CGCompletionContributor
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
public CGCompletionContributor()
{
extend(CompletionType.BASIC, StandardPatterns.psiElement().withLanguage(CGLanguage.INSTANCE), new CompletionProvider()
{
@RequiredReadAction
@Override
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result)
{
for(String keyword : CGKeywords.KEYWORDS)
{
result.addElement(LookupElementBuilder.create(keyword).bold());
}
for(String m : ourMethods)
{
result.addElement(LookupElementBuilder.create(m + "()").withIcon(AllIcons.Nodes.Method).withInsertHandler(ParenthesesInsertHandler.getInstance(true)));
}
}
});
}
示例5: handleInsert
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
for (int i = 0; i < myTypeItems.size(); i++) {
CompletionUtil.emulateInsertion(context, context.getTailOffset(), myTypeItems.get(i));
context.setTailOffset(getTail(i == myTypeItems.size() - 1).processTail(context.getEditor(), context.getTailOffset()));
}
context.setAddCompletionChar(false);
context.commitDocument();
PsiElement leaf = context.getFile().findElementAt(context.getTailOffset() - 1);
if (psiElement().withParents(PsiReferenceParameterList.class, PsiJavaCodeReferenceElement.class, PsiNewExpression.class)
.accepts(leaf)) {
ParenthesesInsertHandler.getInstance(myHasParameters).handleInsert(context, this);
myGlobalTail.processTail(context.getEditor(), context.getTailOffset());
}
}
示例6: completeMethodName
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
private static void completeMethodName(Set<LookupElement> set, PsiElement element, final PrefixMatcher matcher){
if(element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)element;
if (method.isConstructor()) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null) {
final String name = containingClass.getName();
if (StringUtil.isNotEmpty(name)) {
addLookupItems(set, null, matcher, element.getProject(), name);
}
}
return;
}
}
PsiClass ourClassParent = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (ourClassParent == null) return;
if (ourClassParent.isAnnotationType() && matcher.prefixMatches(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME)) {
set.add(LookupElementBuilder.create(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME)
.withIcon(PlatformIcons.METHOD_ICON)
.withTailText("()")
.withInsertHandler(ParenthesesInsertHandler.NO_PARAMETERS));
}
addLookupItems(set, null, matcher, element.getProject(), getUnresolvedReferences(ourClassParent, true));
addLookupItems(set, null, matcher, element.getProject(), getPropertiesHandlersNames(
ourClassParent,
((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC),
PsiUtil.getTypeByPsiElement(element), element));
}
示例7: handleInsert
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
context.commitDocument();
PsiReferenceParameterList list = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiReferenceParameterList.class, false);
PsiTypeElement[] typeElements = list != null ? list.getTypeParameterElements() : PsiTypeElement.EMPTY_ARRAY;
if (typeElements.length == 0) {
return;
}
int listEnd = typeElements[typeElements.length - 1].getTextRange().getEndOffset();
context.setTailOffset(listEnd);
context.getDocument().deleteString(context.getStartOffset(), listEnd);
for (int i = 0; i < myTypeItems.size(); i++) {
PsiTypeLookupItem typeItem = myTypeItems.get(i);
CompletionUtil.emulateInsertion(context, context.getTailOffset(), typeItem);
if (context.getTailOffset() < 0) {
LOG.error("tail offset spoiled by " + typeItem);
return;
}
context.setTailOffset(getTail(i == myTypeItems.size() - 1).processTail(context.getEditor(), context.getTailOffset()));
}
context.setAddCompletionChar(false);
context.commitDocument();
PsiElement leaf = context.getFile().findElementAt(context.getTailOffset() - 1);
if (psiElement().withParents(PsiReferenceParameterList.class, PsiJavaCodeReferenceElement.class, PsiNewExpression.class)
.accepts(leaf)) {
ParenthesesInsertHandler.getInstance(myHasParameters).handleInsert(context, this);
myGlobalTail.processTail(context.getEditor(), context.getTailOffset());
}
}
示例8: toLookUpElement
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
/**
* Creates {@link com.intellij.codeInsight.lookup.LookupElement} to be used in cases like {@link com.jetbrains.python.psi.types.PyType#getCompletionVariants(String, com.intellij.psi.PsiElement, com.intellij.util.ProcessingContext)}
* This method should be in {@link com.jetbrains.python.codeInsight.PyCustomMember} but it does not. We need to move it.
*
* @param member custom member
* @param typeText type text (if any)
* @return lookup element
*/
@NotNull
public static LookupElementBuilder toLookUpElement(@NotNull final PyCustomMember member, @Nullable final String typeText) {
LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(member.getName())
.withIcon(member.getIcon())
.withTypeText(typeText);
if (member.isFunction()) {
lookupElementBuilder = lookupElementBuilder.withInsertHandler(ParenthesesInsertHandler.NO_PARAMETERS).withLookupString("()");
}
return lookupElementBuilder;
}
示例9: addCompletions
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull CompletionResultSet result) {
JqlFieldType operandType;
boolean listFunctionExpected;
PsiElement curElem = parameters.getPosition();
JqlHistoryPredicate predicate = PsiTreeUtil.getParentOfType(curElem, JqlHistoryPredicate.class);
if (predicate != null) {
listFunctionExpected = false;
JqlHistoryPredicate.Type predicateType = predicate.getType();
switch (predicateType) {
case BEFORE:
case AFTER:
case DURING:
case ON:
operandType = JqlFieldType.DATE;
break;
case BY:
operandType = JqlFieldType.USER;
break;
// from, to
default:
operandType = findTypeOfField(curElem);
}
}
else {
operandType = findTypeOfField(curElem);
listFunctionExpected = insideClauseWithListOperator(curElem);
}
for (String functionName : JqlStandardFunction.allOfType(operandType, listFunctionExpected)) {
result.addElement(LookupElementBuilder.create(functionName)
.withInsertHandler(ParenthesesInsertHandler.NO_PARAMETERS));
}
}
示例10: handleInsert
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
final PsiClassType.ClassResolveResult resolveResult = myClassType.resolveGenerics();
final PsiClass psiClass = resolveResult.getElement();
if (psiClass == null || !psiClass.isValid()) {
return;
}
GroovyPsiElement place =
PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GroovyPsiElement.class, false);
boolean hasParams = place != null && GroovyCompletionUtil.hasConstructorParameters(psiClass, place);
if (myTriggerFeature) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW);
}
if (hasParams) {
ParenthesesInsertHandler.WITH_PARAMETERS.handleInsert(context, item);
}
else {
ParenthesesInsertHandler.NO_PARAMETERS.handleInsert(context, item);
}
shortenRefsInGenerics(context);
if (hasParams) {
AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
}
PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());
if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final Editor editor = context.getEditor();
final int offset = context.getTailOffset();
editor.getDocument().insertString(offset, " {}");
editor.getCaretModel().moveToOffset(offset + 2);
context.setLaterRunnable(generateAnonymousBody(editor, context.getFile()));
}
}
示例11: BuiltInFunctionCompletionContributor
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
public BuiltInFunctionCompletionContributor() {
extend(
CompletionType.BASIC,
psiElement()
.withLanguage(BuildFileLanguage.INSTANCE)
.andNot(psiComment())
.andOr(
// Handles only top-level rules, and rules inside a function statement.
// There are several other possibilities (e.g. inside top-level list comprehension),
// but leaving out less common cases to avoid cluttering the autocomplete
// suggestions when it's not valid to enter a rule.
psiElement()
.withParents(
ReferenceExpression.class,
BuildFile.class), // leaf node => BuildReference => BuildFile
psiElement()
.inside(
psiElement(StatementList.class).inside(psiElement(FunctionStatement.class)))
.afterLeaf(
psiElement().withText(".").afterLeaf(psiElement().withText("native")))),
new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(
CompletionParameters parameters,
ProcessingContext context,
CompletionResultSet result) {
ImmutableSet<String> builtInNames =
BuiltInNamesProvider.getBuiltInFunctionNames(parameters.getPosition().getProject());
for (String ruleName : builtInNames) {
result.addElement(
LookupElementBuilder.create(ruleName)
.withIcon(BlazeIcons.BuildRule)
.withInsertHandler(ParenthesesInsertHandler.getInstance(true)));
}
}
});
}
示例12: handleInsert
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
public void handleInsert(final InsertionContext context, LookupItem<PsiClassType> item) {
final PsiClassType.ClassResolveResult resolveResult = myClassType.resolveGenerics();
final PsiClass psiClass = resolveResult.getElement();
if (psiClass == null || !psiClass.isValid()) {
return;
}
GroovyPsiElement place =
PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GroovyPsiElement.class, false);
boolean hasParams = place != null && GroovyCompletionUtil.hasConstructorParameters(psiClass, place);
if (myTriggerFeature) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW);
}
if (hasParams) {
ParenthesesInsertHandler.WITH_PARAMETERS.handleInsert(context, item);
}
else {
ParenthesesInsertHandler.NO_PARAMETERS.handleInsert(context, item);
}
shortenRefsInGenerics(context);
if (hasParams) {
AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
}
PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());
if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final Editor editor = context.getEditor();
final int offset = context.getTailOffset();
editor.getDocument().insertString(offset, " {}");
editor.getCaretModel().moveToOffset(offset + 2);
context.setLaterRunnable(generateAnonymousBody(editor, context.getFile()));
}
}
示例13: addCompletions
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
@Override
public void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull CompletionResultSet result) {
JqlFieldType operandType;
boolean listFunctionExpected;
PsiElement curElem = parameters.getPosition();
JqlHistoryPredicate predicate = PsiTreeUtil.getParentOfType(curElem, JqlHistoryPredicate.class);
if (predicate != null) {
listFunctionExpected = false;
JqlHistoryPredicate.Type predicateType = predicate.getType();
switch (predicateType) {
case BEFORE:
case AFTER:
case DURING:
case ON:
operandType = JqlFieldType.DATE;
break;
case BY:
operandType = JqlFieldType.USER;
break;
// from, to
default:
operandType = findTypeOfField(curElem);
}
}
else {
operandType = findTypeOfField(curElem);
listFunctionExpected = insideClauseWithListOperator(curElem);
}
for (String functionName : JqlStandardFunction.allOfType(operandType, listFunctionExpected)) {
result.addElement(LookupElementBuilder.create(functionName)
.withInsertHandler(ParenthesesInsertHandler.NO_PARAMETERS));
}
}
示例14: JavaScriptKeywordCompletionContributor
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
public JavaScriptKeywordCompletionContributor()
{
extend(CompletionType.BASIC, StandardPatterns.psiElement().withParent(JSReferenceExpression.class), new CompletionProvider()
{
@RequiredReadAction
@Override
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result)
{
PsiElement position = parameters.getPosition();
JSReferenceExpression parent = (JSReferenceExpression) position.getParent();
if(parent.getQualifier() != null)
{
return;
}
boolean parentIsStatement = parent.getParent() instanceof JSExpressionStatement;
LookupElementBuilder functionKeyword = LookupElementBuilder.create("function");
functionKeyword = functionKeyword.bold();
if(parentIsStatement)
{
functionKeyword = functionKeyword.withInsertHandler(SpaceInsertHandler.INSTANCE);
}
else
{
functionKeyword = functionKeyword.withInsertHandler(ParenthesesInsertHandler.getInstance(false));
functionKeyword = functionKeyword.withPresentableText("function()");
}
result.addElement(functionKeyword);
result.addElement(LookupElementBuilder.create("var").withInsertHandler(SpaceInsertHandler.INSTANCE).bold());
}
});
}
示例15: completeMethodName
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; //导入依赖的package包/类
private static void completeMethodName(Set<LookupElement> set, PsiElement element, final PrefixMatcher matcher)
{
if(element instanceof PsiMethod)
{
final PsiMethod method = (PsiMethod) element;
if(method.isConstructor())
{
final PsiClass containingClass = method.getContainingClass();
if(containingClass != null)
{
final String name = containingClass.getName();
if(StringUtil.isNotEmpty(name))
{
addLookupItems(set, null, matcher, element.getProject(), name);
}
}
return;
}
}
PsiClass ourClassParent = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if(ourClassParent == null)
{
return;
}
if(ourClassParent.isAnnotationType() && matcher.prefixMatches(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME))
{
set.add(LookupElementBuilder.create(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME).withIcon(PlatformIcons.METHOD_ICON).withTailText("()").withInsertHandler(ParenthesesInsertHandler
.NO_PARAMETERS));
}
addLookupItems(set, null, matcher, element.getProject(), getUnresolvedReferences(ourClassParent, true));
addLookupItems(set, null, matcher, element.getProject(), getPropertiesHandlersNames(ourClassParent, ((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC), PsiUtil
.getTypeByPsiElement(element), element));
}