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 @@ -33,10 +33,12 @@
* @author mike
*/
public abstract class BaseClassesAnalysisAction extends BaseAnalysisAction {
protected BaseClassesAnalysisAction(LocalizeValue actionText,
LocalizeValue actionDescription,
LocalizeValue title,
LocalizeValue analysisNoon) {
protected BaseClassesAnalysisAction(
LocalizeValue actionText,
LocalizeValue actionDescription,
LocalizeValue title,
LocalizeValue analysisNoon
) {
super(actionText, actionDescription, title, analysisNoon);
}

Expand All @@ -53,13 +55,13 @@ public void run(ProgressIndicator indicator) {
indicator.setIndeterminate(true);
indicator.setText(AnalysisScopeLocalize.checkingClassFiles());

CompilerManager compilerManager = CompilerManager.getInstance((Project)getProject());
CompilerManager compilerManager = CompilerManager.getInstance((Project) getProject());
boolean upToDate = compilerManager.isUpToDate(compilerManager.createProjectCompileScope());

project.getApplication().invokeLater(() -> {
if (!upToDate) {
int i = Messages.showYesNoCancelDialog(
(Project)getProject(),
(Project) getProject(),
AnalysisScopeLocalize.recompileConfirmationMessage().get(),
AnalysisScopeLocalize.projectIsOutOfDate().get(),
UIUtil.getWarningIcon()
Expand Down Expand Up @@ -89,7 +91,7 @@ private void doAnalyze(Project project, AnalysisScope scope) {
@Override
public NotificationInfo getNotificationInfo() {
return new NotificationInfo(
LocalizeValue.localizeTODO("Analysis"),
"Analysis",
LocalizeValue.localizeTODO("\"" + getTitle() + "\" Analysis Finished"),
LocalizeValue.empty()
);
Expand All @@ -105,11 +107,14 @@ public void run(ProgressIndicator indicator) {
@RequiredReadAction
private void compileAndAnalyze(Project project, AnalysisScope scope) {
CompilerManager compilerManager = CompilerManager.getInstance(project);
compilerManager.make(compilerManager.createProjectCompileScope(), (aborted, errors, warnings, compileContext) -> {
if (aborted || errors != 0) {
return;
compilerManager.make(
compilerManager.createProjectCompileScope(),
(aborted, errors, warnings, compileContext) -> {
if (aborted || errors != 0) {
return;
}
project.getApplication().invokeLater(() -> doAnalyze(project, scope));
}
project.getApplication().invokeLater(() -> doAnalyze(project, scope));
});
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.intellij.java.language.impl.psi.controlFlow.*;
import com.intellij.java.language.psi.*;
import consulo.annotation.access.RequiredReadAction;
import consulo.codeEditor.Editor;
import consulo.externalService.statistic.FeatureUsageTracker;
import consulo.ide.impl.idea.codeInsight.highlighting.HighlightUsagesHandler;
Expand All @@ -37,132 +38,139 @@
import java.util.function.Consumer;

public class HighlightExitPointsHandler extends HighlightUsagesHandlerBase<PsiElement> {
private final PsiElement myTarget;

public HighlightExitPointsHandler(Editor editor, PsiFile file, PsiElement target) {
super(editor, file);
myTarget = target;
}

@Override
public List<PsiElement> getTargets() {
return Collections.singletonList(myTarget);
}

@Override
protected void selectTargets(List<PsiElement> targets, Consumer<List<PsiElement>> selectionConsumer) {
selectionConsumer.accept(targets);
}

@Override
public void computeUsages(List<PsiElement> targets) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(ProductivityFeatureNames.CODEASSISTS_HIGHLIGHT_RETURN);

PsiElement parent = myTarget.getParent();
if (!(parent instanceof PsiReturnStatement) && !(parent instanceof PsiThrowStatement)) {
return;
}
private final PsiElement myTarget;

PsiCodeBlock body = null;
PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(myTarget, PsiLambdaExpression.class);
if (lambdaExpression != null) {
PsiElement lambdaBody = lambdaExpression.getBody();
if (lambdaBody instanceof PsiCodeBlock codeBlock) {
body = codeBlock;
}
public HighlightExitPointsHandler(Editor editor, PsiFile file, PsiElement target) {
super(editor, file);
myTarget = target;
}

if (body == null) {
PsiMethod method = PsiTreeUtil.getParentOfType(myTarget, PsiMethod.class);
body = method != null ? method.getBody() : null;
@Override
@RequiredReadAction
public List<PsiElement> getTargets() {
return Collections.singletonList(myTarget);
}

if (body == null) {
return;
@Override
protected void selectTargets(List<PsiElement> targets, Consumer<List<PsiElement>> selectionConsumer) {
selectionConsumer.accept(targets);
}

try {
highlightExitPoints((PsiStatement) parent, body);
} catch (AnalysisCanceledException e) {
// ignore
}
}

@Nullable
private static PsiElement getExitTarget(PsiStatement exitStatement) {
if (exitStatement instanceof PsiReturnStatement) {
return PsiTreeUtil.getParentOfType(exitStatement, PsiMethod.class);
} else if (exitStatement instanceof PsiBreakStatement breakStatement) {
return breakStatement.findExitedStatement();
} else if (exitStatement instanceof PsiContinueStatement continueStatement) {
return continueStatement.findContinuedStatement();
} else if (exitStatement instanceof PsiThrowStatement throwStatement) {
PsiExpression expr = throwStatement.getException();
if (expr == null) {
return null;
}
PsiType exceptionType = expr.getType();
if (!(exceptionType instanceof PsiClassType)) {
return null;
}

PsiElement target = exitStatement;
while (!(target instanceof PsiMethod || target == null || target instanceof PsiClass || target instanceof PsiFile)) {
if (target instanceof PsiTryStatement tryStatement) {
PsiParameter[] params = tryStatement.getCatchBlockParameters();
for (PsiParameter param : params) {
if (param.getType().isAssignableFrom(exceptionType)) {
break;
@Override
@RequiredReadAction
public void computeUsages(List<PsiElement> targets) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(ProductivityFeatureNames.CODEASSISTS_HIGHLIGHT_RETURN);

PsiElement parent = myTarget.getParent();
if (!(parent instanceof PsiReturnStatement) && !(parent instanceof PsiThrowStatement)) {
return;
}

PsiCodeBlock body = null;
PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(myTarget, PsiLambdaExpression.class);
if (lambdaExpression != null) {
PsiElement lambdaBody = lambdaExpression.getBody();
if (lambdaBody instanceof PsiCodeBlock codeBlock) {
body = codeBlock;
}
}
}
target = target.getParent();
}
if (target instanceof PsiMethod || target instanceof PsiTryStatement) {
return target;
}
return null;
}

return null;
}

private void highlightExitPoints(PsiStatement parent, PsiCodeBlock body) throws AnalysisCanceledException {
Project project = myTarget.getProject();
ControlFlow flow = ControlFlowFactory.getInstance(project).getControlFlow(
body,
LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(),
false
);

Collection<PsiStatement> exitStatements = ControlFlowUtil.findExitPointsAndStatements(
flow,
0,
flow.getSize(),
IntLists.newArrayList(),
PsiReturnStatement.class,
PsiBreakStatement.class,
PsiContinueStatement.class,
PsiThrowStatement.class
);
if (!exitStatements.contains(parent)) {
return;
if (body == null) {
PsiMethod method = PsiTreeUtil.getParentOfType(myTarget, PsiMethod.class);
body = method != null ? method.getBody() : null;
}

if (body == null) {
return;
}

try {
highlightExitPoints((PsiStatement) parent, body);
}
catch (AnalysisCanceledException e) {
// ignore
}
}

PsiElement originalTarget = getExitTarget(parent);
@Nullable
private static PsiElement getExitTarget(PsiStatement exitStatement) {
if (exitStatement instanceof PsiReturnStatement) {
return PsiTreeUtil.getParentOfType(exitStatement, PsiMethod.class);
}
else if (exitStatement instanceof PsiBreakStatement breakStatement) {
return breakStatement.findExitedStatement();
}
else if (exitStatement instanceof PsiContinueStatement continueStatement) {
return continueStatement.findContinuedStatement();
}
else if (exitStatement instanceof PsiThrowStatement throwStatement) {
PsiExpression expr = throwStatement.getException();
if (expr == null) {
return null;
}
PsiType exceptionType = expr.getType();
if (!(exceptionType instanceof PsiClassType)) {
return null;
}

PsiElement target = exitStatement;
while (!(target instanceof PsiMethod || target == null || target instanceof PsiClass || target instanceof PsiFile)) {
if (target instanceof PsiTryStatement tryStatement) {
PsiParameter[] params = tryStatement.getCatchBlockParameters();
for (PsiParameter param : params) {
if (param.getType().isAssignableFrom(exceptionType)) {
break;
}
}
}
target = target.getParent();
}
if (target instanceof PsiMethod || target instanceof PsiTryStatement) {
return target;
}
return null;
}

Iterator<PsiStatement> it = exitStatements.iterator();
while (it.hasNext()) {
PsiStatement psiStatement = it.next();
if (getExitTarget(psiStatement) != originalTarget) {
it.remove();
}
return null;
}

for (PsiElement e : exitStatements) {
addOccurrence(e);
@RequiredReadAction
private void highlightExitPoints(PsiStatement parent, PsiCodeBlock body) throws AnalysisCanceledException {
Project project = myTarget.getProject();
ControlFlow flow = ControlFlowFactory.getInstance(project).getControlFlow(
body,
LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(),
false
);

Collection<PsiStatement> exitStatements = ControlFlowUtil.findExitPointsAndStatements(
flow,
0,
flow.getSize(),
IntLists.newArrayList(),
PsiReturnStatement.class,
PsiBreakStatement.class,
PsiContinueStatement.class,
PsiThrowStatement.class
);
if (!exitStatements.contains(parent)) {
return;
}

PsiElement originalTarget = getExitTarget(parent);

Iterator<PsiStatement> it = exitStatements.iterator();
while (it.hasNext()) {
PsiStatement psiStatement = it.next();
if (getExitTarget(psiStatement) != originalTarget) {
it.remove();
}
}

for (PsiElement e : exitStatements) {
addOccurrence(e);
}
myStatusText =
CodeInsightLocalize.statusBarExitPointsHighlightedMessage(exitStatements.size(), HighlightUsagesHandler.getShortcutText());
}
myStatusText =
CodeInsightLocalize.statusBarExitPointsHighlightedMessage(exitStatements.size(), HighlightUsagesHandler.getShortcutText()).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.intellij.java.language.psi.*;
import com.intellij.java.language.psi.util.InheritanceUtil;
import consulo.annotation.access.RequiredReadAction;
import consulo.application.ApplicationManager;
import consulo.codeEditor.Editor;
import consulo.externalService.statistic.FeatureUsageTracker;
import consulo.ide.impl.idea.codeInsight.highlighting.HighlightUsagesHandler;
Expand All @@ -27,6 +26,7 @@
import consulo.language.editor.localize.CodeInsightLocalize;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiFile;
import consulo.localize.LocalizeValue;
import consulo.navigation.ItemPresentation;

import java.util.Arrays;
Expand Down Expand Up @@ -99,15 +99,17 @@ public void computeUsages(List<PsiClass> classes) {
else {
name = "";
}
myHintText = CodeInsightBundle.message("no.methods.overriding.0.are.found", classes.size(), name);
myHintText = LocalizeValue.localizeTODO(
CodeInsightBundle.message("no.methods.overriding.0.are.found", classes.size(), name)
);
}
else {
addOccurrence(myTarget);
int methodCount = myReadUsages.size() - 1; // exclude 'target' keyword
myStatusText = CodeInsightLocalize.statusBarOverriddenMethodsHighlightedMessage(
methodCount,
HighlightUsagesHandler.getShortcutText()
).get();
);
}
}
}
Loading
Loading