com.intellij.psi.search.FileTypeIndex Java Examples

The following examples show how to use com.intellij.psi.search.FileTypeIndex. 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: RemoveUnusedParameterFix.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
private static List<SoyParamSpecificationIdentifier> getReferencingParamSpecificationIdentifiers(
    SoyParamDefinitionIdentifier paramDefinitionIdentifier) {
  Project project = paramDefinitionIdentifier.getProject();
  final ImmutableList.Builder<SoyParamSpecificationIdentifier> result = ImmutableList.builder();
  Collection<VirtualFile> virtualFiles =
      FileTypeIndex.getFiles(SoyFileType.INSTANCE, GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    SoyFile soyFile = (SoyFile) PsiManager.getInstance(project).findFile(virtualFile);
    if (soyFile != null) {
      soyFile.accept(new SoyRecursiveElementVisitor() {
        @Override
        public void visitParamSpecificationIdentifier(
            @NotNull SoyParamSpecificationIdentifier identifier) {
          super.visitParamSpecificationIdentifier(identifier);
          PsiReference reference = identifier.getReference();
          if (reference != null && paramDefinitionIdentifier.equals(reference.resolve())) {
            result.add(identifier);
          }
        }
      });
    }
  }
  return result.build();
}
 
Example #2
Source File: JSGraphQLEndpointCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
private boolean completeImportFile(@NotNull CompletionResultSet result, PsiFile file, PsiElement parent) {
	if ((parent instanceof JSGraphQLEndpointQuotedString || parent instanceof JSGraphQLEndpointString) && PsiTreeUtil.getParentOfType(parent, JSGraphQLEndpointImportFileReference.class) != null) {

		final Project project = file.getProject();
		final VirtualFile entryFile = JSGraphQLConfigurationProvider.getService(project).getEndpointEntryFile(file);
		final GlobalSearchScope scope = JSGraphQLEndpointPsiUtil.getImportScopeFromEntryFile(project, entryFile, file);
		final Collection<VirtualFile> files = FileTypeIndex.getFiles(JSGraphQLEndpointFileType.INSTANCE, scope);
		for (VirtualFile virtualFile : files) {
			if(virtualFile.equals(entryFile)) {
				// entry file should never be imported
				continue;
			}
			final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
			if (psiFile != null) {
				if(psiFile.equals(file)) {
					// don't suggest the current file
					continue;
				}
				String name = JSGraphQLEndpointImportUtil.getImportName(project, psiFile);
				result.addElement(LookupElementBuilder.create(name).withIcon(psiFile.getIcon(0)));
			}
		}
		return true;
	}
	return false;
}
 
Example #3
Source File: ArmaPluginUtil.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
/**
 * Gets the config files (either a description.ext or multiple, at least 1, config.cpp (case sensitivity doesn't matter)).
 * If no description.ext file or config.cpp files could be found, this will return an empty list. This will also
 * return and empty list if a module for the given PsiElement couldn't be found.
 * <p>
 * If a description.ext file is found, this method will return a singleton list of the description.ext file,regardless
 * if there are config.cpp files. If there is no description.ext files, this will return all config.cpp files found
 *
 * @param module a PsiElement used to determine what module the root config file is located in
 * @return a list of VirtualFile instances, or an empty list
 */
@NotNull
public static List<VirtualFile> getConfigVirtualFiles(@NotNull Module module) {
	Collection<VirtualFile> files = FileTypeIndex.getFiles(HeaderFileType.INSTANCE, module.getModuleContentScope());
	List<VirtualFile> configs = new ArrayList<>();
	for (VirtualFile virtFile : files) {
		if (virtFile.getName().equalsIgnoreCase("description.ext")) {
			return Collections.singletonList(virtFile);
		}
		if (virtFile.getName().equalsIgnoreCase("config.cpp")) {
			configs.add(virtFile);
		}

	}
	return configs;
}
 
