Search in sources :

Example 31 with LanguageLevel

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

the class BaseGradleProjectResolverExtension method createJavaProjectData.

@NotNull
@Override
public JavaProjectData createJavaProjectData() {
    final String projectDirPath = resolverCtx.getProjectPath();
    final IdeaProject ideaProject = resolverCtx.getModels().getIdeaProject();
    // Gradle API doesn't expose gradleProject compile output path yet.
    JavaProjectData javaProjectData = new JavaProjectData(GradleConstants.SYSTEM_ID, projectDirPath + "/build/classes");
    javaProjectData.setJdkVersion(ideaProject.getJdkName());
    LanguageLevel resolvedLanguageLevel = null;
    // org.gradle.tooling.model.idea.IdeaLanguageLevel.getLevel() returns something like JDK_1_6
    final String languageLevel = ideaProject.getLanguageLevel().getLevel();
    for (LanguageLevel level : LanguageLevel.values()) {
        if (level.name().equals(languageLevel)) {
            resolvedLanguageLevel = level;
            break;
        }
    }
    if (resolvedLanguageLevel != null) {
        javaProjectData.setLanguageLevel(resolvedLanguageLevel);
    } else {
        javaProjectData.setLanguageLevel(languageLevel);
    }
    return javaProjectData;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) JavaProjectData(com.intellij.externalSystem.JavaProjectData) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with LanguageLevel

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

the class TypesUtil method getLeastUpperBound.

@Nullable
public static PsiType getLeastUpperBound(@NotNull PsiType type1, @NotNull PsiType type2, PsiManager manager) {
    {
        PsiType numericLUB = getNumericLUB(type1, type2);
        if (numericLUB != null)
            return numericLUB;
    }
    if (type1 instanceof GrTupleType && type2 instanceof GrTupleType) {
        GrTupleType tuple1 = (GrTupleType) type1;
        GrTupleType tuple2 = (GrTupleType) type2;
        PsiType[] components1 = tuple1.getComponentTypes();
        PsiType[] components2 = tuple2.getComponentTypes();
        if (components1.length == 0)
            return genNewListBy(type2, manager);
        if (components2.length == 0)
            return genNewListBy(type1, manager);
        PsiType[] components3 = PsiType.createArray(Math.min(components1.length, components2.length));
        for (int i = 0; i < components3.length; i++) {
            PsiType c1 = components1[i];
            PsiType c2 = components2[i];
            if (c1 == null || c2 == null) {
                components3[i] = null;
            } else {
                components3[i] = getLeastUpperBound(c1, c2, manager);
            }
        }
        return new GrImmediateTupleType(components3, JavaPsiFacade.getInstance(manager.getProject()), tuple1.getScope().intersectWith(tuple2.getResolveScope()));
    } else if (checkEmptyListAndList(type1, type2)) {
        return genNewListBy(type2, manager);
    } else if (checkEmptyListAndList(type2, type1)) {
        return genNewListBy(type1, manager);
    } else if (type1 instanceof GrMapType && type2 instanceof GrMapType) {
        return GrMapType.merge(((GrMapType) type1), ((GrMapType) type2));
    } else if (checkEmptyMapAndMap(type1, type2)) {
        return genNewMapBy(type2, manager);
    } else if (checkEmptyMapAndMap(type2, type1)) {
        return genNewMapBy(type1, manager);
    } else if (type1 instanceof GrClosureType && type2 instanceof GrClosureType) {
        GrClosureType clType1 = (GrClosureType) type1;
        GrClosureType clType2 = (GrClosureType) type2;
        GrSignature signature1 = clType1.getSignature();
        GrSignature signature2 = clType2.getSignature();
        if (signature1 instanceof GrClosureSignature && signature2 instanceof GrClosureSignature) {
            if (((GrClosureSignature) signature1).getParameterCount() == ((GrClosureSignature) signature2).getParameterCount()) {
                final GrClosureSignature signature = GrImmediateClosureSignatureImpl.getLeastUpperBound(((GrClosureSignature) signature1), ((GrClosureSignature) signature2), manager);
                if (signature != null) {
                    GlobalSearchScope scope = clType1.getResolveScope().intersectWith(clType2.getResolveScope());
                    final LanguageLevel languageLevel = ComparatorUtil.max(clType1.getLanguageLevel(), clType2.getLanguageLevel());
                    return GrClosureType.create(signature, scope, JavaPsiFacade.getInstance(manager.getProject()), languageLevel, true);
                }
            }
        }
    } else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(getQualifiedName(type1)) && CommonClassNames.JAVA_LANG_STRING.equals(getQualifiedName(type2))) {
        return type2;
    } else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(getQualifiedName(type2)) && CommonClassNames.JAVA_LANG_STRING.equals(getQualifiedName(type1))) {
        return type1;
    }
    return GenericsUtil.getLeastUpperBound(type1, type2, manager);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LanguageLevel(com.intellij.pom.java.LanguageLevel) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with LanguageLevel

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

