Search in sources :

Example 81 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class LanguageLevelCombo method sdkUpdated.

void sdkUpdated(Sdk sdk, boolean isDefaultProject) {
    LanguageLevel newLevel = null;
    if (sdk != null) {
        JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
        if (version != null) {
            newLevel = version.getMaxLanguageLevel();
        }
    }
    updateDefaultLevel(newLevel, isDefaultProject);
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 82 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class PsiScopesUtil method processQualifierType.

private static boolean processQualifierType(@NotNull final PsiType type, final MethodsProcessor processor, PsiManager manager, PsiMethodCallExpression call) throws MethodProcessorSetupFailedException {
    LOG.assertTrue(type.isValid());
    if (type instanceof PsiClassType) {
        JavaResolveResult qualifierResult = ((PsiClassType) type).resolveGenerics();
        return processQualifierResult(qualifierResult, processor, call);
    }
    if (type instanceof PsiArrayType) {
        LanguageLevel languageLevel = PsiUtil.getLanguageLevel(call);
        PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
        JavaResolveResult qualifierResult = factory.getArrayClassType(((PsiArrayType) type).getComponentType(), languageLevel).resolveGenerics();
        return processQualifierResult(qualifierResult, processor, call);
    }
    if (type instanceof PsiIntersectionType) {
        for (PsiType conjunct : ((PsiIntersectionType) type).getConjuncts()) {
            if (!processQualifierType(conjunct, processor, manager, call))
                return false;
        }
    }
    return true;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 83 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class AnnotationFormatterTest method testEnumFormatting.

public void testEnumFormatting() throws Exception {
    defaultSettings();
    FormatterTestCase.getSettings(JavaLanguage.INSTANCE).ENUM_CONSTANTS_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS;
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(LightPlatformTestCase.ourProject).getLanguageLevel();
    try {
        LanguageLevelProjectExtension.getInstance(LightPlatformTestCase.ourProject).setLanguageLevel(LanguageLevel.JDK_1_5);
        doTextTest("  enum Breed {\n" + "     Dalmatian (  \"spotted\" ),Labrador ( \"black\" ),Dachshund( \"brown\" );\n" + "\n" + "     // constructor\n" + "     Breed ( String colour )\n" + "        {\n" + "        this.colour = colour;\n" + "        }\n" + "\n" + "     private String colour;\n" + "\n" + "     // additional method of every Breed object\n" + "     public String getColour()\n" + "        {\n" + "        return colour;\n" + "        }\n" + "  }", "enum Breed {\n" + "    Dalmatian(\"spotted\"),\n" + "    Labrador(\"black\"),\n" + "    Dachshund(\"brown\");\n" + "\n" + "    // constructor\n" + "    Breed(String colour) {\n" + "        this.colour = colour;\n" + "    }\n" + "\n" + "    private String colour;\n" + "\n" + "    // additional method of every Breed object\n" + "    public String getColour() {\n" + "        return colour;\n" + "    }\n" + "}");
        doTextTest("  enum Breed {\n" + "     Dalmatian (  \"spotted\" ),Labrador ( \"black\" ),Dachshund( \"brown\" )\n" + "  }", "enum Breed {\n" + "    Dalmatian(\"spotted\"),\n" + "    Labrador(\"black\"),\n" + "    Dachshund(\"brown\")\n" + "}");
        doTextTest("enum Command { \n" + "        USED \n" + "        , \n" + "        UNUSED\n" + "; \n" + " }", "enum Command {\n" + "    USED,\n" + "    UNUSED;\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(LightPlatformTestCase.ourProject).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 84 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class JavaFormatterTest method testAssertStatementWrapping2.

public void testAssertStatementWrapping2() throws Exception {
    getSettings().BINARY_OPERATION_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
    getSettings().ASSERT_STATEMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    getSettings().RIGHT_MARGIN = 37;
    final CommonCodeStyleSettings.IndentOptions options = getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA);
    options.INDENT_SIZE = 2;
    options.CONTINUATION_INDENT_SIZE = 2;
    getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = true;
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
    try {
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";" + "    }\n" + "}", "class Foo {\n" + "  void foo() {\n" + "    assert i + j + k + l + n + m <= 2\n" + "      : \"assert description\";\n" + "  }\n" + "}");
        getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = false;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";" + "    }\n" + "}", "class Foo {\n" + "  void foo() {\n" + "    assert\n" + "      i + j + k + l + n + m <= 2 :\n" + "      \"assert description\";\n" + "  }\n" + "}");
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 85 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class JavaFormatterTest method testAssertStatementWrapping.

public void testAssertStatementWrapping() throws Exception {
    getSettings().ASSERT_STATEMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    getSettings().BINARY_OPERATION_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
    getSettings().RIGHT_MARGIN = 40;
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    try {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
        getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = false;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName() : foo;\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";\n" + "    }\n" + "}\n", "class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName() :\n" + "                foo;\n" + "        assert i + j + k + l + n + m <= 2 :\n" + "                \"assert description\";\n" + "    }\n" + "}\n");
        getSettings().ASSERT_STATEMENT_COLON_ON_NEXT_LINE = true;
        doTextTest("class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName() : foo;\n" + "        assert i + j + k + l + n + m <= 2 : \"assert description\";\n" + "    }\n" + "}\n", "class Foo {\n" + "    void foo() {\n" + "        assert methodWithVeryVeryLongName()\n" + "                : foo;\n" + "        assert i + j + k + l + n + m <= 2\n" + "                : \"assert description\";\n" + "    }\n" + "}\n");
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Aggregations

LanguageLevel (com.intellij.pom.java.LanguageLevel)98 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)21 Nullable (org.jetbrains.annotations.Nullable)14 Module (com.intellij.openapi.module.Module)13 NotNull (org.jetbrains.annotations.NotNull)9 Sdk (com.intellij.openapi.projectRoots.Sdk)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)7 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 IOException (java.io.IOException)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 Lexer (com.intellij.lexer.Lexer)3 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2