Example #4
Source File: ArmaPluginUtil.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
/**
 * Gets the config files (either a description.ext or multiple, at least 1, config.cpp (case sensitivity doesn't matter)).
 * If no description.ext file or config.cpp files could be found, this will return an empty list. This will also
 * return and empty list if a module for the given PsiElement couldn't be found.
 * <p>
 * If a description.ext file is found, this method will return a singleton list of the description.ext file,regardless
 * if there are config.cpp files. If there is no description.ext files, this will return all config.cpp files found
 *
 * @param module a PsiElement used to determine what module the root config file is located in
 * @return a list of VirtualFile instances, or an empty list
 */
@NotNull
public static List<VirtualFile> getConfigVirtualFiles(@NotNull Module module) {
	Collection<VirtualFile> files = FileTypeIndex.getFiles(HeaderFileType.INSTANCE, module.getModuleContentScope());
	List<VirtualFile> configs = new ArrayList<>();
	for (VirtualFile virtFile : files) {
		if (virtFile.getName().equalsIgnoreCase("description.ext")) {
			return Collections.singletonList(virtFile);
		}
		if (virtFile.getName().equalsIgnoreCase("config.cpp")) {
			configs.add(virtFile);
		}

	}
	return configs;
}
 
Example #5
Source File: SimpleCreatePropertyQuickFix.java    From intellij-sdk-docs with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws
      IncorrectOperationException {
  ApplicationManager.getApplication().invokeLater(() -> {
    Collection<VirtualFile> virtualFiles =
          FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project) );
    if (virtualFiles.size() == 1) {
      createProperty(project, virtualFiles.iterator().next());
    } else {
      final FileChooserDescriptor descriptor =
            FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
      descriptor.setRoots(ProjectUtil.guessProjectDir(project));
      final VirtualFile file1 = FileChooser.chooseFile(descriptor, project, null);
      if (file1 != null) {
        createProperty(project, file1);
      }
    }
  });
}
 
Example #6
Source File: BuckIdentifierUtil.java    From buck with Apache License 2.0 6 votes vote down vote up
/** Returns all known identifiers that match the given key name. */
public static List<BuckIdentifier> findIdentifiers(Project project, String key) {
  List<BuckIdentifier> result = new ArrayList<>();
  Collection<VirtualFile> virtualFiles =
      FileTypeIndex.getFiles(BuckFileType.INSTANCE, GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
    if (psiFile instanceof BuckFile) {
      BuckFile buckFile = (BuckFile) psiFile;
      BuckIdentifier[] identifiers =
          PsiTreeUtil.getChildrenOfType(buckFile, BuckIdentifier.class);
      for (BuckIdentifier identifier : identifiers) {
        if (identifier.getName().equals(key)) {
          result.add(identifier);
        }
      }
    }
  }
  return result;
}
 
Example #7
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
public static List<XmlTag> findFlowRefsForFlow(@NotNull XmlTag flow) {
    List<XmlTag> flowRefs = new ArrayList<>();

    final Project project = flow.getProject();
    final String flowName = flow.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE);

    Collection<VirtualFile> vFiles = FileTypeIndex.getFiles(StdFileTypes.XML, ProjectScope.getContentScope(project));
    for (VirtualFile virtualFile : vFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
        if (psiFile != null) {
            XmlFile xmlFile = (XmlFile) psiFile;
            XmlTag mule = xmlFile.getRootTag();

            FlowRefsFinder finder = new FlowRefsFinder(flowName);
            mule.accept(finder);
            flowRefs.addAll(finder.getFlowRefs());
        }
    }
    return flowRefs;
}
 
Example #8
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@NotNull
private static List<XmlTag> getGlobalElementsInScope(Project project, GlobalSearchScope searchScope) {
    final List<XmlTag> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                final XmlTag[] subTags = rootElement.getXmlTag().getSubTags();
                for (XmlTag subTag : subTags) {
                    if (isGlobalElement(subTag)) {
                        result.add(subTag);
                    }
                }
            }
        }
    }
    return result;
}
 
