summaryrefslogtreecommitdiff
path: root/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsProvider.java
blob: d71b71819c846727752c14ba99ceb963295fc42a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright 2000-2009 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.application.options;

import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.FileTypeIndentOptionsProvider;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiUtil;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.pom.java.LanguageLevel;
import org.jetbrains.annotations.NonNls;

/**
 * @author yole
 */
public class JavaIndentOptionsProvider implements FileTypeIndentOptionsProvider {
  public CommonCodeStyleSettings.IndentOptions createIndentOptions() {
    return new CommonCodeStyleSettings.IndentOptions();
  }

  public FileType getFileType() {
    return StdFileTypes.JAVA;
  }

  public IndentOptionsEditor createOptionsEditor() {
    return new JavaIndentOptionsEditor();
  }

  @NonNls
  public String getPreviewText() {
    return "public class Foo {\n" +
         "  public int[] X = new int[] { 1, 3, 5,\n" +
         "  7, 9, 11};\n" +
         "  public void foo(boolean a, int x,\n" +
         "    int y, int z) {\n" +
         "      a = x == 0 &&\n" +
         "      (y == 0 ||\n" +
         "        z <= 4) &&\n" +
         "      z >= 0;" +
         "    label1: do {\n" +
         "      try {\n" +
         "        if(x > 0) {\n" +
         "          int someVariable = a ? \n" +
         "             x : \n" +
         "             y;\n" +
         "        } else if (x < 0) {\n" +
         "          int someVariable = (y +\n" +
         "          z\n" +
         "          );\n" +
         "          someVariable = x = \n" +
         "          x +\n" +
         "          y;\n" +
         "        } else {\n" +
         "          label2:\n" +
         "          for (int i = 0;\n" +
         "               i < 5;\n" +
         "               i++) doSomething(i);\n" +
         "        }\n" +
         "        switch(a) {\n" +
         "          case 0: \n" +
         "           doCase0();\n" +
         "           break;\n" +
         "          default: \n" +
         "           doDefault();\n" +
         "        }\n" +
         "      }\n" +
         "      catch(Exception e) {\n" +
         "        processException(e.getMessage(),\n" +
         "          x + y, z, a);\n" +
         "      }\n" +
         "      finally {\n" +
         "        processFinally();\n" +
         "      }\n" +
         "    }while(true);\n" +
         "\n" +
         "    if (2 < 3) return;\n" +
         "    if (3 < 4)\n" +
         "       return;\n" +
         "    do x++ while (x < 10000);\n" +
         "    while (x < 50000) x++;\n" +
         "    for (int i = 0; i < 5; i++) System.out.println(i);\n" +
         "  }\n" +
         "  private class InnerClass implements I1,\n" +
         "  I2 {\n" +
         "    public void bar() throws E1,\n" +
         "     E2 {\n" +
         "    }\n" +
         "  }\n" +
         "}";
  }

  public void prepareForReformat(final PsiFile psiFile) {
    psiFile.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST);
  }
}