the class UncheckedWarningLocalInspectionBase method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
    LanguageLevel languageLevel = PsiUtil.getLanguageLevel(session.getFile());
    if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_5))
        return super.buildVisitor(holder, isOnTheFly, session);
    return new UncheckedWarningsVisitor(isOnTheFly, languageLevel) {

        @Override
        protected void registerProblem(@NotNull String message, @Nullable PsiElement callExpression, @NotNull PsiElement psiElement, @NotNull LocalQuickFix[] quickFixes) {
            final String rawExpression = isMethodCalledOnRawType(callExpression);
            if (rawExpression != null) {
                final String referenceName = ((PsiMethodCallExpression) callExpression).getMethodExpression().getReferenceName();
                message += ". Reason: '" + rawExpression + "' has raw type, so result of " + referenceName + " is erased";
            }
            holder.registerProblem(psiElement, message, quickFixes);
        }
    };
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with LanguageLevel

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

the class JavaPsiImplementationHelperImpl method getEffectiveLanguageLevel.

@NotNull
@Override
public LanguageLevel getEffectiveLanguageLevel(@Nullable VirtualFile virtualFile) {
    if (virtualFile == null)
        return PsiUtil.getLanguageLevel(myProject);
    // prevent expensive look-up into VFS
    if (myProject.isDefault())
        return PsiUtil.getLanguageLevel(myProject);
    final VirtualFile folder = virtualFile.getParent();
    if (folder != null) {
        final LanguageLevel level = folder.getUserData(LanguageLevel.KEY);
        if (level != null)
            return level;
    }
    final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
    Module module = index.getModuleForFile(virtualFile);
    if (module != null && index.isInSourceContent(virtualFile)) {
        return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module);
    }
    LanguageLevel classesLanguageLevel = getClassesLanguageLevel(virtualFile);
    return classesLanguageLevel != null ? classesLanguageLevel : PsiUtil.getLanguageLevel(myProject);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with LanguageLevel

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

the class TurnRefsToSuperProcessor method isInSuper.

protected boolean isInSuper(PsiElement member) {
    if (!(member instanceof PsiMember))
        return false;
    final PsiManager manager = member.getManager();
    if (InheritanceUtil.isInheritorOrSelf(mySuper, ((PsiMember) member).getContainingClass(), true))
        return true;
    if (member instanceof PsiField) {
        final PsiClass containingClass = ((PsiField) member).getContainingClass();
        LanguageLevel languageLevel = PsiUtil.getLanguageLevel(member);
        if (manager.areElementsEquivalent(containingClass, JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().getArrayClass(languageLevel))) {
            return true;
        }
    } else if (member instanceof PsiMethod) {
        return mySuper.findMethodBySignature((PsiMethod) member, true) != null;
    }
    return false;
}
Also used : 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