Search in sources :

Example 91 with LanguageLevel

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

the class IdeaJdk method getRequiredJdkVersion.

@Nullable
private static JavaSdkVersion getRequiredJdkVersion(Sdk ideaSdk) {
    if (isFromIDEAProject(ideaSdk.getHomePath()))
        return JavaSdkVersion.JDK_1_8;
    File apiJar = getOpenApiJar(ideaSdk.getHomePath());
    int classFileVersion = apiJar == null ? -1 : getIdeaClassFileVersion(apiJar);
    LanguageLevel languageLevel = classFileVersion <= 0 ? null : ClsParsingUtil.getLanguageLevelByVersion(classFileVersion);
    return languageLevel != null ? JavaSdkVersion.fromLanguageLevel(languageLevel) : null;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 92 with LanguageLevel

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

the class I18NInspectionTest method testEnum.

public void testEnum() throws Exception {
    final JavaPsiFacade facade = getJavaFacade();
    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
    try {
        doTest();
    } finally {
        LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 93 with LanguageLevel

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

the class GrClassImplUtil method processDeclarations.

public static boolean processDeclarations(@NotNull GrTypeDefinition grType, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    if (place instanceof GrCodeReferenceElement && lastParent instanceof GrModifierList) {
        final PsiElement possibleAnnotation = PsiTreeUtil.skipParentsOfType(place, GrCodeReferenceElement.class);
        if (possibleAnnotation instanceof GrAnnotation && possibleAnnotation.getParent() == lastParent) {
            //don't process class members while resolving annotation which annotates current class
            return true;
        }
    }
    for (final PsiTypeParameter typeParameter : grType.getTypeParameters()) {
        if (!ResolveUtil.processElement(processor, typeParameter, state))
            return false;
    }
    NameHint nameHint = processor.getHint(NameHint.KEY);
    String name = nameHint == null ? null : nameHint.getName(state);
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    final PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
    boolean processInstanceMethods = (ResolveUtil.shouldProcessMethods(classHint) || ResolveUtil.shouldProcessProperties(classHint)) && shouldProcessInstanceMembers(grType, lastParent);
    LanguageLevel level = PsiUtil.getLanguageLevel(place);
    if (ResolveUtil.shouldProcessProperties(classHint)) {
        Map<String, CandidateInfo> fieldsMap = CollectClassMembersUtil.getAllFields(grType);
        if (name != null) {
            CandidateInfo fieldInfo = fieldsMap.get(name);
            if (fieldInfo != null) {
                if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, fieldInfo)) {
                    return false;
                }
            } else if (grType.isTrait() && lastParent != null) {
                PsiField field = findFieldByName(grType, name, false, true);
                if (field != null && field.hasModifierProperty(PsiModifier.PUBLIC)) {
                    if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
                        return false;
                    }
                }
            }
        } else {
            for (CandidateInfo info : fieldsMap.values()) {
                if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, info)) {
                    return false;
                }
            }
            if (grType.isTrait() && lastParent != null) {
                for (PsiField field : CollectClassMembersUtil.getFields(grType, true)) {
                    if (field.hasModifierProperty(PsiModifier.PUBLIC)) {
                        if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    if (ResolveUtil.shouldProcessMethods(classHint)) {
        Map<String, List<CandidateInfo>> methodsMap = CollectClassMembersUtil.getAllMethods(grType, true);
        boolean isPlaceGroovy = place.getLanguage() == GroovyLanguage.INSTANCE;
        if (name == null) {
            for (List<CandidateInfo> list : methodsMap.values()) {
                for (CandidateInfo info : list) {
                    if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
                        return false;
                    }
                }
            }
        } else {
            List<CandidateInfo> byName = methodsMap.get(name);
            if (byName != null) {
                for (CandidateInfo info : byName) {
                    if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
                        return false;
                    }
                }
            }
        }
    }
    final GrTypeDefinitionBody body = grType.getBody();
    if (body != null) {
        if (ResolveUtil.shouldProcessClasses(classHint)) {
            for (PsiClass innerClass : getInnerClassesForResolve(grType, lastParent, place)) {
                if (name != null && !name.equals(innerClass.getName()))
                    continue;
                if (!processor.execute(innerClass, state))
                    return false;
            }
        }
    }
    return true;
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) ElementClassHint(com.intellij.psi.scope.ElementClassHint) CandidateInfo(com.intellij.psi.infos.CandidateInfo) GrTypeDefinitionBody(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) LanguageLevel(com.intellij.pom.java.LanguageLevel) GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrReferenceList(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList) NameHint(com.intellij.psi.scope.NameHint)

Example 94 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 95 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