Search in sources :

Example 1 with JavaSourceRootProperties

use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.

the class MavenSourceFoldersModuleExtension method commit.

@Override
public void commit() {
    if (!isJpsSourceFoldersChanged)
        return;
    for (ContentEntry eachEntry : myRootModel.getContentEntries()) {
        for (SourceFolder eachFolder : eachEntry.getSourceFolders()) {
            boolean found = false;
            for (JpsSourceFolder jpsSourceFolder : myJpsSourceFolders) {
                if (StringUtil.equals(jpsSourceFolder.getUrl(), eachFolder.getUrl()) && eachFolder.getRootType().equals(jpsSourceFolder.getRootType())) {
                    found = true;
                    if (eachFolder.getRootType() instanceof JavaSourceRootType) {
                        final JavaSourceRootProperties jpsJavaSourceRootProperties = jpsSourceFolder.getJpsElement().getProperties((JavaSourceRootType) eachFolder.getRootType());
                        final JavaSourceRootProperties javaSourceRootProperties = eachFolder.getJpsElement().getProperties((JavaSourceRootType) eachFolder.getRootType());
                        if (javaSourceRootProperties != null && jpsJavaSourceRootProperties != null) {
                            javaSourceRootProperties.applyChanges(jpsJavaSourceRootProperties);
                        }
                    }
                    myJpsSourceFolders.remove(jpsSourceFolder);
                    Disposer.dispose(jpsSourceFolder);
                    break;
                }
            }
            if (!found) {
                eachEntry.removeSourceFolder(eachFolder);
            }
        }
    }
    for (JpsSourceFolder jpsSourceFolder : myJpsSourceFolders) {
        Url url = new Url(jpsSourceFolder.getUrl());
        ContentEntry e = getContentRootFor(url);
        if (e == null)
            continue;
        //noinspection unchecked
        JpsModuleSourceRootType<JpsElement> sourceRootType = (JpsModuleSourceRootType<JpsElement>) jpsSourceFolder.getRootType();
        final JpsElementBase properties = (JpsElementBase) jpsSourceFolder.getSourceRoot().getProperties();
        //noinspection unchecked
        properties.setParent(null);
        e.addSourceFolder(url.getUrl(), sourceRootType, properties);
    }
    isJpsSourceFoldersChanged = false;
}
Also used : JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder) JpsElement(org.jetbrains.jps.model.JpsElement) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) JpsContentEntry(com.intellij.project.model.impl.module.content.JpsContentEntry) JpsElementBase(org.jetbrains.jps.model.ex.JpsElementBase) JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties) Url(org.jetbrains.idea.maven.utils.Url)

Example 2 with JavaSourceRootProperties

use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.

the class MarkGeneratedSourceRootAction method modifyRoots.

@Override
protected void modifyRoots(@NotNull VirtualFile vFile, @NotNull ContentEntry entry) {
    JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties("", true);
    entry.addSourceFolder(vFile, JavaSourceRootType.SOURCE, properties);
}
Also used : JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 3 with JavaSourceRootProperties

use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.

the class AnalysisScopeTest method testGeneratedSourceRoot.

public void testGeneratedSourceRoot() throws Exception {
    VirtualFile genRoot = getVirtualFile(createTempDir("genSrcRoot"));
    VirtualFile srcRoot = getVirtualFile(createTempDir("srcRoot"));
    JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties("", true);
    PsiTestUtil.addSourceRoot(myModule, genRoot, JavaSourceRootType.SOURCE, properties);
    PsiTestUtil.addSourceRoot(myModule, srcRoot);
    VirtualFile genClass = VfsTestUtil.createFile(genRoot, "Gen.java", "class Gen{}");
    VirtualFile srcClass = VfsTestUtil.createFile(srcRoot, "Src.java", "class Src{}");
    AnalysisScope scope = new AnalysisScope(myModule);
    assertTrue(scope.contains(srcClass));
    assertFalse(scope.contains(genClass));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnalysisScope(com.intellij.analysis.AnalysisScope) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 4 with JavaSourceRootProperties

use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project android by JetBrains.

the class AndroidCompileUtil method markRootAsGenerated.

private static void markRootAsGenerated(ModifiableRootModel model, VirtualFile root, Ref<Boolean> modelChangedFlag) {
    final ContentEntry contentEntry = findContentEntryForRoot(model, root);
    if (contentEntry == null) {
        return;
    }
    for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
        if (root.equals(sourceFolder.getFile())) {
            final JavaSourceRootProperties props = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
            if (props != null) {
                props.setForGeneratedSources(true);
                modelChangedFlag.set(true);
                break;
            }
        }
    }
}
Also used : JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 5 with JavaSourceRootProperties

use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.

the class JavaSourceRootEditHandlerBase method createPropertiesEditor.

@Nullable
@Override
public JComponent createPropertiesEditor(@NotNull final SourceFolder folder, @NotNull final JComponent parentComponent, @NotNull final ContentRootPanel.ActionCallback callback) {
    final IconActionComponent iconComponent = new IconActionComponent(AllIcons.Modules.SetPackagePrefix, AllIcons.Modules.SetPackagePrefixRollover, ProjectBundle.message("module.paths.edit.properties.tooltip"), () -> {
        JavaSourceRootProperties properties = folder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
        assert properties != null;
        SourceRootPropertiesDialog dialog = new SourceRootPropertiesDialog(parentComponent, properties);
        if (dialog.showAndGet()) {
            callback.onSourceRootPropertiesChanged(folder);
        }
    });
    final JPanel panel = new JPanel(new BorderLayout());
    panel.setOpaque(false);
    panel.add(iconComponent, BorderLayout.CENTER);
    panel.add(Box.createHorizontalStrut(3), BorderLayout.EAST);
    return panel;
}
Also used : IconActionComponent(com.intellij.ui.roots.IconActionComponent) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)21 SourceFolder (com.intellij.openapi.roots.SourceFolder)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)5 JpsElement (org.jetbrains.jps.model.JpsElement)4 JavaSourceRootType (org.jetbrains.jps.model.java.JavaSourceRootType)4 File (java.io.File)3 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 JavaResourceRootProperties (org.jetbrains.jps.model.java.JavaResourceRootProperties)2 AnalysisScope (com.intellij.analysis.AnalysisScope)1 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)1 Module (com.intellij.openapi.module.Module)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1