Search in sources :

Example 51 with LanguageLevel

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

the class JavaLanguageLevelModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    LanguageLevel languageLevel = javaModuleModel.getJavaLanguageLevel();
    if (languageLevel == null) {
        // Java language is still not correct. Most likely this module does not have dependents.
        // Get minimum language level from all Android modules.
        languageLevel = getMinimumLanguageLevelForAndroidModules(ideModelsProvider);
    }
    if (languageLevel == null) {
        // The minimum safe Java language level.
        languageLevel = JDK_1_6;
    }
    ModifiableRootModel rootModel = ideModelsProvider.getModifiableRootModel(module);
    LanguageLevelModuleExtensionImpl moduleExtension = rootModel.getModuleExtension(LanguageLevelModuleExtensionImpl.class);
    moduleExtension.setLanguageLevel(languageLevel);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LanguageLevelModuleExtensionImpl(com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 52 with LanguageLevel

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

the class PostProjectBuildTasksExecutorTest method testGetMaxJavaLangLevel4.

public void testGetMaxJavaLangLevel4() {
    expect(myAndroidModel1.getDataBindingEnabled()).andStubReturn(false);
    expect(myAndroidModel2.getDataBindingEnabled()).andStubReturn(false);
    expect(myAndroidModel1.getJavaLanguageLevel()).andStubReturn(LanguageLevel.JDK_1_6);
    expect(myAndroidModel2.getJavaLanguageLevel()).andStubReturn(LanguageLevel.JDK_1_6);
    replay(myAndroidModel1, myAndroidModel2);
    addAndroidModelToFacet(myModule, myAndroidModel1);
    addAndroidModelToFacet(myModule2, myAndroidModel2);
    LanguageLevel maxJavaLangLevel = myExecutor.getMaxJavaLangLevel();
    assertEquals(LanguageLevel.JDK_1_6, maxJavaLangLevel);
    verify(myAndroidModel1, myAndroidModel2);
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 53 with LanguageLevel

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

the class PostProjectBuildTasksExecutorTest method testGetMaxJavaLangLevel3.

public void testGetMaxJavaLangLevel3() {
    expect(myAndroidModel1.getDataBindingEnabled()).andStubReturn(false);
    expect(myAndroidModel2.getDataBindingEnabled()).andStubReturn(false);
    expect(myAndroidModel1.getJavaLanguageLevel()).andStubReturn(LanguageLevel.JDK_1_7);
    expect(myAndroidModel2.getJavaLanguageLevel()).andStubReturn(LanguageLevel.JDK_1_7);
    replay(myAndroidModel1, myAndroidModel2);
    addAndroidModelToFacet(myModule, myAndroidModel1);
    addAndroidModelToFacet(myModule2, myAndroidModel2);
    LanguageLevel maxJavaLangLevel = myExecutor.getMaxJavaLangLevel();
    assertEquals(LanguageLevel.JDK_1_7, maxJavaLangLevel);
    verify(myAndroidModel1, myAndroidModel2);
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 54 with LanguageLevel

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

the class ProcessCandidateParameterTypeInferencePolicy method inferConstraint.

protected static Pair<PsiType, ConstraintType> inferConstraint(PsiTypeParameter typeParameter, PsiExpression innerMethodCall, int parameterIdx, PsiType innerReturnType, JavaResolveResult result, final PsiSubstitutor substitutor) {
    final PsiElement element = result.getElement();
    if (element instanceof PsiMethod) {
        final PsiMethod method = (PsiMethod) element;
        final PsiParameter[] parameters = method.getParameterList().getParameters();
        PsiParameter parameter = null;
        if (parameters.length > parameterIdx) {
            parameter = parameters[parameterIdx];
        } else if (method.isVarArgs()) {
            parameter = parameters[parameters.length - 1];
        }
        if (parameter != null) {
            final PsiParameter finalParameter = parameter;
            PsiType type = PsiResolveHelper.ourGuard.doPreventingRecursion(innerMethodCall, true, () -> substitutor.substitute(finalParameter.getType()));
            final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(finalParameter);
            final Pair<PsiType, ConstraintType> constraint = new PsiOldInferenceHelper(element.getManager()).getSubstitutionForTypeParameterConstraint(typeParameter, innerReturnType, type, false, languageLevel);
            if (constraint != null)
                return constraint;
        }
    }
    return null;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 55 with LanguageLevel

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

the class CompletionStyleTest method testAfterNew15.

public void testAfterNew15() throws Exception {
    final LanguageLevelProjectExtension ll = LanguageLevelProjectExtension.getInstance(getProject());
    final LanguageLevel old = ll.getLanguageLevel();
    ll.setLanguageLevel(LanguageLevel.JDK_1_5);
    try {
        final String path = BASE_PATH;
        configureByFile(path + "/AfterNew15.java");
        performSmartCompletion();
        select('\n', getSelected());
        checkResultByFile(path + "/AfterNew15-out.java");
    } finally {
        ll.setLanguageLevel(old);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

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