Java Code Examples for com.intellij.util.ArrayUtil#contains()

The following examples show how to use com.intellij.util.ArrayUtil#contains() . 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: NonProjectFileWritingAccessProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean isWriteAccessAllowed(@Nonnull VirtualFile file, @Nonnull Project project) {
  if (isAllAccessAllowed()) return true;
  if (file.isDirectory()) return true;

  if (!(file.getFileSystem() instanceof LocalFileSystem)) return true; // do not block e.g., HttpFileSystem, LightFileSystem etc.
  if (file.getFileSystem() instanceof TempFileSystem) return true;

  if (ArrayUtil.contains(file, IdeDocumentHistory.getInstance(project).getChangedFiles())) return true;

  if (!getApp().isUnitTestMode() && FileUtil.isAncestor(new File(FileUtil.getTempDirectory()), VfsUtilCore.virtualToIoFile(file), true)) {
    return true;
  }

  VirtualFile each = file;
  while (each != null) {
    if (ACCESS_ALLOWED.getValue(each).get() > 0) return true;
    each = each.getParent();
  }

  return isProjectFile(file, project);
}
 
Example 2
Source File: HaskellUtil.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Find definitions that have been re-exported.
 *
 * <code>
 *   module Foo (module Bar, foo) where
 *   import Bar
 *   import Baz (foo)
 * </code>
 */
private static void findDefinitionNodeInExport(@NotNull Project project, HaskellFile f, @Nullable String name,
                                               @Nullable PsiNamedElement e, List<PsiNamedElement> result) {
    List<HaskellPsiUtil.Import> imports = HaskellPsiUtil.parseImports(f);
    for (HaskellExport export : PsiTreeUtil.findChildrenOfType(f, HaskellExport.class)) {
        boolean exportFn = export.getQvar() != null && export.getQvar().getQvarid() != null
                && export.getQvar().getQvarid().getVarid().getName().equals(name);
        String moduleName = exportFn
                ? getModule(export.getQvar().getQvarid().getConidList())
                : export.getModuletoken() != null && export.getQconid() != null ? export.getQconid().getText() : null;
        if (!exportFn && moduleName == null) continue;
        for (HaskellPsiUtil.Import imprt : imports) {
            if (moduleName != null && !moduleName.equals(imprt.module) && !moduleName.equals(imprt.alias)) continue;
            boolean hidden = imprt.getHidingNames() != null && ArrayUtil.contains(name, imprt.getHidingNames());
            boolean notImported = imprt.getImportedNames() != null && !ArrayUtil.contains(name, imprt.getImportedNames());
            if (hidden || notImported) continue;
            for (HaskellFile f2 : HaskellModuleIndex.getFilesByModuleName(project, imprt.module, GlobalSearchScope.allScope(project))) {
                findDefinitionNode(f2, name, e, result);
                findDefinitionNodeInExport(project, f2, name, e, result);
            }
        }
    }
}
 
Example 3
Source File: EditorBasedWidget.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean ensureValidEditorFile(Editor editor) {
  Document document = editor.getDocument();
  VirtualFile file = FileDocumentManager.getInstance().getFile(document);
  if (file != null && !file.isValid()) {
    Document cachedDocument = FileDocumentManager.getInstance().getCachedDocument(file);
    Project project = editor.getProject();
    Boolean fileIsOpen = project == null ? null : ArrayUtil.contains(file, FileEditorManager.getInstance(project).getOpenFiles());
    LOG.error("Returned editor for invalid file: " + editor +
              "; disposed=" + editor.isDisposed() +
              "; file " + file.getClass() +
              "; cached document exists: " + (cachedDocument != null) +
              "; same as document: " + (cachedDocument == document) +
              "; file is open: " + fileIsOpen);
    return false;
  }
  return true;
}
 
Example 4
Source File: CS1008.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetType element)
{
	PsiElement parent = element.getParent();
	if(parent instanceof DotNetTypeList && PsiUtilCore.getElementType(parent) == CSharpElements.EXTENDS_LIST)
	{
		PsiElement superParent = parent.getParent();
		if(superParent instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) superParent).isEnum())
		{
			PsiElement psiElement = element.toTypeRef().resolve().getElement();
			if(psiElement instanceof CSharpTypeDeclaration)
			{
				if(!ArrayUtil.contains(((CSharpTypeDeclaration) psiElement).getVmQName(), ourEnumSuperTypes))
				{
					return newBuilder(element);
				}
			}
		}
	}
	return null;
}
 
Example 5
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void clearSelection() {
  if (myListenerHighlighter != null &&
      ArrayUtil.contains(myListenerHighlighter, (Object[])myEditor.getMarkupModel().getAllHighlighters())) {
    myListenerHighlighter.dispose();
    myListenerHighlighter = null;
  }
}
 
