com.intellij.util.indexing.DataIndexer Java Examples

The following examples show how to use com.intellij.util.indexing.DataIndexer. 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: PlatformIdTableBuilding.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Map<TodoIndexEntry, Integer> map(FileContent inputData) {
  Map<TodoIndexEntry, Integer> result = ContainerUtil.newTroveMap();
  for (DataIndexer<TodoIndexEntry, Integer, FileContent> indexer : indexers) {
    for (Map.Entry<TodoIndexEntry, Integer> entry : indexer.map(inputData).entrySet()) {
      TodoIndexEntry key = entry.getKey();
      if (result.containsKey(key)) {
        result.put(key, result.get(key) + entry.getValue());
      }
      else {
        result.put(key, entry.getValue());
      }
    }
  }
  return result;
}
 
Example #2
Source File: PlatformIdTableBuilding.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, Project project, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), project, virtualFile), getTodoIndexer(sft.getFileType(), project, virtualFile));
  }
  else {
    extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
  }
  if (extIndexer != null) {
    return extIndexer;
  }

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    LanguageVersion languageVersion = LanguageVersionUtil.findLanguageVersion(lang, project, virtualFile);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens(languageVersion) : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, languageVersion, virtualFile, project);
    }
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, null, virtualFile, project);
  }

  return null;
}
 
Example #3
Source File: PlatformIdTableBuilding.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int getVersion() {
  int version = VersionedTodoIndexer.super.getVersion();
  for (DataIndexer dataIndexer : indexers) {
    version += dataIndexer instanceof VersionedTodoIndexer ? ((VersionedTodoIndexer)dataIndexer).getVersion() : 0xFF;
  }
  return version;
}
 
Example #4
Source File: FileModuleIndex.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, FileModuleData, FileContent> getIndexer() {
    return inputData -> {
        if (FileHelper.isReason(inputData.getFileType()) || FileHelper.isOCaml(inputData.getFileType())) {
            PsiFile inputPsiFile = inputData.getPsiFile();
            if (inputPsiFile instanceof FileBase) {
                FileBase psiFile = (FileBase) inputPsiFile;
                Map<String, FileModuleData> map = new HashMap<>();

                String namespace = "";
                Optional<VirtualFile> bsconfigFile = BsPlatform.findBsConfigForFile(inputData.getProject(),
                        inputData.getFile());
                if (bsconfigFile.isPresent()) {
                    VirtualFile parent = bsconfigFile.get().getParent();
                    boolean useExternalAsSource = "bs-platform".equals(parent.getName());
                    BsConfig bsConfig = BsConfigReader.read(bsconfigFile.get(), useExternalAsSource);
                    if (!bsConfig.isInSources(inputData.getFile())) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("»» SKIP " + inputData.getFile() + " / bsconf: " + bsconfigFile);
                        }
                        return Collections.emptyMap();
                    }

                    namespace = bsConfig.getNamespace();
                }
                String moduleName = psiFile.getModuleName();

                FileModuleData value = new FileModuleData(inputData.getFile(), namespace, moduleName, FileHelper.isOCaml(inputData.getFileType()),
                                                          psiFile.isInterface(), psiFile.isComponent());
                if (LOG.isDebugEnabled()) {
                    String path = inputData.getFile().getPath();
                    LOG.debug("indexing " + Platform.removeProjectDir(inputData.getProject(), path) + ": " + value);
                }

                map.put(moduleName, value);
                if (!namespace.isEmpty()) {
                    map.put(namespace + "." + moduleName, value);
                }

                return map;
            }
        }
        return Collections.emptyMap();
    };
}
 
Example #5
Source File: MethodArgumentDroppedIndex.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Integer, FileContent> getIndexer() {
    return inputData -> {
        Set<PsiElement> elements = new HashSet<>();

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(inputData.getPsiFile(), el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );

        Map<String, Integer> methodMap = new HashMap<>();

        for (PsiElement gatheredElement : elements) {
            PsiElement parent = gatheredElement.getParent().getParent();
            if (parent instanceof ArrayHashElement) {
                ArrayHashElement arr = (ArrayHashElement) parent;
                PhpPsiElement value = arr.getValue();
                if (value instanceof ArrayCreationExpression) {
                    ArrayCreationExpression creationExpression = (ArrayCreationExpression) value;
                    creationExpression.getHashElements().forEach(x -> {
                        PhpPsiElement key = x.getKey();
                        if (key != null && key.getText().contains("maximumNumberOfArguments")) {
                            methodMap.put("\\" + ((StringLiteralExpression) gatheredElement).getContents(), Integer.parseInt(x.getValue().getText()));
                        }
                    });
                }
            }
        }

        return methodMap;
    };
}
 
Example #6
Source File: NodeTypesYamlFileIndex.java    From intellij-neos with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
    return new NodeTypesYamlIndexer();
}
 
Example #7
Source File: PantsAddressesIndex.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
  return indexer;
}
 
Example #8
Source File: Unity3dYMLAssetIndexExtension.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DataIndexer<Integer, List<Unity3dYMLAsset>, FileContent> getIndexer()
{
	return myIndexer;
}
 
Example #9
Source File: Unity3dMetaIndexExtension.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DataIndexer<String, Integer, FileContent> getIndexer()
{
	return myIndexer;
}
 
Example #10
Source File: PlatformIdTableBuilding.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
public CompositeTodoIndexer(@Nonnull DataIndexer<TodoIndexEntry, Integer, FileContent>... indexers) {
  this.indexers = indexers;
}