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

The following examples show how to use com.intellij.openapi.module.Module#equals() . 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: WeaveConfigurationProducer.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isConfigurationFromContext(WeaveConfiguration muleConfiguration, ConfigurationContext configurationContext)
{
    final Module module = configurationContext.getModule();
    final PsiFile containingFile = configurationContext.getPsiLocation().getContainingFile();
    if (containingFile == null)
    {
        return false;
    }
    final String canonicalPath = containingFile.getVirtualFile().getCanonicalPath();
    final String weaveFile = muleConfiguration.getWeaveFile();
    if (weaveFile == null)
    {
        return false;
    }
    return module != null && module.equals(muleConfiguration.getModule()) && weaveFile.equals(canonicalPath);
}
 
Example 2
Source File: ModuleDeleteProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void removeModule(@Nonnull final Module moduleToRemove,
                                 @Nullable ModifiableRootModel modifiableRootModelToRemove,
                                 @Nonnull Collection<ModifiableRootModel> otherModuleRootModels,
                                 @Nonnull final ModifiableModuleModel moduleModel) {
  // remove all dependencies on the module that is about to be removed
  for (final ModifiableRootModel modifiableRootModel : otherModuleRootModels) {
    final OrderEntry[] orderEntries = modifiableRootModel.getOrderEntries();
    for (final OrderEntry orderEntry : orderEntries) {
      if (orderEntry instanceof ModuleOrderEntry && orderEntry.isValid()) {
        final Module orderEntryModule = ((ModuleOrderEntry)orderEntry).getModule();
        if (orderEntryModule != null && orderEntryModule.equals(moduleToRemove)) {
          modifiableRootModel.removeOrderEntry(orderEntry);
        }
      }
    }
  }
  // destroyProcess editor
  if (modifiableRootModelToRemove != null) {
    modifiableRootModelToRemove.dispose();
  }
  // destroyProcess module
  moduleModel.disposeModule(moduleToRemove);
}
 
Example 3
Source File: LanguageServerWrapper.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Check whether this LS is suitable for provided project. Starts the LS if not
 * already started.
 *
 * @return whether this language server can operate on the given project
 * @since 0.5
 */
public boolean canOperate(Module project) {
    if (project != null && (project.equals(this.initialProject) || this.allWatchedProjects.contains(project))) {
        return true;
    }

    return serverDefinition.isSingleton || supportsWorkspaceFolderCapability();
}
 
Example 4
Source File: MuleApplicationConfigurationProducer.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isConfigurationFromContext(MuleConfiguration muleConfiguration, ConfigurationContext configurationContext)
{
    final Module module = configurationContext.getModule();
    if (module != null) {
        Module[] modules = muleConfiguration.getModules();
        for (Module m : modules) {
            if (module.equals(m))
                return true;
        }
    }
    return false;
}
 
Example 5
Source File: FileIsNotAttachedProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile virtualFile, @Nonnull FileEditor fileEditor)
{
	if(virtualFile.getFileType() != CSharpFileType.INSTANCE)
	{
		return null;
	}

	Unity3dRootModuleExtension rootModuleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(myProject);
	if(rootModuleExtension == null)
	{
		return null;
	}

	if(ProjectFileIndex.getInstance(myProject).isInLibraryClasses(virtualFile) || virtualFile instanceof MsilFileRepresentationVirtualFile)
	{
		return null;
	}

	Module module = ModuleUtilCore.findModuleForFile(virtualFile, myProject);

	if(module == null || module.equals(rootModuleExtension.getModule()))
	{
		EditorNotificationPanel panel = new EditorNotificationPanel();
		panel.text("File is not attached to project. Some features are unavailable (code analysis, debugging, etc)");
		panel.createActionLabel("Re-import Unity Project", () ->
		{
			Unity3dProjectImportUtil.syncProjectStep1(myProject, rootModuleExtension.getSdk(), null, true);
		});
		return panel;
	}
	return null;
}
 
Example 6
Source File: AssemblyModuleCache.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private static Set<String> calcSourceAllowedAssemblies(Module module)
{
	Set<String> assemblies = new HashSet<>();

	Collection<CSharpAttributeList> attributeLists = AttributeListIndex.getInstance().get(DotNetAttributeTargetType.ASSEMBLY, module.getProject(), GlobalSearchScope.moduleScope(module));

	for(CSharpAttributeList attributeList : attributeLists)
	{
		for(CSharpAttribute attribute : attributeList.getAttributes())
		{
			DotNetTypeDeclaration dotNetTypeDeclaration = attribute.resolveToType();
			if(dotNetTypeDeclaration == null)
			{
				continue;
			}

			if(DotNetTypes2.System.Runtime.CompilerServices.InternalsVisibleToAttribute.equalsIgnoreCase(dotNetTypeDeclaration.getVmQName()))
			{
				Module attributeModule = ModuleUtilCore.findModuleForPsiElement(attribute);
				if(attributeModule == null || !attributeModule.equals(module))
				{
					continue;
				}

				DotNetExpression[] parameterExpressions = attribute.getParameterExpressions();
				if(parameterExpressions.length == 0)
				{
					continue;
				}
				String valueAs = new ConstantExpressionEvaluator(parameterExpressions[0]).getValueAs(String.class);
				assemblies.add(valueAs);
			}
		}
	}
	return assemblies;
}
 
Example 7
Source File: ModulesConfigurator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public ModuleEditor getModuleEditor(Module module) {
  for (final ModuleEditor moduleEditor : myModuleEditors) {
    if (module.equals(moduleEditor.getModule())) {
      return moduleEditor;
    }
  }
  return null;
}
 
