mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Cleanup (minor optimization; typos; formatting)
GitOrigin-RevId: 0ee801a8ecd200f01c8a033aa0a9c26ba8b81661
This commit is contained in:
committed by
intellij-monorepo-bot
parent
665b70894a
commit
127ee4ec2f
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.search;
|
||||
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
@@ -12,14 +12,14 @@ import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
* A single pattern the occurrences of which in comments are indexed by IDEA.
|
||||
* A single pattern, the occurrences of which in comments are indexed by the IDE.
|
||||
*
|
||||
* @see IndexPatternProvider#getIndexPatterns()
|
||||
*/
|
||||
public final class IndexPattern {
|
||||
|
||||
public static final IndexPattern[] EMPTY_ARRAY = new IndexPattern[0];
|
||||
|
||||
@NotNull private String myPatternString;
|
||||
private @NotNull String myPatternString;
|
||||
private Pattern myOptimizedIndexingPattern;
|
||||
private boolean myCaseSensitive;
|
||||
private Pattern myPattern;
|
||||
@@ -31,15 +31,13 @@ public final class IndexPattern {
|
||||
* @param patternString the text of the Java regular expression to match.
|
||||
* @param caseSensitive whether the regular expression should be case-sensitive.
|
||||
*/
|
||||
public IndexPattern(@NotNull String patternString, final boolean caseSensitive) {
|
||||
public IndexPattern(@NotNull String patternString, boolean caseSensitive) {
|
||||
myPatternString = patternString;
|
||||
myCaseSensitive = caseSensitive;
|
||||
compilePattern();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NlsSafe
|
||||
public String getPatternString() {
|
||||
public @NotNull @NlsSafe String getPatternString() {
|
||||
return myPatternString;
|
||||
}
|
||||
|
||||
@@ -51,8 +49,7 @@ public final class IndexPattern {
|
||||
return myOptimizedIndexingPattern;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getWordsToFindFirst() {
|
||||
public @NotNull List<String> getWordsToFindFirst() {
|
||||
return myStringsToFindFirst;
|
||||
}
|
||||
|
||||
@@ -60,12 +57,12 @@ public final class IndexPattern {
|
||||
return myCaseSensitive;
|
||||
}
|
||||
|
||||
public void setPatternString(@NotNull final String patternString) {
|
||||
public void setPatternString(@NotNull String patternString) {
|
||||
myPatternString = patternString;
|
||||
compilePattern();
|
||||
}
|
||||
|
||||
public void setCaseSensitive(final boolean caseSensitive) {
|
||||
public void setCaseSensitive(boolean caseSensitive) {
|
||||
myCaseSensitive = caseSensitive;
|
||||
compilePattern();
|
||||
}
|
||||
@@ -80,7 +77,7 @@ public final class IndexPattern {
|
||||
}
|
||||
}
|
||||
myPattern = Pattern.compile(myPatternString, flags);
|
||||
String optimizedPattern = myPatternString;
|
||||
var optimizedPattern = myPatternString;
|
||||
optimizedPattern = StringUtil.trimStart(optimizedPattern, ".*");
|
||||
myOptimizedIndexingPattern = Pattern.compile(optimizedPattern, flags);
|
||||
myStringsToFindFirst = IndexPatternOptimizer.getInstance().extractStringsToFind(myPatternString);
|
||||
@@ -93,22 +90,12 @@ public final class IndexPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final IndexPattern that = (IndexPattern)o;
|
||||
|
||||
if (myCaseSensitive != that.myCaseSensitive) return false;
|
||||
if (!myPatternString.equals(that.myPatternString)) return false;
|
||||
|
||||
return true;
|
||||
public boolean equals(Object o) {
|
||||
return this == o || o instanceof IndexPattern ip && myCaseSensitive == ip.myCaseSensitive && myPatternString.equals(ip.myPatternString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myPatternString.hashCode();
|
||||
result = 29 * result + (myCaseSensitive ? 1 : 0);
|
||||
return result;
|
||||
return 29 * myPatternString.hashCode() + (myCaseSensitive ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.intellij.ui.IconManager;
|
||||
import com.intellij.ui.PlatformIcons;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -15,18 +14,18 @@ import javax.swing.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class TodoAttributes implements Cloneable {
|
||||
private static final String ATTRIBUTE_ICON = "icon";
|
||||
private static final String ICON_NULL = "null";
|
||||
private static final String ICON_DEFAULT = "default";
|
||||
private static final String ICON_QUESTION = "question";
|
||||
private static final String ICON_IMPORTANT = "important";
|
||||
private static final String ELEMENT_OPTION = "option";
|
||||
private static final String USE_CUSTOM_COLORS_ATT = "useCustomColors";
|
||||
|
||||
private @Nullable Icon myIcon;
|
||||
private TextAttributes myTextAttributes;
|
||||
private boolean myShouldUseCustomColors;
|
||||
|
||||
private static final @NonNls String ATTRIBUTE_ICON = "icon";
|
||||
private static final @NonNls String ICON_NULL = "null";
|
||||
private static final @NonNls String ICON_DEFAULT = "default";
|
||||
private static final @NonNls String ICON_QUESTION = "question";
|
||||
private static final @NonNls String ICON_IMPORTANT = "important";
|
||||
private static final @NonNls String ELEMENT_OPTION = "option";
|
||||
private static final @NonNls String USE_CUSTOM_COLORS_ATT = "useCustomColors";
|
||||
|
||||
@Internal
|
||||
TodoAttributes(@NotNull Element element, @NotNull TextAttributes defaultTodoAttributes) {
|
||||
String icon = element.getAttributeValue(ATTRIBUTE_ICON, ICON_NULL);
|
||||
@@ -58,6 +57,10 @@ public final class TodoAttributes implements Cloneable {
|
||||
return myIcon;
|
||||
}
|
||||
|
||||
public void setIcon(@Nullable Icon icon) {
|
||||
myIcon = icon;
|
||||
}
|
||||
|
||||
public @NotNull TextAttributes getTextAttributes() {
|
||||
return getCustomizedTextAttributes();
|
||||
}
|
||||
@@ -66,8 +69,15 @@ public final class TodoAttributes implements Cloneable {
|
||||
return myTextAttributes;
|
||||
}
|
||||
|
||||
public void setIcon(@Nullable Icon icon) {
|
||||
myIcon = icon;
|
||||
public boolean shouldUseCustomTodoColor() {
|
||||
return myShouldUseCustomColors;
|
||||
}
|
||||
|
||||
public void setUseCustomTodoColor(boolean useCustomColors, @NotNull TextAttributes defaultTodoAttributes) {
|
||||
myShouldUseCustomColors = useCustomColors;
|
||||
if (!useCustomColors) {
|
||||
myTextAttributes = defaultTodoAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
@@ -92,15 +102,16 @@ public final class TodoAttributes implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof TodoAttributes attributes)) return false;
|
||||
|
||||
return myIcon == attributes.myIcon &&
|
||||
Objects.equals(myTextAttributes, attributes.myTextAttributes) &&
|
||||
myShouldUseCustomColors == attributes.myShouldUseCustomColors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myIcon != null ? myIcon.hashCode() : 0;
|
||||
result = 29 * result + (myTextAttributes != null ? myTextAttributes.hashCode() : 0);
|
||||
@@ -108,28 +119,11 @@ public final class TodoAttributes implements Cloneable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean shouldUseCustomTodoColor() {
|
||||
return myShouldUseCustomColors;
|
||||
}
|
||||
|
||||
public void setUseCustomTodoColor(boolean useCustomColors, @NotNull TextAttributes defaultTodoAttributes) {
|
||||
myShouldUseCustomColors = useCustomColors;
|
||||
if (!useCustomColors) {
|
||||
myTextAttributes = defaultTodoAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||
public TodoAttributes clone() {
|
||||
try {
|
||||
TextAttributes textAttributes = myTextAttributes.clone();
|
||||
TodoAttributes attributes = (TodoAttributes)super.clone();
|
||||
attributes.myTextAttributes = textAttributes;
|
||||
attributes.myShouldUseCustomColors = myShouldUseCustomColors;
|
||||
return attributes;
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
var attributes = new TodoAttributes(myIcon, myTextAttributes.clone());
|
||||
attributes.myShouldUseCustomColors = myShouldUseCustomColors;
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.search;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class TodoPattern implements Cloneable {
|
||||
private static final Logger LOG = Logger.getInstance(TodoPattern.class);
|
||||
private static final String CASE_SENS_ATT = "case-sensitive";
|
||||
private static final String PATTERN_ATT = "pattern";
|
||||
|
||||
private IndexPattern indexPattern;
|
||||
|
||||
private TodoAttributes attributes;
|
||||
|
||||
private static final @NonNls String CASE_SENS_ATT = "case-sensitive";
|
||||
private static final @NonNls String PATTERN_ATT = "pattern";
|
||||
private final IndexPattern myIndexPattern;
|
||||
private TodoAttributes myAttributes;
|
||||
|
||||
@Internal
|
||||
public TodoPattern(@NotNull TodoAttributes attributes) {
|
||||
@@ -30,89 +24,68 @@ public final class TodoPattern implements Cloneable {
|
||||
|
||||
@Internal
|
||||
public TodoPattern(@NotNull Element state, @NotNull TextAttributes defaultTodoAttributes) {
|
||||
attributes = new TodoAttributes(state, defaultTodoAttributes);
|
||||
indexPattern = new IndexPattern(state.getAttributeValue(PATTERN_ATT, "").trim(),
|
||||
Boolean.parseBoolean(state.getAttributeValue(CASE_SENS_ATT)));
|
||||
myAttributes = new TodoAttributes(state, defaultTodoAttributes);
|
||||
myIndexPattern = new IndexPattern(
|
||||
state.getAttributeValue(PATTERN_ATT, "").trim(),
|
||||
Boolean.parseBoolean(state.getAttributeValue(CASE_SENS_ATT)));
|
||||
}
|
||||
|
||||
public TodoPattern(@NotNull String patternString, @NotNull TodoAttributes attributes, boolean caseSensitive) {
|
||||
indexPattern = new IndexPattern(patternString, caseSensitive);
|
||||
this.attributes = attributes;
|
||||
myIndexPattern = new IndexPattern(patternString, caseSensitive);
|
||||
myAttributes = attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||
public TodoPattern clone() {
|
||||
try {
|
||||
TodoAttributes attributes = this.attributes.clone();
|
||||
TodoPattern pattern = (TodoPattern)super.clone();
|
||||
pattern.indexPattern = new IndexPattern(indexPattern.getPatternString(), indexPattern.isCaseSensitive());
|
||||
pattern.attributes = attributes;
|
||||
|
||||
return pattern;
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
return new TodoPattern(myIndexPattern.getPatternString(), myAttributes.clone(), myIndexPattern.isCaseSensitive());
|
||||
}
|
||||
|
||||
public @NotNull @NlsSafe String getPatternString() {
|
||||
return indexPattern.getPatternString();
|
||||
return myIndexPattern.getPatternString();
|
||||
}
|
||||
|
||||
public void setPatternString(@NotNull String patternString) {
|
||||
indexPattern.setPatternString(patternString);
|
||||
myIndexPattern.setPatternString(patternString);
|
||||
}
|
||||
|
||||
public @NotNull TodoAttributes getAttributes() {
|
||||
return attributes;
|
||||
return myAttributes;
|
||||
}
|
||||
|
||||
public void setAttributes(@NotNull TodoAttributes attributes) {
|
||||
this.attributes = attributes;
|
||||
myAttributes = attributes;
|
||||
}
|
||||
|
||||
public boolean isCaseSensitive() {
|
||||
return indexPattern.isCaseSensitive();
|
||||
return myIndexPattern.isCaseSensitive();
|
||||
}
|
||||
|
||||
public void setCaseSensitive(boolean caseSensitive) {
|
||||
indexPattern.setCaseSensitive(caseSensitive);
|
||||
myIndexPattern.setCaseSensitive(caseSensitive);
|
||||
}
|
||||
|
||||
public @Nullable Pattern getPattern() {
|
||||
return indexPattern.getPattern();
|
||||
return myIndexPattern.getPattern();
|
||||
}
|
||||
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
attributes.writeExternal(element);
|
||||
if (indexPattern.isCaseSensitive()) {
|
||||
myAttributes.writeExternal(element);
|
||||
if (myIndexPattern.isCaseSensitive()) {
|
||||
element.setAttribute(CASE_SENS_ATT, "true");
|
||||
}
|
||||
element.setAttribute(PATTERN_ATT, indexPattern.getPatternString());
|
||||
element.setAttribute(PATTERN_ATT, myIndexPattern.getPatternString());
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof TodoPattern pattern)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!indexPattern.equals(pattern.indexPattern)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Comparing.equal(attributes, pattern.attributes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
public boolean equals(Object o) {
|
||||
return this == o || o instanceof TodoPattern that && myIndexPattern.equals(that.myIndexPattern);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return indexPattern.hashCode();
|
||||
return myIndexPattern.hashCode();
|
||||
}
|
||||
|
||||
public IndexPattern getIndexPattern() {
|
||||
return indexPattern;
|
||||
return myIndexPattern;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.todo;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -9,7 +9,6 @@ import com.intellij.psi.search.TodoPattern;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -20,9 +19,9 @@ import java.util.Set;
|
||||
public final class TodoFilter implements Cloneable {
|
||||
private static final Logger LOG = Logger.getInstance(TodoFilter.class);
|
||||
|
||||
private static final @NonNls String ATTRIBUTE_NAME = "name";
|
||||
private static final @NonNls String ELEMENT_PATTERN = "pattern";
|
||||
private static final @NonNls String ATTRIBUTE_INDEX = "index";
|
||||
private static final String ATTRIBUTE_NAME = "name";
|
||||
private static final String ELEMENT_PATTERN = "pattern";
|
||||
private static final String ATTRIBUTE_INDEX = "index";
|
||||
|
||||
private @NlsSafe String myName;
|
||||
private Set<TodoPattern> myTodoPatterns;
|
||||
@@ -108,20 +107,19 @@ public final class TodoFilter implements Cloneable {
|
||||
}
|
||||
|
||||
myTodoPatterns.clear();
|
||||
for (Element child : element.getChildren(ELEMENT_PATTERN)) {
|
||||
for (var child : element.getChildren(ELEMENT_PATTERN)) {
|
||||
try {
|
||||
int index = Integer.parseInt(child.getAttributeValue(ATTRIBUTE_INDEX));
|
||||
if (index < 0 || index > patterns.size() - 1) {
|
||||
continue;
|
||||
}
|
||||
TodoPattern pattern = patterns.get(index);
|
||||
var pattern = patterns.get(index);
|
||||
if (myTodoPatterns.contains(pattern)) {
|
||||
continue;
|
||||
}
|
||||
myTodoPatterns.add(pattern);
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
catch (NumberFormatException ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,55 +129,32 @@ public final class TodoFilter implements Cloneable {
|
||||
*/
|
||||
public void writeExternal(Element element, TodoPattern[] patterns) {
|
||||
element.setAttribute(ATTRIBUTE_NAME, myName);
|
||||
for (TodoPattern pattern : myTodoPatterns) {
|
||||
for (var pattern : myTodoPatterns) {
|
||||
int index = ArrayUtilRt.find(patterns, pattern);
|
||||
LOG.assertTrue(index != -1);
|
||||
Element child = new Element(ELEMENT_PATTERN);
|
||||
var child = new Element(ELEMENT_PATTERN);
|
||||
child.setAttribute(ATTRIBUTE_INDEX, Integer.toString(index));
|
||||
element.addContent(child);
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hashCode = myName.hashCode();
|
||||
for (TodoPattern myTodoPattern : myTodoPatterns) {
|
||||
hashCode += myTodoPattern.hashCode();
|
||||
}
|
||||
return hashCode;
|
||||
return myName.hashCode() * 31 + myTodoPatterns.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof TodoFilter filter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!myName.equals(filter.myName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (myTodoPatterns.size() != filter.myTodoPatterns.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (TodoPattern pattern : myTodoPatterns) {
|
||||
if (!filter.contains(pattern)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return obj instanceof TodoFilter filter &&
|
||||
myName.equals(filter.myName) &&
|
||||
myTodoPatterns.size() == filter.myTodoPatterns.size() &&
|
||||
filter.myTodoPatterns.containsAll(myTodoPatterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||
public TodoFilter clone() {
|
||||
try {
|
||||
TodoFilter filter = (TodoFilter)super.clone();
|
||||
filter.myTodoPatterns = new HashSet<>(myTodoPatterns);
|
||||
return filter;
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
var filter = new TodoFilter();
|
||||
filter.myName = myName;
|
||||
filter.myTodoPatterns = new HashSet<>(myTodoPatterns);
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.todo.configurable;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
@@ -26,12 +11,7 @@ import javax.swing.table.AbstractTableModel;
|
||||
import java.util.List;
|
||||
|
||||
final class FiltersTableModel extends AbstractTableModel implements ItemRemovable {
|
||||
private final String[] ourColumnNames = new String[]{
|
||||
IdeBundle.message("column.todo.filters.name"),
|
||||
IdeBundle.message("column.todo.filter.patterns")
|
||||
};
|
||||
private final Class<?>[] ourColumnClasses = new Class[]{String.class, String.class};
|
||||
|
||||
private final String[] myColumnNames = {IdeBundle.message("column.todo.filters.name"), IdeBundle.message("column.todo.filter.patterns")};
|
||||
private final List<TodoFilter> myFilters;
|
||||
|
||||
FiltersTableModel(List<TodoFilter> filters) {
|
||||
@@ -40,12 +20,15 @@ final class FiltersTableModel extends AbstractTableModel implements ItemRemovabl
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
return ourColumnNames[column];
|
||||
return myColumnNames[column];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column) {
|
||||
return ourColumnClasses[column];
|
||||
return switch (column) {
|
||||
case 0, 1 -> String.class;
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,9 +43,9 @@ final class FiltersTableModel extends AbstractTableModel implements ItemRemovabl
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int row, int column) {
|
||||
TodoFilter filter = myFilters.get(row);
|
||||
var filter = myFilters.get(row);
|
||||
return switch (column) {
|
||||
case 0 -> filter.getName(); // "Name" column
|
||||
case 0 -> filter.getName();
|
||||
case 1 -> StreamEx.of(filter.iterator()).map(TodoPattern::getPatternString).joining(" | ");
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
|
||||
@@ -9,57 +9,53 @@ import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.List;
|
||||
|
||||
final class PatternsTableModel extends AbstractTableModel implements ItemRemovable{
|
||||
private final String[] ourColumnNames=new String[]{
|
||||
IdeBundle.message("column.todo.patterns.icon"),
|
||||
IdeBundle.message("column.todo.patterns.case.sensitive"),
|
||||
IdeBundle.message("column.todo.patterns.pattern")
|
||||
};
|
||||
private final Class[] ourColumnClasses=new Class[]{Icon.class,Boolean.class,String.class};
|
||||
|
||||
final class PatternsTableModel extends AbstractTableModel implements ItemRemovable {
|
||||
private final String[] myColumnNames = {IdeBundle.message("column.todo.patterns.icon"), IdeBundle.message("column.todo.patterns.case.sensitive"), IdeBundle.message("column.todo.patterns.pattern")};
|
||||
private final List<TodoPattern> myPatterns;
|
||||
|
||||
PatternsTableModel(List<TodoPattern> patterns){
|
||||
myPatterns=patterns;
|
||||
PatternsTableModel(List<TodoPattern> patterns) {
|
||||
myPatterns = patterns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column){
|
||||
return ourColumnNames[column];
|
||||
public String getColumnName(int column) {
|
||||
return myColumnNames[column];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int column){
|
||||
return ourColumnClasses[column];
|
||||
public Class<?> getColumnClass(int column) {
|
||||
return switch (column) {
|
||||
case 0 -> Icon.class;
|
||||
case 1 -> Boolean.class;
|
||||
case 2 -> String.class;
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount(){
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount(){
|
||||
public int getRowCount() {
|
||||
return myPatterns.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int row,int column){
|
||||
TodoPattern pattern=myPatterns.get(row);
|
||||
public Object getValueAt(int row, int column) {
|
||||
var pattern = myPatterns.get(row);
|
||||
return switch (column) {
|
||||
// "Icon" column
|
||||
case 0 -> pattern.getAttributes().getIcon();
|
||||
// "Case Sensitive" column
|
||||
case 1 -> Boolean.valueOf(pattern.isCaseSensitive());
|
||||
// "Pattern" column
|
||||
case 2 -> pattern.getPatternString();
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object value,int row,int column){
|
||||
TodoPattern pattern=myPatterns.get(row);
|
||||
public void setValueAt(Object value, int row, int column) {
|
||||
var pattern = myPatterns.get(row);
|
||||
switch (column) {
|
||||
case 0 -> pattern.getAttributes().setIcon((Icon)value);
|
||||
case 1 -> pattern.setCaseSensitive(((Boolean)value).booleanValue());
|
||||
@@ -69,8 +65,8 @@ final class PatternsTableModel extends AbstractTableModel implements ItemRemovab
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRow(int index){
|
||||
public void removeRow(int index) {
|
||||
myPatterns.remove(index);
|
||||
fireTableRowsDeleted(index,index);
|
||||
fireTableRowsDeleted(index, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
@@ -30,9 +27,7 @@ import java.util.List;
|
||||
|
||||
public class TodoConfigurable implements SearchableConfigurable, Configurable.NoScroll {
|
||||
private static final int HEADER_GAP = JBUIScale.scale(20);
|
||||
/*
|
||||
* UI resources
|
||||
*/
|
||||
|
||||
private JPanel myPanel;
|
||||
private JCheckBox myMultiLineCheckBox;
|
||||
private JBTable myPatternsTable;
|
||||
@@ -53,12 +48,12 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
}
|
||||
|
||||
protected boolean arePatternsModified() {
|
||||
TodoConfiguration todoConfiguration = TodoConfiguration.getInstance();
|
||||
TodoPattern[] initialPatterns = getTodoPatternsToDisplay(todoConfiguration);
|
||||
var todoConfiguration = TodoConfiguration.getInstance();
|
||||
var initialPatterns = getTodoPatternsToDisplay(todoConfiguration);
|
||||
if (initialPatterns.length != myPatterns.size()) {
|
||||
return true;
|
||||
}
|
||||
for (TodoPattern initialPattern : initialPatterns) {
|
||||
for (var initialPattern : initialPatterns) {
|
||||
if (!myPatterns.contains(initialPattern)) {
|
||||
return true;
|
||||
}
|
||||
@@ -67,12 +62,12 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
}
|
||||
|
||||
protected boolean areFiltersModified() {
|
||||
TodoConfiguration todoConfiguration = TodoConfiguration.getInstance();
|
||||
TodoFilter[] initialFilters = todoConfiguration.getTodoFilters();
|
||||
var todoConfiguration = TodoConfiguration.getInstance();
|
||||
var initialFilters = todoConfiguration.getTodoFilters();
|
||||
if (initialFilters.length != myFilters.size()) {
|
||||
return true;
|
||||
}
|
||||
for (TodoFilter initialFilter : initialFilters) {
|
||||
for (var initialFilter : initialFilters) {
|
||||
if (!myFilters.contains(initialFilter)) {
|
||||
return true;
|
||||
}
|
||||
@@ -82,11 +77,8 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
// This method is always invoked before close configuration dialog or leave "ToDo" page.
|
||||
// So it's a good place to commit all changes.
|
||||
stopEditing();
|
||||
return TodoConfiguration.getInstance().isMultiLine() != myMultiLineCheckBox.isSelected() ||
|
||||
arePatternsModified() || areFiltersModified();
|
||||
return TodoConfiguration.getInstance().isMultiLine() != myMultiLineCheckBox.isSelected() || arePatternsModified() || areFiltersModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,11 +86,11 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
stopEditing();
|
||||
TodoConfiguration.getInstance().setMultiLine(myMultiLineCheckBox.isSelected());
|
||||
if (arePatternsModified()) {
|
||||
TodoPattern[] patterns = myPatterns.toArray(new TodoPattern[0]);
|
||||
var patterns = myPatterns.toArray(new TodoPattern[0]);
|
||||
TodoConfiguration.getInstance().setTodoPatterns(patterns);
|
||||
}
|
||||
if (areFiltersModified()) {
|
||||
TodoFilter[] filters = myFilters.toArray(new TodoFilter[0]);
|
||||
var filters = myFilters.toArray(new TodoFilter[0]);
|
||||
TodoConfiguration.getInstance().setTodoFilters(filters);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +100,6 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
myPanel = null;
|
||||
myPatternsModel.removeTableModelListener(myPatternsTable);
|
||||
myPatternsTable = null;
|
||||
|
||||
myFiltersModel.removeTableModelListener(myFiltersTable);
|
||||
myFiltersTable = null;
|
||||
}
|
||||
@@ -120,16 +111,17 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
myPatternsTable = new JBTable(myPatternsModel);
|
||||
myPatternsTable.setShowGrid(false);
|
||||
myPatternsTable.getEmptyText().setText(IdeBundle.message("text.todo.no.patterns"));
|
||||
TableColumn typeColumn = myPatternsTable.getColumnModel().getColumn(0);
|
||||
JTableHeader tableHeader = myPatternsTable.getTableHeader();
|
||||
|
||||
var tableHeader = myPatternsTable.getTableHeader();
|
||||
FontMetrics headerFontMetrics = tableHeader.getFontMetrics(tableHeader.getFont());
|
||||
|
||||
var typeColumn = myPatternsTable.getColumnModel().getColumn(0);
|
||||
int typeColumnWidth = headerFontMetrics.stringWidth(myPatternsTable.getColumnName(0) + HEADER_GAP);
|
||||
typeColumn.setPreferredWidth(typeColumnWidth);
|
||||
typeColumn.setMinWidth(typeColumnWidth);
|
||||
typeColumn.setCellRenderer(new IconTableCellRenderer<Icon>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Icon getIcon(@NotNull Icon value, JTable table, int row) {
|
||||
protected @NotNull Icon getIcon(@NotNull Icon value, JTable table, int row) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -146,28 +138,25 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
}
|
||||
});
|
||||
|
||||
// Column "Case Sensitive"
|
||||
TableColumn todoCaseSensitiveColumn = myPatternsTable.getColumnModel().getColumn(1);
|
||||
var todoCaseSensitiveColumn = myPatternsTable.getColumnModel().getColumn(1);
|
||||
int caseSensitiveColumnWidth = headerFontMetrics.stringWidth(myPatternsTable.getColumnName(1)) + HEADER_GAP;
|
||||
todoCaseSensitiveColumn.setPreferredWidth(caseSensitiveColumnWidth);
|
||||
todoCaseSensitiveColumn.setMinWidth(caseSensitiveColumnWidth);
|
||||
todoCaseSensitiveColumn.setCellRenderer(new BooleanTableCellRenderer());
|
||||
|
||||
// Column "Pattern"
|
||||
TodoPatternTableCellRenderer todoPatternRenderer = new TodoPatternTableCellRenderer(myPatterns);
|
||||
TableColumn patternColumn = myPatternsTable.getColumnModel().getColumn(2);
|
||||
patternColumn.setCellRenderer(todoPatternRenderer);
|
||||
var patternColumn = myPatternsTable.getColumnModel().getColumn(2);
|
||||
patternColumn.setCellRenderer(new TodoPatternTableCellRenderer(myPatterns));
|
||||
patternColumn.setPreferredWidth(patternColumn.getMaxWidth());
|
||||
|
||||
JPanel patternsPanel = new JPanel(new BorderLayout());
|
||||
var patternsPanel = new JPanel(new BorderLayout());
|
||||
patternsPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.patterns"), false, JBUI.insetsTop(8)).setShowLine(false));
|
||||
patternsPanel.add(ToolbarDecorator.createDecorator(myPatternsTable)
|
||||
.setAddAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
stopEditing();
|
||||
TodoPattern pattern = new TodoPattern(TodoAttributesUtil.createDefault());
|
||||
PatternDialog dialog = new PatternDialog(myPanel, pattern, -1, myPatterns);
|
||||
var pattern = new TodoPattern(TodoAttributesUtil.createDefault());
|
||||
var dialog = new PatternDialog(myPanel, pattern, -1, myPatterns);
|
||||
if (!dialog.showAndGet()) {
|
||||
return;
|
||||
}
|
||||
@@ -192,10 +181,10 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
if (selectedIndex < 0 || selectedIndex >= myPatternsModel.getRowCount()) {
|
||||
return;
|
||||
}
|
||||
TodoPattern patternToBeRemoved = myPatterns.get(selectedIndex);
|
||||
var patternToBeRemoved = myPatterns.get(selectedIndex);
|
||||
TableUtil.removeSelectedItems(myPatternsTable);
|
||||
for (int i = 0; i < myFilters.size(); i++) {
|
||||
TodoFilter filter = myFilters.get(i);
|
||||
var filter = myFilters.get(i);
|
||||
if (filter.contains(patternToBeRemoved)) {
|
||||
filter.removeTodoPattern(patternToBeRemoved);
|
||||
myFiltersModel.fireTableRowsUpdated(i, i);
|
||||
@@ -205,7 +194,6 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
})
|
||||
.disableUpDownActions().createPanel(), BorderLayout.CENTER);
|
||||
|
||||
// double click in "Patterns" table should also start editing of selected pattern
|
||||
new DoubleClickListener() {
|
||||
@Override
|
||||
protected boolean onDoubleClick(@NotNull MouseEvent e) {
|
||||
@@ -214,31 +202,28 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
}
|
||||
}.installOn(myPatternsTable);
|
||||
|
||||
// Panel with filters
|
||||
myFiltersTable = new JBTable(myFiltersModel);
|
||||
myFiltersTable.setShowGrid(false);
|
||||
myFiltersTable.getEmptyText().setText(IdeBundle.message("text.todo.no.filters"));
|
||||
|
||||
// Column "Name"
|
||||
TableColumn nameColumn = myFiltersTable.getColumnModel().getColumn(0);
|
||||
var nameColumn = myFiltersTable.getColumnModel().getColumn(0);
|
||||
int nameColumnWidth = caseSensitiveColumnWidth + typeColumnWidth;
|
||||
nameColumn.setPreferredWidth(nameColumnWidth);
|
||||
nameColumn.setMinWidth(nameColumnWidth);
|
||||
nameColumn.setCellRenderer(new MyFilterNameTableCellRenderer());
|
||||
|
||||
TableColumn patternsColumn = myFiltersTable.getColumnModel().getColumn(1);
|
||||
var patternsColumn = myFiltersTable.getColumnModel().getColumn(1);
|
||||
patternsColumn.setPreferredWidth(patternsColumn.getMaxWidth());
|
||||
|
||||
JPanel filtersPanel = new JPanel(new BorderLayout());
|
||||
filtersPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.filters"), false, JBUI.insetsTop(13))
|
||||
.setShowLine(false));
|
||||
var filtersPanel = new JPanel(new BorderLayout());
|
||||
filtersPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.filters"), false, JBUI.insetsTop(13)).setShowLine(false));
|
||||
filtersPanel.add(ToolbarDecorator.createDecorator(myFiltersTable)
|
||||
.setAddAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
stopEditing();
|
||||
TodoFilter filter = new TodoFilter();
|
||||
FilterDialog dialog = new FilterDialog(myPanel, filter, -1, myFilters, myPatterns);
|
||||
var filter = new TodoFilter();
|
||||
var dialog = new FilterDialog(myPanel, filter, -1, myFilters, myPatterns);
|
||||
if (dialog.showAndGet()) {
|
||||
myFilters.add(filter);
|
||||
int index = myFilters.size() - 1;
|
||||
@@ -271,10 +256,10 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
}.installOn(myFiltersTable);
|
||||
|
||||
myPanel = FormBuilder.createFormBuilder()
|
||||
.addComponent(myMultiLineCheckBox)
|
||||
.addComponentFillVertically(patternsPanel, 0)
|
||||
.addComponentFillVertically(filtersPanel, 0)
|
||||
.getPanel();
|
||||
.addComponent(myMultiLineCheckBox)
|
||||
.addComponentFillVertically(patternsPanel, 0)
|
||||
.addComponentFillVertically(filtersPanel, 0)
|
||||
.getPanel();
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
@@ -284,9 +269,9 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
if (selectedIndex < 0 || selectedIndex >= myPatternsModel.getRowCount()) {
|
||||
return;
|
||||
}
|
||||
TodoPattern sourcePattern = myPatterns.get(selectedIndex);
|
||||
TodoPattern pattern = sourcePattern.clone();
|
||||
PatternDialog dialog = new PatternDialog(myPanel, pattern, selectedIndex, myPatterns);
|
||||
var sourcePattern = myPatterns.get(selectedIndex);
|
||||
var pattern = sourcePattern.clone();
|
||||
var dialog = new PatternDialog(myPanel, pattern, selectedIndex, myPatterns);
|
||||
dialog.setTitle(IdeBundle.message("title.edit.todo.pattern"));
|
||||
if (!dialog.showAndGet()) {
|
||||
return;
|
||||
@@ -296,7 +281,7 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
myPatternsTable.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
|
||||
// Update model with patterns
|
||||
for (int i = 0; i < myFilters.size(); i++) {
|
||||
TodoFilter filter = myFilters.get(i);
|
||||
var filter = myFilters.get(i);
|
||||
if (filter.contains(sourcePattern)) {
|
||||
filter.removeTodoPattern(sourcePattern);
|
||||
filter.addTodoPattern(pattern);
|
||||
@@ -311,9 +296,9 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
if (selectedIndex < 0 || selectedIndex >= myFiltersModel.getRowCount()) {
|
||||
return;
|
||||
}
|
||||
TodoFilter sourceFilter = myFilters.get(selectedIndex);
|
||||
TodoFilter filter = sourceFilter.clone();
|
||||
FilterDialog dialog = new FilterDialog(myPanel, filter, selectedIndex, myFilters, myPatterns);
|
||||
var sourceFilter = myFilters.get(selectedIndex);
|
||||
var filter = sourceFilter.clone();
|
||||
var dialog = new FilterDialog(myPanel, filter, selectedIndex, myFilters, myPatterns);
|
||||
dialog.setTitle(IdeBundle.message("title.edit.todo.filter"));
|
||||
dialog.show();
|
||||
int exitCode = dialog.getExitCode();
|
||||
@@ -326,13 +311,13 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
|
||||
protected void stopEditing() {
|
||||
if (myPatternsTable.isEditing()) {
|
||||
TableCellEditor editor = myPatternsTable.getCellEditor();
|
||||
var editor = myPatternsTable.getCellEditor();
|
||||
if (editor != null) {
|
||||
editor.stopCellEditing();
|
||||
}
|
||||
}
|
||||
if (myFiltersTable.isEditing()) {
|
||||
TableCellEditor editor = myFiltersTable.getCellEditor();
|
||||
var editor = myFiltersTable.getCellEditor();
|
||||
if (editor != null) {
|
||||
editor.stopCellEditing();
|
||||
}
|
||||
@@ -345,26 +330,23 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getHelpTopic() {
|
||||
public @NotNull String getHelpTopic() {
|
||||
return "preferences.toDoOptions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
myMultiLineCheckBox.setSelected(TodoConfiguration.getInstance().isMultiLine());
|
||||
// Patterns
|
||||
|
||||
myPatterns.clear();
|
||||
TodoConfiguration todoConfiguration = TodoConfiguration.getInstance();
|
||||
TodoPattern[] patterns = getTodoPatternsToDisplay(todoConfiguration);
|
||||
for (TodoPattern pattern : patterns) {
|
||||
var todoConfiguration = TodoConfiguration.getInstance();
|
||||
for (var pattern : getTodoPatternsToDisplay(todoConfiguration)) {
|
||||
myPatterns.add(pattern.clone());
|
||||
}
|
||||
myPatternsModel.fireTableDataChanged();
|
||||
// Filters
|
||||
|
||||
myFilters.clear();
|
||||
TodoFilter[] filters = todoConfiguration.getTodoFilters();
|
||||
for (TodoFilter filter : filters) {
|
||||
for (var filter : todoConfiguration.getTodoFilters()) {
|
||||
myFilters.add(filter.clone());
|
||||
}
|
||||
myFiltersModel.fireTableDataChanged();
|
||||
@@ -378,26 +360,22 @@ public class TodoConfigurable implements SearchableConfigurable, Configurable.No
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
TodoFilter filter = myFilters.get(row);
|
||||
var filter = myFilters.get(row);
|
||||
if (isSelected) {
|
||||
setForeground(UIUtil.getTableSelectionForeground(true));
|
||||
}
|
||||
else if (filter.isEmpty()) {
|
||||
setForeground(JBColor.RED);
|
||||
}
|
||||
else {
|
||||
if (filter.isEmpty()) {
|
||||
setForeground(JBColor.RED);
|
||||
}
|
||||
else {
|
||||
setForeground(UIUtil.getTableForeground());
|
||||
}
|
||||
setForeground(UIUtil.getTableForeground());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getId() {
|
||||
public @NotNull String getId() {
|
||||
return getHelpTopic();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user