Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ public static boolean processUsages(
}

// if we've resolved all references, find usages will be fast
PsiSearchHelper.SearchCostResult cheapEnough = RefResolveService.ENABLED && RefResolveService.getInstance
(project).isUpToDate() ? PsiSearchHelper.SearchCostResult.FEW_OCCURRENCES : searchHelper
.isCheapEnoughToSearch(name, (GlobalSearchScope)useScope, ignoreFile, progress);
PsiSearchHelper.SearchCostResult cheapEnough =
RefResolveService.ENABLED && RefResolveService.getInstance(project).isUpToDate()
? PsiSearchHelper.SearchCostResult.FEW_OCCURRENCES
: searchHelper.isCheapEnoughToSearch(name, globalSearchScope, ignoreFile, progress);
if (cheapEnough == TOO_MANY_OCCURRENCES) {
log("* " + member.getName() + " too many usages; false");
return false;
Expand All @@ -263,18 +264,11 @@ public static boolean processUsages(

if (member instanceof PsiMethod) {
String propertyName = PropertyUtil.getPropertyName(member);
if (propertyName != null) {
SearchScope fileScope = containingFile.getUseScope();
if (fileScope instanceof GlobalSearchScope
&& searchHelper.isCheapEnoughToSearch(
propertyName,
(GlobalSearchScope)fileScope,
ignoreFile,
progress
) == TOO_MANY_OCCURRENCES) {
log("* " + member.getName() + " too many prop usages; false");
return false;
}
if (propertyName != null
&& containingFile.getUseScope() instanceof GlobalSearchScope fileScope
&& searchHelper.isCheapEnoughToSearch(propertyName, fileScope, ignoreFile, progress) == TOO_MANY_OCCURRENCES) {
log("* " + member.getName() + " too many prop usages; false");
return false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1984,17 +1984,16 @@ else if (resolved != null) {
return HighlightClassUtil.reportIllegalEnclosingUsage(expr, null, aClass, expr);
}

if (expr instanceof PsiSuperExpression) {
PsiElement resolved = ((PsiReferenceExpression)expr.getParent()).resolve();
//15.11.2
//The form T.super.Identifier refers to the field named Identifier of the lexically enclosing instance corresponding to T,
//but with that instance viewed as an instance of the superclass of T.
if (resolved instanceof PsiField) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(expr)
.descriptionAndTooltip(JavaErrorLocalize.isNotAnEnclosingClass(formatClass(aClass)))
.create();
}
//15.11.2
//The form T.super.Identifier refers to the field named Identifier of the lexically enclosing instance corresponding to T,
//but with that instance viewed as an instance of the superclass of T.
if (expr instanceof PsiSuperExpression
&& expr.getParent() instanceof PsiReferenceExpression refExpr
&& refExpr.resolve() instanceof PsiField) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(expr)
.descriptionAndTooltip(JavaErrorLocalize.isNotAnEnclosingClass(formatClass(aClass)))
.create();
}
}

Expand Down Expand Up @@ -2157,7 +2156,7 @@ private static boolean isInstanceReference(@Nonnull PsiJavaCodeReferenceElement
if (q != null) {
return true;
}
String qname = ((PsiJavaCodeReferenceElement)qualifier).getQualifiedName();
String qname = codeReferenceElement.getQualifiedName();
return qname == null || !Character.isLowerCase(qname.charAt(0));
}

Expand Down Expand Up @@ -2527,18 +2526,15 @@ public static Collection<HighlightInfo> checkSwitchLabelValues(@Nonnull PsiSwitc
LocalizeValue message = values.isEmpty()
? JavaErrorLocalize.switchExprEmpty()
: JavaErrorLocalize.switchExprIncomplete();
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
QuickFixFactory factory = QuickFixFactory.getInstance();
HighlightInfo.Builder hlBuilder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(ObjectUtil.notNull(selectorExpression, switchBlock))
.descriptionAndTooltip(message)
.create();
.descriptionAndTooltip(message);
if (!missingConstants.isEmpty()) {
QuickFixAction.registerQuickFixAction(
info,
QuickFixFactory.getInstance().createAddMissingEnumBranchesFix(switchBlock, missingConstants)
);
hlBuilder.registerFix(factory.createAddMissingEnumBranchesFix(switchBlock, missingConstants));
}
QuickFixAction.registerQuickFixAction(info, QuickFixFactory.getInstance().createAddSwitchDefaultFix(switchBlock, null));
results.add(info);
hlBuilder.registerFix(factory.createAddSwitchDefaultFix(switchBlock, null));
results.add(hlBuilder.create());
}
}

Expand Down Expand Up @@ -3764,19 +3760,11 @@ private static IntentionAction getChangeParameterClassFix(PsiType lType, PsiType
PsiClass lClass = PsiUtil.resolveClassInClassTypeOnly(lType);
PsiClass rClass = PsiUtil.resolveClassInClassTypeOnly(rType);

if (rClass == null || lClass == null) {
return null;
}
if (rClass instanceof PsiAnonymousClass) {
return null;
}
if (rClass.isInheritor(lClass, true)) {
return null;
}
if (lClass.isInheritor(rClass, true)) {
return null;
}
if (lClass == rClass) {
if (rClass == null || lClass == null
|| rClass instanceof PsiAnonymousClass
|| rClass.isInheritor(lClass, true)
|| lClass.isInheritor(rClass, true)
|| lClass == rClass) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,12 @@ private static boolean addResult(

@RequiredReadAction
private static boolean filterUsage(PsiElement usage, @Nonnull FindUsagesOptions options) {
if (!(usage instanceof PsiJavaCodeReferenceElement)) {
if (!(usage instanceof PsiJavaCodeReferenceElement javaCodeRef)) {
return true;
}
if (options instanceof JavaPackageFindUsagesOptions packageOptions
&& !packageOptions.isIncludeSubpackages
&& ((PsiReference)usage).resolve() instanceof PsiPackage
&& javaCodeRef.resolve() instanceof PsiPackage
&& usage.getParent() instanceof PsiJavaCodeReferenceElement codeRef
&& codeRef.resolve() instanceof PsiPackage) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import consulo.language.psi.PsiPackage;
import consulo.language.psi.scope.GlobalSearchScope;
import consulo.language.psi.util.PsiTreeUtil;
import consulo.language.util.ModuleUtilCore;
import consulo.logging.Logger;
import consulo.module.Module;
import consulo.module.content.ModuleRootManager;
Expand Down Expand Up @@ -155,7 +154,7 @@ public boolean coverageEditorHighlightingApplicableTo(@Nonnull PsiFile psiFile)
return false;
}
// let's show coverage only for module files
Module module = psiFile.getApplication().runReadAction((Supplier<Module>)() -> ModuleUtilCore.findModuleForPsiElement(psiFile));
Module module = psiFile.getApplication().runReadAction((Supplier<Module>)psiFile::getModule);
return module != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
if (value == null) {
return "null";
}
if (value instanceof StringReference) {
return ((StringReference)value).value();
if (value instanceof StringReference stringRef) {
return stringRef.value();
}
if (isInteger(value)) {
long v = ((PrimitiveValue)value).longValue();
Expand All @@ -83,19 +83,19 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
double v = ((PrimitiveValue)value).doubleValue();
return String.valueOf(v);
}
if (value instanceof BooleanValue) {
boolean v = ((PrimitiveValue)value).booleanValue();
if (value instanceof BooleanValue booleanValue) {
boolean v = booleanValue.booleanValue();
return String.valueOf(v);
}
if (value instanceof CharValue) {
char v = ((PrimitiveValue)value).charValue();
if (value instanceof CharValue charValue) {
char v = charValue.charValue();
return String.valueOf(v);
}
if (value instanceof ObjectReference) {
if (value instanceof ArrayReference) {
if (value instanceof ObjectReference objRef) {
if (objRef instanceof ArrayReference arrayRef) {
StringBuilder builder = new StringBuilder();
builder.append("[");
for (Iterator<Value> iterator = ((ArrayReference)value).getValues().iterator(); iterator.hasNext(); ) {
for (Iterator<Value> iterator = arrayRef.getValues().iterator(); iterator.hasNext(); ) {
Value element = iterator.next();
builder.append(getValueAsString(evaluationContext, element));
if (iterator.hasNext()) {
Expand All @@ -106,7 +106,6 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
return builder.toString();
}

ObjectReference objRef = (ObjectReference)value;
DebugProcess debugProcess = evaluationContext.getDebugProcess();
Method toStringMethod = debugProcess.getUserData(TO_STRING_METHOD_KEY);
if (toStringMethod == null) {
Expand All @@ -133,7 +132,7 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
if (result == null) {
return "null";
}
return result instanceof StringReference ? ((StringReference)result).value() : result.toString();
return result instanceof StringReference stringRef ? stringRef.value() : result.toString();
}
throw EvaluateExceptionUtil.createEvaluateException(JavaDebuggerLocalize.evaluationErrorUnsupportedExpressionType());
}
Expand Down Expand Up @@ -170,8 +169,8 @@ public static Method findMethod(@Nonnull ReferenceType refType, String methodNam

Method method = null;
if (methodSignature != null) {
if (refType instanceof ClassType) {
method = ((ClassType)refType).concreteMethodByName(methodName, methodSignature);
if (refType instanceof ClassType classType) {
method = classType.concreteMethodByName(methodName, methodSignature);
}
if (method == null) {
List<Method> methods = refType.methodsByName(methodName, methodSignature);
Expand All @@ -193,16 +192,12 @@ public static Method findMethod(@Nonnull ReferenceType refType, String methodNam
}

public static boolean isNumeric(Value value) {
return value != null && (isInteger(value) ||
value instanceof FloatValue ||
value instanceof DoubleValue);
return value != null && (isInteger(value) || value instanceof FloatValue || value instanceof DoubleValue);
}

public static boolean isInteger(Value value) {
return value != null && (value instanceof ByteValue ||
value instanceof ShortValue ||
value instanceof LongValue ||
value instanceof IntegerValue);
return value != null
&& (value instanceof ByteValue || value instanceof ShortValue || value instanceof LongValue || value instanceof IntegerValue);
}

public static String translateStringValue(String str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ public void contextAction() throws Exception {
boolean sourceMissing = foundFile instanceof PsiCompiledElement;
for (Pair<Breakpoint, consulo.internal.com.sun.jdi.event.Event> eventDescriptor : eventDescriptors) {
Breakpoint breakpoint = eventDescriptor.getFirst();
if (breakpoint instanceof LineBreakpoint) {
SourcePosition breakpointPosition = ((BreakpointWithHighlighter)breakpoint).getSourcePosition();
if (breakpoint instanceof LineBreakpoint lineBreakpoint) {
SourcePosition breakpointPosition = lineBreakpoint.getSourcePosition();
if (breakpointPosition == null || (!sourceMissing && breakpointPosition.getLine() != position.getLine())) {
requestsManager.deleteRequest(breakpoint);
requestsManager.setInvalid(breakpoint, JavaDebuggerLocalize.errorInvalidBreakpointSourceChanged().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,15 +1088,15 @@ private E invokeMethodAndFork(SuspendContextImpl context)
if (lastIndex >= 0 && myArgs.size() > lastIndex) { // at least one varargs param
Object firstVararg = myArgs.get(lastIndex);
if (myArgs.size() == lastIndex + 1) { // only one vararg param
if (firstVararg instanceof ArrayReference arrayRef) {
if (((ArrayType)arrayRef.referenceType()).componentType() instanceof InterfaceType) {
List<String> argTypes = myMethod.argumentTypeNames();
if (argTypes.size() > lastIndex
&& argTypes.get(lastIndex).startsWith(JavaClassNames.JAVA_LANG_OBJECT)) {
// unwrap array of interfaces for vararg param
myArgs.remove(lastIndex);
myArgs.addAll(arrayRef.getValues());
}
if (firstVararg instanceof ArrayReference arrayRef
&& arrayRef.referenceType() instanceof ArrayType arrayType
&& arrayType.componentType() instanceof InterfaceType) {
List<String> argTypes = myMethod.argumentTypeNames();
if (argTypes.size() > lastIndex
&& argTypes.get(lastIndex).startsWith(JavaClassNames.JAVA_LANG_OBJECT)) {
// unwrap array of interfaces for vararg param
myArgs.remove(lastIndex);
myArgs.addAll(arrayRef.getValues());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ else if (location != null) {
Set<ObjectReference> exceptions = new HashSet<>();
for (Pair<Breakpoint, Event> pair : DebuggerUtilsEx.getEventDescriptors(debuggerContext.getSuspendContext())) {
Event debugEvent = pair.getSecond();
if (debugEvent instanceof ExceptionEvent) {
ObjectReference exception = ((ExceptionEvent)debugEvent).exception();
if (debugEvent instanceof ExceptionEvent exceptionEvent) {
ObjectReference exception = exceptionEvent.exception();
if (exception != null) {
exceptions.add(exception);
}
Expand Down Expand Up @@ -523,8 +523,8 @@ public void visitReferenceExpression(PsiReferenceExpression reference) {
if (var instanceof PsiField field) {
if (myCollectExpressions && !DebuggerUtils.hasSideEffectsOrReferencesMissingVars(reference, myVisibleLocals)) {
/*
if (var instanceof PsiEnumConstant && reference.getQualifier() == null) {
PsiClass enumClass = ((PsiEnumConstant)var).getContainingClass();
if (var instanceof PsiEnumConstant enumConst && reference.getQualifier() == null) {
PsiClass enumClass = enumConst.getContainingClass();
if (enumClass != null) {
PsiExpression expression = JavaPsiFacade.getInstance(var.getProject()).getParserFacade()
.createExpressionFromText(enumClass.getName() + "." + var.getName(), var);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public ListObjectRenderer(NodeRendererSettings rendererSettings) {

@Override
public PsiElement getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
LOG.assertTrue(node.getDescriptor() instanceof ArrayElementDescriptorImpl);
LOG.assertTrue(node.getDescriptor() instanceof ArrayElementDescriptorImpl arrayElementDescriptor);
try {
return getChildValueExpression(
"this.get(" + ((ArrayElementDescriptorImpl)node.getDescriptor()).getIndex() + ")",
Expand Down
Loading
Loading