Example #9
Source File: BuckIdentifierUtil.java    From buck with Apache License 2.0 6 votes vote down vote up
/** Returns all known identifiers. */
public static List<BuckIdentifier> findIdentifiers(Project project) {
  List<BuckIdentifier> result = new ArrayList<>();
  Collection<VirtualFile> virtualFiles =
      FileTypeIndex.getFiles(BuckFileType.INSTANCE, GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
    if (psiFile instanceof BuckFile) {
      BuckFile buckFile = (BuckFile) psiFile;
      BuckIdentifier[] identifiers =
          PsiTreeUtil.getChildrenOfType(buckFile, BuckIdentifier.class);
      if (identifiers != null) {
        Collections.addAll(result, identifiers);
      }
    }
  }
  return result;
}
 
Example #10
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@NotNull
private static List<DomElement> getFlowsInScope(Project project, GlobalSearchScope searchScope) {
    final List<DomElement> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                result.addAll(rootElement.getFlows());
                result.addAll(rootElement.getSubFlows());
            }
        }
    }
    return result;
}
 
Example #11
Source File: CoreServiceParser.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
private void collectServices(Project project) {
    FileBasedIndex index = FileBasedIndex.getInstance();
    Collection<VirtualFile> containingFiles = index.getContainingFiles(
            FileTypeIndex.NAME,
            PhpFileType.INSTANCE,
            GlobalSearchScope.allScope(project)
    );
    containingFiles.removeIf(virtualFile -> !(virtualFile.getName().contains("ext_localconf.php")));

    for (VirtualFile projectFile : containingFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(projectFile);
        if (psiFile != null) {
            CoreServiceDefinitionParserVisitor visitor = new CoreServiceDefinitionParserVisitor(serviceMap);
            psiFile.accept(visitor);

            serviceMap.putAll(visitor.getServiceMap());
        }
    }
}
 
Example #12
Source File: FileManager.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
public static List<PsiFile> getAllConceptFiles(Project project) {
    Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(ConceptFileType.INSTANCE, GlobalSearchScope.projectScope(project));
    List<PsiFile> files = new ArrayList<>();

    for (VirtualFile ConceptVFile : virtualFiles) {
        PsiFile file = PsiManager.getInstance(project).findFile(ConceptVFile);
        if (file != null) {
            files.add(file);
        }
    }
    Collections.sort(files, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    return files;
}
 
Example #13
Source File: FileManager.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
public static List<PsiFile> getAllJavaFiles(Module module) {
    Collection<VirtualFile> javaVirtualFiles = FileTypeIndex.getFiles(JavaFileType.INSTANCE, moduleScope(module));
    List<PsiFile> javaFiles = new ArrayList<>();

    for (VirtualFile javaVFile : javaVirtualFiles) {
        PsiFile file = PsiManager.getInstance(module.getProject()).findFile(javaVFile);
        if (file != null && PsiTreeUtil.findChildrenOfType(file, PsiClass.class).size() > 0) {
            javaFiles.add(file);
        }
    }
    Collections.sort(javaFiles, (o1, o2) -> FileManager.getJavaFileName(o1).compareToIgnoreCase(FileManager.getJavaFileName(o2)));
    return javaFiles;
}
 
Example #14
Source File: HaskellFileIndex.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
public static Collection<VirtualFile> getVirtualFiles(@NotNull Project project) {
  return FileBasedIndex.getInstance().getContainingFiles(
    FileTypeIndex.NAME,
    HaskellFileType.INSTANCE,
    GlobalSearchScope.projectScope(project)
  );
}
 
Example #15
Source File: BcfgUtils.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Returns the known buckconfig files in the given {@link Project}. */
public static Stream<BcfgFile> findBcfgFiles(Project project) {
  // TODO:  Replace this with a method that returns the buckconfig
  // files for a given cell, accounting for included config files and
  // Buck's rules of precedence, as per:
  //   https://buck.build/files-and-dirs/buckconfig.html#config-precedence
  PsiManager psiManager = PsiManager.getInstance(project);
  GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
  return FileBasedIndex.getInstance()
      .getContainingFiles(FileTypeIndex.NAME, BcfgFileType.INSTANCE, searchScope).stream()
      .map(psiManager::findFile)
      .map(BcfgFile.class::cast)
      .filter(Objects::nonNull);
}
 
Example #16
Source File: SQFReferenceContributor.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all {@link SQFVariable}s in the current module that is equal to findVar into a list and returns it
 * <p>
 * If findVar is a local variable, the list returned will be empty.
 *
 * @param project project
 * @param findVar variable
 * @return list
 */
@NotNull
public static List<SQFVariable> findGlobalVariables(@NotNull Project project, @NotNull SQFVariable findVar) {
	List<SQFVariable> result = new ArrayList<>();
	if (findVar.isLocal()) {
		return result;
	}
	Module m = ModuleUtil.findModuleForPsiElement(findVar);
	if (m == null) {
		return result;
	}
	GlobalSearchScope searchScope = m.getModuleContentScope();
	Collection<VirtualFile> files = FileTypeIndex.getFiles(SQFFileType.INSTANCE, searchScope);
	for (VirtualFile virtualFile : files) {
		PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
		if (!(file instanceof SQFFile)) {
			continue;
		}
		SQFFile sqfFile = (SQFFile) file;
		PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
			PsiElement nodeAsElement = astNode.getPsi();
			if (nodeAsElement instanceof SQFVariable) {
				SQFVariable var = (SQFVariable) nodeAsElement;
				if (var.isLocal()) {
					return false;
				}
				if (SQFVariableName.nameEquals(var.getVarName(), findVar.getVarName())) {
					result.add(var);
				}
			}
			return false;
		});
	}
	return result;
}
 
