package com.intellij.codeInsight.editorActions.wordSelection;

import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler;
import com.intellij.lang.Language;
import com.intellij.lang.StdLanguages;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class AntLikePropertySelectionHandler implements ExtendWordSelectionHandler {
  public boolean canSelect(PsiElement e) {
    Language l = e.getLanguage();
    return StdLanguages.JAVA.equals(l)
           || StdLanguages.XML.equals(l)
           || StdLanguages.ANT.equals(l);
  }

  public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    TextRange range = e.getTextRange();
    char prevLeftChar = ' ';
    for (int left = cursorOffset; left >= range.getStartOffset(); left--) {
      char leftChar = editorText.charAt(left);
      if (leftChar == '}') return Collections.emptyList();
      if (leftChar == '$' && prevLeftChar == '{') {
        for (int right = cursorOffset; right < range.getEndOffset(); right++) {
          char rightChar = editorText.charAt(right);
          if (rightChar == '{') return Collections.emptyList();
          if (rightChar == '}') {
            return Arrays.asList(new TextRange(left + 2, right), new TextRange(left, right + 1));
          }
        }
      }
      prevLeftChar = leftChar;
    }
    return Collections.emptyList();
  }
}

@@ -318,23 +318,101 @@
 .psi.Psi
-Element
+Comment;%0Aimport com.intellij.psi.PsiElement;%0Aimport com.intellij.psi.util.PsiTreeUtil
 ;%0A%0Aimpor
@@ -651,23 +651,22 @@
 ();%0A    
-return 
+if (!(
 StdLangu
@@ -687,33 +687,32 @@
 ls(l)%0A          
- 
 %7C%7C StdLanguages.
@@ -727,33 +727,32 @@
 ls(l)%0A          
- 
 %7C%7C StdLanguages.
@@ -764,16 +764,115 @@
 quals(l)
+)) %7B%0A      return false;%0A    %7D%0A%0A    return PsiTreeUtil.getParentOfType(e, PsiComment.class) == null
 ;%0A  %7D%0A%0A 

test fix