mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-103092 Xml arranger: Support xml namespace rule
This commit is contained in:
@@ -58,18 +58,25 @@ import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.Ge
|
||||
public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>, ArrangementStandardSettingsAware, ArrangementColorsAware {
|
||||
|
||||
// Type
|
||||
@NotNull private static final Set<ArrangementSettingsToken> SUPPORTED_TYPES = ContainerUtilRt.newLinkedHashSet(
|
||||
FIELD, CONSTRUCTOR, METHOD, CLASS, INTERFACE, ENUM
|
||||
);
|
||||
@NotNull private static final Set<ArrangementSettingsToken> SUPPORTED_TYPES =
|
||||
ContainerUtilRt.newLinkedHashSet(
|
||||
FIELD, CONSTRUCTOR, METHOD, CLASS, INTERFACE, ENUM
|
||||
);
|
||||
// Modifier
|
||||
@NotNull private static final Set<ArrangementSettingsToken> SUPPORTED_MODIFIERS = ContainerUtilRt.newLinkedHashSet(
|
||||
PUBLIC, PROTECTED, PACKAGE_PRIVATE, PRIVATE, STATIC, FINAL, ABSTRACT, SYNCHRONIZED, TRANSIENT, VOLATILE
|
||||
);
|
||||
@NotNull private static final List<ArrangementSettingsToken> SUPPORTED_ORDERS = ContainerUtilRt.newArrayList(KEEP, BY_NAME);
|
||||
@NotNull private static final ArrangementSettingsToken NO_TYPE = new ArrangementSettingsToken("NO_TYPE", "NO_TYPE");
|
||||
@NotNull private static final Set<ArrangementSettingsToken> SUPPORTED_MODIFIERS =
|
||||
ContainerUtilRt.newLinkedHashSet(
|
||||
PUBLIC, PROTECTED, PACKAGE_PRIVATE, PRIVATE, STATIC, FINAL, ABSTRACT, SYNCHRONIZED, TRANSIENT, VOLATILE
|
||||
);
|
||||
@NotNull private static final List<ArrangementSettingsToken> SUPPORTED_ORDERS =
|
||||
ContainerUtilRt.newArrayList(KEEP, BY_NAME);
|
||||
@NotNull private static final ArrangementSettingsToken NO_TYPE =
|
||||
new ArrangementSettingsToken("NO_TYPE", "NO_TYPE");
|
||||
@NotNull
|
||||
private static final Map<ArrangementSettingsToken, Set<ArrangementSettingsToken>> MODIFIERS_BY_TYPE = ContainerUtilRt.newHashMap();
|
||||
@NotNull private static final Collection<Set<ArrangementSettingsToken>> MUTEXES = ContainerUtilRt.newArrayList();
|
||||
private static final Map<ArrangementSettingsToken, Set<ArrangementSettingsToken>> MODIFIERS_BY_TYPE =
|
||||
ContainerUtilRt.newHashMap();
|
||||
@NotNull private static final Collection<Set<ArrangementSettingsToken>> MUTEXES =
|
||||
ContainerUtilRt.newArrayList();
|
||||
|
||||
static {
|
||||
Set<ArrangementSettingsToken> visibilityModifiers = ContainerUtilRt.newHashSet(PUBLIC, PROTECTED, PACKAGE_PRIVATE, PRIVATE);
|
||||
MUTEXES.add(visibilityModifiers);
|
||||
@@ -85,7 +92,9 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
|
||||
MODIFIERS_BY_TYPE.put(CONSTRUCTOR, concat(commonModifiers, SYNCHRONIZED));
|
||||
MODIFIERS_BY_TYPE.put(FIELD, concat(commonModifiers, TRANSIENT, VOLATILE));
|
||||
}
|
||||
|
||||
private static final Map<ArrangementSettingsToken, List<ArrangementSettingsToken>> GROUPING_RULES = ContainerUtilRt.newLinkedHashMap();
|
||||
|
||||
static {
|
||||
GROUPING_RULES.put(GETTERS_AND_SETTERS, Collections.<ArrangementSettingsToken>emptyList());
|
||||
GROUPING_RULES.put(OVERRIDDEN_METHODS, ContainerUtilRt.newArrayList(BY_NAME, KEEP));
|
||||
@@ -302,14 +311,14 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
|
||||
return ContainerUtilRt.newArrayList(
|
||||
new CompositeArrangementSettingsToken(TYPE, SUPPORTED_TYPES),
|
||||
new CompositeArrangementSettingsToken(MODIFIER, SUPPORTED_MODIFIERS),
|
||||
new CompositeArrangementSettingsToken(NAME),
|
||||
new CompositeArrangementSettingsToken(StdArrangementTokens.Regexp.NAME),
|
||||
new CompositeArrangementSettingsToken(ORDER, KEEP, BY_NAME)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(@NotNull ArrangementSettingsToken token, @Nullable ArrangementMatchCondition current) {
|
||||
if (SUPPORTED_TYPES.contains(token) || SUPPORTED_ORDERS.contains(token) || NAME.equals(token)) {
|
||||
if (SUPPORTED_TYPES.contains(token) || SUPPORTED_ORDERS.contains(token) || StdArrangementTokens.Regexp.NAME.equals(token)) {
|
||||
return true;
|
||||
}
|
||||
ArrangementSettingsToken type = null;
|
||||
|
||||
@@ -245,15 +245,17 @@ public class ArrangementUtil {
|
||||
else if (StdArrangementTokens.Modifier.is(condition.getType())) {
|
||||
return new ByModifierArrangementEntryMatcher(condition.getType());
|
||||
}
|
||||
else if (StdArrangementTokens.General.NAME.equals(condition.getType())) {
|
||||
else if (StdArrangementTokens.Regexp.NAME.equals(condition.getType())) {
|
||||
return new ByNameArrangementEntryMatcher(condition.getValue().toString());
|
||||
}
|
||||
else if (StdArrangementTokens.Regexp.XML_NAMESPACE.equals(condition.getType())) {
|
||||
return new ByNamespaceArrangementEntryMatcher(condition.getValue().toString());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO den add doc
|
||||
@NotNull
|
||||
public static ArrangementUiComponent buildUiComponent(@NotNull StdArrangementTokenUiRole role,
|
||||
@NotNull List<ArrangementSettingsToken> tokens,
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.psi.codeStyle.arrangement;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 3/14/13 1:00 PM
|
||||
*/
|
||||
public interface NamespaceAwareArrangementEntry {
|
||||
|
||||
@Nullable
|
||||
String getNamespace();
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.psi.codeStyle.arrangement.match;
|
||||
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementEntry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 3/14/13 1:02 PM
|
||||
*/
|
||||
public abstract class AbstractRegexpArrangementMatcher implements ArrangementEntryMatcher {
|
||||
|
||||
@NotNull private final String myPattern;
|
||||
|
||||
@Nullable private final Pattern myCompiledPattern;
|
||||
|
||||
public AbstractRegexpArrangementMatcher(@NotNull String pattern) {
|
||||
myPattern = pattern;
|
||||
Pattern p = null;
|
||||
try {
|
||||
p = Pattern.compile(pattern);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
myCompiledPattern = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatched(@NotNull ArrangementEntry entry) {
|
||||
if (myCompiledPattern == null) {
|
||||
return false;
|
||||
}
|
||||
String text = getTextToMatch(entry);
|
||||
return text != null && myCompiledPattern.matcher(text).matches();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract String getTextToMatch(@NotNull ArrangementEntry entry);
|
||||
|
||||
@NotNull
|
||||
public String getPattern() {
|
||||
return myPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myPattern.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
AbstractRegexpArrangementMatcher that = (AbstractRegexpArrangementMatcher)o;
|
||||
return myPattern.equals(that.myPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("regexp '%s'", myPattern);
|
||||
}
|
||||
}
|
||||
+8
-50
@@ -20,66 +20,24 @@ import com.intellij.psi.codeStyle.arrangement.NameAwareArrangementEntry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 7/19/12 6:36 PM
|
||||
*/
|
||||
public class ByNameArrangementEntryMatcher implements ArrangementEntryMatcher {
|
||||
|
||||
@NotNull private final String myPattern;
|
||||
|
||||
@Nullable private final Pattern myCompiledPattern;
|
||||
public class ByNameArrangementEntryMatcher extends AbstractRegexpArrangementMatcher {
|
||||
|
||||
public ByNameArrangementEntryMatcher(@NotNull String pattern) {
|
||||
myPattern = pattern;
|
||||
Pattern p = null;
|
||||
try {
|
||||
p = Pattern.compile(pattern);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
myCompiledPattern = p;
|
||||
super(pattern);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public boolean isMatched(@NotNull ArrangementEntry entry) {
|
||||
if (myCompiledPattern == null) {
|
||||
return false;
|
||||
}
|
||||
protected String getTextToMatch(@NotNull ArrangementEntry entry) {
|
||||
if (entry instanceof NameAwareArrangementEntry) {
|
||||
String name = ((NameAwareArrangementEntry)entry).getName();
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
return myCompiledPattern.matcher(name).matches();
|
||||
return ((NameAwareArrangementEntry)entry).getName();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPattern() {
|
||||
return myPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myPattern.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ByNameArrangementEntryMatcher that = (ByNameArrangementEntryMatcher)o;
|
||||
return myPattern.equals(that.myPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("with name like '%s'", myPattern);
|
||||
}
|
||||
}
|
||||
|
||||
+43
@@ -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.psi.codeStyle.arrangement.match;
|
||||
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementEntry;
|
||||
import com.intellij.psi.codeStyle.arrangement.NamespaceAwareArrangementEntry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 3/14/13 1:01 PM
|
||||
*/
|
||||
public class ByNamespaceArrangementEntryMatcher extends AbstractRegexpArrangementMatcher {
|
||||
|
||||
public ByNamespaceArrangementEntryMatcher(@NotNull String pattern) {
|
||||
super(pattern);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected String getTextToMatch(@NotNull ArrangementEntry entry) {
|
||||
if (entry instanceof NamespaceAwareArrangementEntry) {
|
||||
return ((NamespaceAwareArrangementEntry)entry).getNamespace();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -162,8 +162,9 @@ public class DefaultArrangementEntryMatcherSerializer {
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull ArrangementAtomMatchCondition condition) {
|
||||
final Element element = new Element(condition.getType().getId());
|
||||
if (StdArrangementTokens.General.NAME.equals(condition.getType())) {
|
||||
ArrangementSettingsToken type = condition.getType();
|
||||
final Element element = new Element(type.getId());
|
||||
if (StdArrangementTokens.Regexp.is(type)) {
|
||||
element.setText(StringUtil.escapeStringCharacters(condition.getValue().toString()));
|
||||
}
|
||||
register(element);
|
||||
|
||||
+14
-2
@@ -91,15 +91,19 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher {
|
||||
@NotNull private final Set<ArrangementSettingsToken> myModifiers = ContainerUtilRt.newHashSet();
|
||||
|
||||
@Nullable private String myNamePattern;
|
||||
@Nullable private String myNamespacePattern;
|
||||
|
||||
private boolean nestedComposite;
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull ArrangementAtomMatchCondition condition) {
|
||||
if (StdArrangementTokens.General.NAME.equals(condition.getType())) {
|
||||
if (StdArrangementTokens.Regexp.NAME.equals(condition.getType())) {
|
||||
myNamePattern = condition.getValue().toString();
|
||||
return;
|
||||
}
|
||||
else if (StdArrangementTokens.Regexp.XML_NAMESPACE.equals(condition.getType())) {
|
||||
myNamespacePattern = condition.getValue().toString();
|
||||
}
|
||||
Object v = condition.getValue();
|
||||
if (v instanceof ArrangementSettingsToken) {
|
||||
ArrangementSettingsToken token = (ArrangementSettingsToken)v;
|
||||
@@ -131,6 +135,8 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher {
|
||||
ByTypeArrangementEntryMatcher byType = myTypes.isEmpty() ? null : new ByTypeArrangementEntryMatcher(myTypes);
|
||||
ByModifierArrangementEntryMatcher byModifiers = myModifiers.isEmpty() ? null : new ByModifierArrangementEntryMatcher(myModifiers);
|
||||
ByNameArrangementEntryMatcher byName = myNamePattern == null ? null : new ByNameArrangementEntryMatcher(myNamePattern);
|
||||
ByNamespaceArrangementEntryMatcher byNamespace = myNamespacePattern == null
|
||||
? null : new ByNamespaceArrangementEntryMatcher(myNamespacePattern);
|
||||
int i = countNonNulls(byType, byModifiers, byName);
|
||||
if (i == 0 && myMatchers.isEmpty()) {
|
||||
return ArrangementEntryMatcher.EMPTY;
|
||||
@@ -142,9 +148,12 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher {
|
||||
else if (byModifiers != null) {
|
||||
return byModifiers;
|
||||
}
|
||||
else {
|
||||
else if (byName != null) {
|
||||
return byName;
|
||||
}
|
||||
else {
|
||||
return byNamespace;
|
||||
}
|
||||
}
|
||||
else if (myMatchers.size() == 1) {
|
||||
return myMatchers.get(0);
|
||||
@@ -163,6 +172,9 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher {
|
||||
if (byName != null) {
|
||||
result.addMatcher(byName);
|
||||
}
|
||||
if (byNamespace != null) {
|
||||
result.addMatcher(byNamespace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+21
-5
@@ -29,7 +29,7 @@ import java.util.Set;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokenUiRole.*;
|
||||
|
||||
/**
|
||||
* // TODO den add doc
|
||||
* Holds settings tokens used by built-in IJ arrangers.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 3/6/13 3:16 PM
|
||||
@@ -119,7 +119,6 @@ public class StdArrangementTokens {
|
||||
|
||||
@NotNull public static final ArrangementSettingsToken TYPE = token("TYPE", "arrangement.settings.text.general.type", LABEL);
|
||||
@NotNull public static final ArrangementSettingsToken MODIFIER = token("MODIFIER", "arrangement.settings.text.general.modifier", LABEL);
|
||||
@NotNull public static final ArrangementSettingsToken NAME = token("NAME", "arrangement.settings.text.general.name", TEXT_FIELD);
|
||||
@NotNull public static final ArrangementSettingsToken ORDER = token("ORDER", "arrangement.settings.text.general.order", LABEL);
|
||||
|
||||
private static final NotNullLazyValue<Set<ArrangementSettingsToken>> TOKENS = collectFields(General.class);
|
||||
@@ -131,6 +130,23 @@ public class StdArrangementTokens {
|
||||
return TOKENS.getValue().contains(token);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Regexp {
|
||||
|
||||
@NotNull public static final ArrangementSettingsToken NAME = token("NAME", "arrangement.settings.text.general.name", TEXT_FIELD);
|
||||
|
||||
@NotNull public static final ArrangementSettingsToken XML_NAMESPACE =
|
||||
token("XML_NAMESPACE", "arrangement.settings.text.general.xml.namespace", TEXT_FIELD);
|
||||
|
||||
private static final NotNullLazyValue<Set<ArrangementSettingsToken>> TOKENS = collectFields(Regexp.class);
|
||||
|
||||
private Regexp() {
|
||||
}
|
||||
|
||||
public static boolean is(@NotNull ArrangementSettingsToken token) {
|
||||
return TOKENS.getValue().contains(token);
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntryType {
|
||||
|
||||
@@ -214,9 +230,9 @@ public class StdArrangementTokens {
|
||||
|
||||
public static class Order {
|
||||
|
||||
@NotNull public static final ArrangementSettingsToken KEEP = token("KEEP", "arrangement.settings.order.type.keep",
|
||||
COMBO_BOX);
|
||||
@NotNull public static final ArrangementSettingsToken BY_NAME = token("BY_NAME", "arrangement.settings.order.type.by.name",
|
||||
@NotNull public static final ArrangementSettingsToken KEEP = token("KEEP", "arrangement.settings.order.type.keep",
|
||||
COMBO_BOX);
|
||||
@NotNull public static final ArrangementSettingsToken BY_NAME = token("BY_NAME", "arrangement.settings.order.type.by.name",
|
||||
COMBO_BOX);
|
||||
@NotNull public static final ArrangementSettingsToken DEPTH_FIRST = token("DEPTH_FIRST",
|
||||
"arrangement.settings.order.type.depth.first",
|
||||
|
||||
+2
-3
@@ -31,7 +31,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.EntryType.*;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.General.*;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.Modifier.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -109,7 +108,7 @@ public class DefaultArrangementEntryMatcherSerializerTest {
|
||||
|
||||
@Test
|
||||
public void nameConditionOnly() {
|
||||
ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(NAME, "get*");
|
||||
ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, "get*");
|
||||
doTest(condition);
|
||||
}
|
||||
|
||||
@@ -118,7 +117,7 @@ public class DefaultArrangementEntryMatcherSerializerTest {
|
||||
ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
|
||||
condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
|
||||
condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
|
||||
condition.addOperand(new ArrangementAtomMatchCondition(NAME, ("get*")));
|
||||
condition.addOperand(new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, ("get*")));
|
||||
doTest(condition);
|
||||
}
|
||||
|
||||
|
||||
+17
-8
@@ -51,7 +51,7 @@ import java.awt.event.MouseEvent;
|
||||
*/
|
||||
public class ArrangementAtomMatchConditionComponent implements ArrangementUiComponent {
|
||||
|
||||
@NotNull private static final BorderStrategy NAME_BORDER_STRATEGY = new NameBorderStrategy();
|
||||
@NotNull private static final BorderStrategy TEXT_BORDER_STRATEGY = new NameBorderStrategy();
|
||||
@NotNull private static final BorderStrategy PREDEFINED_BORDER_STRATEGY = new PredefinedConditionBorderStrategy();
|
||||
|
||||
@NotNull
|
||||
@@ -92,7 +92,7 @@ public class ArrangementAtomMatchConditionComponent implements ArrangementUiComp
|
||||
|
||||
@Nullable private Dimension myTextControlSize;
|
||||
@Nullable private Rectangle myScreenBounds;
|
||||
@Nullable private Listener myListener;
|
||||
@Nullable private Listener myListener;
|
||||
|
||||
private boolean myEnabled = true;
|
||||
private boolean mySelected;
|
||||
@@ -106,18 +106,27 @@ public class ArrangementAtomMatchConditionComponent implements ArrangementUiComp
|
||||
myColorsProvider = colorsProvider;
|
||||
myCondition = condition;
|
||||
myCloseCallback = closeCallback;
|
||||
myBorderStrategy = StdArrangementTokens.General.NAME.equals(condition.getType()) ? NAME_BORDER_STRATEGY : PREDEFINED_BORDER_STRATEGY;
|
||||
if (condition.getType().equals(condition.getValue())) {
|
||||
myText = condition.getType().getRepresentationValue();
|
||||
ArrangementSettingsToken type = condition.getType();
|
||||
if (StdArrangementTokens.Regexp.is(type)) {
|
||||
myBorderStrategy = TEXT_BORDER_STRATEGY;
|
||||
}
|
||||
else {
|
||||
myBorderStrategy = PREDEFINED_BORDER_STRATEGY;
|
||||
}
|
||||
if (type.equals(condition.getValue())) {
|
||||
myText = type.getRepresentationValue();
|
||||
}
|
||||
else if (StdArrangementTokens.Regexp.is(type)) {
|
||||
myText = String.format("%s %s", type.getRepresentationValue().toLowerCase(), condition.getValue());
|
||||
}
|
||||
else {
|
||||
myText = condition.getValue().toString();
|
||||
}
|
||||
myTextControl.setTextAlign(SwingConstants.CENTER);
|
||||
myTextControl.append(myText, SimpleTextAttributes.fromTextAttributes(colorsProvider.getTextAttributes(condition.getType(), false)));
|
||||
myTextControl.append(myText, SimpleTextAttributes.fromTextAttributes(colorsProvider.getTextAttributes(type, false)));
|
||||
myTextControl.setOpaque(false);
|
||||
int maxWidth = manager.getWidth(condition.getType());
|
||||
if (maxWidth > 0) {
|
||||
int maxWidth = manager.getWidth(type);
|
||||
if (!StdArrangementTokens.Regexp.is(type) && maxWidth > 0) {
|
||||
myTextControlSize = new Dimension(maxWidth, myTextControl.getPreferredSize().height);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -593,6 +593,7 @@ arrangement.settings.text.general.type=Type:
|
||||
arrangement.settings.text.general.modifier=Modifier:
|
||||
arrangement.settings.text.general.name=Name:
|
||||
arrangement.settings.text.general.order=Order:
|
||||
arrangement.settings.text.general.xml.namespace=Namespace:
|
||||
arrangement.settings.text.entry.type.xml.tag=tag
|
||||
arrangement.settings.text.entry.type.xml.attribute=attribute
|
||||
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ abstract class AbstractRearrangerTest extends LightPlatformCodeInsightFixtureTes
|
||||
|
||||
@NotNull
|
||||
protected static ArrangementAtomMatchCondition atom(@NotNull String nameFilter) {
|
||||
new ArrangementAtomMatchCondition(StdArrangementTokens.General.NAME, nameFilter)
|
||||
new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, nameFilter)
|
||||
}
|
||||
|
||||
protected void doTest(@NotNull args) {
|
||||
|
||||
@@ -11,10 +11,7 @@ import com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken;
|
||||
import com.intellij.psi.codeStyle.arrangement.std.ArrangementStandardSettingsAware;
|
||||
import com.intellij.psi.codeStyle.arrangement.std.CompositeArrangementSettingsToken;
|
||||
import com.intellij.psi.codeStyle.arrangement.std.StdArrangementSettings;
|
||||
import com.intellij.psi.codeStyle.arrangement.std.*;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -23,9 +20,7 @@ import java.util.*;
|
||||
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.EntryType.XML_ATTRIBUTE;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.EntryType.XML_TAG;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.General.NAME;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.General.ORDER;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.General.TYPE;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.General.*;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.Order.BY_NAME;
|
||||
import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.Order.KEEP;
|
||||
|
||||
@@ -50,7 +45,8 @@ public class XmlRearranger
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(@NotNull ArrangementSettingsToken token, @Nullable ArrangementMatchCondition current) {
|
||||
return NAME.equals(token) || KEEP.equals(token) || BY_NAME.equals(token) || SUPPORTED_TYPES.contains(token);
|
||||
return SUPPORTED_TYPES.contains(token) || StdArrangementTokens.Regexp.NAME.equals(token) || StdArrangementTokens.Regexp.XML_NAMESPACE.equals(token) || KEEP.equals(token)
|
||||
|| BY_NAME.equals(token) || SUPPORTED_TYPES.contains(token);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -109,7 +105,8 @@ public class XmlRearranger
|
||||
public List<CompositeArrangementSettingsToken> getSupportedMatchingTokens() {
|
||||
return ContainerUtilRt.newArrayList(
|
||||
new CompositeArrangementSettingsToken(TYPE, SUPPORTED_TYPES),
|
||||
new CompositeArrangementSettingsToken(NAME),
|
||||
new CompositeArrangementSettingsToken(StdArrangementTokens.Regexp.NAME),
|
||||
new CompositeArrangementSettingsToken(StdArrangementTokens.Regexp.XML_NAMESPACE),
|
||||
new CompositeArrangementSettingsToken(ORDER, KEEP, BY_NAME)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user