Search in sources :

Example 6 with Variable

use of com.intellij.codeInsight.template.impl.Variable in project intellij-community by JetBrains.

the class SubstitutionShortInfoHandler method handleInputFocusMovement.

private void handleInputFocusMovement(LogicalPosition position) {
    checkModelValidity();
    String text = "";
    final int offset = editor.logicalPositionToOffset(position);
    final int length = editor.getDocument().getTextLength();
    final CharSequence elements = editor.getDocument().getCharsSequence();
    int start = offset - 1;
    int end = -1;
    while (start >= 0 && Character.isJavaIdentifierPart(elements.charAt(start)) && elements.charAt(start) != '$') start--;
    if (start >= 0 && elements.charAt(start) == '$') {
        end = offset;
        while (end < length && Character.isJavaIdentifierPart(elements.charAt(end)) && elements.charAt(end) != '$') end++;
        if (end < length && elements.charAt(end) == '$') {
            String varname = elements.subSequence(start + 1, end).toString();
            Variable foundVar = null;
            for (final Variable var : variables) {
                if (var.getName().equals(varname)) {
                    foundVar = var;
                    break;
                }
            }
            if (foundVar != null) {
                text = UIUtil.getShortParamString(editor.getUserData(CURRENT_CONFIGURATION_KEY), varname);
            }
        }
    }
    if (text.length() > 0) {
        UIUtil.showTooltip(editor, start, end + 1, text);
    } else {
        TooltipController.getInstance().cancelTooltips();
    }
}
Also used : Variable(com.intellij.codeInsight.template.impl.Variable)

Aggregations

Variable (com.intellij.codeInsight.template.impl.Variable)6 TemplateImpl (com.intellij.codeInsight.template.impl.TemplateImpl)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1