[performancePlugin] command supports implementation detail plugins
[idea/community.git] / java / java-psi-api / src / com / intellij / patterns / PsiTypePattern.java
1 // Copyright 2000-2018 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.
2 package com.intellij.patterns;
3
4 import com.intellij.psi.PsiArrayType;
5 import com.intellij.psi.PsiClass;
6 import com.intellij.psi.PsiClassType;
7 import com.intellij.psi.PsiType;
8 import com.intellij.util.ProcessingContext;
9 import org.jetbrains.annotations.NotNull;
10
11 /**
12  * @author peter
13  */
14 public class PsiTypePattern extends ObjectPattern<PsiType,PsiTypePattern> {
15   protected PsiTypePattern() {
16     super(PsiType.class);
17   }
18
19   public PsiTypePattern arrayOf(final ElementPattern pattern) {
20     return with(new PatternCondition<PsiType>("arrayOf") {
21       @Override
22       public boolean accepts(@NotNull final PsiType psiType, final ProcessingContext context) {
23         return psiType instanceof PsiArrayType &&
24                pattern.accepts(((PsiArrayType)psiType).getComponentType(), context);
25       }
26     });
27   }
28
29   public PsiTypePattern classType(final ElementPattern<? extends PsiClass> pattern) {
30     return with(new PatternCondition<PsiType>("classType") {
31       @Override
32       public boolean accepts(@NotNull final PsiType psiType, final ProcessingContext context) {
33         return psiType instanceof PsiClassType &&
34                pattern.accepts(((PsiClassType)psiType).resolve(), context);
35       }
36     });
37   }
38 }