Example #17
Source File: SQFReferenceContributor.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all {@link SQFCommand} instances in the current module that is equal to findCommand into a list and returns it
 *
 * @param project     project
 * @param findCommand the command
 * @return list
 */
@NotNull
public static List<SQFCommand> findAllCommandInstances(@NotNull Project project, @NotNull SQFCommand findCommand) {
	List<SQFCommand> result = new ArrayList<>();
	Module m = ModuleUtil.findModuleForPsiElement(findCommand);
	if (m == null) {
		return result;
	}
	GlobalSearchScope searchScope = m.getModuleContentScope();
	Collection<VirtualFile> files = FileTypeIndex.getFiles(SQFFileType.INSTANCE, searchScope);
	for (VirtualFile virtualFile : files) {
		PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
		if (!(file instanceof SQFFile)) {
			continue;
		}
		SQFFile sqfFile = (SQFFile) file;
		PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
			PsiElement nodeAsElement = astNode.getPsi();
			if (nodeAsElement instanceof SQFCommand) {
				SQFCommand command = (SQFCommand) nodeAsElement;
				if (command.commandNameEquals(findCommand.getCommandName())) {
					result.add(command);
				}
			}
			return false;
		});
	}
	return result;
}
 
Example #18
Source File: ArmaPluginUtil.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * @param module {@link Module} instance to get a stringtable.xml file for
 * @return a {@link VirtualFile} that maps to a Stringtable.xml file (name case sensitivity doesn't matter),
 * or null if couldn't be found
 */
@Nullable
public static VirtualFile getStringTableXmlFile(@NotNull Module module) {
	Collection<VirtualFile> files = FileTypeIndex.getFiles(XmlFileType.INSTANCE, module.getModuleContentScope());
	for (VirtualFile virtFile : files) {
		if (virtFile.getName().equalsIgnoreCase("stringtable.xml")) {
			return virtFile;
		}
	}
	return null;
}
 
Example #19
Source File: IdeaUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public static List<PsiExtraFile> findPsiFileLinksForProjectScope(final Project project) {
  List<PsiExtraFile> result = new ArrayList<PsiExtraFile>();
  Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, MindMapFileType.INSTANCE,
      GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    final MMDFile simpleFile = (MMDFile) PsiManager.getInstance(project).findFile(virtualFile);
    if (simpleFile != null) {
      final PsiExtraFile[] fileLinks = PsiTreeUtil.getChildrenOfType(simpleFile, PsiExtraFile.class);
      if (fileLinks != null) {
        Collections.addAll(result, fileLinks);
      }
    }
  }
  return result;
}
 
