update copyright
[fedora-idea.git] / xml / dom-openapi / src / com / intellij / patterns / GenericDomValuePattern.java
blobf02965b1835342ab080ba29ae6c11101fad3732b
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.patterns;
18 import com.intellij.util.xml.DomUtil;
19 import com.intellij.util.xml.GenericDomValue;
20 import com.intellij.util.ProcessingContext;
21 import org.jetbrains.annotations.NotNull;
22 import org.jetbrains.annotations.Nullable;
24 /**
25 * @author peter
27 public class GenericDomValuePattern<T> extends DomElementPattern<GenericDomValue<T>, GenericDomValuePattern<T>>{
28 private static final InitialPatternCondition CONDITION = new InitialPatternCondition(GenericDomValue.class) {
29 public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
30 return o instanceof GenericDomValue;
34 protected GenericDomValuePattern() {
35 super(CONDITION);
38 protected GenericDomValuePattern(final Class<T> aClass) {
39 super(new InitialPatternCondition(aClass) {
40 public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
41 return o instanceof GenericDomValue && aClass.equals(DomUtil.getGenericValueParameter(((GenericDomValue)o).getDomElementType()));
44 });
47 public GenericDomValuePattern<T> withStringValue(final ElementPattern<String> pattern) {
48 return with(new PatternCondition<GenericDomValue<T>>("withStringValue") {
49 public boolean accepts(@NotNull final GenericDomValue<T> genericDomValue, final ProcessingContext context) {
50 return pattern.getCondition().accepts(genericDomValue.getStringValue(), context);
53 });
56 public GenericDomValuePattern<T> withValue(@NotNull final T value) {
57 return withValue(StandardPatterns.object(value));
60 public GenericDomValuePattern<T> withValue(final ElementPattern<?> pattern) {
61 return with(new PatternCondition<GenericDomValue<T>>("withValue") {
62 public boolean accepts(@NotNull final GenericDomValue<T> genericDomValue, final ProcessingContext context) {
63 return pattern.getCondition().accepts(genericDomValue.getValue(), context);
65 });