当前位置: 首页>>代码示例>>Java>>正文


Java LookupElementBuilder.withInsertHandler方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.lookup.LookupElementBuilder.withInsertHandler方法的典型用法代码示例。如果您正苦于以下问题:Java LookupElementBuilder.withInsertHandler方法的具体用法?Java LookupElementBuilder.withInsertHandler怎么用?Java LookupElementBuilder.withInsertHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.lookup.LookupElementBuilder的用法示例。


在下文中一共展示了LookupElementBuilder.withInsertHandler方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildLookup

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@NotNull
private LookupElementBuilder buildLookup(PhpClassMember field, PhpExpression position, boolean autoValue) {
    String lookupString = field instanceof Method ? ClassUtils.getAsPropertyName((Method) field) : field.getName();
    LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString).withIcon(field.getIcon());
    if (autoValue) {
        builder = builder.withInsertHandler((insertionContext, lookupElement) -> {

            Document document = insertionContext.getDocument();
            int insertPosition = insertionContext.getSelectionEndOffset();

            if (position.getParent().getParent() instanceof ArrayCreationExpression) {
                document.insertString(insertPosition + 1, " => ");
                insertPosition += 5;
                insertionContext.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition);
            }
        });
    }
    if (field instanceof Field) {
        builder = builder.withTypeText(field.getType().toString());
    }
    return builder;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:23,代码来源:ValidationCompletionProvider.java

示例2: newLookupElement

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
public LookupElementBuilder newLookupElement(ClassLoader classLoader) {
  LookupElementBuilder builder = LookupElementBuilder.create(this, suggestion);
  if (referringToValue) {
    if (description != null) {
      builder = builder.withTypeText(description, true);
    }
    if (representingDefaultValue) {
      builder = builder.bold();
    }
    if (yaml) {
      builder = builder.withInsertHandler(new YamlValueInsertHandler());
    }
  } else {
    builder = builder.withRenderer(CUSTOM_SUGGESTION_RENDERER).withInsertHandler(yaml ?
        new YamlKeyInsertHandler(ref, classLoader) :
        new YamlKeyInsertHandler(ref, classLoader));
  }
  return builder;
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:20,代码来源:Suggestion.java

示例3: addLookupElement

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的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);
}
 
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:23,代码来源:AppleScriptReferenceElementImpl.java

示例4: createLookupBuilder

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
public LookupElementBuilder createLookupBuilder(@NotNull final T item) {
  LookupElementBuilder builder = LookupElementBuilder.create(item, getLookupString(item))
    .withIcon(getIcon(item));

  final InsertHandler<LookupElement> handler = createInsertHandler(item);
  if (handler != null) {
    builder = builder.withInsertHandler(handler);
  }

  final String tailText = getTailText(item);
  if (tailText != null) {
    builder = builder.withTailText(tailText, true);
  }

  final String typeText = getTypeText(item);
  if (typeText != null) {
    builder = builder.withTypeText(typeText);
  }
  return builder;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:TextFieldWithAutoCompletionListProvider.java

示例5: addInsertHandler

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
/**
 * We need special logic to determine when it should insert "=" at the end of the options
 */
@NotNull
private static LookupElementBuilder addInsertHandler(final Editor editor, final LookupElementBuilder builder, String suffix) {
    return builder.withInsertHandler((context, item) -> {
        // enforce using replace select char as we want to replace any existing option
        if (context.getCompletionChar() == Lookup.NORMAL_SELECT_CHAR) {
            int endSelectOffBy = 0;
            if (context.getFile() instanceof PropertiesFileImpl) {
                //if it's a property file the PsiElement does not start and end with an quot
                endSelectOffBy = 1;
            }
            final char text = context.getDocument().getCharsSequence().charAt(context.getSelectionEndOffset() - endSelectOffBy);
            if (text != '=') {
                EditorModificationUtil.insertStringAtCaret(editor, "=");
            }
        } else if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
            // we still want to keep the suffix because they are other options
            String value = suffix;
            int pos = value.indexOf("&");
            if (pos > -1) {
                // strip out first part of suffix until next option
                value = value.substring(pos);
            }
            EditorModificationUtil.insertStringAtCaret(editor, "=" + value);
            // and move cursor back again
            int offset = -1 * value.length();
            EditorModificationUtil.moveCaretRelatively(editor, offset);
        }

    });
}
 
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:34,代码来源:CamelSmartCompletionEndpointOptions.java