Example #20
Source File: TreeFileChooserDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String[] getNames(final boolean checkBoxState) {
  final String[] fileNames;
  if (myFileType != null && myProject != null) {
    GlobalSearchScope scope = myShowLibraryContents ? GlobalSearchScope.allScope(myProject) : GlobalSearchScope.projectScope(myProject);
    Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(myFileType, scope);
    fileNames = ContainerUtil.map2Array(virtualFiles, String.class, new Function<VirtualFile, String>() {
      @Override
      public String fun(VirtualFile file) {
        return file.getName();
      }
    });
  }
  else {
    fileNames = FilenameIndex.getAllFilenames(myProject);
  }
  final Set<String> array = new THashSet<String>();
  for (String fileName : fileNames) {
    if (!array.contains(fileName)) {
      array.add(fileName);
    }
  }

  final String[] result = ArrayUtil.toStringArray(array);
  Arrays.sort(result);
  return result;
}
 
Example #21
Source File: CypherUtil.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
public static <T extends CypherNamedElement> List<T> findAllAndFilter(Project project, IElementType elementType, Filter filter) {
    Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance()
            .getContainingFiles(FileTypeIndex.NAME, CypherFileType.INSTANCE, GlobalSearchScope.allScope(project));

    List<T> result = new ArrayList<>();
    for (VirtualFile virtualFile : virtualFiles) {
        CypherFile cypherFile = (CypherFile) PsiManager.getInstance(project).findFile(virtualFile);
        if (cypherFile != null) {
            List<T> found = findAllAndFilter(cypherFile, elementType, filter);
            result.addAll(found);
        }
    }

    return result;
}
 
Example #22
Source File: SQFReferenceContributor.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all {@link SQFVariable}s in the current module that is equal to findVar into a list and returns it
 * <p>
 * If findVar is a local variable, the list returned will be empty.
 *
 * @param project project
 * @param findVar variable
 * @return list
 */
@NotNull
public static List<SQFVariable> findGlobalVariables(@NotNull Project project, @NotNull SQFVariable findVar) {
	List<SQFVariable> result = new ArrayList<>();
	if (findVar.isLocal()) {
		return result;
	}
	Module m = ModuleUtil.findModuleForPsiElement(findVar);
	if (m == null) {
		return result;
	}
	GlobalSearchScope searchScope = m.getModuleContentScope();
	Collection<VirtualFile> files = FileTypeIndex.getFiles(SQFFileType.INSTANCE, searchScope);
	for (VirtualFile virtualFile : files) {
		PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
		if (!(file instanceof SQFFile)) {
			continue;
		}
		SQFFile sqfFile = (SQFFile) file;
		PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
			PsiElement nodeAsElement = astNode.getPsi();
			if (nodeAsElement instanceof SQFVariable) {
				SQFVariable var = (SQFVariable) nodeAsElement;
				if (var.isLocal()) {
					return false;
				}
				if (SQFVariableName.nameEquals(var.getVarName(), findVar.getVarName())) {
					result.add(var);
				}
			}
			return false;
		});
	}
	return result;
}
 
Example #23
Source File: SQFReferenceContributor.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all {@link SQFCommand} instances in the current module that is equal to findCommand into a list and returns it
 *
 * @param project     project
 * @param findCommand the command
 * @return list
 */
@NotNull
public static List<SQFCommand> findAllCommandInstances(@NotNull Project project, @NotNull SQFCommand findCommand) {
	List<SQFCommand> result = new ArrayList<>();
	Module m = ModuleUtil.findModuleForPsiElement(findCommand);
	if (m == null) {
		return result;
	}
	GlobalSearchScope searchScope = m.getModuleContentScope();
	Collection<VirtualFile> files = FileTypeIndex.getFiles(SQFFileType.INSTANCE, searchScope);
	for (VirtualFile virtualFile : files) {
		PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
		if (!(file instanceof SQFFile)) {
			continue;
		}
		SQFFile sqfFile = (SQFFile) file;
		PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
			PsiElement nodeAsElement = astNode.getPsi();
			if (nodeAsElement instanceof SQFCommand) {
				SQFCommand command = (SQFCommand) nodeAsElement;
				if (command.commandNameEquals(findCommand.getCommandName())) {
					result.add(command);
				}
			}
			return false;
		});
	}
	return result;
}
 
