下面列出了com.intellij.psi.PsiRecursiveElementVisitor#gnu.trove.THashMap 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void processAllKeysAsDeleted(final RemovedKeyProcessor<? super Key> removeProcessor) throws StorageException {
if (myMap instanceof THashMap) {
final StorageException[] exception = new StorageException[]{null};
((THashMap<Key, Value>)myMap).forEachEntry(new TObjectObjectProcedure<Key, Value>() {
@Override
public boolean execute(Key k, Value v) {
try {
removeProcessor.process(k, myInputId);
}
catch (StorageException e) {
exception[0] = e;
return false;
}
return true;
}
});
if (exception[0] != null) throw exception[0];
}
else {
for (Key key : myMap.keySet()) {
removeProcessor.process(key, myInputId);
}
}
}
private synchronized Map<Module, MultiValuesMap<LogicalRootType, LogicalRoot>> getRoots(final ModuleManager moduleManager) {
if (myRoots == null) {
myRoots = new THashMap<Module, MultiValuesMap<LogicalRootType, LogicalRoot>>();
final Module[] modules = moduleManager.getModules();
for (Module module : modules) {
final MultiValuesMap<LogicalRootType, LogicalRoot> map = new MultiValuesMap<LogicalRootType, LogicalRoot>();
for (Map.Entry<LogicalRootType, Collection<NotNullFunction>> entry : myProviders.entrySet()) {
final Collection<NotNullFunction> functions = entry.getValue();
for (NotNullFunction function : functions) {
map.putAll(entry.getKey(), (List<LogicalRoot>) function.fun(module));
}
}
myRoots.put(module, map);
}
}
return myRoots;
}
@Override
public void run() {
EditorFoldingInfo info = EditorFoldingInfo.get(myEditor);
FoldingModelEx foldingModel = (FoldingModelEx)myEditor.getFoldingModel();
Map<TextRange, Boolean> rangeToExpandStatusMap = new THashMap<>();
removeInvalidRegions(info, foldingModel, rangeToExpandStatusMap);
Map<FoldRegion, Boolean> shouldExpand = new THashMap<>();
Map<FoldingGroup, Boolean> groupExpand = new THashMap<>();
List<FoldRegion> newRegions = addNewRegions(info, foldingModel, rangeToExpandStatusMap, shouldExpand, groupExpand);
applyExpandStatus(newRegions, shouldExpand, groupExpand);
foldingModel.clearDocumentRangesModificationStatus();
}
protected void initializeParameterIndexes() {
A = new Alphabet();
V = new LDouble[PARAMETER_TABLE_INITIAL_CAPACITY];
G = new LDouble[PARAMETER_TABLE_INITIAL_CAPACITY];
m_trainingData = new ArrayList<TDoubleArrayList>(1000);
m_trainingLabels = new TIntArrayList(1000);
m_testData = new ArrayList<TDoubleArrayList>(100);
m_testLabels = new TIntArrayList(100);
m_devData = new ArrayList<TDoubleArrayList>(100);
m_devLabels = new TIntArrayList(100);
savedValues = new TObjectDoubleHashMap<String>(1000);
m_savedFormulas = new ArrayList<LogFormula>(FORMULA_LIST_INITIAL_CAPACITY);
m_current = 0;
m_savedLLFormulas = new ArrayList<LazyLookupLogFormula>(LLFORMULA_LIST_INITIAL_CAPACITY);
m_llcurrent = 0;
mLookupChart = new THashMap<Integer,LogFormula>(PARAMETER_TABLE_INITIAL_CAPACITY);
}
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
return inputData -> {
Map<String, Void> map = new THashMap<>();
PsiFile psiFile = inputData.getPsiFile();
if(!(psiFile instanceof YAMLFile) || !psiFile.getName().endsWith(".permissions.yml")) {
return map;
}
for (YAMLKeyValue yamlKeyValue : YamlHelper.getTopLevelKeyValues((YAMLFile) psiFile)) {
String keyText = yamlKeyValue.getKeyText();
if(StringUtils.isBlank(keyText)) {
continue;
}
map.put(keyText, null);
}
return map;
};
}
/**
* @return environment map of the default user in wsl
*/
@Nonnull
public Map<String, String> getEnvironment() {
try {
ProcessOutput processOutput = executeOnWsl(5000, "env");
Map<String, String> result = new THashMap<>();
for (String string : processOutput.getStdoutLines()) {
int assignIndex = string.indexOf('=');
if (assignIndex == -1) {
result.put(string, "");
}
else {
result.put(string.substring(0, assignIndex), string.substring(assignIndex + 1));
}
}
return result;
}
catch (ExecutionException e) {
LOG.warn(e);
}
return Collections.emptyMap();
}
@Override
public List<ArrangementSectionRule> getExtendedSectionRules() {
synchronized (myExtendedSectionRules) {
if (myExtendedSectionRules.isEmpty()) {
final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition = new THashMap<String, StdArrangementRuleAliasToken>(myRulesAliases.size());
for (StdArrangementRuleAliasToken alias : myRulesAliases) {
final String id = alias.getId();
tokenIdToDefinition.put(id, alias);
}
final List<ArrangementSectionRule> sections = getSections();
for (ArrangementSectionRule section : sections) {
final List<StdArrangementMatchRule> extendedRules = new ArrayList<StdArrangementMatchRule>();
for (StdArrangementMatchRule rule : section.getMatchRules()) {
appendExpandedRules(rule, extendedRules, tokenIdToDefinition);
}
myExtendedSectionRules.add(ArrangementSectionRule.create(section.getStartComment(), section.getEndComment(), extendedRules));
}
}
}
return myExtendedSectionRules;
}
@Nullable
FileAttributes getAttributes(@Nonnull VirtualFile file) {
VirtualFile parent = file.getParent();
int parentId = parent instanceof VirtualFileWithId ? ((VirtualFileWithId)parent).getId() : -((VirtualFileWithId)file).getId();
TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
THashMap<String, FileAttributes> nestedMap = map.get(parentId);
String name = file.getName();
FileAttributes attributes = nestedMap != null ? nestedMap.get(name) : null;
if (attributes == null) {
if (nestedMap != null && !(nestedMap instanceof IncompleteChildrenMap)) {
return null; // our info from parent doesn't mention the child in this refresh session
}
FileInfo info = myKernel.getInfo(file.getPath());
if (info == null) {
return null;
}
attributes = info.toFileAttributes();
if (nestedMap == null) {
nestedMap = new IncompleteChildrenMap<>(FileUtil.PATH_HASHING_STRATEGY);
map.put(parentId, nestedMap);
}
nestedMap.put(name, attributes);
}
return attributes;
}
public static void convertGoldTestToFramesFile()
{
String goldFile = malRootDir+"/testdata/johansson.fulltest.sentences.frames";
String outFile = malRootDir+"/FrameStructureExtraction/release/temp_johansson_full/file.frame.elements";
ArrayList<String> inLines = ParsePreparation.readSentencesFromFile(goldFile);
ArrayList<String> outLines = new ArrayList<String>();
THashMap<String,THashSet<String>> frameMap = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject("lrdata/framenet.original.map");
for(String inLine: inLines)
{
String[] toks = inLine.split("\t");
if(!frameMap.contains(toks[0]))
continue;
String outLine = "1\t"+toks[0]+"\t"+toks[1]+"\t"+toks[2]+"\t"+toks[3]+"\t"+toks[4];
outLines.add(outLine);
}
ParsePreparation.writeSentencesToTempFile(outFile, outLines);
}
public static void convertGoldJohanssonToFramesFile()
{
String goldFile = malRootDir+"/testdata/semeval.fulltest.sentences.frame.elements";
String outFile = malRootDir+"/testdata/file.frame.elements";
ArrayList<String> inLines = ParsePreparation.readSentencesFromFile(goldFile);
ArrayList<String> outLines = new ArrayList<String>();
THashMap<String,THashSet<String>> frameMap = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject("lrdata/framenet.original.map");
for(String inLine: inLines)
{
String[] toks = inLine.split("\t");
if(!frameMap.contains(toks[1]))
continue;
String outLine = "1\t"+toks[1]+"\t"+toks[2]+"\t"+toks[3]+"\t"+toks[4]+"\t"+toks[5];
outLines.add(outLine);
}
ParsePreparation.writeSentencesToTempFile(outFile, outLines);
}
@Nonnull
private synchronized Map<Class<?>, Binding> getElementBindings() {
if (itemBindings == null) {
Binding binding = XmlSerializerImpl.getBinding(itemType);
if (annotation == null || annotation.elementTypes().length == 0) {
itemBindings = binding == null ? Collections.<Class<?>, Binding>emptyMap() : Collections.<Class<?>, Binding>singletonMap(itemType, binding);
}
else {
itemBindings = new THashMap<Class<?>, Binding>();
if (binding != null) {
itemBindings.put(itemType, binding);
}
for (Class aClass : annotation.elementTypes()) {
Binding b = XmlSerializerImpl.getBinding(aClass);
if (b != null) {
itemBindings.put(aClass, b);
}
}
if (itemBindings.isEmpty()) {
itemBindings = Collections.emptyMap();
}
}
}
return itemBindings;
}
public static void fixTokenization(String inputFile, String outputFile, THashMap<String, String> conv)
{
try
{
BufferedReader bReader = new BufferedReader(new FileReader(inputFile));
BufferedWriter bWriter = new BufferedWriter(new FileWriter(outputFile));
String line = null;
while((line=bReader.readLine())!=null)
{
line = line.trim();
System.out.println(line);
line = fixDoubleQuotes(line,conv);
line = fixOpeningQuote(line,conv);
line = fixClosingQuote(line,conv);
bWriter.write(line+"\n");
}
bReader.close();
bWriter.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
return inputData -> {
final Map<String, Void> map = new THashMap<>();
PsiFile psiFile = inputData.getPsiFile();
if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
return map;
}
if(!(psiFile instanceof TwigFile)) {
return map;
}
TwigUtil.visitTemplateIncludes((TwigFile) psiFile, templateInclude ->
map.put(TwigUtil.normalizeTemplateName(templateInclude.getTemplateName()), null)
);
return map;
};
}
/**
* @param fileOrDir
* @param refreshContext
* @param childrenToRefresh null means all
* @param existingPersistentChildren
*/
RefreshingFileVisitor(@Nonnull NewVirtualFile fileOrDir,
@Nonnull RefreshContext refreshContext,
@Nullable Collection<String> childrenToRefresh,
@Nonnull Collection<? extends VirtualFile> existingPersistentChildren) {
myFileOrDir = fileOrDir;
myRefreshContext = refreshContext;
myPersistentChildren = new THashMap<>(existingPersistentChildren.size(), refreshContext.strategy);
myChildrenWeAreInterested = childrenToRefresh == null ? null : new THashSet<>(childrenToRefresh, refreshContext.strategy);
for (VirtualFile child : existingPersistentChildren) {
String name = child.getName();
myPersistentChildren.put(name, child);
if (myChildrenWeAreInterested != null) myChildrenWeAreInterested.add(name);
}
}
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
return fileContent -> {
final Map<String, Void> map = new THashMap<>();
PsiFile psiFile = fileContent.getPsiFile();
if(!(psiFile instanceof BladeFileImpl)) {
return map;
}
psiFile.acceptChildren(new BladeDirectivePsiElementWalkingVisitor(BladeTokenTypes.STACK_DIRECTIVE, map));
return map;
};
}
@RequiredReadAction
@Override
public void process(@Nonnull CSharpResolveOptions options,
@Nonnull DotNetGenericExtractor defaultExtractor,
@Nullable PsiElement forceQualifierElement,
@Nonnull Processor<ResolveResult> processor)
{
DotNetTypeDeclaration thisTypeDeclaration = PsiTreeUtil.getContextOfType(options.getElement(), DotNetTypeDeclaration.class);
if(thisTypeDeclaration != null)
{
thisTypeDeclaration = CSharpCompositeTypeDeclaration.selectCompositeOrSelfType(thisTypeDeclaration);
DotNetGenericExtractor genericExtractor = DotNetGenericExtractor.EMPTY;
int genericParametersCount = thisTypeDeclaration.getGenericParametersCount();
if(genericParametersCount > 0)
{
Map<DotNetGenericParameter, DotNetTypeRef> map = new THashMap<>(genericParametersCount);
for(DotNetGenericParameter genericParameter : thisTypeDeclaration.getGenericParameters())
{
map.put(genericParameter, new CSharpTypeRefFromGenericParameter(genericParameter));
}
genericExtractor = CSharpGenericExtractor.create(map);
}
processor.process(new CSharpResolveResultWithExtractor(thisTypeDeclaration, genericExtractor));
}
}
@Override
@NotNull
public Map<String, Void> map(@NotNull final FileContent inputData) {
final PsiFile psiFile = inputData.getPsiFile();
final List<HaxeClass> classes = HaxeResolveUtil.findComponentDeclarations(psiFile);
if (classes.isEmpty()) {
return Collections.emptyMap();
}
final Map<String, Void> result = new THashMap<>();
for (HaxeClass haxeClass : classes) {
final String className = haxeClass.getName();
if (className == null) {
continue;
}
result.put(className, null);
for (HaxeNamedComponent namedComponent : getNamedComponents(haxeClass)) {
result.put(namedComponent.getName(), null);
}
}
return result;
}
public void testAddEqualStringsAndMuchGarbage() throws IOException {
final Map<Integer,String> strings = new THashMap<Integer, String>(10001);
String s = "IntelliJ IDEA";
final int index = myEnumerator.enumerate(s);
strings.put(index, s);
// clear strings and nodes cache
for (int i = 0; i < 10000; ++i) {
final String v = Integer.toString(i) + "Just another string";
final int idx = myEnumerator.enumerate(v);
assertEquals(v, myEnumerator.valueOf(idx));
strings.put(idx, v);
}
for(Map.Entry<Integer, String> e:strings.entrySet()) {
assertEquals((int)e.getKey(), myEnumerator.enumerate(e.getValue()));
}
final Set<String> enumerated = new HashSet<String>(myEnumerator.getAllDataObjects(null));
assertEquals(new HashSet<String>(strings.values()), enumerated);
}
@NotNull
@Override
public DataIndexer<String, String, FileContent> getIndexer() {
return inputData -> {
final Map<String, String> map = new THashMap<>();
PsiFile psiFile = inputData.getPsiFile();
if(!(psiFile instanceof PhpFile)) {
return map;
}
if(!IndexUtil.isValidForIndex(inputData, psiFile)) {
return map;
}
psiFile.accept(new MyPsiRecursiveElementWalkingVisitor(map));
return map;
};
}
public static THashMap<String, THashMap<String, Double>>
readTrainDistFile(String trainDistFile) {
THashMap<String, THashMap<String, Double>> result =
new THashMap<String, THashMap<String, Double>>();
ArrayList<String> sents = ParsePreparation.readSentencesFromFile(trainDistFile);
for (String sent: sents) {
sent = sent.trim();
String[] toks = sent.split("\t");
String pred = toks[0];
String[] toks1 = toks[1].trim().split(" ");
THashMap<String, Double> map = new THashMap<String, Double>();
for (int i = 0; i < toks1.length; i = i + 2) {
String frame = toks1[i];
double prob = new Double(toks1[i+1]);
map.put(frame, prob);
}
result.put(pred, map);
}
return result;
}
@Override
@Nullable
public <T extends SemElement> List<T> getSemElements(final SemKey<T> key, @Nonnull final PsiElement psi) {
List<T> cached = _getCachedSemElements(key, true, psi);
if (cached != null) {
return cached;
}
ensureInitialized();
RecursionGuard.StackStamp stamp = RecursionManager.createGuard("semService").markStack();
LinkedHashSet<T> result = new LinkedHashSet<>();
final Map<SemKey, List<SemElement>> map = new THashMap<>();
for (final SemKey each : key.getInheritors()) {
List<SemElement> list = createSemElements(each, psi);
map.put(each, list);
result.addAll((List<T>)list);
}
if (stamp.mayCacheNow()) {
final SemCacheChunk persistent = getOrCreateChunk(psi);
for (SemKey semKey : map.keySet()) {
persistent.putSemElements(semKey, map.get(semKey));
}
}
return new ArrayList<>(result);
}
private static Map<String, TextAttributesKey> createAdditionalHlAttrs() {
final Map<String, TextAttributesKey> descriptors = new THashMap<>();
descriptors.put("keyword", JSColorSettings.JSKEYWORD);
descriptors.put("function", JSColorSettings.FUNCTION);
descriptors.put("function_name", JSColorSettings.FUNCTION_NAME);
descriptors.put("val", JSColorSettings.VAL);
descriptors.put("local_variable", JSColorSettings.VARIABLE);
descriptors.put("this", JSColorSettings.THIS_SUPER);
descriptors.put("null", JSColorSettings.NULL);
descriptors.put("debugger", JSColorSettings.DEBUGGER);
descriptors.put("import", JSColorSettings.MODULE);
return descriptors;
}
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
return inputData -> {
Map<String, Void> map = new THashMap<>();
String path = inputData.getFile().getPath();
if (path.contains("sysext") || path.contains("typo3conf/ext")) {
map.putAll(compileId(inputData));
return map;
}
VirtualFile extensionRootFolder = FilesystemUtil.findExtensionRootFolder(inputData.getFile());
if (extensionRootFolder != null) {
// 1. try to read sibling composer.json
VirtualFile composerJsonFile = extensionRootFolder.findChild("composer.json");
if (composerJsonFile != null) {
String extensionKey = findExtensionKey(composerJsonFile);
if (extensionKey != null) {
map.putAll(compileId(extensionRootFolder, extensionKey, inputData.getFile()));
return map;
}
}
// 2. try to infer from directory name
map.putAll(compileId(extensionRootFolder.getName(), extensionRootFolder.getPath(), inputData.getFile()));
}
return map;
};
}
@Nonnull
public static Map<LocalInspectionToolWrapper, Set<String>> getToolsToSpecifiedLanguages(@Nonnull List<LocalInspectionToolWrapper> toolWrappers) {
Map<LocalInspectionToolWrapper, Set<String>> toolToLanguages = new THashMap<>();
for (LocalInspectionToolWrapper wrapper : toolWrappers) {
ProgressManager.checkCanceled();
Set<String> specifiedLangIds = getDialectIdsSpecifiedForTool(wrapper);
toolToLanguages.put(wrapper, specifiedLangIds);
}
return toolToLanguages;
}
private Map<Group, GroupWrapper> createGroupNodes(Collection<Group> groups) {
Map<Group, GroupWrapper> result = new THashMap<Group, GroupWrapper>();
for (Group group : groups) {
result.put(group, createGroupWrapper(getProject(), group, myTreeModel));
}
return result;
}
@NotNull
public HaxeGenericSpecialization getInnerSpecialization(PsiElement element) {
final String prefixToRemove = getGenericKey(element, "");
final Map<String, HaxeClassResolveResult> result = new THashMap<String, HaxeClassResolveResult>();
for (String key : map.keySet()) {
final HaxeClassResolveResult value = map.get(key);
String newKey = key;
if (newKey.startsWith(prefixToRemove)) {
newKey = newKey.substring(prefixToRemove.length());
}
result.put(newKey, value);
}
return new HaxeGenericSpecialization(result);
}
@NotNull
@Override
public DataIndexer<String, Set<String>, FileContent> getIndexer() {
return inputData -> {
Map<String, Set<String>> map = new THashMap<>();
PsiFile psiFile = inputData.getPsiFile();
if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
return map;
}
if(!(psiFile instanceof YAMLFile) || !isValidForIndex(psiFile)) {
return map;
}
for(YAMLKeyValue yamlKeyValue: YamlHelper.getTopLevelKeyValues((YAMLFile) psiFile)) {
String key = PsiElementUtils.trimQuote(yamlKeyValue.getKeyText());
if(StringUtils.isBlank(key) || key.contains("*")) {
continue;
}
Set<String> mappings = new HashSet<>();
YAMLKeyValue mapping = YamlHelper.getYamlKeyValue(yamlKeyValue, "mapping");
if(mapping == null) {
continue;
}
Set<String> keySet = YamlHelper.getKeySet(mapping);
if(keySet != null) {
mappings.addAll(keySet);
}
map.put(key, mappings);
}
return map;
};
}
public static Map<String, FluidVariable> collectControllerVariables(FluidFile templateFile) {
Map<String, FluidVariable> collected = new THashMap<>();
String controllerName = inferControllerNameFromTemplateFile(templateFile);
String actionName = inferActionNameFromTemplateFile(templateFile);
findPossibleMethodTargetsForControllerAction(templateFile.getProject(), controllerName, actionName).forEach(c -> {
ControllerMethodWalkerVisitor visitor = new ControllerMethodWalkerVisitor();
c.accept(visitor);
collected.putAll(visitor.variables);
});
return collected;
}
@Override
public <B extends XBreakpoint<?>> XBreakpointType<B, ?> findBreakpointType(@Nonnull Class<? extends XBreakpointType<B, ?>> typeClass) {
if (myBreakpointTypeByClass == null) {
myBreakpointTypeByClass = new THashMap<Class<? extends XBreakpointType>, XBreakpointType<?, ?>>();
for (XBreakpointType<?, ?> breakpointType : XBreakpointUtil.getBreakpointTypes()) {
myBreakpointTypeByClass.put(breakpointType.getClass(), breakpointType);
}
}
XBreakpointType<?, ?> type = myBreakpointTypeByClass.get(typeClass);
//noinspection unchecked
return (XBreakpointType<B, ?>)type;
}
private Map<String, FluidVariable> collectXmlMapViewHelperSetVariables(PsiElement psiElement) {
if (!containsLanguage(HTMLLanguage.INSTANCE, psiElement)) {
return new THashMap<>();
}
PsiFile psi = extractLanguagePsiForElement(HTMLLanguage.INSTANCE, psiElement);
if (psi == null) {
return new THashMap<>();
}
XmlFAliasVisitor visitor = new XmlFAliasVisitor();
psi.accept(visitor);
return visitor.variables;
}