GitOrigin-RevId: 7a3bf3ae1ccca53ce39742c320ebcdcc788ab298
This commit is contained in:
Alexey Kudravtsev
2020-05-06 21:05:05 +00:00
committed by intellij-monorepo-bot
parent 5754f8e2d0
commit dc5ebd15c8
8 changed files with 49 additions and 57 deletions
@@ -369,7 +369,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
@Nullable String commandName,
@Nullable Runnable postRunnable,
final boolean modal) {
codeCleanup(scope, profile, commandName, postRunnable, modal, d -> true);
codeCleanup(scope, profile, commandName, postRunnable, modal, __ -> true);
}
public static void modalCodeCleanup(@NotNull Project project, @NotNull AnalysisScope scope, @Nullable Runnable runnable) {
@@ -17,10 +17,12 @@ package com.intellij.openapi.fileTypes.impl;
import com.intellij.ide.highlighter.custom.SyntaxTable;
import com.intellij.openapi.fileTypes.FileType;
import org.jetbrains.annotations.NotNull;
/**
* Author: dmitrylomov
*/
public interface CustomSyntaxTableFileType extends FileType {
@NotNull
SyntaxTable getSyntaxTable();
}
@@ -320,7 +320,7 @@ public abstract class AbstractLayoutCodeProcessor {
}
}
private static boolean canBeFormatted(PsiFile file) {
private static boolean canBeFormatted(@NotNull PsiFile file) {
if (!file.isValid()) return false;
if (LanguageFormatting.INSTANCE.forContext(file) == null) {
return false;
@@ -337,7 +337,7 @@ public abstract class AbstractLayoutCodeProcessor {
new ReformatFilesTask(new EmptyProgressIndicator()).performFileProcessing(myFile);
}
private List<AbstractLayoutCodeProcessor> getAllProcessors() {
private @NotNull List<AbstractLayoutCodeProcessor> getAllProcessors() {
AbstractLayoutCodeProcessor current = this;
List<AbstractLayoutCodeProcessor> all = new ArrayList<>();
while (current != null) {
@@ -451,7 +451,7 @@ public abstract class AbstractLayoutCodeProcessor {
myStopFormatting = true;
}
public boolean process() {
private boolean process() {
myCountingIterator.processAll(file -> {
updateIndicatorText(ApplicationBundle.message("bulk.reformat.prepare.progress.text"), "");
countingIteration();
@@ -84,8 +84,8 @@ public final class IntentionManagerImpl extends IntentionManager implements Disp
@Override
@NotNull
public List<IntentionAction> getStandardIntentionOptions(@NotNull final HighlightDisplayKey displayKey,
@NotNull final PsiElement context) {
public List<IntentionAction> getStandardIntentionOptions(@NotNull HighlightDisplayKey displayKey,
@NotNull PsiElement context) {
checkForDuplicates();
List<IntentionAction> options = new ArrayList<>(9);
options.add(new EditInspectionToolsSettingsAction(displayKey));
@@ -152,7 +152,7 @@ public final class IntentionManagerImpl extends IntentionManager implements Disp
@Override
@NotNull
public LocalQuickFix convertToFix(@NotNull final IntentionAction action) {
public LocalQuickFix convertToFix(@NotNull IntentionAction action) {
if (action instanceof LocalQuickFix) {
return (LocalQuickFix)action;
}
@@ -170,8 +170,8 @@ public final class IntentionManagerImpl extends IntentionManager implements Disp
}
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
try {
action.invoke(project, new LazyEditor(psiFile), psiFile);
}
@@ -745,23 +745,23 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextEx {
Task task = modal ? new Task.Modal(getProject(), title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
cleanup(scope, profile, postRunnable, commandName, shouldApplyFix, indicator);
cleanup(scope, profile, postRunnable, commandName, indicator, shouldApplyFix);
}
} : new Task.Backgroundable(getProject(), title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
cleanup(scope, profile, postRunnable, commandName, shouldApplyFix, indicator);
cleanup(scope, profile, postRunnable, commandName, indicator, shouldApplyFix);
}
};
ProgressManager.getInstance().run(task);
}
private void cleanup(final @NotNull AnalysisScope scope,
private void cleanup(@NotNull AnalysisScope scope,
@NotNull InspectionProfile profile,
final @Nullable Runnable postRunnable,
final @Nullable String commandName,
@NotNull Predicate<? super ProblemDescriptor> shouldApplyFix,
@NotNull ProgressIndicator progressIndicator) {
@Nullable Runnable postRunnable,
@Nullable String commandName,
@NotNull ProgressIndicator progressIndicator,
@NotNull Predicate<? super ProblemDescriptor> shouldApplyFix) {
setCurrentScope(scope);
final int fileCount = scope.getFileCount();
progressIndicator.setIndeterminate(false);
@@ -774,7 +774,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextEx {
else {
range = null;
}
final Iterable<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> {
Iterable<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> {
assert tools != null;
return tools.getTool().isCleanupTool();
});
@@ -804,9 +804,9 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextEx {
if (!lTools.isEmpty()) {
try {
final LocalInspectionsPass pass = new LocalInspectionsPass(file, file.getViewProvider().getDocument(), range != null ? range.getStartOffset() : 0,
range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true,
HighlightInfoProcessor.getEmpty(), true);
LocalInspectionsPass pass = new LocalInspectionsPass(file, file.getViewProvider().getDocument(), range != null ? range.getStartOffset() : 0,
range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true,
HighlightInfoProcessor.getEmpty(), true);
Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(getProject()), lTools);
ApplicationManager.getApplication().runReadAction(runnable);
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
public abstract class UserFileType <T extends UserFileType> implements FileType, Cloneable {
public abstract class UserFileType<T extends UserFileType<T>> implements FileType, Cloneable {
@NotNull private String myName = "";
private String myDescription = "";
@@ -19,9 +19,10 @@ public abstract class UserFileType <T extends UserFileType> implements FileType,
public abstract SettingsEditor<T> getEditor();
@Override
public UserFileType clone() {
public UserFileType<T> clone() {
try {
return (UserFileType)super.clone();
//noinspection unchecked
return (UserFileType<T>)super.clone();
}
catch (CloneNotSupportedException e) {
return null; //Can't be
@@ -81,7 +82,7 @@ public abstract class UserFileType <T extends UserFileType> implements FileType,
return null;
}
public void copyFrom(@NotNull UserFileType newType) {
public void copyFrom(@NotNull UserFileType<T> newType) {
myName = newType.getName();
myDescription = newType.getDescription();
}
@@ -172,6 +172,7 @@ public class CustomFileTypeEditor extends SettingsEditor<AbstractFileType> {
return panel;
}
@NotNull
public SyntaxTable getSyntaxTable() {
SyntaxTable syntaxTable = new SyntaxTable();
syntaxTable.setLineComment(myLineComment.getText());
@@ -11,18 +11,15 @@ import com.intellij.openapi.options.ExternalizableScheme;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.Pair;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.SmartList;
import com.intellij.util.text.StringTokenizer;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -31,10 +28,11 @@ import java.util.Set;
public class AbstractFileType extends UserFileType<AbstractFileType> implements ExternalizableFileType, ExternalizableScheme,
CustomSyntaxTableFileType, PlainTextLikeFileType {
private static final String SEMICOLON = ";";
protected SyntaxTable mySyntaxTable;
@NotNull
private SyntaxTable mySyntaxTable;
private SyntaxTable myDefaultSyntaxTable;
protected Commenter myCommenter;
@NonNls public static final String ELEMENT_HIGHLIGHTING = "highlighting";
private Commenter myCommenter;
@NonNls static final String ELEMENT_HIGHLIGHTING = "highlighting";
@NonNls private static final String ELEMENT_OPTIONS = "options";
@NonNls private static final String ELEMENT_OPTION = "option";
@NonNls private static final String ATTRIBUTE_VALUE = "value";
@@ -55,9 +53,9 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
@NonNls private static final String ELEMENT_KEYWORDS3 = "keywords3";
@NonNls private static final String ELEMENT_KEYWORDS4 = "keywords4";
@NonNls private static final String ATTRIBUTE_NAME = "name";
@NonNls public static final String ELEMENT_EXTENSION_MAP = "extensionMap";
@NonNls static final String ELEMENT_EXTENSION_MAP = "extensionMap";
public AbstractFileType(SyntaxTable syntaxTable) {
public AbstractFileType(@NotNull SyntaxTable syntaxTable) {
mySyntaxTable = syntaxTable;
}
@@ -68,7 +66,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
}
@Override
public SyntaxTable getSyntaxTable() {
public @NotNull SyntaxTable getSyntaxTable() {
return mySyntaxTable;
}
@@ -76,7 +74,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
return myCommenter;
}
public void setSyntaxTable(SyntaxTable syntaxTable) {
public void setSyntaxTable(@NotNull SyntaxTable syntaxTable) {
mySyntaxTable = syntaxTable;
}
@@ -86,7 +84,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
}
@Override
public void copyFrom(@NotNull UserFileType newType) {
public void copyFrom(@NotNull UserFileType<AbstractFileType> newType) {
super.copyFrom(newType);
if (newType instanceof AbstractFileType) {
@@ -133,24 +131,24 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
table.setNumPostfixChars(value);
}
else if (VALUE_LINE_COMMENT_AT_START.equals(name)) {
table.lineCommentOnlyAtStart = Boolean.valueOf(value).booleanValue();
table.lineCommentOnlyAtStart = Boolean.parseBoolean(value);
}
else if (VALUE_HAS_BRACES.equals(name)) {
table.setHasBraces(Boolean.valueOf(value).booleanValue());
table.setHasBraces(Boolean.parseBoolean(value));
}
else if (VALUE_HAS_BRACKETS.equals(name)) {
table.setHasBrackets(Boolean.valueOf(value).booleanValue());
table.setHasBrackets(Boolean.parseBoolean(value));
}
else if (VALUE_HAS_PARENS.equals(name)) {
table.setHasParens(Boolean.valueOf(value).booleanValue());
table.setHasParens(Boolean.parseBoolean(value));
}
else if (VALUE_HAS_STRING_ESCAPES.equals(name)) {
table.setHasStringEscapes(Boolean.valueOf(value).booleanValue());
table.setHasStringEscapes(Boolean.parseBoolean(value));
}
}
}
else if (ELEMENT_KEYWORDS.equals(element.getName())) {
boolean ignoreCase = Boolean.valueOf(element.getAttributeValue(ATTRIBUTE_IGNORE_CASE)).booleanValue();
boolean ignoreCase = Boolean.parseBoolean(element.getAttributeValue(ATTRIBUTE_IGNORE_CASE));
table.setIgnoreCase(ignoreCase);
loadKeywords(element, table.getKeywords1());
}
@@ -165,21 +163,10 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
}
}
boolean DUMP_TABLE = false;
if (DUMP_TABLE) {
Element element = new Element("temp");
writeTable(element, table);
XMLOutputter outputter = JDOMUtil.createOutputter("\n");
try {
outputter.output((Element)element.getContent().get(0), System.out);
}
catch (IOException ignored) {
}
}
return table;
}
private static void loadKeywords(Element element, Set<? super String> keywords) {
private static void loadKeywords(@NotNull Element element, @NotNull Set<? super String> keywords) {
String value = element.getAttributeValue(ELEMENT_KEYWORDS);
if (value != null) {
StringTokenizer tokenizer = new StringTokenizer(value, SEMICOLON);
@@ -259,7 +246,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
element.addContent(highlightingElement);
}
private static void addElementOption(final Element optionsElement, final String valueHasParens, final boolean hasParens) {
private static void addElementOption(@NotNull Element optionsElement, @NotNull String valueHasParens, final boolean hasParens) {
if (!hasParens) {
return;
}
@@ -270,7 +257,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
optionsElement.addContent(supportParens);
}
private static Element writeKeywords(Set<String> keywords, String tagName, Element highlightingElement) {
private static Element writeKeywords(@NotNull Set<String> keywords, @NotNull String tagName, @NotNull Element highlightingElement) {
if (keywords.isEmpty() && !ELEMENT_KEYWORDS.equals(tagName)) return null;
Element keywordsElement = new Element(tagName);
String[] strings = ArrayUtilRt.toStringArray(keywords);
@@ -281,7 +268,8 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
if (!keyword.contains(SEMICOLON)) {
if (keywordsAttribute.length() != 0) keywordsAttribute.append(SEMICOLON);
keywordsAttribute.append(keyword);
} else {
}
else {
Element e = new Element(ELEMENT_KEYWORD);
e.setAttribute(ATTRIBUTE_NAME, keyword);
keywordsElement.addContent(e);
@@ -363,7 +351,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
return new CustomFileTypeEditor();
}
public void setCommenter(final Commenter commenter) {
public void setCommenter(@NotNull Commenter commenter) {
myCommenter = commenter;
}
}