Get rid of using LookupValue

This commit is contained in:
Alexander Zolotov
2015-08-30 20:13:00 +03:00
parent d5cbd31a12
commit 1ba222e929
@@ -15,9 +15,9 @@
*/
package org.intellij.lang.regexp.psi.impl;
import com.intellij.codeInsight.lookup.LookupValueFactory;
import com.intellij.codeInsight.lookup.LookupValueWithPriority;
import com.intellij.codeInsight.lookup.LookupValueWithUIHint;
import com.intellij.codeInsight.completion.PrioritizedLookupElement;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiReference;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.PlatformIcons;
import com.intellij.util.containers.ContainerUtil;
import org.intellij.lang.regexp.RegExpLanguageHosts;
import org.intellij.lang.regexp.RegExpTT;
import org.intellij.lang.regexp.psi.RegExpElementVisitor;
@@ -32,10 +33,10 @@ import org.intellij.lang.regexp.psi.RegExpProperty;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpProperty {
@@ -100,67 +101,40 @@ public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpPrope
return false;
}
@NotNull
public Object[] getVariants() {
final ASTNode categoryNode = getCategoryNode();
if (categoryNode != null && categoryNode.getText().startsWith("In") && !categoryNode.getText().startsWith("Intelli")) {
return UNICODE_BLOCKS;
} else {
final String[][] knownProperties = RegExpLanguageHosts.getInstance().getAllKnownProperties(getElement());
final Object[] objects = new Object[knownProperties.length];
for (int i = 0; i < objects.length; i++) {
final String[] prop = knownProperties[i];
objects[i] = new MyLookupValue(prop);
}
return objects;
}
}
public boolean isSoft() {
return true;
}
private class MyLookupValue extends LookupValueFactory.LookupValueWithIcon implements LookupValueWithPriority, LookupValueWithUIHint {
private final String[] myProp;
public MyLookupValue(String[] prop) {
super(prop[0], PlatformIcons.PROPERTY_ICON);
myProp = prop;
}
public String getPresentation() {
final ASTNode categoryNode = getCategoryNode();
if (categoryNode != null) {
if (categoryNode.getText().startsWith("Is")) {
return "Is" + super.getPresentation();
}
}
return super.getPresentation();
}
public int getPriority() {
final String name = myProp[0];
if (name.equals("all")) return HIGH + 1;
if (name.startsWith("java")) return HIGHER;
return name.length() > 2 ? HIGH : NORMAL;
}
public String getTypeHint() {
return myProp.length > 1 ? myProp[1] : ("Character.is" + myProp[0].substring("java".length()) + "()");
}
@Nullable
public Color getColorHint() {
return null;
}
public boolean isBold() {
return false;
}
@NotNull
public Object[] getVariants() {
final ASTNode categoryNode = getCategoryNode();
if (categoryNode != null && categoryNode.getText().startsWith("In") && !categoryNode.getText().startsWith("Intelli")) {
return UNICODE_BLOCKS;
}
else {
boolean startsWithIs = categoryNode != null && categoryNode.getText().startsWith("Is");
Collection<LookupElement> result = ContainerUtil.newArrayList();
for (String[] properties : RegExpLanguageHosts.getInstance().getAllKnownProperties(getElement())) {
String name = ArrayUtil.getFirstElement(properties);
if (name != null) {
String typeText = properties.length > 1 ? properties[1] : ("Character.is" + name.substring("java".length()) + "()");
result.add(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(name)
.withPresentableText(startsWithIs ? "Is" + name : name)
.withIcon(PlatformIcons.PROPERTY_ICON)
.withTypeText(typeText), getPriority(name)));
}
}
return ArrayUtil.toObjectArray(result);
}
}
private int getPriority(@NotNull String propertyName) {
if (propertyName.equals("all")) return 3;
if (propertyName.startsWith("java")) return 1;
if (propertyName.length() > 2) return 2;
return 0;
}
public boolean isSoft() {
return true;
}
}
private static final String[] UNICODE_BLOCKS;
static {