Java Code Examples for com.intellij.openapi.module.Module#getName()

The following examples show how to use com.intellij.openapi.module.Module#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiElementModuleRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showProjectLocation(PsiFile psiFile, Module module, ProjectFileIndex fileIndex) {
  boolean inTestSource = false;
  if (psiFile != null) {
    VirtualFile vFile = psiFile.getVirtualFile();
    if (vFile != null) {
      inTestSource = fileIndex.isInTestSourceContent(vFile);
    }
  }
  myText = module.getName();
  if (inTestSource) {
    setIcon(AllIcons.Nodes.TestPackage);
  }
  else {
    setIcon(AllIcons.Nodes.Module);
  }
}
 
Example 2
Source File: ProgramParametersConfigurator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void checkWorkingDirectoryExist(CommonProgramRunConfigurationParameters configuration, Project project, Module module) throws RuntimeConfigurationWarning {
  final String workingDir = getWorkingDir(configuration, project, module);
  if (workingDir == null) {
    throw new RuntimeConfigurationWarning("Working directory is null for " +
                                          "project '" +
                                          project.getName() +
                                          "' (" +
                                          project.getBasePath() +
                                          ")" +
                                          ", module " +
                                          (module == null ? "null" : "'" + module.getName() + "' (" + module.getModuleDirPath() + ")"));
  }
  if (!new File(workingDir).exists()) {
    throw new RuntimeConfigurationWarning("Working directory '" + workingDir + "' doesn't exist");
  }
}
 
Example 3
Source File: ModuleUrl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public AbstractUrl createUrlByElement(Object element) {
  if (element instanceof Module) {
    Module module = (Module)element;
    return new ModuleUrl("", module.getName());
  }
  return null;
}
 
Example 4
Source File: FavoritesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void beforePropertyChange(@Nonnull final PsiTreeChangeEvent event) {
  if (event.getPropertyName().equals(PsiTreeChangeEvent.PROP_FILE_NAME) || event.getPropertyName().equals(PsiTreeChangeEvent.PROP_DIRECTORY_NAME)) {
    final PsiElement psiElement = event.getChild();
    if (psiElement instanceof PsiFile || psiElement instanceof PsiDirectory) {
      final Module module = ModuleUtil.findModuleForPsiElement(psiElement);
      if (module == null) return;
      final String url = ((PsiDirectory)psiElement.getParent()).getVirtualFile().getUrl() + "/" + event.getNewValue();
      final AbstractUrl childUrl = psiElement instanceof PsiFile ? new PsiFileUrl(url) : new DirectoryUrl(url, module.getName());

      for (String listName : myName2FavoritesRoots.keySet()) {
        final List<TreeItem<Pair<AbstractUrl, String>>> roots = myName2FavoritesRoots.get(listName);
        iterateTreeItems(roots, new Consumer<TreeItem<Pair<AbstractUrl, String>>>() {
          @Override
          public void consume(TreeItem<Pair<AbstractUrl, String>> item) {
            final Pair<AbstractUrl, String> root = item.getData();
            final Object[] path = root.first.createPath(myProject);
            if (path == null || path.length < 1 || path[0] == null) {
              return;
            }
            final Object element = path[path.length - 1];
            if (element == psiElement && psiElement instanceof PsiFile) {
              item.setData(Pair.create(childUrl, root.second));
            }
            else {
              item.setData(root);
            }
          }
        });
      }
    }
  }
}
 
Example 5
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
public void getState0(Element element) {
  final Element modulesElement = new Element(ELEMENT_MODULES);
  final Module[] modules = getModules();

  for (Module module : modules) {
    Element moduleElement = new Element(ELEMENT_MODULE);
    String name = module.getName();
    final String[] moduleGroupPath = getModuleGroupPath(module);
    if (moduleGroupPath != null) {
      name = StringUtil.join(moduleGroupPath, MODULE_GROUP_SEPARATOR) + MODULE_GROUP_SEPARATOR + name;
    }
    moduleElement.setAttribute(ATTRIBUTE_NAME, name);
    String moduleDirUrl = module.getModuleDirUrl();
    if (moduleDirUrl != null) {
      moduleElement.setAttribute(ATTRIBUTE_DIRURL, moduleDirUrl);
    }

    final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
    moduleRootManager.saveState(moduleElement);

    collapseOrExpandMacros(module, moduleElement, true);

    modulesElement.addContent(moduleElement);
  }

  for (ModuleLoadItem failedModulePath : new ArrayList<>(myFailedModulePaths)) {
    final Element clone = failedModulePath.getElement().clone();
    modulesElement.addContent(clone);
  }

  element.addContent(modulesElement);
}
 
