mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-09 08:09:39 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -90,6 +90,10 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
|
||||
if (myStateSize != that.myStateSize) return false;
|
||||
if (myDistinctClasses.size() != that.myDistinctClasses.size()) return false;
|
||||
if (myStack.size() != that.myStack.size()) return false;
|
||||
if (myOffsetStack.size() != that.myOffsetStack.size()) return false;
|
||||
if (myVariableStates.size() != that.myVariableStates.size()) return false;
|
||||
if (myUnknownVariables.size() != that.myUnknownVariables.size()) return false;
|
||||
|
||||
if (!myStack.equals(that.myStack)) return false;
|
||||
if (!myOffsetStack.equals(that.myOffsetStack)) return false;
|
||||
|
||||
@@ -21,10 +21,12 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,6 +34,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class DfaPsiUtil {
|
||||
public static boolean isPlainMutableField(PsiVariable var) {
|
||||
@@ -97,66 +100,48 @@ public class DfaPsiUtil {
|
||||
final List<PsiExpression> result = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
ContainerUtil.addIfNotNull(result, field.getInitializer());
|
||||
|
||||
PsiClass containingClass = field.getContainingClass();
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
LocalSearchScope scope = new LocalSearchScope(containingClass.getConstructors());
|
||||
ReferencesSearch.search(field, scope, false).forEach(new Processor<PsiReference>() {
|
||||
@Override
|
||||
public boolean process(PsiReference reference) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (element instanceof PsiReferenceExpression) {
|
||||
final PsiAssignmentExpression assignment = getAssignmentExpressionIfOnAssignmentLhs(element);
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(assignment, PsiMethod.class);
|
||||
if (method != null && method.isConstructor() && assignment != null) {
|
||||
ContainerUtil.addIfNotNull(result, assignment.getRExpression());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
result.addAll(getAllConstructorFieldInitializers(containingClass).get(field));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiAssignmentExpression getAssignmentExpressionIfOnAssignmentLhs(PsiElement expression) {
|
||||
PsiElement parent = PsiTreeUtil.skipParentsOfType(expression, PsiParenthesizedExpression.class);
|
||||
if (!(parent instanceof PsiAssignmentExpression)) {
|
||||
return null;
|
||||
}
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
|
||||
if (!PsiTreeUtil.isAncestor(assignmentExpression.getLExpression(), expression, false)) {
|
||||
return null;
|
||||
}
|
||||
return assignmentExpression;
|
||||
}
|
||||
private static MultiMap<PsiField, PsiExpression> getAllConstructorFieldInitializers(final PsiClass psiClass) {
|
||||
return CachedValuesManager.getManager(psiClass.getProject()).getCachedValue(psiClass, new CachedValueProvider<MultiMap<PsiField, PsiExpression>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Result<MultiMap<PsiField, PsiExpression>> compute() {
|
||||
final Set<String> fieldNames = ContainerUtil.newHashSet();
|
||||
for (PsiField field : psiClass.getFields()) {
|
||||
ContainerUtil.addIfNotNull(fieldNames, field.getName());
|
||||
}
|
||||
|
||||
public static boolean isNullableInitialized(PsiVariable var, boolean nullable) {
|
||||
if (!isFinalField(var)) {
|
||||
return false;
|
||||
}
|
||||
final MultiMap<PsiField, PsiExpression> result = new MultiMap<PsiField, PsiExpression>();
|
||||
JavaRecursiveElementWalkingVisitor visitor = new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitAssignmentExpression(PsiAssignmentExpression assignment) {
|
||||
super.visitAssignmentExpression(assignment);
|
||||
PsiExpression lExpression = assignment.getLExpression();
|
||||
PsiExpression rExpression = assignment.getRExpression();
|
||||
if (rExpression != null &&
|
||||
lExpression instanceof PsiReferenceExpression &&
|
||||
fieldNames.contains(((PsiReferenceExpression)lExpression).getReferenceName())) {
|
||||
PsiElement target = ((PsiReferenceExpression)lExpression).resolve();
|
||||
if (target instanceof PsiField && ((PsiField)target).getContainingClass() == psiClass) {
|
||||
result.putValue((PsiField)target, rExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<PsiExpression> initializers = findAllConstructorInitializers((PsiField)var);
|
||||
if (initializers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (PsiMethod constructor : psiClass.getConstructors()) {
|
||||
constructor.accept(visitor);
|
||||
}
|
||||
|
||||
for (PsiExpression expression : initializers) {
|
||||
if (!(expression instanceof PsiReferenceExpression)) {
|
||||
return false;
|
||||
return Result.create(result, psiClass);
|
||||
}
|
||||
PsiElement target = ((PsiReferenceExpression)expression).resolve();
|
||||
if (!(target instanceof PsiParameter)) {
|
||||
return false;
|
||||
}
|
||||
if (nullable && NullableNotNullManager.isNullable((PsiParameter)target)) {
|
||||
return true;
|
||||
}
|
||||
if (!nullable && !NullableNotNullManager.isNotNull((PsiParameter)target)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !nullable;
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -169,7 +169,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
DfaValue dfaValue = instruction.getValue();
|
||||
if (dfaValue instanceof DfaVariableValue) {
|
||||
DfaConstValue constValue = memState.getConstantValue((DfaVariableValue)dfaValue);
|
||||
myPossibleVariableValues.putValue(instruction, constValue != null ? constValue : ANY_VALUE);
|
||||
myPossibleVariableValues.putValue(instruction, constValue != null && (constValue.getValue() == null || constValue.getValue() instanceof Boolean) ? constValue : ANY_VALUE);
|
||||
}
|
||||
}
|
||||
return super.visitPush(instruction, runner, memState);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.dataFlow.value;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInspection.dataFlow.DfaPsiUtil;
|
||||
import com.intellij.codeInspection.dataFlow.Nullness;
|
||||
import com.intellij.psi.*;
|
||||
@@ -174,13 +175,28 @@ public class DfaVariableValue extends DfaValue {
|
||||
return nullability;
|
||||
}
|
||||
|
||||
if (var != null) {
|
||||
if (DfaPsiUtil.isNullableInitialized(var, true)) {
|
||||
return Nullness.NULLABLE;
|
||||
if (var != null && DfaPsiUtil.isFinalField(var)) {
|
||||
List<PsiExpression> initializers = DfaPsiUtil.findAllConstructorInitializers((PsiField)var);
|
||||
if (initializers.isEmpty()) {
|
||||
return Nullness.UNKNOWN;
|
||||
}
|
||||
if (DfaPsiUtil.isNullableInitialized(var, false)) {
|
||||
return Nullness.NOT_NULL;
|
||||
|
||||
for (PsiExpression expression : initializers) {
|
||||
if (!(expression instanceof PsiReferenceExpression)) {
|
||||
return Nullness.UNKNOWN;
|
||||
}
|
||||
PsiElement target = ((PsiReferenceExpression)expression).resolve();
|
||||
if (!(target instanceof PsiParameter)) {
|
||||
return Nullness.UNKNOWN;
|
||||
}
|
||||
if (NullableNotNullManager.isNullable((PsiParameter)target)) {
|
||||
return Nullness.NULLABLE;
|
||||
}
|
||||
if (!NullableNotNullManager.isNotNull((PsiParameter)target)) {
|
||||
return Nullness.NOT_NULL;
|
||||
}
|
||||
}
|
||||
return Nullness.NOT_NULL;
|
||||
}
|
||||
|
||||
return Nullness.UNKNOWN;
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PatternCondition;
|
||||
import com.intellij.patterns.PsiJavaElementPattern;
|
||||
import com.intellij.patterns.PsiNameValuePairPattern;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -78,6 +79,8 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
|
||||
public static final ElementPattern<PsiElement> ANNOTATION_NAME = psiElement().
|
||||
withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).afterLeaf("@");
|
||||
private static final PsiJavaElementPattern.Capture<PsiElement> UNEXPECTED_REFERENCE_AFTER_DOT =
|
||||
psiElement().afterLeaf(".").insideStarting(psiExpressionStatement());
|
||||
|
||||
private static JavaCompletionData getCompletionData(LanguageLevel level) {
|
||||
final Set<Map.Entry<LanguageLevel, JavaCompletionData>> entries = ourCompletionData.entrySet();
|
||||
@@ -203,7 +206,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (AFTER_NUMBER_LITERAL.accepts(position)) {
|
||||
if (AFTER_NUMBER_LITERAL.accepts(position) || UNEXPECTED_REFERENCE_AFTER_DOT.accepts(position)) {
|
||||
_result.stopHere();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,4 +50,13 @@ class Foo {{ Object o = Fo<caret>x }}
|
||||
class Foo {{ Object o = Foo::<caret>x }}
|
||||
"""
|
||||
}
|
||||
|
||||
public void testNoSuggestionsAfterMethodReferenceAndDot() {
|
||||
String text = """
|
||||
class Foo {{ Object o = StringBuilder::append.<caret> }}
|
||||
"""
|
||||
myFixture.configureByText "a.java", text
|
||||
assertEmpty(myFixture.completeBasic())
|
||||
myFixture.checkResult(text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,28 +161,27 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testReportConstantReferences_ReplaceWithString() {
|
||||
public void _testReportConstantReferences_ReplaceWithString() {
|
||||
doTestReportConstantReferences();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
public void testReportConstantReferences_ReplaceWithIntConstant() {
|
||||
public void _testReportConstantReferences_ReplaceWithIntConstant() {
|
||||
doTestReportConstantReferences();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
public void testReportConstantReferences_ReplaceWithEnum() {
|
||||
public void _testReportConstantReferences_ReplaceWithEnum() {
|
||||
myFixture.addClass("package foo; public enum MyEnum { FOO }");
|
||||
doTestReportConstantReferences();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'FOO'"));
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
public void testReportConstantReferences_NotInComplexAssignment() {
|
||||
myFixture.addClass("package foo; public enum MyEnum { FOO }");
|
||||
public void _testReportConstantReferences_NotInComplexAssignment() {
|
||||
doTestReportConstantReferences();
|
||||
assertEmpty(myFixture.filterAvailableIntentions("Replace with"));
|
||||
}
|
||||
public void testReportConstantReferences_Switch() { doTestReportConstantReferences(); }
|
||||
public void _testReportConstantReferences_Switch() { doTestReportConstantReferences(); }
|
||||
|
||||
public void testCheckFieldInitializers() {
|
||||
doTest();
|
||||
|
||||
@@ -148,7 +148,7 @@ public class LowLevelSearchUtil {
|
||||
if (progress != null) progress.checkCanceled();
|
||||
|
||||
PsiFile file = scope.getContainingFile();
|
||||
final CharSequence buffer = file.getText();
|
||||
final CharSequence buffer = file.getViewProvider().getContents();
|
||||
|
||||
TextRange range = scope.getTextRange();
|
||||
if (range == null) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.xdebugger.frame.presentation;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class XKeywordValuePresentation extends XValuePresentation {
|
||||
private final String myValue;
|
||||
|
||||
public XKeywordValuePresentation(String value) {
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderValue(@NotNull XValueTextRenderer renderer) {
|
||||
renderer.renderKeywordValue(myValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.xdebugger.frame.presentation;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class XNumericValuePresentation extends XValuePresentation {
|
||||
private final String myValue;
|
||||
|
||||
public XNumericValuePresentation(String value) {
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderValue(@NotNull XValueTextRenderer renderer) {
|
||||
renderer.renderNumericValue(myValue);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Determines how a value is shown in debugger trees. Use one of the standard implementations (for {@link com.intellij.xdebugger.frame.presentation.XStringValuePresentation strings}
|
||||
* Determines how a value is shown in debugger trees. Use one of the standard implementations (for {@link com.intellij.xdebugger.frame.presentation.XStringValuePresentation strings},
|
||||
* {@link com.intellij.xdebugger.frame.presentation.XNumericValuePresentation numbers}, {@link com.intellij.xdebugger.frame.presentation.XKeywordValuePresentation keywords}
|
||||
* and for {@link com.intellij.xdebugger.frame.presentation.XRegularValuePresentation other values}) or override this class if you need something special
|
||||
*
|
||||
* @see com.intellij.xdebugger.frame.XValueNode#setPresentation(javax.swing.Icon, XValuePresentation, boolean)
|
||||
@@ -60,6 +61,16 @@ public abstract class XValuePresentation {
|
||||
*/
|
||||
void renderStringValue(@NotNull String value);
|
||||
|
||||
/**
|
||||
* Appends {@code value} highlighted as a number
|
||||
*/
|
||||
void renderNumericValue(@NotNull String value);
|
||||
|
||||
/**
|
||||
* Appends {@code value} highlighted as a keyword
|
||||
*/
|
||||
void renderKeywordValue(@NotNull String value);
|
||||
|
||||
/**
|
||||
* Appends {@code value} surrounded by quotes to the node text colored as a string
|
||||
* @param value value to be shown
|
||||
|
||||
@@ -89,7 +89,7 @@ public class XValueHint extends AbstractValueHint {
|
||||
|
||||
SimpleColoredText text = new SimpleColoredText();
|
||||
text.append(myExpression, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
|
||||
XValueNodeImpl.buildText(valuePresenter, text, false);
|
||||
XValueNodeImpl.buildText(valuePresenter, text);
|
||||
if (!hasChildren) {
|
||||
showHint(HintUtil.createInformationLabel(text));
|
||||
}
|
||||
|
||||
@@ -141,23 +141,23 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
|
||||
}
|
||||
}
|
||||
appendName();
|
||||
buildText(myValuePresentation, myText, myChanged);
|
||||
buildText(myValuePresentation, myText);
|
||||
}
|
||||
|
||||
private void appendName() {
|
||||
if (!StringUtil.isEmpty(myName)) {
|
||||
XValuePresentationUtil.renderValue(myName, myText, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES, MAX_VALUE_LENGTH, null);
|
||||
SimpleTextAttributes attributes = myChanged ? XDebuggerUIConstants.CHANGED_VALUE_ATTRIBUTES : XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES;
|
||||
XValuePresentationUtil.renderValue(myName, myText, attributes, MAX_VALUE_LENGTH, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void buildText(@NotNull XValuePresentation valuePresenter, @NotNull final ColoredTextContainer text,
|
||||
final boolean changed) {
|
||||
public static void buildText(@NotNull XValuePresentation valuePresenter, @NotNull final ColoredTextContainer text) {
|
||||
XValuePresentationUtil.appendSeparator(text, valuePresenter.getSeparator());
|
||||
String type = valuePresenter.getType();
|
||||
if (type != null) {
|
||||
text.append("{" + type + "} ", XDebuggerUIConstants.TYPE_ATTRIBUTES);
|
||||
}
|
||||
valuePresenter.renderValue(new XValueTextRendererImpl(text, changed));
|
||||
valuePresenter.renderValue(new XValueTextRendererImpl(text));
|
||||
}
|
||||
|
||||
public void markChanged() {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.xdebugger.impl.ui.tree.nodes;
|
||||
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.ui.ColoredTextContainer;
|
||||
import com.intellij.ui.JBColor;
|
||||
@@ -91,7 +92,7 @@ public class XValuePresentationUtil {
|
||||
return extractor.getText();
|
||||
}
|
||||
|
||||
private static class XValuePresentationTextExtractor implements XValuePresentation.XValueTextRenderer {
|
||||
private static class XValuePresentationTextExtractor extends XValueTextRendererBase {
|
||||
private final StringBuilder myBuilder;
|
||||
|
||||
public XValuePresentationTextExtractor() {
|
||||
@@ -104,7 +105,7 @@ public class XValuePresentationUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStringValue(@NotNull String value) {
|
||||
protected void renderRawValue(@NotNull String value, @NotNull TextAttributesKey key) {
|
||||
myBuilder.append(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.xdebugger.impl.ui.tree.nodes;
|
||||
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.xdebugger.frame.presentation.XValuePresentation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class XValueTextRendererBase implements XValuePresentation.XValueTextRenderer {
|
||||
@Override
|
||||
public void renderStringValue(@NotNull String value) {
|
||||
renderStringValue(value, null, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNumericValue(@NotNull String value) {
|
||||
renderRawValue(value, DefaultLanguageHighlighterColors.NUMBER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderKeywordValue(@NotNull String value) {
|
||||
renderRawValue(value, DefaultLanguageHighlighterColors.KEYWORD);
|
||||
}
|
||||
|
||||
protected abstract void renderRawValue(@NotNull String value, @NotNull TextAttributesKey key);
|
||||
}
|
||||
@@ -17,45 +17,39 @@ package com.intellij.xdebugger.impl.ui.tree.nodes;
|
||||
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.ui.ColoredTextContainer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.xdebugger.frame.presentation.XValuePresentation;
|
||||
import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class XValueTextRendererImpl implements XValuePresentation.XValueTextRenderer {
|
||||
class XValueTextRendererImpl extends XValueTextRendererBase {
|
||||
private final ColoredTextContainer myText;
|
||||
private final boolean myChanged;
|
||||
|
||||
public XValueTextRendererImpl(ColoredTextContainer text, boolean changed) {
|
||||
public XValueTextRendererImpl(ColoredTextContainer text) {
|
||||
myText = text;
|
||||
myChanged = changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderValue(@NotNull String value) {
|
||||
SimpleTextAttributes attributes = myChanged ? XDebuggerUIConstants.CHANGED_VALUE_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES;
|
||||
XValuePresentationUtil.renderValue(value, myText, attributes, -1, null);
|
||||
XValuePresentationUtil.renderValue(value, myText, SimpleTextAttributes.REGULAR_ATTRIBUTES, -1, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStringValue(@NotNull String value) {
|
||||
renderStringValue(value, null, -1);
|
||||
protected void renderRawValue(@NotNull String value, @NotNull TextAttributesKey key) {
|
||||
TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
|
||||
SimpleTextAttributes attributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
|
||||
myText.append(value, attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStringValue(@NotNull String value, @Nullable String additionalSpecialCharsToHighlight, int maxLength) {
|
||||
SimpleTextAttributes attributes;
|
||||
if (myChanged) {
|
||||
attributes = XDebuggerUIConstants.CHANGED_VALUE_ATTRIBUTES;
|
||||
}
|
||||
else {
|
||||
attributes = SimpleTextAttributes.fromTextAttributes(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DefaultLanguageHighlighterColors.STRING));
|
||||
}
|
||||
TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DefaultLanguageHighlighterColors.STRING);
|
||||
SimpleTextAttributes attributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
|
||||
myText.append("\"", attributes);
|
||||
XValuePresentationUtil.renderValue(value, myText, attributes, maxLength, additionalSpecialCharsToHighlight);
|
||||
myText.append("\"", attributes);
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlo
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
|
||||
|
||||
@@ -94,7 +93,7 @@ public class GroovyCompletionConfidence extends CompletionConfidence {
|
||||
@NotNull
|
||||
@Override
|
||||
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
|
||||
if (PsiUtil.isLeafElementOfType(contextElement, TokenSets.STRING_LITERALS)) {
|
||||
if (com.intellij.psi.impl.PsiImplUtil.isLeafElementOfType(contextElement, TokenSets.STRING_LITERALS)) {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
PsiElement parent = contextElement.getParent();
|
||||
if (parent != null) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.light.JavaIdentifier;
|
||||
import com.intellij.psi.impl.light.LightElement;
|
||||
import com.intellij.psi.impl.source.tree.LeafElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
@@ -969,14 +968,6 @@ public class PsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLeafElementOfType(@Nullable PsiElement element, IElementType type) {
|
||||
return element instanceof LeafElement && ((LeafElement)element).getElementType() == type;
|
||||
}
|
||||
|
||||
public static boolean isLeafElementOfType(PsiElement element, TokenSet tokenSet) {
|
||||
return element instanceof LeafElement && tokenSet.contains(((LeafElement)element).getElementType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all arguments passed to method. First argument is null if Named Arguments is present.
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.spock;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -34,7 +35,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.arithmetic.GrShiftExpressionImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
import org.jetbrains.plugins.groovy.util.LightCacheKey;
|
||||
|
||||
import java.util.*;
|
||||
@@ -234,7 +234,7 @@ public class SpockUtils {
|
||||
else {
|
||||
e = e.getNextSibling();
|
||||
}
|
||||
} while (PsiUtil.isLeafElementOfType(e, TokenSets.WHITE_SPACES_OR_COMMENTS));
|
||||
} while (PsiImplUtil.isLeafElementOfType(e, TokenSets.WHITE_SPACES_OR_COMMENTS));
|
||||
|
||||
if (e instanceof GrLabeledStatement) return null;
|
||||
|
||||
@@ -246,7 +246,7 @@ public class SpockUtils {
|
||||
if (!(expression instanceof GrReferenceExpression)) return null;
|
||||
|
||||
PsiElement firstChild = expression.getFirstChild();
|
||||
if (firstChild != expression.getLastChild() || !PsiUtil.isLeafElementOfType(firstChild, GroovyTokenTypes.mIDENT)) return null;
|
||||
if (firstChild != expression.getLastChild() || !PsiImplUtil.isLeafElementOfType(firstChild, GroovyTokenTypes.mIDENT)) return null;
|
||||
|
||||
GrReferenceExpression ref = (GrReferenceExpression)expression;
|
||||
if (ref.isQualified()) return null;
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
package org.jetbrains.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIfStatement;
|
||||
import com.intellij.psi.PsiStatement;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -37,7 +35,7 @@ public abstract class GroovyElseUnwrapperBase extends GroovyUnwrapper {
|
||||
|
||||
private static boolean isElseKeyword(PsiElement e) {
|
||||
PsiElement p = e.getParent();
|
||||
return p instanceof GrIfStatement && PsiUtil.isLeafElementOfType(e, GroovyTokenTypes.kELSE);
|
||||
return p instanceof GrIfStatement && PsiImplUtil.isLeafElementOfType(e, GroovyTokenTypes.kELSE);
|
||||
}
|
||||
|
||||
private static boolean isValidConstruct(PsiElement e) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.unwrap;
|
||||
import com.intellij.codeInsight.unwrap.AbstractUnwrapper;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,7 +29,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class GroovyUnwrapper extends AbstractUnwrapper<GroovyUnwrapper.
|
||||
List<PsiElement> res = super.unwrap(editor, element);
|
||||
|
||||
for (PsiElement e : res) {
|
||||
if (PsiUtil.isLeafElementOfType(e, GroovyTokenTypes.mNLS)) {
|
||||
if (PsiImplUtil.isLeafElementOfType(e, GroovyTokenTypes.mNLS)) {
|
||||
CodeEditUtil.setNodeGenerated(e.getNode(), true);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public abstract class GroovyUnwrapper extends AbstractUnwrapper<GroovyUnwrapper.
|
||||
}
|
||||
|
||||
protected boolean isWhiteSpace(PsiElement element) {
|
||||
return PsiUtil.isLeafElementOfType(element, TokenSets.WHITE_SPACES_SET);
|
||||
return PsiImplUtil.isLeafElementOfType(element, TokenSets.WHITE_SPACES_SET);
|
||||
}
|
||||
|
||||
public void setElseBranch(GrIfStatement ifStatement, GrStatement elseBranch) throws IncorrectOperationException {
|
||||
|
||||
Reference in New Issue
Block a user