update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / generation / surroundWith / JavaExpressionSurroundDescriptor.java
blobca3d83297e693e8cc87b92e81b7c3e907720ea2b
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.codeInsight.generation.surroundWith;
18 import com.intellij.codeInsight.CodeInsightUtil;
19 import com.intellij.featureStatistics.FeatureUsageTracker;
20 import com.intellij.lang.surroundWith.SurroundDescriptor;
21 import com.intellij.lang.surroundWith.Surrounder;
22 import com.intellij.openapi.extensions.Extensions;
23 import com.intellij.psi.PsiElement;
24 import com.intellij.psi.PsiExpression;
25 import com.intellij.psi.PsiFile;
26 import org.jetbrains.annotations.NotNull;
28 import java.util.ArrayList;
29 import java.util.Collections;
31 /**
32 * @author ven
34 public class JavaExpressionSurroundDescriptor implements SurroundDescriptor {
35 private Surrounder[] mySurrounders = null;
37 private static final Surrounder[] SURROUNDERS = {
38 new JavaWithParenthesesSurrounder(),
39 new JavaWithCastSurrounder(),
40 new JavaWithNotSurrounder(),
41 new JavaWithNotInstanceofSurrounder(),
42 new JavaWithIfExpressionSurrounder(),
43 new JavaWithIfElseExpressionSurrounder()
46 @NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
47 final PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
48 if (expr == null) return PsiElement.EMPTY_ARRAY;
49 FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.surroundwith.expression");
50 return new PsiElement[] {expr};
53 @NotNull public Surrounder[] getSurrounders() {
54 if (mySurrounders == null) {
55 final ArrayList<Surrounder> list = new ArrayList<Surrounder>();
56 Collections.addAll(list, SURROUNDERS);
57 Collections.addAll(list, Extensions.getExtensions(JavaExpressionSurrounder.EP_NAME));
58 mySurrounders = list.toArray(new Surrounder[list.size()]);
60 return mySurrounders;