示例6: createParametersLookupElement

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
private static LookupElement createParametersLookupElement(final PsiMethod takeParametersFrom, PsiElement call, PsiMethod invoked) {
  final PsiParameter[] parameters = takeParametersFrom.getParameterList().getParameters();
  final String lookupString = StringUtil.join(parameters, new Function<PsiParameter, String>() {
    @Override
    public String fun(PsiParameter psiParameter) {
      return psiParameter.getName();
    }
  }, ", ");

  final int w = PlatformIcons.PARAMETER_ICON.getIconWidth();
  LayeredIcon icon = new LayeredIcon(2);
  icon.setIcon(PlatformIcons.PARAMETER_ICON, 0, 2*w/5, 0);
  icon.setIcon(PlatformIcons.PARAMETER_ICON, 1);

  LookupElementBuilder element = LookupElementBuilder.create(lookupString).withIcon(icon);
  if (PsiTreeUtil.isAncestor(takeParametersFrom, call, true)) {
    element = element.withInsertHandler(new InsertHandler<LookupElement>() {
      @Override
      public void handleInsert(InsertionContext context, LookupElement item) {
        context.commitDocument();
        for (PsiParameter parameter : CompletionUtil.getOriginalOrSelf(takeParametersFrom).getParameterList().getParameters()) {
          VariableLookupItem.makeFinalIfNeeded(context, parameter);
        }
      }
    });
  }
  element.putUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS, Boolean.TRUE);

  return TailTypeDecorator.withTail(element, ExpectedTypesProvider.getFinalCallParameterTailType(call, invoked.getReturnType(), invoked));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:SameSignatureCallParametersProvider.java

示例7: createNamedParameterLookup

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
/**
 * Constructs new lookup element for completion of keyword argument with equals sign appended.
 *
 * @param name    name of the parameter
 * @param project project instance to check code style settings and surround equals sign with spaces if necessary
 * @return lookup element
 */