Example 8
Source File: OrderEntryUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ModuleOrderEntry findModuleOrderEntry(@Nonnull ModuleRootModel model, @Nullable Module module) {
  if (module == null) return null;

  for (OrderEntry orderEntry : model.getOrderEntries()) {
    if (orderEntry instanceof ModuleOrderEntry && module.equals(((ModuleOrderEntry)orderEntry).getModule())) {
      return (ModuleOrderEntry)orderEntry;
    }
  }
  return null;
}
 
Example 9
Source File: BaseCSharpModuleExtension.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public String getAssemblyTitle()
{
	GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(getModule());
	Collection<CSharpAttributeList> attributeLists = AttributeListIndex.getInstance().get(DotNetAttributeTargetType.ASSEMBLY, getProject(), moduleScope);

	loop:
	for(CSharpAttributeList attributeList : attributeLists)
	{
		for(CSharpAttribute attribute : attributeList.getAttributes())
		{
			DotNetTypeDeclaration typeDeclaration = attribute.resolveToType();
			if(typeDeclaration == null)
			{
				continue;
			}

			if(DotNetTypes.System.Reflection.AssemblyTitleAttribute.equals(typeDeclaration.getVmQName()))
			{
				Module attributeModule = ModuleUtilCore.findModuleForPsiElement(attribute);
				if(attributeModule == null || !attributeModule.equals(getModule()))
				{
					continue;
				}
				DotNetExpression[] parameterExpressions = attribute.getParameterExpressions();
				if(parameterExpressions.length == 0)
				{
					break loop;
				}
				String valueAs = new ConstantExpressionEvaluator(parameterExpressions[0]).getValueAs(String.class);
				if(valueAs != null)
				{
					return valueAs;
				}
			}
		}
	}
	return null;
}
 
Example 10
Source File: ModuleRootCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean belongs(final String url) {
  if (myScopeModules.isEmpty()) {
    return false; // optimization
  }
  Module candidateModule = null;
  int maxUrlLength = 0;
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
  for (final Module module : myModules) {
    final String[] contentRootUrls = getModuleContentUrls(module);
    for (final String contentRootUrl : contentRootUrls) {
      if (contentRootUrl.length() < maxUrlLength) {
        continue;
      }
      if (!isUrlUnderRoot(url, contentRootUrl)) {
        continue;
      }
      if (contentRootUrl.length() == maxUrlLength) {
        if (candidateModule == null) {
          candidateModule = module;
        }
        else {
          // the same content root exists in several modules
          if (!candidateModule.equals(module)) {
            candidateModule = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
              @Override
              public Module compute() {
                final VirtualFile contentRootFile = VirtualFileManager.getInstance().findFileByUrl(contentRootUrl);
                if (contentRootFile != null) {
                  return projectFileIndex.getModuleForFile(contentRootFile);
                }
                return null;
              }
            });
          }
        }
      }
      else {
        maxUrlLength = contentRootUrl.length();
        candidateModule = module;
      }
    }
  }

  if (candidateModule != null && myScopeModules.contains(candidateModule)) {
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(candidateModule);
    String[] excludeRootUrls = moduleRootManager.getContentFolderUrls(ContentFolderScopes.excluded());
    for (String excludeRootUrl : excludeRootUrls) {
      if (isUrlUnderRoot(url, excludeRootUrl)) {
        return false;
      }
    }
    for (String sourceRootUrl : getModuleContentUrls(candidateModule)) {
      if (isUrlUnderRoot(url, sourceRootUrl)) {
        return true;
      }
    }
  }

  return false;
}
 
Example 11
Source File: ModuleCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean belongs(final String url) {
  if (myScopeModules.isEmpty()) {
    return false; // optimization
  }
  Module candidateModule = null;
  int maxUrlLength = 0;
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
  for (final Module module : myModules) {
    final String[] contentRootUrls = getModuleContentUrls(module);
    for (final String contentRootUrl : contentRootUrls) {
      if (contentRootUrl.length() < maxUrlLength) {
        continue;
      }
      if (!isUrlUnderRoot(url, contentRootUrl)) {
        continue;
      }
      if (contentRootUrl.length() == maxUrlLength) {
        if (candidateModule == null) {
          candidateModule = module;
        }
        else {
          // the same content root exists in several modules
          if (!candidateModule.equals(module)) {
            candidateModule = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
              public Module compute() {
                final VirtualFile contentRootFile = VirtualFileManager.getInstance().findFileByUrl(contentRootUrl);
                if (contentRootFile != null) {
                  return projectFileIndex.getModuleForFile(contentRootFile);
                }
                return null;
              }
            });
          }
        }
      }
      else {
        maxUrlLength = contentRootUrl.length();
        candidateModule = module;
      }
    }
  }

  if (candidateModule != null && myScopeModules.contains(candidateModule)) {
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(candidateModule);
    final String[] excludeRootUrls = moduleRootManager.getContentFolderUrls(ContentFolderScopes.excluded());
    for (String excludeRootUrl : excludeRootUrls) {
      if (isUrlUnderRoot(url, excludeRootUrl)) {
        return false;
      }
    }
    final String[] sourceRootUrls = moduleRootManager.getContentFolderUrls(ContentFolderScopes.all(false));
    for (String sourceRootUrl : sourceRootUrls) {
      if (isUrlUnderRoot(url, sourceRootUrl)) {
        return true;
      }
    }
  }

  return false;
}