Example #24
Source File: ArmaPluginUtil.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * @param module {@link Module} instance to get a stringtable.xml file for
 * @return a {@link VirtualFile} that maps to a Stringtable.xml file (name case sensitivity doesn't matter),
 * or null if couldn't be found
 */
@Nullable
public static VirtualFile getStringTableXmlFile(@NotNull Module module) {
	Collection<VirtualFile> files = FileTypeIndex.getFiles(XmlFileType.INSTANCE, module.getModuleContentScope());
	for (VirtualFile virtFile : files) {
		if (virtFile.getName().equalsIgnoreCase("stringtable.xml")) {
			return virtFile;
		}
	}
	return null;
}
 
Example #25
Source File: GlobalConfigsTreeStructure.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
        protected SimpleNode[] buildChildren() {
            List<SimpleNode> myConfigNodes = new ArrayList<>();

            final DomManager manager = DomManager.getDomManager(myProject);

            final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, GlobalSearchScope.projectScope(myProject));

            for (VirtualFile file : files) {

                final PsiFile xmlFile = PsiManager.getInstance(myProject).findFile(file);

                if (xmlFile != null) {
//                    PsiDirectory directory = xmlFile.getParent();
//                    Module module = ModuleUtilCore.findModuleForPsiElement((PsiElement) (directory == null ? xmlFile : directory));

                    if (MuleConfigUtils.isMuleFile(xmlFile)) {
                        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);

                        if (fileElement != null) {
                            final Mule rootElement = fileElement.getRootElement();
                            XmlTag[] subTags = rootElement.getXmlTag().getSubTags();

                            for (XmlTag nextTag : subTags) {
                                MuleElementType muleElementType = MuleConfigUtils.getMuleElementTypeFromXmlElement(nextTag);

                                if (muleElementType != null && //This is a global config file and it has at least one connector
                                        (MuleElementType.CONFIG.equals(muleElementType) || (MuleElementType.TRANSPORT_CONNECTOR.equals(muleElementType)))) {
                                    MuleConfigNode nextConfigNode = new MuleConfigNode(this, xmlFile);
                                    myConfigNodes.add(nextConfigNode);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return myConfigNodes.toArray(new SimpleNode[]{});
        }
 
Example #26
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Nullable
private static XmlTag findFlowInScope(Project project, String flowName, GlobalSearchScope searchScope) {
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    for (VirtualFile file : files) {
        XmlTag flow = findFlowInFile(project, flowName, file);
        if (flow != null) {
            return flow;
        }
    }
    return null;
}
 
Example #27
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Nullable
private static XmlTag findGlobalElementInScope(Project project, String elementName, GlobalSearchScope searchScope) {
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    for (VirtualFile file : files) {
        XmlTag flow = findGlobalElementInFile(project, elementName, file);
        if (flow != null) {
            return flow;
        }
    }
    return null;
}
 
Example #28
Source File: GoToClassContributor.java    From protobuf-jetbrains-plugin with Apache License 2.0 4 votes vote down vote up
private void addProjectAndLibraryFiles(Project project, boolean includeNonProjectItems, List<VirtualFile> files) {
    GlobalSearchScope scope = getSearchScope(project, includeNonProjectItems);
    files.addAll(FileTypeIndex.getFiles(ProtoFileType.INSTANCE, scope));
}
 
Example #29
Source File: FlutterRunConfigurationType.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Defined here for all Flutter run configurations.
 */
public static boolean doShowFlutterRunConfigurationForProject(@NotNull Project project) {
  return FileTypeIndex.containsFileOfType(DartFileType.INSTANCE, GlobalSearchScope.projectScope(project)) &&
         FlutterModuleUtils.hasFlutterModule(project);
}
 
Example #30
Source File: FlutterBazelRunConfigurationType.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Defined here for all Flutter Bazel run configurations.
 */
public static boolean doShowBazelRunConfigurationForProject(@NotNull Project project) {
  return FileTypeIndex.containsFileOfType(DartFileType.INSTANCE, GlobalSearchScope.projectScope(project)) &&
         FlutterModuleUtils.isFlutterBazelProject(project);
}