Java 类com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition 实例源码

项目:intellij-ce-playground    文件:StdArrangementExtendableSettings.java   
public void appendExpandedRules(@NotNull final StdArrangementMatchRule rule,
                                @NotNull final List<StdArrangementMatchRule> rules,
                                @NotNull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) {
  final List<StdArrangementMatchRule> sequence = getRuleSequence(rule, tokenIdToDefinition);
  if (sequence == null || sequence.isEmpty()) {
    rules.add(rule);
    return;
  }

  final ArrangementCompositeMatchCondition ruleTemplate = removeAliasRuleToken(rule.getMatcher().getCondition());
  for (StdArrangementMatchRule matchRule : sequence) {
    final ArrangementCompositeMatchCondition extendedRule = ruleTemplate.clone();
    extendedRule.addOperand(matchRule.getMatcher().getCondition());
    rules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(extendedRule)));
  }
}
项目:intellij-ce-playground    文件:DefaultArrangementEntryMatcherSerializer.java   
@Nullable
private ArrangementMatchCondition deserializeCondition(@NotNull Element matcherElement) {
  String name = matcherElement.getName();
  if (COMPOSITE_CONDITION_NAME.equals(name)) {
    ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
    for (Object child : matcherElement.getChildren()) {
      ArrangementMatchCondition deserialised = deserializeCondition((Element)child);
      if (deserialised != null) {
        composite.addOperand(deserialised);
      }
    }
    return composite;
  }
  else {
    return deserializeAtomCondition(matcherElement);
  }
}
项目:tools-idea    文件:DefaultArrangementEntryMatcherSerializer.java   
@Nullable
private ArrangementMatchCondition deserializeCondition(@NotNull Element matcherElement) {
  String name = matcherElement.getName();
  if (COMPOSITE_CONDITION_NAME.equals(name)) {
    ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
    for (Object child : matcherElement.getChildren()) {
      ArrangementMatchCondition deserialised = deserializeCondition((Element)child);
      if (deserialised != null) {
        composite.addOperand(deserialised);
      }
    }
    return composite;
  }
  else {
    return deserializeAtomCondition(matcherElement);
  }
}
项目:consulo    文件:StdArrangementExtendableSettings.java   
public void appendExpandedRules(@Nonnull final StdArrangementMatchRule rule,
                                @Nonnull final List<StdArrangementMatchRule> rules,
                                @Nonnull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) {
  final List<StdArrangementMatchRule> sequence = getRuleSequence(rule, tokenIdToDefinition);
  if (sequence == null || sequence.isEmpty()) {
    rules.add(rule);
    return;
  }

  final ArrangementCompositeMatchCondition ruleTemplate = removeAliasRuleToken(rule.getMatcher().getCondition());
  for (StdArrangementMatchRule matchRule : sequence) {
    final ArrangementCompositeMatchCondition extendedRule = ruleTemplate.clone();
    extendedRule.addOperand(matchRule.getMatcher().getCondition());
    rules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(extendedRule)));
  }
}
项目:consulo    文件:DefaultArrangementEntryMatcherSerializer.java   
@Nullable
private ArrangementMatchCondition deserializeCondition(@Nonnull Element matcherElement) {
  String name = matcherElement.getName();
  if (COMPOSITE_CONDITION_NAME.equals(name)) {
    ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
    for (Object child : matcherElement.getChildren()) {
      ArrangementMatchCondition deserialised = deserializeCondition((Element)child);
      if (deserialised != null) {
        composite.addOperand(deserialised);
      }
    }
    return composite;
  }
  else {
    return deserializeAtomCondition(matcherElement);
  }
}
项目:consulo-java    文件:JavaRearranger.java   
private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions)
{
    if(conditions.length == 1)
    {
        matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition(conditions[0],
                conditions[0]))));
        return;
    }

    ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
    for(ArrangementSettingsToken condition : conditions)
    {
        composite.addOperand(new ArrangementAtomMatchCondition(condition, condition));
    }
    matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite)));
}
项目:intellij-ce-playground    文件:JavaRearranger.java   
private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions) {
  if (conditions.length == 1) {
    matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition(
      conditions[0]
    ))));
    return;
  }

  ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
  for (ArrangementSettingsToken condition : conditions) {
    composite.addOperand(new ArrangementAtomMatchCondition(condition));
  }
  matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite)));
}
项目:intellij-ce-playground    文件:ArrangementSettingsSerializationTest.java   
private static StdArrangementMatchRule rule(boolean byName, @NotNull ArrangementSettingsToken... tokens) {
  final List<ArrangementAtomMatchCondition> conditions = new ArrayList<ArrangementAtomMatchCondition>();
  for (ArrangementSettingsToken token : tokens) {
    conditions.add(new ArrangementAtomMatchCondition(token));
  }
  final StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(new ArrangementCompositeMatchCondition(conditions));
  return byName ? new StdArrangementMatchRule(matcher, BY_NAME) : new StdArrangementMatchRule(matcher);
}
项目:intellij-ce-playground    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@Test
public void compositeConditionWithName() {
  ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
  condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
  condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
  condition.addOperand(new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, ("get*")));
  doTest(condition);
}
项目:intellij-ce-playground    文件:StandardArrangementEntryMatcherTest.java   
@Test
public void compositeAndCondition() {
  ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
  condition.addOperand(new ArrangementAtomMatchCondition(FIELD));
  condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC));

  StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
  assertEquals(condition, matcher.getCondition());

  final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
  final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
  final TypeAndModifierAware privateFieldEntry = myMockery.mock(TypeAndModifierAware.class, "private field");
  final TypeAndModifierAware publicMethodEntry = myMockery.mock(TypeAndModifierAware.class, "public method");
  final TypeAndModifierAware publicFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public field");
  final TypeAndModifierAware publicStaticFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public static field");
  myMockery.checking(new Expectations() {{
    allowing(fieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));

    allowing(publicEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(privateFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(privateFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PRIVATE)));

    allowing(publicMethodEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(METHOD)));
    allowing(publicMethodEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(publicFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(publicFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(publicStaticFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(publicStaticFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC, STATIC)));
  }});

  assertFalse(matcher.isMatched(fieldEntry));
  assertFalse(matcher.isMatched(publicEntry));
  assertFalse(matcher.isMatched(privateFieldEntry));
  assertFalse(matcher.isMatched(publicMethodEntry));
  assertTrue(matcher.isMatched(publicFieldEntry));
  assertTrue(matcher.isMatched(publicStaticFieldEntry));
}
项目:intellij-ce-playground    文件:DefaultArrangementEntryMatcherSerializer.java   
@Override
public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
  Element composite = new Element(COMPOSITE_CONDITION_NAME);
  register(composite);
  parent = composite;
  List<ArrangementMatchCondition> operands = ContainerUtilRt.newArrayList(condition.getOperands());
  ContainerUtil.sort(operands, CONDITION_COMPARATOR);
  for (ArrangementMatchCondition c : operands) {
    c.invite(this);
  }
}
项目:intellij-ce-playground    文件:ArrangementAndMatchConditionComponent.java   
public ArrangementAndMatchConditionComponent(@NotNull StdArrangementMatchRule rule,
                                             @NotNull ArrangementCompositeMatchCondition setting,
                                             @NotNull ArrangementMatchNodeComponentFactory factory,
                                             @NotNull ArrangementStandardSettingsManager manager,
                                             boolean allowModification)
{
  mySetting = setting;
  setOpaque(false);
  setLayout(new GridBagLayout());
  final Map<ArrangementSettingsToken, ArrangementMatchCondition> operands = ContainerUtilRt.newHashMap();
  ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() {
    @Override
    public void visit(@NotNull ArrangementAtomMatchCondition condition) {
      operands.put(condition.getType(), condition);
    }

    @Override
    public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
      assert false;
    }
  };
  for (ArrangementMatchCondition operand : setting.getOperands()) {
    operand.invite(visitor);
  }

  List<ArrangementSettingsToken> ordered = manager.sort(operands.keySet());
  GridBagConstraints constraints = new GridBag().anchor(GridBagConstraints.EAST).insets(0, 0, 0, ArrangementConstants.HORIZONTAL_GAP);
  for (ArrangementSettingsToken key : ordered) {
    ArrangementMatchCondition operand = operands.get(key);
    assert operand != null;
    ArrangementUiComponent component = factory.getComponent(operand, rule, allowModification);
    myComponents.add(component);
    myAvailableTokens.addAll(component.getAvailableTokens());
    JComponent uiComponent = component.getUiComponent();
    add(uiComponent, constraints);
  }
}
项目:tools-idea    文件:JavaRearranger.java   
private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions) {
  if (conditions.length == 1) {
    matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition(
      conditions[0], conditions[0]
    ))));
    return;
  }

  ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition();
  for (ArrangementSettingsToken condition : conditions) {
    composite.addOperand(new ArrangementAtomMatchCondition(condition, condition));
  }
  matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite)));
}
项目:tools-idea    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@Test
public void compositeConditionWithName() {
  ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
  condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
  condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
  condition.addOperand(new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, ("get*")));
  doTest(condition);
}
项目:tools-idea    文件:StandardArrangementEntryMatcherTest.java   
@Test
public void compositeAndCondition() {
  ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
  condition.addOperand(new ArrangementAtomMatchCondition(FIELD));
  condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC));

  StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
  assertEquals(condition, matcher.getCondition());

  final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
  final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
  final TypeAndModifierAware privateFieldEntry = myMockery.mock(TypeAndModifierAware.class, "private field");
  final TypeAndModifierAware publicMethodEntry = myMockery.mock(TypeAndModifierAware.class, "public method");
  final TypeAndModifierAware publicFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public field");
  final TypeAndModifierAware publicStaticFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public static field");
  myMockery.checking(new Expectations() {{
    allowing(fieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));

    allowing(publicEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(privateFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(privateFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PRIVATE)));

    allowing(publicMethodEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(METHOD)));
    allowing(publicMethodEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(publicFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(publicFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(publicStaticFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(publicStaticFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC, STATIC)));
  }});

  assertFalse(matcher.isMatched(fieldEntry));
  assertFalse(matcher.isMatched(publicEntry));
  assertFalse(matcher.isMatched(privateFieldEntry));
  assertFalse(matcher.isMatched(publicMethodEntry));
  assertTrue(matcher.isMatched(publicFieldEntry));
  assertTrue(matcher.isMatched(publicStaticFieldEntry));
}
项目:tools-idea    文件:DefaultArrangementEntryMatcherSerializer.java   
@Override
public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
  Element composite = new Element(COMPOSITE_CONDITION_NAME);
  register(composite);
  parent = composite;
  List<ArrangementMatchCondition> operands = ContainerUtilRt.newArrayList(condition.getOperands());
  ContainerUtil.sort(operands, CONDITION_COMPARATOR);
  for (ArrangementMatchCondition c : operands) {
    c.invite(this);
  }
}
项目:tools-idea    文件:ArrangementAndMatchConditionComponent.java   
public ArrangementAndMatchConditionComponent(@NotNull StdArrangementMatchRule rule,
                                             @NotNull ArrangementCompositeMatchCondition setting,
                                             @NotNull ArrangementMatchNodeComponentFactory factory,
                                             @NotNull ArrangementStandardSettingsManager manager)
{
  mySetting = setting;
  setOpaque(false);
  setLayout(new GridBagLayout());
  final Map<ArrangementSettingsToken, ArrangementMatchCondition> operands = ContainerUtilRt.newHashMap();
  ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() {
    @Override
    public void visit(@NotNull ArrangementAtomMatchCondition condition) {
      operands.put(condition.getType(), condition);
    }

    @Override
    public void visit(@NotNull ArrangementCompositeMatchCondition condition) {
      assert false;
    }
  };
  for (ArrangementMatchCondition operand : setting.getOperands()) {
    operand.invite(visitor);
  }

  List<ArrangementSettingsToken> ordered = manager.sort(operands.keySet());
  GridBagConstraints constraints = new GridBag().anchor(GridBagConstraints.EAST).insets(0, 0, 0, ArrangementConstants.HORIZONTAL_GAP);
  for (ArrangementSettingsToken key : ordered) {
    ArrangementMatchCondition operand = operands.get(key);
    assert operand != null;
    ArrangementUiComponent component = factory.getComponent(operand, rule, true);
    myComponents.add(component);
    myAvailableTokens.addAll(component.getAvailableTokens());
    JComponent uiComponent = component.getUiComponent();
    add(uiComponent, constraints);
  }
}
项目:consulo    文件:DefaultArrangementEntryMatcherSerializer.java   
@Override
public void visit(@Nonnull ArrangementCompositeMatchCondition condition) {
  Element composite = new Element(COMPOSITE_CONDITION_NAME);
  register(composite);
  parent = composite;
  List<ArrangementMatchCondition> operands = ContainerUtilRt.newArrayList(condition.getOperands());
  ContainerUtil.sort(operands, CONDITION_COMPARATOR);
  for (ArrangementMatchCondition c : operands) {
    c.invite(this);
  }
}
项目:consulo    文件:DefaultArrangementEntryMatcherSerializerTest.java   
@Test
public void compositeConditionWithName() {
  ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
  condition.addOperand(new ArrangementAtomMatchCondition(METHOD));
  condition.addOperand(new ArrangementAtomMatchCondition(SYNCHRONIZED));
  condition.addOperand(new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, ("get*")));
  doTest(condition);
}
项目:consulo    文件:StandardArrangementEntryMatcherTest.java   
@Test
public void compositeAndCondition() {
  ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition();
  condition.addOperand(new ArrangementAtomMatchCondition(FIELD));
  condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC));

  StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
  assertEquals(condition, matcher.getCondition());

  final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
  final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
  final TypeAndModifierAware privateFieldEntry = myMockery.mock(TypeAndModifierAware.class, "private field");
  final TypeAndModifierAware publicMethodEntry = myMockery.mock(TypeAndModifierAware.class, "public method");
  final TypeAndModifierAware publicFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public field");
  final TypeAndModifierAware publicStaticFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public static field");
  myMockery.checking(new Expectations() {{
    allowing(fieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));

    allowing(publicEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(privateFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(privateFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PRIVATE)));

    allowing(publicMethodEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(METHOD)));
    allowing(publicMethodEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(publicFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(publicFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));

    allowing(publicStaticFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(publicStaticFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC, STATIC)));
  }});

  assertFalse(matcher.isMatched(fieldEntry));
  assertFalse(matcher.isMatched(publicEntry));
  assertFalse(matcher.isMatched(privateFieldEntry));
  assertFalse(matcher.isMatched(publicMethodEntry));
  assertTrue(matcher.isMatched(publicFieldEntry));
  assertTrue(matcher.isMatched(publicStaticFieldEntry));
}
项目:consulo    文件:ArrangementAndMatchConditionComponent.java   
public ArrangementAndMatchConditionComponent(@Nonnull StdArrangementMatchRule rule,
                                             @Nonnull ArrangementCompositeMatchCondition setting,
                                             @Nonnull ArrangementMatchNodeComponentFactory factory,
                                             @Nonnull ArrangementStandardSettingsManager manager,
                                             boolean allowModification)
{
  mySetting = setting;
  setOpaque(false);
  setLayout(new GridBagLayout());
  final Map<ArrangementSettingsToken, ArrangementMatchCondition> operands = ContainerUtilRt.newHashMap();
  ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() {
    @Override
    public void visit(@Nonnull ArrangementAtomMatchCondition condition) {
      operands.put(condition.getType(), condition);
    }

    @Override
    public void visit(@Nonnull ArrangementCompositeMatchCondition condition) {
      assert false;
    }
  };
  for (ArrangementMatchCondition operand : setting.getOperands()) {
    operand.invite(visitor);
  }

  List<ArrangementSettingsToken> ordered = manager.sort(operands.keySet());
  GridBagConstraints constraints = new GridBag().anchor(GridBagConstraints.EAST).insets(0, 0, 0, ArrangementConstants.HORIZONTAL_GAP);
  for (ArrangementSettingsToken key : ordered) {
    ArrangementMatchCondition operand = operands.get(key);
    assert operand != null;
    ArrangementUiComponent component = factory.getComponent(operand, rule, allowModification);
    myComponents.add(component);
    myAvailableTokens.addAll(component.getAvailableTokens());
    JComponent uiComponent = component.getUiComponent();
    add(uiComponent, constraints);
  }
}