mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
green named arguments from other calls, underlined unresolved references
This commit is contained in:
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -129,6 +130,18 @@ public class LookupElementBuilder extends LookupElement {
|
||||
myAllLookupStrings, caseSensitive);
|
||||
}
|
||||
|
||||
public LookupElementBuilder setItemTextForeground(@NotNull Color itemTextForeground) {
|
||||
final LookupElementPresentation presentation = copyPresentation();
|
||||
presentation.setItemTextForeground(itemTextForeground);
|
||||
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation, myAllLookupStrings, myCaseSensitive);
|
||||
}
|
||||
|
||||
public LookupElementBuilder setItemTextUnderlined(boolean underlined) {
|
||||
final LookupElementPresentation presentation = copyPresentation();
|
||||
presentation.setItemTextUnderlined(underlined);
|
||||
return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation, myAllLookupStrings, myCaseSensitive);
|
||||
}
|
||||
|
||||
public LookupElementBuilder setTypeText(@Nullable String typeText) {
|
||||
return setTypeText(typeText, false);
|
||||
}
|
||||
@@ -162,7 +175,7 @@ public class LookupElementBuilder extends LookupElement {
|
||||
public LookupElementBuilder setStrikeout() {
|
||||
return setStrikeout(true);
|
||||
}
|
||||
|
||||
|
||||
public LookupElementBuilder setStrikeout(boolean strikeout) {
|
||||
final LookupElementPresentation presentation = copyPresentation();
|
||||
presentation.setStrikeout(strikeout);
|
||||
@@ -228,7 +241,7 @@ public class LookupElementBuilder extends LookupElement {
|
||||
: myInsertHandler != insertHandler) return false;
|
||||
if (!myLookupString.equals(that.myLookupString)) return false;
|
||||
if (!myObject.equals(that.myObject)) return false;
|
||||
|
||||
|
||||
final LookupElementRenderer<LookupElement> renderer = that.myRenderer;
|
||||
if (myRenderer != null && renderer != null ? !myRenderer.getClass().equals(renderer.getClass()) : myRenderer != renderer) return false;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ public class LookupElementPresentation {
|
||||
private boolean myStrikeout;
|
||||
private boolean myTailGrayed;
|
||||
private Color myTailForeground;
|
||||
private Color myItemTextForeground = Color.black;
|
||||
private boolean myItemTextBold;
|
||||
private boolean myItemTextUnderlined;
|
||||
private boolean myTypeGrayed;
|
||||
@@ -136,6 +137,14 @@ public class LookupElementPresentation {
|
||||
myItemTextUnderlined = itemTextUnderlined;
|
||||
}
|
||||
|
||||
@NotNull public Color getItemTextForeground() {
|
||||
return myItemTextForeground;
|
||||
}
|
||||
|
||||
public void setItemTextForeground(@NotNull Color itemTextForeground) {
|
||||
myItemTextForeground = itemTextForeground;
|
||||
}
|
||||
|
||||
public void copyFrom(@NotNull LookupElementPresentation presentation) {
|
||||
myIcon = presentation.myIcon;
|
||||
myTypeIcon = presentation.myTypeIcon;
|
||||
@@ -147,6 +156,8 @@ public class LookupElementPresentation {
|
||||
myTailForeground = presentation.myTailForeground;
|
||||
myItemTextBold = presentation.myItemTextBold;
|
||||
myTypeGrayed = presentation.myTypeGrayed;
|
||||
myItemTextUnderlined = presentation.myItemTextUnderlined;
|
||||
myItemTextForeground = presentation.myItemTextForeground;
|
||||
}
|
||||
|
||||
public boolean isTypeGrayed() {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
private final FontMetrics myBoldMetrics;
|
||||
|
||||
public static final Color BACKGROUND_COLOR = new Color(235, 244, 254);
|
||||
static final Color FOREGROUND_COLOR = Color.black;
|
||||
private static final Color FOREGROUND_COLOR = Color.black;
|
||||
private static final Color GRAYED_FOREGROUND_COLOR = new Color(160, 160, 160);
|
||||
private static final Color SELECTED_BACKGROUND_COLOR = new Color(0, 82, 164);
|
||||
private static final Color SELECTED_FOREGROUND_COLOR = Color.white;
|
||||
@@ -126,7 +126,7 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
myNameComponent.clear();
|
||||
myNameComponent.setIcon(augmentIcon(presentation.getIcon(), myEmptyIcon));
|
||||
myNameComponent.setBackground(background);
|
||||
allowedWidth -= setItemTextLabel(item, foreground, isSelected, presentation, allowedWidth);
|
||||
allowedWidth -= setItemTextLabel(item, presentation.getItemTextForeground(), isSelected, presentation, allowedWidth);
|
||||
|
||||
myTypeLabel.clear();
|
||||
if (allowedWidth > 0) {
|
||||
|
||||
@@ -183,8 +183,11 @@ public class DefaultHighlighter {
|
||||
}
|
||||
|
||||
public static final TextAttributes MAP_KEY_ATTRIBUTES = HighlighterColors.TEXT.getDefaultAttributes().clone();
|
||||
|
||||
public static final Color MAP_KEY_COLOR = new Color(0, 128, 0);
|
||||
|
||||
static {
|
||||
MAP_KEY_ATTRIBUTES.setForegroundColor(new Color(0, 128, 0));
|
||||
MAP_KEY_ATTRIBUTES.setForegroundColor(MAP_KEY_COLOR);
|
||||
}
|
||||
public static TextAttributesKey UNRESOLVED_ACCESS = TextAttributesKey.createTextAttributesKey(UNRESOLVED_ACCESS_ID, UNRESOLVED_ACCESS_ATTRIBUTES);
|
||||
public static TextAttributesKey LITERAL_CONVERSION = TextAttributesKey.createTextAttributesKey(LITERAL_CONVERSION_ID, LITERAL_CONVERSION_ATTRIBUTES);
|
||||
|
||||
+6
-21
@@ -33,7 +33,6 @@ import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.impl.light.LightMethodBuilder;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
@@ -47,8 +46,6 @@ import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.GroovyIcons;
|
||||
import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
@@ -271,30 +268,17 @@ public class GroovyCompletionUtil {
|
||||
return setupLookupBuilder(element, substitutor, builder);
|
||||
}
|
||||
|
||||
private static PsiMethod generateMethodInCategory(GroovyResolveResult result) {
|
||||
final PsiElement element = result.getElement();
|
||||
assert element instanceof PsiMethod;
|
||||
final LightMethodBuilder builder = new LightMethodBuilder(element.getManager(), GroovyFileType.GROOVY_LANGUAGE, ((PsiMethod)element).getName());
|
||||
final PsiParameter[] params = ((PsiMethod)element).getParameterList().getParameters();
|
||||
for (int i = 1; i < params.length; i++) {
|
||||
builder.addParameter(params[i]);
|
||||
}
|
||||
builder.setBaseIcon(GroovyIcons.METHOD);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static LookupElement getLookupElement(Object o) {
|
||||
if (o instanceof LookupElement) return (LookupElement)o;
|
||||
if (o instanceof PsiNamedElement) return generateLookupElement((PsiNamedElement)o);
|
||||
if (o instanceof PsiElement) return setupLookupBuilder((PsiElement)o, PsiSubstitutor.EMPTY, LookupElementBuilder.create(o, ((PsiElement)o).getText()));
|
||||
return LookupElementBuilder.create(o, o.toString());
|
||||
return LookupElementBuilder.create(o, o.toString()).setItemTextUnderlined(true);
|
||||
}
|
||||
public static LookupElementBuilder generateLookupElement(PsiNamedElement element) {
|
||||
LookupElementBuilder builder = LookupElementBuilder.create(element);
|
||||
return setupLookupBuilder(element, PsiSubstitutor.EMPTY, builder);
|
||||
private static LookupElementBuilder generateLookupElement(PsiNamedElement element) {
|
||||
return setupLookupBuilder(element, PsiSubstitutor.EMPTY, LookupElementBuilder.create(element));
|
||||
}
|
||||
|
||||
public static LookupElementBuilder setupLookupBuilder(PsiElement element, PsiSubstitutor substitutor, LookupElementBuilder builder) {
|
||||
private static LookupElementBuilder setupLookupBuilder(PsiElement element, PsiSubstitutor substitutor, LookupElementBuilder builder) {
|
||||
builder = builder.setIcon(element.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS))
|
||||
.setInsertHandler(GroovyInsertHandler.INSTANCE);
|
||||
builder = setTailText(element, builder, substitutor);
|
||||
@@ -426,9 +410,10 @@ public class GroovyCompletionUtil {
|
||||
}
|
||||
|
||||
//need to shorten references in type argument list
|
||||
public static void shortenReference(final PsiFile file, final int offset) throws IncorrectOperationException {
|
||||
private static void shortenReference(final PsiFile file, final int offset) throws IncorrectOperationException {
|
||||
final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());
|
||||
final Document document = manager.getDocument(file);
|
||||
assert document != null;
|
||||
manager.commitDocument(document);
|
||||
final PsiReference ref = file.findReferenceAt(offset);
|
||||
if (ref instanceof GrCodeReferenceElement) {
|
||||
|
||||
+10
-4
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.plugins.groovy.lang.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.StandardPatterns;
|
||||
@@ -26,6 +25,7 @@ import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyIcons;
|
||||
import org.jetbrains.plugins.groovy.extensions.GroovyNamedArgumentProvider;
|
||||
import org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter;
|
||||
import org.jetbrains.plugins.groovy.lang.completion.handlers.NamedArgumentInsertHandler;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
@@ -89,7 +89,8 @@ class MapArgumentCompletionProvider extends CompletionProvider<CompletionParamet
|
||||
}
|
||||
|
||||
Map<String, GroovyNamedArgumentProvider.ArgumentDescriptor> map = calcNamedArgumentsForCall(mapOrArgumentList);
|
||||
if (map.isEmpty()) {
|
||||
boolean sure = !map.isEmpty();
|
||||
if (!sure) {
|
||||
map = findOtherNamedArgumentsInFile(mapOrArgumentList);
|
||||
}
|
||||
|
||||
@@ -98,11 +99,16 @@ class MapArgumentCompletionProvider extends CompletionProvider<CompletionParamet
|
||||
}
|
||||
|
||||
for (Map.Entry<String, GroovyNamedArgumentProvider.ArgumentDescriptor> entry : map.entrySet()) {
|
||||
LookupElement lookup = LookupElementBuilder.create(entry.getValue(), entry.getKey())
|
||||
.setIcon(GroovyIcons.DYNAMIC)
|
||||
LookupElementBuilder lookup = LookupElementBuilder.create(entry.getValue(), entry.getKey())
|
||||
.setInsertHandler(NamedArgumentInsertHandler.INSTANCE)
|
||||
.setTailText(":");
|
||||
|
||||
if (sure) {
|
||||
lookup = lookup.setIcon(GroovyIcons.DYNAMIC);
|
||||
} else {
|
||||
lookup = lookup.setItemTextForeground(DefaultHighlighter.MAP_KEY_COLOR);
|
||||
}
|
||||
|
||||
result.addElement(lookup);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user