Search in sources :

Example 1 with LanguageLevel

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

the class GroovyHotSwapper method patchJavaParameters.

@Override
public void patchJavaParameters(Executor executor, RunProfile configuration, JavaParameters javaParameters) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    if (!executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
        return;
    }
    if (!GroovyDebuggerSettings.getInstance().ENABLE_GROOVY_HOTSWAP) {
        return;
    }
    if (hasSpringLoadedReloader(javaParameters)) {
        return;
    }
    if (!(configuration instanceof RunConfiguration)) {
        return;
    }
    final Project project = ((RunConfiguration) configuration).getProject();
    if (project == null) {
        return;
    }
    if (!LanguageLevelProjectExtension.getInstance(project).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
        return;
    }
    if (configuration instanceof ModuleBasedConfiguration) {
        final Module module = ((ModuleBasedConfiguration) configuration).getConfigurationModule().getModule();
        if (module != null) {
            final LanguageLevel level = LanguageLevelModuleExtensionImpl.getInstance(module).getLanguageLevel();
            if (level != null && !level.isAtLeast(LanguageLevel.JDK_1_5)) {
                return;
            }
        }
    }
    Sdk jdk = javaParameters.getJdk();
    if (jdk != null) {
        String vendor = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VENDOR);
        if (vendor != null && vendor.contains("IBM")) {
            LOG.info("Due to IBM JDK peculiarities (IDEA-59070) we don't add Groovy agent when running applications under it");
            return;
        }
    }
    if (!project.isDefault() && containsGroovyClasses(project)) {
        final String agentPath = handleSpacesInPath(getAgentJarPath());
        if (agentPath != null) {
            javaParameters.getVMParametersList().add("-javaagent:" + agentPath);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) LanguageLevel(com.intellij.pom.java.LanguageLevel) Sdk(com.intellij.openapi.projectRoots.Sdk) ModuleBasedConfiguration(com.intellij.execution.configurations.ModuleBasedConfiguration) Module(com.intellij.openapi.module.Module)

Example 2 with LanguageLevel

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

the class MavenModuleImporter method configLanguageLevel.

private void configLanguageLevel() {
    if ("false".equalsIgnoreCase(System.getProperty("idea.maven.configure.language.level")))
        return;
    LanguageLevel level = null;
    Element cfg = myMavenProject.getPluginConfiguration("com.googlecode", "maven-idea-plugin");
    if (cfg != null) {
        level = MAVEN_IDEA_PLUGIN_LEVELS.get(cfg.getChildTextTrim("jdkLevel"));
    }
    if (level == null) {
        level = LanguageLevel.parse(myMavenProject.getSourceLevel());
    }
    // default source and target settings of maven-compiler-plugin is 1.5, see details at http://maven.apache.org/plugins/maven-compiler-plugin
    if (level == null) {
        level = LanguageLevel.JDK_1_5;
    }
    myRootModelAdapter.setLanguageLevel(level);
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) Element(org.jdom.Element)

Example 3 with LanguageLevel

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

the class Java15FormInspection method checkComponentProperties.

protected void checkComponentProperties(Module module, final IComponent component, final FormErrorCollector collector) {
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
    if (aClass == null) {
        return;
    }
    for (final IProperty prop : component.getModifiedProperties()) {
        final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, prop.getName(), false, true);
        if (getter == null)
            continue;
        final LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
        if (Java15APIUsageInspection.getLastIncompatibleLanguageLevel(getter, languageLevel) != null) {
            registerError(component, collector, prop, "@since " + Java15APIUsageInspection.getShortName(languageLevel));
        }
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IProperty(com.intellij.uiDesigner.lw.IProperty) PsiMethod(com.intellij.psi.PsiMethod) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

Example 4 with LanguageLevel

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

the class SceneBuilderImpl method collectCustomComponents.

private Collection<CustomComponent> collectCustomComponents() {
    if (myProject.isDisposed()) {
        return Collections.emptyList();
    }
    final PsiClass nodeClass = JavaPsiFacade.getInstance(myProject).findClass(JavaFxCommonNames.JAVAFX_SCENE_NODE, GlobalSearchScope.allScope(myProject));
    if (nodeClass == null) {
        return Collections.emptyList();
    }
    final Collection<PsiClass> psiClasses = CachedValuesManager.getCachedValue(nodeClass, () -> {
        // Take custom components from libraries, but not from the project modules, because SceneBuilder instantiates the components' classes.
        // Modules might be not compiled or may change since last compile, it's too expensive to keep track of that.
        final GlobalSearchScope scope = ProjectScope.getLibrariesScope(nodeClass.getProject());
        final String ideJdkVersion = Object.class.getPackage().getSpecificationVersion();
        final LanguageLevel ideLanguageLevel = LanguageLevel.parse(ideJdkVersion);
        final Query<PsiClass> query = ClassInheritorsSearch.search(nodeClass, scope, true, true, false);
        final Set<PsiClass> result = new THashSet<>();
        query.forEach(psiClass -> {
            if (psiClass.hasModifierProperty(PsiModifier.PUBLIC) && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT) && !isBuiltInComponent(psiClass) && isCompatibleLanguageLevel(psiClass, ideLanguageLevel)) {
                result.add(psiClass);
            }
        });
        return CachedValueProvider.Result.create(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    });
    if (psiClasses.isEmpty()) {
        return Collections.emptyList();
    }
    return prepareCustomComponents(psiClasses);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) THashSet(gnu.trove.THashSet)

Example 5 with LanguageLevel

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

the class CompileDriver method validateCompilerConfiguration.

private boolean validateCompilerConfiguration(final CompileScope scope) {
    try {
        final Module[] scopeModules = scope.getAffectedModules();
        final List<String> modulesWithoutOutputPathSpecified = new ArrayList<>();
        final List<String> modulesWithoutJdkAssigned = new ArrayList<>();
        final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
        for (final Module module : scopeModules) {
            if (!compilerManager.isValidationEnabled(module)) {
                continue;
            }
            final boolean hasSources = hasSources(module, JavaSourceRootType.SOURCE);
            final boolean hasTestSources = hasSources(module, JavaSourceRootType.TEST_SOURCE);
            if (!hasSources && !hasTestSources) {
                // todo still there may be problems with this approach if some generated files are attributed by this module
                continue;
            }
            final Sdk jdk = ModuleRootManager.getInstance(module).getSdk();
            if (jdk == null) {
                modulesWithoutJdkAssigned.add(module.getName());
            }
            final String outputPath = getModuleOutputPath(module, false);
            final String testsOutputPath = getModuleOutputPath(module, true);
            if (outputPath == null && testsOutputPath == null) {
                modulesWithoutOutputPathSpecified.add(module.getName());
            } else {
                if (outputPath == null) {
                    if (hasSources) {
                        modulesWithoutOutputPathSpecified.add(module.getName());
                    }
                }
                if (testsOutputPath == null) {
                    if (hasTestSources) {
                        modulesWithoutOutputPathSpecified.add(module.getName());
                    }
                }
            }
        }
        if (!modulesWithoutJdkAssigned.isEmpty()) {
            showNotSpecifiedError("error.jdk.not.specified", modulesWithoutJdkAssigned, ProjectBundle.message("modules.classpath.title"));
            return false;
        }
        if (!modulesWithoutOutputPathSpecified.isEmpty()) {
            showNotSpecifiedError("error.output.not.specified", modulesWithoutOutputPathSpecified, CommonContentEntriesEditor.NAME);
            return false;
        }
        final List<Chunk<ModuleSourceSet>> chunks = ModuleCompilerUtil.getCyclicDependencies(myProject, Arrays.asList(scopeModules));
        for (final Chunk<ModuleSourceSet> chunk : chunks) {
            final Set<ModuleSourceSet> sourceSets = chunk.getNodes();
            if (sourceSets.size() <= 1) {
                // no need to check one-module chunks
                continue;
            }
            Sdk jdk = null;
            LanguageLevel languageLevel = null;
            for (final ModuleSourceSet sourceSet : sourceSets) {
                Module module = sourceSet.getModule();
                final Sdk moduleJdk = ModuleRootManager.getInstance(module).getSdk();
                if (jdk == null) {
                    jdk = moduleJdk;
                } else {
                    if (!jdk.equals(moduleJdk)) {
                        showCyclicModulesHaveDifferentJdksError(ModuleSourceSet.getModules(sourceSets));
                        return false;
                    }
                }
                LanguageLevel moduleLanguageLevel = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module);
                if (languageLevel == null) {
                    languageLevel = moduleLanguageLevel;
                } else {
                    if (!languageLevel.equals(moduleLanguageLevel)) {
                        showCyclicModulesHaveDifferentLanguageLevel(ModuleSourceSet.getModules(sourceSets));
                        return false;
                    }
                }
            }
        }
        return true;
    } catch (Throwable e) {
        LOG.info(e);
        return false;
    }
}
Also used : Chunk(com.intellij.util.Chunk) LanguageLevel(com.intellij.pom.java.LanguageLevel) Sdk(com.intellij.openapi.projectRoots.Sdk) 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