Example 6
Source File: ModuleElementPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void render(@Nonnull PresentationData presentationData,
                   SimpleTextAttributes mainAttributes,
                   SimpleTextAttributes commentAttributes) {
  final Module module = findModule();
  presentationData.setIcon(myContentFolderType.getIcon());

  String moduleName;
  if (module != null) {
    moduleName = module.getName();
    final ModifiableModuleModel moduleModel = myContext.getModifiableModuleModel();
    if (moduleModel != null) {
      final String newName = moduleModel.getNewName(module);
      if (newName != null) {
        moduleName = newName;
      }
    }
  }
  else if (myModulePointer != null) {
    moduleName = myModulePointer.getName();
  }
  else {
    moduleName = "<unknown>";
  }

  presentationData
    .addText(CompilerBundle.message("node.text.0.1.compile.output", moduleName, StringUtil.toLowerCase(myContentFolderType.getName())),
             module != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES);
}
 
Example 7
Source File: HaxeModuleConfigurationEditorProvider.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public ModuleConfigurationEditor[] createEditors(final ModuleConfigurationState state) {
  final Module module = state.getRootModel().getModule();
  if (ModuleType.get(module) != HaxeModuleType.getInstance()) {
    return ModuleConfigurationEditor.EMPTY;
  }
  return new ModuleConfigurationEditor[]{
    new CommonContentEntriesEditor(module.getName(), state, JavaSourceRootType.SOURCE, JavaSourceRootType.TEST_SOURCE),
    new ClasspathEditor(state),
    new HaxeModuleConfigurationEditor(state)
  };
}
 
Example 8
Source File: RoutesView.java    From railways with MIT License 5 votes vote down vote up
public void addModulePane(Module module) {
    // Skip if RoutesView is not initialized or if added module is not
    // Rails application.
    RailsApp railsApp = RailsApp.fromModule(module);
    if ((myContentManager == null) || railsApp == null)
        return;

    // Register content, so we'll have a combo-box instead tool window
    // title, and each item will represent a module.
    String contentTitle = module.getName();
    Content content = myContentManager.getFactory().createContent(getComponent(),
            contentTitle, false);
    content.setTabName(contentTitle);
    content.setIcon(ModuleType.get(module).getIcon());

    // Set tool window icon to be the same as selected module icon
    content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
    myContentManager.addContent(content);

    // Bind content with pane for further use
    RoutesViewPane pane = new RoutesViewPane(railsApp, myToolWindow, content);
    myPanes.add(pane);

    // Register contributor
    ChooseByRouteRegistry.getInstance(myProject)
            .addContributorFor(pane.getRoutesManager());

    // Subscribe to RoutesManager events.
    pane.getRoutesManager().addListener(new MyRoutesManagerListener());

    // And select pane if it's the first one.
    if (myPanes.size() == 1)
        setCurrentPane(pane);
}
 
Example 9
Source File: ModuleNameTracker.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void modulesRenamed(final Project project, final List<Module> modules) {
  if (myProject != project) {
    return;
  }

  Map<String, String> old2newNames = new HashMap<String, String>(modules.size());
  for (Module module : modules) {
    String newName = module.getName();
    String oldName = myModulesNames.put(module, newName);
    old2newNames.put(oldName, newName);
  }
  modulesRenamed(project, old2newNames);
}
 
Example 10
Source File: HaskellModuleConfigurationEditor.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) {
    Module module = state.getRootModel().getModule();
    if (!(ModuleType.get(module) instanceof HaskellModuleType)) {
        return ModuleConfigurationEditor.EMPTY;
    }
    return new ModuleConfigurationEditor[]{
            new JavaContentEntriesEditor(module.getName(), state),
            // new CabalFilesEditor(state),
            new ClasspathEditor(state),
    };
}
 
Example 11
Source File: IBIntegratorManager.java    From robovm-idea with GNU General Public License v2.0 5 votes vote down vote up
public static String getModuleId(Module module) {
    if(module.getProject().getName().equals(module.getName())) {
        return module.getName();
    } else {
        return module.getProject().getName() + "." + module.getName();
    }
}
 
Example 12
Source File: ModuleVcsDetector.java    From consulo with Apache License 2.0 5 votes vote down vote up
private List<Pair<String, VcsDirectoryMapping>> getMappings(final Module module) {
  List<Pair<String, VcsDirectoryMapping>> result = new ArrayList<Pair<String, VcsDirectoryMapping>>();
  final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
  final String moduleName = module.getName();
  for(final VirtualFile file: files) {
    for(final VcsDirectoryMapping mapping: myVcsManager.getDirectoryMappings()) {
      if (FileUtil.toSystemIndependentName(mapping.getDirectory()).equals(file.getPath())) {
        result.add(new Pair<String, VcsDirectoryMapping>(moduleName, mapping));
        break;
      }
    }
  }
  return result;
}
 
Example 13
Source File: MuleModulesCheckBoxList.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public void setModules(Collection<Module> modules) {
    DefaultListModel<JCheckBox> myModel = (DefaultListModel<JCheckBox>)getModel();
    for (Module module : modules) {
        if (!containsModule(module.getName())) {
            JCheckBox cb = new JCheckBox(module.getName());
            myModel.addElement(cb);
        }
    }
}
 
Example 14
Source File: OCamlDefaultModuleEditorsProvider.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ModuleConfigurationEditor[] createEditors(@NotNull ModuleConfigurationState state) {
    Module module = state.getRootModel().getModule();
    if (ModuleType.get(module) instanceof OCamlModuleType) {
        return new ModuleConfigurationEditor[]{
                new OCamlContentEntriesEditor(module.getName(), state)
        };
    }

    return ModuleConfigurationEditor.EMPTY;
}
 
