Java Code Examples for com.intellij.codeInsight.lookup.LookupElement#getObject()
The following examples show how to use
com.intellij.codeInsight.lookup.LookupElement#getObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSharpParameterInfoHandler.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @Override @RequiredReadAction public ItemToShow[] getParametersForLookup(LookupElement item, ParameterInfoContext context) { Object object = item.getObject(); if(object instanceof DotNetLikeMethodDeclaration) { return new ItemToShow[]{new ItemToShow((CSharpSimpleLikeMethod) object, context.getFile())}; } if(object instanceof DotNetVariable) { DotNetVariable variable = (DotNetVariable) object; DotNetTypeRef dotNetTypeRef = variable.toTypeRef(tracksParameterIndex()); DotNetTypeResolveResult typeResolveResult = dotNetTypeRef.resolve(); if(typeResolveResult instanceof CSharpLambdaResolveResult) { return new ItemToShow[]{new ItemToShow((CSharpSimpleLikeMethod) typeResolveResult, variable)}; } } return ItemToShow.EMPTY_ARRAY; }
Example 2
Source File: PhpClassReferenceInsertHandler.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { Object object = lookupElement.getObject(); if (!(object instanceof PhpClass)) { return; } StringBuilder textToInsertBuilder = new StringBuilder(); PhpClass aClass = (PhpClass)object; String fqn = aClass.getNamespaceName(); if(fqn.startsWith("\\")) { fqn = fqn.substring(1); } textToInsertBuilder.append(fqn); context.getDocument().insertString(context.getStartOffset(), textToInsertBuilder); }
Example 3
Source File: InheritorsHolder.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public void consume(LookupElement lookupElement) { final Object object = lookupElement.getObject(); if(object instanceof PsiElement && CSharpPsiUtilImpl.isTypeLikeElement((PsiElement) object)) { registerTypeLike((DotNetQualifiedElement) object); } myResult.addElement(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(lookupElement)); }
Example 4
Source File: HaxeParameterInfoHandler.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override public Object[] getParametersForLookup(@NotNull LookupElement item, ParameterInfoContext context) { final Object object = item.getObject(); if (object instanceof PsiElement) { final PsiElement element = (PsiElement)object; final HaxeComponentType type = HaxeComponentType.typeOf(element.getParent()); if (type == HaxeComponentType.METHOD) { return new Object[]{element.getParent()}; } } return ArrayUtil.EMPTY_OBJECT_ARRAY; }
Example 5
Source File: ClassConstantInsertHandler.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override public void handleInsert(InsertionContext context, LookupElement lookupElement) { if(!(lookupElement instanceof ClassConstantLookupElementInterface) || !(lookupElement.getObject() instanceof PhpClass)) { return; } PhpReferenceInsertHandler.getInstance().handleInsert(context, lookupElement); PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), "::class"); }
Example 6
Source File: ParameterPercentWrapInsertHandler.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { String insertText = null; if((lookupElement.getObject() instanceof PsiElement)) { return; } if((lookupElement.getObject() instanceof String)) { insertText = (String) lookupElement.getObject(); } if(insertText == null) { return; } // "<caret>", '<caret>' insertText = PsiElementUtils.trimQuote(insertText); if(!insertText.startsWith("%")) { context.getDocument().insertString(context.getStartOffset(), "%"); } // %| is also fired if(!insertText.endsWith("%") || insertText.length() == 1) { context.getDocument().insertString(context.getTailOffset(), "%"); context.getEditor().getCaretModel().moveCaretRelatively(1, 0, false, false, true); } }
Example 7
Source File: Suggestion.java From intellij-spring-assistant with MIT License | 5 votes |
public void renderElement(LookupElement element, LookupElementPresentation presentation) { Suggestion suggestion = (Suggestion) element.getObject(); if (suggestion.icon != null) { presentation.setIcon(suggestion.icon); } presentation.setStrikeout(suggestion.deprecationLevel != null); if (suggestion.deprecationLevel != null) { if (suggestion.deprecationLevel == SpringConfigurationMetadataDeprecationLevel.error) { presentation.setItemTextForeground(RED); } else { presentation.setItemTextForeground(YELLOW); } } String lookupString = element.getLookupString(); presentation.setItemText(lookupString); if (!lookupString.equals(suggestion.suggestionToDisplay)) { presentation.setItemTextBold(true); } String shortDescription; if (suggestion.defaultValue != null) { shortDescription = shortenTextWithEllipsis(suggestion.defaultValue, 60, 0, true); TextAttributes attrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SCALAR_TEXT); presentation.setTailText("=" + shortDescription, attrs.getForegroundColor()); } if (suggestion.description != null) { presentation .appendTailText(" (" + getFirstSentenceWithoutDot(suggestion.description) + ")", true); } if (suggestion.shortType != null) { presentation.setTypeText(suggestion.shortType); } }
Example 8
Source File: AnnotationMethodInsertHandler.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { if(lookupElement.getObject() instanceof AnnotationValue) { String addText = "=\"\""; if(((AnnotationValue) lookupElement.getObject()).getType() == AnnotationValue.Type.Array) { addText = "={}"; } PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), addText); } else { PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), "=\"\""); } context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true); }
Example 9
Source File: AnnotationPropertyInsertHandler.java From idea-php-annotation-plugin with MIT License | 5 votes |
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { // value completion should not fire when already presented: // eng| = "value" // eng|="value" if(PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), "=") || PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), " =")) { return; } // move caret back int i = -1; // append completion text depend on value: // engine="|" // engine={|} // engine=<boolean|integer> if(lookupElement.getObject() instanceof AnnotationProperty) { String addText = "=\"\""; if(((AnnotationProperty) lookupElement.getObject()).getAnnotationPropertyEnum() == AnnotationPropertyEnum.ARRAY) { addText = "={}"; } if(((AnnotationProperty) lookupElement.getObject()).getAnnotationPropertyEnum() == AnnotationPropertyEnum.INTEGER || ((AnnotationProperty) lookupElement.getObject()).getAnnotationPropertyEnum() == AnnotationPropertyEnum.BOOLEAN) { addText = "="; i = 0; } PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), addText); } else { PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), "=\"\""); } if(i != 0) { context.getEditor().getCaretModel().moveCaretRelatively(i, 0, false, false, true); } }
Example 10
Source File: CompletionUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static PsiElement getTargetElement(LookupElement lookupElement) { PsiElement psiElement = lookupElement.getPsiElement(); if (psiElement != null && psiElement.isValid()) { return getOriginalElement(psiElement); } Object object = lookupElement.getObject(); if (object instanceof LookupValueWithPsiElement) { final PsiElement element = ((LookupValueWithPsiElement)object).getElement(); if (element != null && element.isValid()) return getOriginalElement(element); } return null; }
Example 11
Source File: LookupElementProximityWeigher.java From consulo with Apache License 2.0 | 5 votes |
@Override public Comparable weigh(@Nonnull final LookupElement item, @Nonnull final CompletionLocation location) { if (item.getObject() instanceof PsiElement) { return PsiProximityComparator.getProximity((NullableComputable<PsiElement>)() -> item.getPsiElement(), location.getCompletionParameters().getPosition(), location.getProcessingContext()); } return null; }
Example 12
Source File: DirectoryTemplateCompletionProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean nextTabOnItemSelected(final ExpressionContext context, final LookupElement item) { Object object = item.getObject(); if (object instanceof PsiFileSystemItem && ((PsiFileSystemItem)object).isDirectory()) { return false; } return true; }
Example 13
Source File: LookupCellRenderer.java From consulo with Apache License 2.0 | 5 votes |
private int setTypeTextLabel(LookupElement item, final Color background, Color foreground, final LookupElementPresentation presentation, int allowedWidth, boolean selected, boolean nonFocusedSelection, FontMetrics normalMetrics) { final String givenText = presentation.getTypeText(); final String labelText = trimLabelText(StringUtil.isEmpty(givenText) ? "" : " " + givenText, allowedWidth, normalMetrics); int used = RealLookupElementPresentation.getStringWidth(labelText, normalMetrics); final Icon icon = presentation.getTypeIcon(); if (icon != null) { myTypeLabel.setIcon(icon); used += icon.getIconWidth(); } Color sampleBackground = background; Object o = item.isValid() ? item.getObject() : null; //noinspection deprecation if (o instanceof LookupValueWithUIHint && StringUtil.isEmpty(labelText)) { //noinspection deprecation Color proposedBackground = ((LookupValueWithUIHint)o).getColorHint(); if (proposedBackground != null) { sampleBackground = proposedBackground; } myTypeLabel.append(" "); used += normalMetrics.stringWidth("WW"); } else { myTypeLabel.append(labelText); } myTypeLabel.setBackground(sampleBackground); myTypeLabel.setForeground(getTypeTextColor(item, foreground, presentation, selected, nonFocusedSelection)); return used; }
Example 14
Source File: FileReferenceCharFilter.java From consulo with Apache License 2.0 | 5 votes |
@Override public Result acceptChar(char c, int prefixLength, Lookup lookup) { final LookupElement item = lookup.getCurrentItem(); if ('.' == c && item != null && item.getObject() instanceof PsiFileSystemItem) { PsiReference referenceAtCaret = lookup.getPsiFile().findReferenceAt(lookup.getLookupStart()); if (referenceAtCaret != null && FileReference.findFileReference(referenceAtCaret) != null) { return Result.ADD_TO_PREFIX; } } return null; }
Example 15
Source File: InheritorsHolder.java From consulo-csharp with Apache License 2.0 | 4 votes |
public boolean alreadyProcessed(@Nonnull LookupElement element) { final Object object = element.getObject(); return object instanceof DotNetQualifiedElement && alreadyProcessed((DotNetQualifiedElement) object); }
Example 16
Source File: CSharpNoVariantsDelegator.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction @RequiredUIAccess public static void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { final InheritorsHolder holder = new InheritorsHolder(result); ResultTracker tracker = new ResultTracker(result) { @Override public void consume(CompletionResult plainResult) { super.consume(plainResult); LookupElement element = plainResult.getLookupElement(); Object o = element.getObject(); if(o instanceof PsiElement && CSharpPsiUtilImpl.isTypeLikeElement((PsiElement) o)) { holder.registerTypeLike((DotNetQualifiedElement) o); } } }; result.runRemainingContributors(parameters, tracker); final boolean empty = tracker.containsOnlyNamespaces; if(!empty && parameters.getInvocationCount() == 0) { result.restartCompletionWhenNothingMatches(); } if(empty) { delegate(parameters, result, holder); } else { if(parameters.getCompletionType() == CompletionType.BASIC && parameters.getInvocationCount() <= 1 && CSharpCompletionUtil.mayStartClassName(result) && CSharpCompletionUtil .isClassNamePossible(parameters)) { addTypesForUsing(parameters, result.withPrefixMatcher(tracker.betterMatcher), holder); } } }
Example 17
Source File: CSharpInheritCompletionWeighter.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Override @RequiredReadAction public Comparable weigh(@Nonnull LookupElement element, @Nonnull CompletionLocation completionLocation) { if(element.getPsiElement() instanceof CSharpConstructorDeclaration) { return null; } CSharpCompletionSorting.KindSorter.Type sort = CSharpCompletionSorting.getSort(element); if(sort == CSharpCompletionSorting.KindSorter.Type.top1) { return Position.HIGH; } List<ExpectedTypeInfo> expectedTypeInfoList = ourExpectedInfoTypes.getValue(completionLocation); if(expectedTypeInfoList.isEmpty()) { return null; } CSharpReferenceExpressionEx referenceExpressionEx = (CSharpReferenceExpressionEx) completionLocation.getCompletionParameters().getPosition().getParent(); DotNetGenericExtractor extractor = DotNetGenericExtractor.EMPTY; if(element instanceof CSharpTypeLikeLookupElement) { extractor = ((CSharpTypeLikeLookupElement) element).getExtractor(); } PsiElement psiElement = element.getPsiElement(); if(psiElement == null) { Object object = element.getObject(); if(object instanceof IElementType) { DotNetTypeRef typeRef = typeRefFromTokeType((IElementType) object, referenceExpressionEx); if(typeRef == null) { return null; } PsiElement resolvedElement = typeRef.resolve().getElement(); if(resolvedElement == null) { return null; } return weighElement(resolvedElement, extractor, referenceExpressionEx, expectedTypeInfoList, Position.UP_KEYWORD); } return null; } else { return weighElement(psiElement, extractor, referenceExpressionEx, expectedTypeInfoList, Position.UP_REF); } }
Example 18
Source File: AnnotationTagInsertHandler.java From idea-php-annotation-plugin with MIT License | 4 votes |
/** * Insert class alias before PhpStorm tries to import a new use statement "\Foo\Bar as Car" */ private void preAliasInsertion(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { Collection<UseAliasOption> importsAliases = AnnotationUtil.getActiveImportsAliasesFromSettings(); if(importsAliases.size() == 0) { return; } Object object = lookupElement.getObject(); if(!(object instanceof PhpClass)) { return; } final String fqn = StringUtils.stripStart(((PhpClass) object).getFQN(), "\\"); UseAliasOption useAliasOption = ContainerUtil.find(importsAliases, useAliasOption1 -> useAliasOption1.getAlias() != null && useAliasOption1.getClassName() != null && fqn.startsWith(StringUtils.stripStart(useAliasOption1.getClassName(), "\\")) ); if(useAliasOption == null || useAliasOption.getClassName() == null || useAliasOption.getAlias() == null) { return; } PsiElement elementAt = context.getFile().findElementAt(context.getEditor().getCaretModel().getOffset()); if(elementAt == null) { return; } PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator(elementAt); if(scopeForUseOperator == null) { return; } String className = useAliasOption.getClassName(); if(!className.startsWith("\\")) { className = "\\" + className; } PhpElementsUtil.insertUseIfNecessary(scopeForUseOperator, className, useAliasOption.getAlias()); PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument()); }