Example 6
Source File: CommandMerger.java    From consulo with Apache License 2.0 5 votes vote down vote up
boolean hasChangesOf(DocumentReference ref, boolean onlyDirectChanges) {
  for (UndoableAction action : myCurrentActions) {
    DocumentReference[] refs = action.getAffectedDocuments();
    if (refs == null) {
      if (!onlyDirectChanges) return true;
    }
    else if (ArrayUtil.contains(ref, refs)) return true;
  }
  return hasActions() && myAdditionalAffectedDocuments.contains(ref);
}
 
Example 7
Source File: ChooseByNameBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void setElementsToList(@Nonnull SelectionPolicy pos, @Nonnull Collection<?> elements) {
  if (checkDisposed()) return;
  if (isCloseByFocusLost() && Registry.is("focus.follows.mouse.workarounds")) {
    PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    if (pointerInfo != null) {
      myFocusPoint = pointerInfo.getLocation();
    }
  }
  if (elements.isEmpty()) {
    myListModel.removeAll();
    myTextField.setForeground(JBColor.red);
    hideList();
    return;
  }

  Object[] oldElements = myListModel.getItems().toArray();
  Object[] newElements = elements.toArray();
  if (ArrayUtil.contains(null, newElements)) {
    LOG.error("Null after filtering elements by " + this);
  }
  List<ModelDiff.Cmd> commands = ModelDiff.createDiffCmds(myListModel, oldElements, newElements);

  myTextField.setForeground(UIUtil.getTextFieldForeground());
  if (commands == null || commands.isEmpty()) {
    applySelection(pos);
    showList();
    myTextFieldPanel.repositionHint();
  }
  else {
    appendToModel(commands, pos);
  }
}
 
Example 8
Source File: ModuleOutputPackagingElementImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@javax.annotation.Nullable
public Module findModule(PackagingElementResolvingContext context) {
  final Module module = NamedPointerUtil.get(myModulePointer);
  final ModulesProvider modulesProvider = context.getModulesProvider();
  if (module != null) {
    if (modulesProvider instanceof DefaultModulesProvider//optimization
        || ArrayUtil.contains(module, modulesProvider.getModules())) {
      return module;
    }
  }
  return modulesProvider.getModule(myModulePointer.getName());
}
 
Example 9
Source File: DiffUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void addActionBlock(@Nonnull DefaultActionGroup group, @Nullable List<? extends AnAction> actions) {
  if (actions == null || actions.isEmpty()) return;
  group.addSeparator();

  AnAction[] children = group.getChildren(null);
  for (AnAction action : actions) {
    if (!ArrayUtil.contains(action, children)) {
      group.add(action);
    }
  }
}
 
Example 10
Source File: FileOrDirectoryDependencyTabContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isIncluded(OrderRoot root, Library[] libraries) {
  for (Library library : libraries) {
    if (ArrayUtil.contains(root.getFile(), library.getFiles(root.getType()))) {
      return true;
    }
  }
  return false;
}
 
Example 11
Source File: CS0151.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private boolean isValidTypeRef(DotNetTypeRef typeRef)
{
	DotNetTypeResolveResult typeResolveResult = typeRef.resolve();
	PsiElement resolvedElement = typeResolveResult.getElement();

	if(resolvedElement instanceof CSharpTypeDeclaration)
	{
		CSharpTypeDeclaration typeDeclaration = (CSharpTypeDeclaration) resolvedElement;
		if(typeDeclaration.isEnum())
		{
			return true;
		}
		String vmQName = typeDeclaration.getVmQName();
		if(ArrayUtil.contains(vmQName, ourSwitchTypes))
		{
			return true;
		}

		if(DotNetTypes.System.Nullable$1.equals(vmQName))
		{
			int genericParametersCount = typeDeclaration.getGenericParametersCount();
			if(genericParametersCount > 0)
			{
				DotNetGenericParameter genericParameter = typeDeclaration.getGenericParameters()[0];

				DotNetGenericExtractor genericExtractor = typeResolveResult.getGenericExtractor();
				DotNetTypeRef extractedTypRef = genericExtractor.extract(genericParameter);
				if(extractedTypRef == null)
				{
					return false;
				}

				return isValidTypeRef(extractedTypRef);
			}
		}
	}

	return false;
}
 
Example 12
Source File: LibraryRootsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private List<OrderRoot> filterAlreadyAdded(@Nonnull List<OrderRoot> roots) {
  List<OrderRoot> result = new ArrayList<OrderRoot>();
  for (OrderRoot root : roots) {
    final VirtualFile[] libraryFiles = getLibraryEditor().getFiles(root.getType());
    if (!ArrayUtil.contains(root.getFile(), libraryFiles)) {
      result.add(root);
    }
  }
  return result;
}
 