@NotNull
public static LookupElement createNamedParameterLookup(@NotNull String name, @Nullable Project project) {
  final String suffix;
  if (CodeStyleSettingsManager.getSettings(project).getCustomSettings(PyCodeStyleSettings.class).SPACE_AROUND_EQ_IN_KEYWORD_ARGUMENT) {
    suffix = " = ";
  }
  else {
    suffix = "=";
  }
  LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(name + suffix).withIcon(PlatformIcons.PARAMETER_ICON);
  lookupElementBuilder = lookupElementBuilder.withInsertHandler(OverwriteEqualsInsertHandler.INSTANCE);
  return PrioritizedLookupElement.withGrouping(lookupElementBuilder, 1);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PyUtil.java

示例8: createLookupElement

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@Nullable
@Override
public LookupElement createLookupElement(String s) {
  LookupElementBuilder res = LookupElementBuilder.create(s);
  res = res.withInsertHandler(MavenGroupIdInsertHandler.INSTANCE);
  return res;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:MavenArtifactCoordinatesGroupIdConverter.java

示例9: createLookupElement

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@Nullable
@Override
public LookupElement createLookupElement(String s) {
  LookupElementBuilder res = LookupElementBuilder.create(s);
  res = res.withInsertHandler(MavenArtifactInsertHandler.INSTANCE);
  return res;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:MavenArtifactCoordinatesArtifactIdConverter.java

示例10: buildLookup

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@NotNull
public static LookupElementBuilder buildLookup(Object field, boolean showSchema, Project project) {
    String lookupString = "-";

    if (field instanceof DasObject) {
        lookupString = ((DasObject) field).getName();
        lookupString = RemoveTablePrefix(lookupString, project);
    }
    if (field instanceof Field) {
        lookupString = ((Field) field).getName();
    }
    LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString);

    if (field instanceof Field) {
        builder = builder.withTypeText(((Field) field).getType().toString())
                .withIcon(((Field) field).getIcon());
    }
    if (field instanceof PhpDocProperty) {
        builder = builder.withTypeText(((PhpDocProperty) field).getType().toString())
                .withIcon(((PhpDocProperty) field).getIcon());
    }
    if (field instanceof DasColumn) {
        DasColumn column = (DasColumn) field;
        builder = builder.withTypeText(column.getDataType().typeName, true);
        if (column.getDbParent() != null && showSchema && column.getDbParent().getDbParent() != null) {
            builder = builder.withTailText(" (" + column.getDbParent().getDbParent().getName() + "." + RemoveTablePrefix(column.getDbParent().getName(), project) + ")", true);
        }
        if (column instanceof DasColumn)
            builder = builder.withIcon(TypePresentationService.getService().getIcon(field));
        if (column instanceof DbColumnImpl)
            builder = builder.withIcon(((DbColumnImpl) column).getIcon());
    }
    if (field instanceof DasTable) {
        DasTable table = (DasTable) field;
        DasObject tableSchema = table.getDbParent();
        if (tableSchema != null) {
            if (tableSchema instanceof DbNamespaceImpl) {
                Object dataSource = tableSchema.getDbParent();
               // DbDataSourceImpl dataSource = (DbDataSourceImpl) ((DbNamespaceImpl) tableSchema).getDbParent();
                if (dataSource != null && dataSource instanceof DbDataSourceImpl ) {
                    builder = builder.withTypeText(((DbDataSourceImpl)dataSource).getName(), true);
                }
                if (dataSource != null && dataSource instanceof DbDataSourceImpl ) {
                    builder = builder.withTypeText(((DbDataSourceImpl)dataSource).getName(), true);
                }
            }
        }
        if (showSchema && tableSchema != null) {
            builder = builder.withTailText(" (" + table.getDbParent().getName() + ")", true);
        }
        if (table instanceof DasTable)
            builder = builder.withIcon(TypePresentationService.getService().getIcon(table));
        if (table instanceof DbElement)
            builder = builder.withIcon(((DbElement) table).getIcon());

        builder = builder.withInsertHandler((insertionContext, lookupElement) -> {
            if (Yii2SupportSettings.getInstance(project).insertWithTablePrefix) {
                Document document = insertionContext.getDocument();
                int insertPosition = insertionContext.getSelectionEndOffset();
                document.insertString(insertPosition - lookupElement.getLookupString().length(), "{{%");
                document.insertString(insertPosition + 3, "}}");
                insertionContext.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition + 5);
            }
        });
    }


    return builder;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:70,代码来源:DatabaseUtils.java

示例11: getVariants

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@NotNull
public Object[] getVariants() {
  Map<String, LookupElement> variants = Maps.newHashMap();
  try {
    final List<PydevCompletionVariant> completions = myCommunication.getCompletions(getText(), myPrefix);
    for (PydevCompletionVariant completion : completions) {
      final PsiManager manager = myElement.getManager();
      final String name = completion.getName();
      final int type = completion.getType();
      LookupElementBuilder builder = LookupElementBuilder
        .create(new PydevConsoleElement(manager, name, completion.getDescription()))
        .withIcon(PyCodeCompletionImages.getImageForType(type));


      String args = completion.getArgs();
      if (args.equals("(%)")) {
        builder.withPresentableText("%" + completion.getName());
        builder = builder.withInsertHandler(new InsertHandler<LookupElement>() {
          @Override
          public void handleInsert(InsertionContext context, LookupElement item) {
            final Editor editor = context.getEditor();
            final Document document = editor.getDocument();
            int offset = context.getStartOffset();
            if (offset == 0 || !"%".equals(document.getText(TextRange.from(offset - 1, 1)))) {
              document.insertString(offset, "%");
            }
          }
        });
        args = "";
      }
      else if (!StringUtil.isEmptyOrSpaces(args)) {
        builder = builder.withTailText(args);
      }
      // Set function insert handler
      if (type == IToken.TYPE_FUNCTION || args.endsWith(")")) {
        builder = builder.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS);
      }
      variants.put(name, builder);
    }
  }
  catch (Exception e) {
    //LOG.error(e);
  }
  return variants.values().toArray();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:46,代码来源:PydevConsoleReference.java

示例12: setupItem

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
protected LookupElementBuilder setupItem(LookupElementBuilder item) {
  final Object object = item.getObject();
  if (!myPlainNamesOnly) {
    if (!mySuppressParentheses &&
        object instanceof PyFunction && ((PyFunction)object).getProperty() == null &&
        !PyUtil.hasCustomDecorators((PyFunction)object) &&
        !isSingleArgDecoratorCall(myContext, (PyFunction)object)) {
      final Project project = ((PyFunction)object).getProject();
      item = item.withInsertHandler(PyFunctionInsertHandler.INSTANCE);
      final TypeEvalContext context = TypeEvalContext.codeCompletion(project, myContext != null ? myContext.getContainingFile() : null);
      final List<PyParameter> parameters = PyUtil.getParameters((PyFunction)object, context);
      final String params = StringUtil.join(parameters, new Function<PyParameter, String>() {
        @Override
        public String fun(PyParameter pyParameter) {
          return pyParameter.getName();
        }
      }, ", ");
      item = item.withTailText("(" + params + ")");
    }
    else if (object instanceof PyClass) {
      item = item.withInsertHandler(PyClassInsertHandler.INSTANCE);
    }
  }
  String source = null;
  if (object instanceof PsiElement) {
    final PsiElement element = (PsiElement)object;
    PyClass cls = null;

    if (element instanceof PyFunction) {
      cls = ((PyFunction)element).getContainingClass();
    }
    else if (element instanceof PyTargetExpression) {
      final PyTargetExpression expr = (PyTargetExpression)element;
      if (expr.isQualified() || ScopeUtil.getScopeOwner(expr) instanceof PyClass) {
        cls = expr.getContainingClass();
      }
    }
    else if (element instanceof PyClass) {
      final ScopeOwner owner = ScopeUtil.getScopeOwner(element);
      if (owner instanceof PyClass) {
        cls = (PyClass)owner;
      }
    }

    if (cls != null) {
      source = cls.getName();
    }
    else if (myContext == null || !PyUtil.inSameFile(myContext, element)) {
      QualifiedName path = QualifiedNameFinder.findCanonicalImportPath(element, null);
      if (path != null) {
        if (element instanceof PyFile) {
          path = path.removeLastComponent();
        }
        source = path.toString();
      }
    }
  }
  if (source != null) {
    item = item.withTypeText(source);
  }
  return item;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:63,代码来源:CompletionVariantsProcessor.java

示例13: addTagNameVariants

import com.intellij.codeInsight.lookup.LookupElementBuilder; //导入方法依赖的package包/类
@Override
public void addTagNameVariants(List<LookupElement> elements, @NotNull XmlTag tag, String prefix) {
  final List<String> namespaces;
  if (prefix.isEmpty()) {
    namespaces = new ArrayList<String>(Arrays.asList(tag.knownNamespaces()));
    namespaces.add(XmlUtil.EMPTY_URI); // empty namespace
  }
  else {
    namespaces = new ArrayList<String>(Collections.singletonList(tag.getNamespace()));
  }
  PsiFile psiFile = tag.getContainingFile();
  XmlExtension xmlExtension = XmlExtension.getExtension(psiFile);
  List<String> nsInfo = new ArrayList<String>();
  List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(tag, namespaces, nsInfo);

  if (variants.isEmpty() && psiFile instanceof XmlFile && ((XmlFile)psiFile).getRootTag() == tag) {
    getRootTagsVariants(tag, elements);
    return;
  }

  final Set<String> visited = new HashSet<String>();
  for (int i = 0; i < variants.size(); i++) {
    XmlElementDescriptor descriptor = variants.get(i);
    String qname = descriptor.getName(tag);
    if (!visited.add(qname)) continue;
    if (!prefix.isEmpty() && qname.startsWith(prefix + ":")) {
      qname = qname.substring(prefix.length() + 1);
    }

    PsiElement declaration = descriptor.getDeclaration();
    if (declaration != null && !declaration.isValid()) {
      LOG.error(descriptor + " contains invalid declaration: " + declaration);
    }
    LookupElementBuilder lookupElement = declaration == null ? LookupElementBuilder.create(qname) : LookupElementBuilder.create(declaration, qname);
    final int separator = qname.indexOf(':');
    if (separator > 0) {
      lookupElement = lookupElement.withLookupString(qname.substring(separator + 1));
    }
    String ns = nsInfo.get(i);
    if (StringUtil.isNotEmpty(ns)) {
      lookupElement = lookupElement.withTypeText(ns, true);
    }
    if (descriptor instanceof PsiPresentableMetaData) {
      lookupElement = lookupElement.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
    }
    if (xmlExtension.useXmlTagInsertHandler()) {
      lookupElement = lookupElement.withInsertHandler(XmlTagInsertHandler.INSTANCE);
    }

    elements.add(PrioritizedLookupElement.withPriority(lookupElement, separator > 0 ? 0 : 1));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:53,代码来源:DefaultXmlTagNameProvider.java


注:本文中的com.intellij.codeInsight.lookup.LookupElementBuilder.withInsertHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。