Example 15
Source File: ModuleCellRenderer.java    From Plugin with MIT License 4 votes vote down vote up
public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus)
{
    Module module = (Module)value;

    //Check for first runthrough
    if(nameLabel == null){
        //Initialize name panel
        this.setLayout(new FlowLayout());

        //Set layout
        this.setLayout(new FlowLayout(FlowLayout.LEFT));

        //Set name label
        nameLabel = new JLabel(module.getName(), JLabel.LEFT);
        //nameLabel.setFont(new Font(nameLabel.getFont().getName(), Font.PLAIN, 18));



        //Add components
        this.add(nameLabel);
    }
    else {
        //Set name label
        nameLabel.setText(module.getName());
    }

    if(isSelected) {
        setBackground(cellBackgroundColor.darker());
        setOpaque(true);
        //setForeground(Color.white);
    } else {
        setOpaque(false);
        //setForeground(Color.black);
    }
    return this;
}
 
Example 16
Source File: KnowledgeViewProjectNode.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
  final ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
  final PsiManager psiManager = PsiManager.getInstance(getProject());

  for (final Module m : ModuleManager.getInstance(myProject).getModules()) {
    final VirtualFile knowledgeFolder = IdeaUtils.findKnowledgeFolderForModule(m, false);
    if (knowledgeFolder != null) {

      final String moduleName = m.getName();

      final PsiDirectory dir = psiManager.findDirectory(knowledgeFolder);
      final PsiDirectoryNode node = new PsiDirectoryNode(myProject, dir, getSettings()) {

        protected Icon patchIcon(final Icon original, final VirtualFile file) {
          return AllIcons.File.FOLDER;
        }

        @Override
        public String getTitle() {
          return moduleName;
        }

        @Override
        public String toString() {
          return moduleName;
        }

        @Override
        public boolean isFQNameShown() {
          return false;
        }

        @Override
        public VirtualFile getVirtualFile() {
          return knowledgeFolder;
        }

        @Nullable
        @Override
        protected String calcTooltip() {
          return "The Knowledge folder for " + m.getName();
        }

        @Override
        protected boolean shouldShowModuleName() {
          return false;
        }

      };
      result.add(node);
    }
  }
  return result;
}
 
Example 17
Source File: GaugeRunConfiguration.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
public void setModule(Module module) {
    this.module = module;
    this.moduleName = module.getName();
}
 
Example 18
Source File: BlazePythonSyncPlugin.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
private static LibraryContributingFacet<?> getOrCreatePythonFacet(
    Project project, BlazeContext context, Module module, BlazeProjectData blazeProjectData) {
  LibraryContributingFacet<?> facet = findPythonFacet(module);
  if (facet != null && isValidPythonSdk(PythonFacetUtil.getSdk(facet))) {
    return facet;
  }
  FacetManager manager = FacetManager.getInstance(module);
  ModifiableFacetModel facetModel = manager.createModifiableModel();
  if (facet != null) {
    // we can't modify in place, IntelliJ has no hook to trigger change events. Instead we create
    // a new facet.
    facetModel.removeFacet(facet);
  }

  Sdk sdk = getPythonSdk(project, blazeProjectData, context);
  if (sdk == null) {
    String fixDirections =
        "Configure a suitable Python Interpreter for the module \""
            + module.getName()
            + "\" via File->\"Project Structure...\", \"Project Settings\"->\"Facets\", then"
            + " sync the project again.";
    if (PlatformUtils.isCLion()) {
      fixDirections =
          "Configure a suitable Python Interpreter for the module \""
              + module.getName()
              + "\" via File->\"Settings...\", \"Build,"
              + " Execution, Deployment\"->\"Python Interpreter\", then sync the project again.";
    }
    String msg = "Unable to find a compatible Python SDK installed.\n" + fixDirections;
    IssueOutput.error(msg).submit(context);
    return null;
  }

  facet = manager.createFacet(PythonFacetUtil.getFacetType(), "Python", null);
  // This is ugly like this to get around PythonFacet related classes being in different package
  // paths in different IDEs. Thankfully, PythonFacetSettings is in the same packackage path.
  if (facet.getConfiguration() instanceof PythonFacetSettings) {
    ((PythonFacetSettings) facet.getConfiguration()).setSdk(sdk);
  }
  facetModel.addFacet(facet);
  facetModel.commit();
  return facet;
}
 
Example 19
Source File: DirectoryUrl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static DirectoryUrl create(PsiDirectory directory) {
  Project project = directory.getProject();
  final VirtualFile virtualFile = directory.getVirtualFile();
  final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
  return new DirectoryUrl(virtualFile.getUrl(), module != null ? module.getName() : null);
}
 
Example 20
Source File: StructureConfigurableContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
public String getRealName(final Module module) {
  final ModifiableModuleModel moduleModel = myModulesConfigurator.getModuleModel();
  String newName = moduleModel.getNewName(module);
  return newName != null ? newName : module.getName();
}