Java Code Examples for com.intellij.codeInsight.lookup.LookupElement#getPsiElement()

The following examples show how to use com.intellij.codeInsight.lookup.LookupElement#getPsiElement() . 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: CSharpRecursiveGuardWeigher.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Integer weigh(@Nonnull LookupElement element)
{
	PsiElement psiElement = element.getPsiElement();
	if(psiElement == null)
	{
		return 0;
	}

	for(PsiElement e : myElementSet)
	{
		if(psiElement.isEquivalentTo(e))
		{
			return Integer.MIN_VALUE;
		}
	}
	return 0;
}
 
Example 2
Source File: FreeExpressionCompletionProvider.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
private static void insertExpression(@NotNull InsertionContext insertionContext, @NotNull LookupElement element) {
    PsiElement psiElement = element.getPsiElement();
    if (psiElement instanceof PsiLet) {
        PsiLet let = (PsiLet) psiElement;
        if (let.isFunction()) {
            insertionContext.setAddCompletionChar(false);
            Editor editor = insertionContext.getEditor();
            EditorModificationUtil.insertStringAtCaret(editor, "()");
            editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 1);
        }
    }
}
 
Example 3
Source File: FluidTypeInsertHandler.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {

        PsiElement psiElement = lookupElement.getPsiElement();
        if (psiElement instanceof Method && needParameter((Method) psiElement)) {
            if (PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), "(")) {
                return;
            }

            String addText = "()";
            PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), addText);

            context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true);
        }
    }
 
Example 4
Source File: CSharpCompletionSorting.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
private static String getName(LookupElement element)
{
	PsiElement psiElement = element.getPsiElement();
	return getName(psiElement);
}
 
Example 5
Source File: CompletionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: CSharpCompletionSorting.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public Type weigh(@Nonnull LookupElement element)
{
	Type type = element.getUserData(ourForceType);
	if(type != null)
	{
		return type;
	}

	IElementType keywordElementType = element.getUserData(CSharpCompletionUtil.KEYWORD_ELEMENT_TYPE);

	String lookupString = element.getLookupString();
	if(lookupString.startsWith("__") && keywordElementType != null)
	{
		return Type.hiddenKeywords;
	}
	else if(keywordElementType != null)
	{
		return Type.keyword;
	}
	else if(lookupString.startsWith("#"))
	{
		return Type.preprocessorKeywords;
	}

	PsiElement psiElement = element.getPsiElement();
	if(psiElement instanceof CSharpLocalVariable || psiElement instanceof DotNetParameter || psiElement instanceof CSharpLambdaParameter)
	{
		return Type.localVariableOrParameter;
	}

	if(psiElement instanceof CSharpFieldDeclaration && ((CSharpFieldDeclaration) psiElement).isConstant() || psiElement instanceof CSharpEnumConstantDeclaration)
	{
		return Type.constants;
	}

	if(psiElement instanceof CSharpPropertyDeclaration || psiElement instanceof CSharpEventDeclaration || psiElement instanceof CSharpFieldDeclaration || psiElement instanceof
			CSharpMethodDeclaration && !((CSharpMethodDeclaration) psiElement).isDelegate())
	{
		return Type.member;
	}

	if(psiElement instanceof DotNetNamespaceAsElement)
	{
		return Type.namespace;
	}
	return Type.any;
}
 
Example 7
Source File: CSharpInheritCompletionWeighter.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: TwigTypeInsertHandler.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {

        PsiElement psiElement = lookupElement.getPsiElement();
        if(psiElement instanceof Method && needParameter((Method) psiElement)) {

            // check this:
            // {{ form_javasc|() }}
            // {{ form_javasc| }}
            if(PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), "(")) {
                return;
            }

            String addText = "()";
            PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), addText);

            context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true);

        }


    }