Java Code Examples for com.jetbrains.php.completion.insert.PhpInsertHandlerUtil#isStringAtCaret()

The following examples show how to use com.jetbrains.php.completion.insert.PhpInsertHandlerUtil#isStringAtCaret() . 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: 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 2
Source File: PhpConstGotoCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {
    super.handleInsert(context, lookupElement);

    if (context.getCompletionChar() == ':') {
        context.setAddCompletionChar(false);
    }

    if (!PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), SCOPE_OPERATOR)) {
        PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), SCOPE_OPERATOR);
    }

    PhpCompletionUtil.showCompletion(context);
}
 
Example 3
Source File: FunctionInsertHandler.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {

        // 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);

    }
 
Example 4
Source File: AnnotationPropertyInsertHandler.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
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 5
Source File: TwigExtensionInsertHandler.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement, @NotNull TwigExtension twigExtension) {
    // {{ form_javasc|() }}
    // {{ form_javasc| }}
    if(PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), "(")) {
        return;
    }

    FunctionInsertHandler.getInstance().handleInsert(context, lookupElement);

    // if first parameter is a string type; add quotes
    for (PsiElement psiElement : PhpElementsUtil.getPsiElementsBySignature(context.getProject(), twigExtension.getSignature())) {
        if(!(psiElement instanceof Function)) {
            continue;
        }

        Parameter[] parameters = ((Function) psiElement).getParameters();

        // skip Twig parameter, we need first function parameter
        int parameter = 0;
        if(twigExtension.getOption("needs_context") != null) {
            parameter++;
        }

        if(twigExtension.getOption("needs_environment") != null) {
            parameter++;
        }

        if(parameters.length <= parameter) {
            continue;
        }

        if(!isString(parameters[parameter].getType())) {
            continue;
        }

        // wrap caret with '' so we have foobar('<caret>')
        PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), "''");
        context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true);

        return;
    }
}
 
Example 6
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);

        }


    }
 
Example 7
Source File: ViewHelperArgumentInsertHandler.java    From idea-php-typo3-plugin with MIT License 3 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {

        if (PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), ":")) {
            return;
        }

        PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), ": ");

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