Search in sources :

Example 26 with LanguageLevel

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

the class IntroduceParameterObjectTest method testTypeParametersWithSubstitution.

public void testTypeParametersWithSubstitution() throws Exception {
    final LanguageLevelProjectExtension projectExtension = LanguageLevelProjectExtension.getInstance(getProject());
    final LanguageLevel oldLevel = projectExtension.getLanguageLevel();
    try {
        projectExtension.setLanguageLevel(LanguageLevel.HIGHEST);
        doTest();
    } finally {
        projectExtension.setLanguageLevel(oldLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 27 with LanguageLevel

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

the class MoveMembersTest method testFromNestedToOuterMethodRef.

public void testFromNestedToOuterMethodRef() throws Exception {
    final LanguageLevelProjectExtension projectExtension = LanguageLevelProjectExtension.getInstance(getProject());
    final LanguageLevel oldLevel = projectExtension.getLanguageLevel();
    try {
        projectExtension.setLanguageLevel(LanguageLevel.HIGHEST);
        doTest("Outer.Inner", "Outer", true, VisibilityUtil.ESCALATE_VISIBILITY, 0);
    } finally {
        projectExtension.setLanguageLevel(oldLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 28 with LanguageLevel

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

the class MoveMembersTest method testStaticToInterface.

public void testStaticToInterface() throws Exception {
    final LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject());
    final LanguageLevel level = levelProjectExtension.getLanguageLevel();
    try {
        levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_8);
        doTest("A", "B", 0);
    } finally {
        levelProjectExtension.setLanguageLevel(level);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 29 with LanguageLevel

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

the class HighlightUtil method checkSwitchSelectorType.

@Nullable
static HighlightInfo checkSwitchSelectorType(@NotNull PsiSwitchStatement statement, @NotNull LanguageLevel level) {
    PsiExpression expression = statement.getExpression();
    if (expression == null)
        return null;
    PsiType type = expression.getType();
    if (type == null)
        return null;
    SelectorKind kind = getSwitchSelectorKind(type);
    if (kind == SelectorKind.INT)
        return null;
    LanguageLevel requiredLevel = null;
    if (kind == SelectorKind.ENUM)
        requiredLevel = LanguageLevel.JDK_1_5;
    if (kind == SelectorKind.STRING)
        requiredLevel = LanguageLevel.JDK_1_7;
    if (kind == null || requiredLevel != null && !level.isAtLeast(requiredLevel)) {
        boolean is7 = level.isAtLeast(LanguageLevel.JDK_1_7);
        String expected = JavaErrorMessages.message(is7 ? "valid.switch.17.selector.types" : "valid.switch.selector.types");
        String message = JavaErrorMessages.message("incompatible.types", expected, JavaHighlightUtil.formatType(type));
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
        QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createConvertSwitchToIfIntention(statement));
        if (PsiType.LONG.equals(type) || PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type)) {
            QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createAddTypeCastFix(PsiType.INT, expression));
            QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createWrapLongWithMathToIntExactFix(PsiType.INT, expression));
        }
        if (requiredLevel != null) {
            QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createIncreaseLanguageLevelFix(requiredLevel));
        }
        return info;
    }
    PsiClass member = PsiUtil.resolveClassInClassTypeOnly(type);
    if (member != null && !PsiUtil.isAccessible(member.getProject(), member, expression, null)) {
        String className = PsiFormatUtil.formatClass(member, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
        String message = JavaErrorMessages.message("inaccessible.type", className);
        return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
    }
    return null;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo)

Example 30 with LanguageLevel

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

the class HighlightUtil method getUnsupportedFeatureMessage.

private static String getUnsupportedFeatureMessage(PsiElement element, Feature feature, LanguageLevel level, PsiFile file) {
    String name = JavaErrorMessages.message(feature.key);
    String message = JavaErrorMessages.message("insufficient.language.level", name, level.getCompilerComplianceDefaultOption());
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module != null) {
        LanguageLevel moduleLanguageLevel = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module);
        if (moduleLanguageLevel.isAtLeast(feature.level)) {
            for (FilePropertyPusher pusher : FilePropertyPusher.EP_NAME.getExtensions()) {
                if (pusher instanceof JavaLanguageLevelPusher) {
                    String newMessage = ((JavaLanguageLevelPusher) pusher).getInconsistencyLanguageLevelMessage(message, element, level, file);
                    if (newMessage != null) {
                        return newMessage;
                    }
                }
            }
        }
    }
    return message;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) FilePropertyPusher(com.intellij.openapi.roots.impl.FilePropertyPusher) JavaLanguageLevelPusher(com.intellij.openapi.roots.impl.JavaLanguageLevelPusher) Module(com.intellij.openapi.module.Module)

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