IDEA-CR-3132 honor exact selection; some javadoc with HTML warnings

This commit is contained in:
Gregory.Shrago
2015-06-17 19:22:02 +03:00
parent 9f9b57a27d
commit df404bb813
2 changed files with 16 additions and 1 deletions
@@ -21,15 +21,27 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @see com.intellij.codeInsight.hint.actions.ShowExpressionTypeAction
*
* @author gregsh
*/
public abstract class ExpressionTypeProvider<T extends PsiElement> {
/**
* Returns HTML string for type info hint.
* @see com.intellij.openapi.util.text.StringUtil#escapeXml(String)
*/
@NotNull
public abstract String getInformationHint(@NotNull T element);
/**
* Returns HTML string if no target found at position.
*/
@NotNull
public abstract String getErrorHint();
/**
* Returns the list of all possible targets at specified position.
*/
@NotNull
public abstract List<T> getExpressionsAt(@NotNull PsiElement elementAt);
}
@@ -60,11 +60,14 @@ public class ShowExpressionTypeHandler implements CodeInsightActionHandler {
final Set<ExpressionTypeProvider> handlers = getHandlers(project, language, file.getViewProvider().getBaseLanguage());
if (handlers.isEmpty()) return;
boolean exactRange = false;
TextRange range = EditorUtil.getSelectionInAnyMode(editor);
final Map<PsiElement, ExpressionTypeProvider> map = ContainerUtil.newLinkedHashMap();
for (ExpressionTypeProvider handler : handlers) {
for (PsiElement element : ((ExpressionTypeProvider<? extends PsiElement>)handler).getExpressionsAt(elementAt)) {
if (!element.getTextRange().contains(range)) continue;
TextRange r = element.getTextRange();
if (exactRange && !r.equals(range) || !r.contains(range)) continue;
if (!exactRange) exactRange = r.equals(range);
map.put(element, handler);
}
}