Example 13
Source File: MsilModifierListToCSharpModifierList.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetAttribute[] getAttributes()
{
	DotNetAttribute[] oldAttributes = myModifierList.getAttributes();
	List<DotNetAttribute> attributes = new ArrayList<>(oldAttributes.length + myAdditionalAttributes.size());
	for(DotNetAttribute oldAttribute : oldAttributes)
	{
		DotNetTypeDeclaration resolvedType = oldAttribute.resolveToType();
		if(resolvedType != null && ArrayUtil.contains(resolvedType.getVmQName(), ourAttributeBans))
		{
			continue;
		}
		attributes.add(oldAttribute);
	}
	attributes.addAll(myAdditionalAttributes);

	ExternalAttributeHolder holder = myAttributeHolderValue.getValue();

	if(holder != null)
	{
		List<ExternalAttributeNode> nodes = findAttributes(holder);
		for(ExternalAttributeNode node : nodes)
		{
			CSharpLightAttributeWithSelfTypeBuilder builder = new CSharpLightAttributeWithSelfTypeBuilder(myModifierList, node.getName());

			for(ExternalAttributeArgumentNode argumentNode : node.getArguments())
			{
				builder.addParameterExpression(argumentNode.toJavaObject());
			}
			attributes.add(builder);
		}
	}
	return attributes.toArray(new DotNetAttribute[attributes.size()]);
}
 
Example 14
Source File: CSharpTypeDeclarationImplUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private static boolean isInheritOrSelf0(DotNetTypeDeclaration typeDeclaration, String... vmQNames)
{
	if(ArrayUtil.contains(typeDeclaration.getVmQName(), vmQNames))
	{
		return true;
	}

	DotNetTypeRef[] anExtends = typeDeclaration.getExtendTypeRefs();
	if(anExtends.length > 0)
	{
		for(DotNetTypeRef dotNetType : anExtends)
		{
			PsiElement psiElement = dotNetType.resolve().getElement();
			if(psiElement instanceof DotNetTypeDeclaration)
			{
				if(psiElement.isEquivalentTo(typeDeclaration))
				{
					return false;
				}

				if(ArrayUtil.contains(((DotNetTypeDeclaration) psiElement).getVmQName(), vmQNames))
				{
					return true;
				}

				if(isInheritOrSelf0((DotNetTypeDeclaration) psiElement, vmQNames))
				{
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 15
Source File: HaskellCompletionContributor.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
public static boolean completeLocalNames(@NotNull final PsiElement position,
                                         @NotNull final List<HaskellPsiUtil.Import> imports,
                                         @NotNull final Cache holder,
                                         @NotNull final CompletionResultSet result) {
    if (PsiTreeUtil.getParentOfType(position, HaskellExp.class) == null) {
        return false;
    }
    final Map<String, Set<LookupElementWrapper>> cachedNames = holder.moduleSymbols();
    if (cachedNames == null) {
        return false;
    }
    for (HaskellPsiUtil.Import anImport : imports) {
        Set<LookupElementWrapper> names = cachedNames.get(anImport.module);
        if (names == null) continue;
        String[] importedNames = anImport.getImportedNames();
        String[] hidingNames = anImport.getHidingNames();
        for (LookupElementWrapper cachedName : names) {
            String lookupString = cachedName.get().getLookupString();
            boolean noExplicitNames = importedNames == null;
            boolean isImportedName = importedNames != null && ArrayUtil.contains(lookupString, importedNames);
            boolean isHidingName = hidingNames != null && ArrayUtil.contains(lookupString, hidingNames);
            if ((noExplicitNames || isImportedName) && !isHidingName) {
                result.addElement(cachedName.get());
            }
        }
    }
    return true;
}
 
Example 16
Source File: DefaultInspectionToolPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isProblemResolved(RefEntity refEntity, CommonProblemDescriptor descriptor) {
  if (descriptor == null) return true;
  for (RefEntity entity : getIgnoredElements().keySet()) {
    if (Comparing.equal(entity, refEntity)) {
      final CommonProblemDescriptor[] descriptors = getIgnoredElements().get(refEntity);
      return ArrayUtil.contains(descriptor, descriptors);
    }
  }
  return false;
}
 
Example 17
Source File: IgnoreBundle.java    From idea-gitignore with MIT License 4 votes vote down vote up
public static boolean isExcludedFromHighlighting(@NotNull IgnoreLanguage language) {
    return ArrayUtil.contains(language, IGNORE_LANGUAGES_HIGHLIGHTING_EXCLUDED);
}
 
Example 18
Source File: CS0106.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public boolean isValidModifier(DotNetModifier modifier)
{
	return ArrayUtil.contains(modifier, myValidModifiers);
}
 
Example 19
Source File: ModuleExtensionConditionImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean value(ModuleExtension<?> extension) {
  return extension.isEnabled() && ArrayUtil.contains(extension.getId(), myExtensionIds);
}
 
Example 20
Source File: PlatformOrPluginUpdateChecker.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isPlatform(@Nonnull PluginId pluginId) {
  return ArrayUtil.contains(pluginId, ourPlatformIds);
}