Java Code Examples for gnu.trove.TIntObjectHashMap#put()

The following examples show how to use gnu.trove.TIntObjectHashMap#put() . 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: Win32FsCache.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
String[] list(@Nonnull VirtualFile file) {
  String path = file.getPath();
  FileInfo[] fileInfo = myKernel.listChildren(path);
  if (fileInfo == null || fileInfo.length == 0) {
    return ArrayUtil.EMPTY_STRING_ARRAY;
  }

  String[] names = new String[fileInfo.length];
  TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
  int parentId = ((VirtualFileWithId)file).getId();
  THashMap<String, FileAttributes> nestedMap = map.get(parentId);
  if (nestedMap == null) {
    nestedMap = new THashMap<String, FileAttributes>(fileInfo.length, FileUtil.PATH_HASHING_STRATEGY);
    map.put(parentId, nestedMap);
  }
  for (int i = 0, length = fileInfo.length; i < length; i++) {
    FileInfo info = fileInfo[i];
    String name = info.getName();
    nestedMap.put(name, info.toFileAttributes());
    names[i] = name;
  }
  return names;
}
 
Example 2
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 6 votes vote down vote up
private static void addOneErrorInfo(String str, TIntObjectHashMap<MessageInfo> indexToErrorInfo) {
  int firstDelimPos = str.indexOf(Communicator.DELIMITER);
  int secondDelimPos = str.indexOf(Communicator.DELIMITER, firstDelimPos + 1);
  int lastDelimPos = str.lastIndexOf(Communicator.DELIMITER);
  int messageId = Integer.parseInt(str.substring(0, firstDelimPos));
  String type = str.substring(firstDelimPos + 1, secondDelimPos);

  AnalyzeProcessor.MessageType messageType = type.indexOf("WARNING") != -1 ?
    AnalyzeProcessor.MessageType.Warning :
    type.equals("INFO") ? AnalyzeProcessor.MessageType.Info :
    type.equals("INTENTION") ? AnalyzeProcessor.MessageType.Intention :
    AnalyzeProcessor.MessageType.Error;

  indexToErrorInfo.put(
    messageId,
    new MessageInfo(
      str.substring(secondDelimPos + 1, lastDelimPos),
      messageType,
      getIntFromStringWithDefault(str.substring(lastDelimPos + 1))
    )
  );
}
 
Example 3
Source File: DuplicatesProfileCache.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static DuplicatesProfile getProfile(@Nonnull DupInfo dupInfo, int index) {
  TIntObjectHashMap<DuplicatesProfile> patternCache = ourProfileCache.get(dupInfo);
  if (patternCache == null) {
    patternCache = new TIntObjectHashMap<>();
    ourProfileCache.put(dupInfo, patternCache);
  }
  DuplicatesProfile result = patternCache.get(index);
  if (result == null) {
    DuplicatesProfile theProfile = null;
    for (DuplicatesProfile profile : DuplicatesProfile.EP_NAME.getExtensionList()) {
      if (profile.isMyDuplicate(dupInfo, index)) {
        theProfile = profile;
        break;
      }
    }
    result = theProfile == null ? NULL_PROFILE : theProfile;
    patternCache.put(index, result);
  }
  return result == NULL_PROFILE ? null : result;
}
 
Example 4
Source File: Win32FsCache.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: ExpandedSupModel.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static TIntObjectHashMap<String> readAlphabet(String alphabetFile) {
	TIntObjectHashMap<String> map = new TIntObjectHashMap<String>();
	try
	{
		String line = null;
		int count = 0;
		BufferedReader bReader = new BufferedReader(new FileReader(alphabetFile));
		while((line=bReader.readLine())!=null)
		{
			if(count==0)
			{
				count++;
				continue;
			}
			String[] toks = line.trim().split("\t");
			map.put(new Integer(toks[1]),toks[0]);
		}
		bReader.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	return map;
}
 
Example 6
Source File: ObservatoryFile.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Unpacks a position token table into a map from position id to Position.
 * <p>
 * <p>See <a href="https://github.com/dart-lang/vm_service_drivers/blob/master/dart/tool/service.md#scrip">docs</a>.
 */
@NotNull
private static TIntObjectHashMap<Position> createPositionMap(@NotNull final List<List<Integer>> table) {
  final TIntObjectHashMap<Position> result = new TIntObjectHashMap<>();

  for (List<Integer> line : table) {
    // Each line consists of a line number followed by (tokenId, columnNumber) pairs.
    // Both lines and columns are one-based.
    final Iterator<Integer> items = line.iterator();

    // Convert line number from one-based to zero-based.
    final int lineNumber = Math.max(0, items.next() - 1);
    while (items.hasNext()) {
      final int tokenId = items.next();
      // Convert column from one-based to zero-based.
      final int column = Math.max(0, items.next() - 1);
      result.put(tokenId, new Position(lineNumber, column));
    }
  }
  return result;
}
 
Example 7
Source File: DartVmServiceDebugProcess.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
private static TIntObjectHashMap<Pair<Integer, Integer>> createTokenPosToLineAndColumnMap(@NotNull final List<List<Integer>> tokenPosTable) {
  // Each subarray consists of a line number followed by (tokenPos, columnNumber) pairs
  // see https://github.com/dart-lang/vm_service_drivers/blob/master/dart/tool/service.md#script
  final TIntObjectHashMap<Pair<Integer, Integer>> result = new TIntObjectHashMap<>();

  for (List<Integer> lineAndPairs : tokenPosTable) {
    final Iterator<Integer> iterator = lineAndPairs.iterator();
    final int line = Math.max(0, iterator.next() - 1);
    while (iterator.hasNext()) {
      final int tokenPos = iterator.next();
      final int column = Math.max(0, iterator.next() - 1);
      result.put(tokenPos, Pair.create(line, column));
    }
  }

  return result;
}
 
Example 8
Source File: ObservatoryFile.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Unpacks a position token table into a map from position id to Position.
 * <p>
 * <p>See <a href="https://github.com/dart-lang/vm_service_drivers/blob/master/dart/tool/service.md#scrip">docs</a>.
 */
@NotNull
private static TIntObjectHashMap<Position> createPositionMap(@NotNull final List<List<Integer>> table) {
  final TIntObjectHashMap<Position> result = new TIntObjectHashMap<>();

  for (List<Integer> line : table) {
    // Each line consists of a line number followed by (tokenId, columnNumber) pairs.
    // Both lines and columns are one-based.
    final Iterator<Integer> items = line.iterator();

    // Convert line number from one-based to zero-based.
    final int lineNumber = Math.max(0, items.next() - 1);
    while (items.hasNext()) {
      final int tokenId = items.next();
      // Convert column from one-based to zero-based.
      final int column = Math.max(0, items.next() - 1);
      result.put(tokenId, new Position(lineNumber, column));
    }
  }
  return result;
}
 
Example 9
Source File: DartVmServiceDebugProcess.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
private static TIntObjectHashMap<Pair<Integer, Integer>> createTokenPosToLineAndColumnMap(@NotNull final List<List<Integer>> tokenPosTable) {
  // Each subarray consists of a line number followed by (tokenPos, columnNumber) pairs
  // see https://github.com/dart-lang/vm_service_drivers/blob/master/dart/tool/service.md#script
  final TIntObjectHashMap<Pair<Integer, Integer>> result = new TIntObjectHashMap<>();

  for (List<Integer> lineAndPairs : tokenPosTable) {
    final Iterator<Integer> iterator = lineAndPairs.iterator();
    final int line = Math.max(0, iterator.next() - 1);
    while (iterator.hasNext()) {
      final int tokenPos = iterator.next();
      final int column = Math.max(0, iterator.next() - 1);
      result.put(tokenPos, Pair.create(line, column));
    }
  }

  return result;
}
 
Example 10
Source File: AbstractDataGetter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public TIntObjectHashMap<T> preLoadCommitData(@Nonnull TIntHashSet commits) throws VcsException {
  TIntObjectHashMap<T> result = new TIntObjectHashMap<>();
  final MultiMap<VirtualFile, String> rootsAndHashes = MultiMap.create();
  commits.forEach(commit -> {
    CommitId commitId = myHashMap.getCommitId(commit);
    if (commitId != null) {
      rootsAndHashes.putValue(commitId.getRoot(), commitId.getHash().asString());
    }
    return true;
  });

  for (Map.Entry<VirtualFile, Collection<String>> entry : rootsAndHashes.entrySet()) {
    VcsLogProvider logProvider = myLogProviders.get(entry.getKey());
    if (logProvider != null) {
      List<? extends T> details = readDetails(logProvider, entry.getKey(), ContainerUtil.newArrayList(entry.getValue()));
      for (T data : details) {
        int index = myHashMap.getCommitIndex(data.getId(), data.getRoot());
        result.put(index, data);
      }
      saveInCache(result);
    }
    else {
      LOG.error("No log provider for root " + entry.getKey().getPath() + ". All known log providers " + myLogProviders);
    }
  }

  return result;
}
 
Example 11
Source File: LineMarkersPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<LineMarkerInfo<PsiElement>> mergeLineMarkers(@Nonnull List<LineMarkerInfo<PsiElement>> markers, @Nonnull Document document) {
  List<MergeableLineMarkerInfo<PsiElement>> forMerge = new ArrayList<>();
  TIntObjectHashMap<List<MergeableLineMarkerInfo<PsiElement>>> sameLineMarkers = new TIntObjectHashMap<>();

  for (int i = markers.size() - 1; i >= 0; i--) {
    LineMarkerInfo<PsiElement> marker = markers.get(i);
    if (marker instanceof MergeableLineMarkerInfo) {
      MergeableLineMarkerInfo<PsiElement> mergeable = (MergeableLineMarkerInfo<PsiElement>)marker;
      forMerge.add(mergeable);
      markers.remove(i);

      int line = document.getLineNumber(marker.startOffset);
      List<MergeableLineMarkerInfo<PsiElement>> infos = sameLineMarkers.get(line);
      if (infos == null) {
        infos = new ArrayList<>();
        sameLineMarkers.put(line, infos);
      }
      infos.add(mergeable);
    }
  }

  if (forMerge.isEmpty()) return markers;

  List<LineMarkerInfo<PsiElement>> result = new ArrayList<>(markers);

  sameLineMarkers.forEachValue(infos -> result.addAll(MergeableLineMarkerInfo.merge(infos)));

  return result;
}
 
Example 12
Source File: FileTemplateUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String templateToRegex(String text, TIntObjectHashMap<String> offsetToProperty, Project project) {
  List<Object> properties = ContainerUtil.newArrayList(FileTemplateManager.getInstance(project).getDefaultProperties().keySet());
  properties.add(FileTemplate.ATTRIBUTE_PACKAGE_NAME);

  String regex = escapeRegexChars(text);
  // first group is a whole file header
  int groupNumber = 1;
  for (Object property : properties) {
    String name = property.toString();
    String escaped = escapeRegexChars("${" + name + "}");
    boolean first = true;
    for (int i = regex.indexOf(escaped); i != -1 && i < regex.length(); i = regex.indexOf(escaped, i + 1)) {
      String replacement = first ? "([^\\n]*)" : "\\" + groupNumber;
      int delta = escaped.length() - replacement.length();
      int[] offs = offsetToProperty.keys();
      for (int off : offs) {
        if (off > i) {
          String prop = offsetToProperty.remove(off);
          offsetToProperty.put(off - delta, prop);
        }
      }
      offsetToProperty.put(i, name);
      regex = regex.substring(0, i) + replacement + regex.substring(i + escaped.length());
      if (first) {
        groupNumber++;
        first = false;
      }
    }
  }
  return regex;
}
 
Example 13
Source File: BlockRangesMap.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static TIntObjectHashMap<LeafBlockWrapper> buildTextRangeToInfoMap(final LeafBlockWrapper first) {
  final TIntObjectHashMap<LeafBlockWrapper> result = new TIntObjectHashMap<>();
  LeafBlockWrapper current = first;
  while (current != null) {
    result.put(current.getStartOffset(), current);
    current = current.getNextBlock();
  }
  return result;
}
 
Example 14
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private static RangeHighlighter processHighlighter(int hFrom, int hTo, int colorIndex, TextAttributes attrs,
                                                   Editor editor, TIntObjectHashMap<RangeHighlighter> lastOffsetToMarkersMap,
                                                   THashSet<RangeHighlighter> highlightersSet,
                                                   THashSet<RangeHighlighter> invalidMarkersSet
                                                   ) {
  RangeHighlighter rangeHighlighter = lastOffsetToMarkersMap.get(hFrom);

  if (rangeHighlighter == null ||
      rangeHighlighter.getEndOffset() != hTo ||
      rangeHighlighter.getTextAttributes() != attrs
      ) {
    highlightersSet.add(
      rangeHighlighter = HighlightUtils.createRangeMarker(
        editor,
        hFrom,
        hTo,
        colorIndex,
        attrs
      )
    );

    lastOffsetToMarkersMap.put(hFrom, rangeHighlighter);
  } else {
    highlightersSet.add(rangeHighlighter);
    invalidMarkersSet.remove(rangeHighlighter);
  }

  return rangeHighlighter;
}
 
Example 15
Source File: CompressedRefs.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void putRef(@Nonnull TIntObjectHashMap<List<VcsRef>> map, @Nonnull VcsRef ref, @Nonnull VcsLogStorage hashMap) {
  int index = hashMap.getCommitIndex(ref.getCommitHash(), ref.getRoot());
  List<VcsRef> list = map.get(index);
  if (list == null) map.put(index, list = new SmartList<>());
  list.add(ref);
}
 
Example 16
Source File: CompressedRefs.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void putRefIndex(@Nonnull TIntObjectHashMap<TIntArrayList> map, @Nonnull VcsRef ref, @Nonnull VcsLogStorage hashMap) {
  int index = hashMap.getCommitIndex(ref.getCommitHash(), ref.getRoot());
  TIntArrayList list = map.get(index);
  if (list == null) map.put(index, list = new TIntArrayList());
  list.add(hashMap.getRefIndex(ref));
}
 
Example 17
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private void doAddHighlighters(Editor editor, List<String> highlighterStringList, boolean overriden) {
  if (stamp != communicator.getModificationCount() || failed) return;

  final long started = System.currentTimeMillis();
  Key<THashSet<RangeHighlighter>> highlightersKey = overriden ? myOverridenHighlightersKey : myHighlightersKey;
  THashSet<RangeHighlighter> currentHighlighters = editor.getUserData(highlightersKey);
  final THashSet<RangeHighlighter> invalidMarkers;    

  if (currentHighlighters == null) {
    invalidMarkers = new THashSet<RangeHighlighter>(10000);
  } else {
    invalidMarkers = currentHighlighters;
  }

  currentHighlighters = new THashSet<RangeHighlighter>();
  editor.putUserData(highlightersKey, currentHighlighters);

  final TIntObjectHashMap<RangeHighlighter> lastOffsetToHighlightersMap = new TIntObjectHashMap<RangeHighlighter>();
  final TIntObjectHashMap<RangeHighlighter> overridenMap = new TIntObjectHashMap<RangeHighlighter>();
  final TIntObjectHashMap<RangeHighlighter> overriddingMap = new TIntObjectHashMap<RangeHighlighter>();

  for(RangeHighlighter h:invalidMarkers) {
    if (!h.isValid()) continue;

    final GutterIconRenderer gutterIconRenderer = h.getGutterIconRenderer();
    final int offset = h.getStartOffset();

    if ((!overriden && gutterIconRenderer == null)) {
      lastOffsetToHighlightersMap.put(offset, h);
    } else if (overriden && gutterIconRenderer != null) {
      final HighlightUtils.MyGutterIconRenderer myGutterIconRenderer = (HighlightUtils.MyGutterIconRenderer) gutterIconRenderer;
      final boolean overrides = myGutterIconRenderer.isOverrides();
      
      ((HighlightUtils.MyGutterIconRenderer) gutterIconRenderer).clearData();
      ((overrides)?overriddingMap:overridenMap).put(offset, h);
    }
  }

  final EditorColorsScheme colorsScheme = editor.getColorsScheme();

  for(String s: highlighterStringList) {
    processHighlighterString(editor, colorsScheme, s, overriddingMap, overridenMap, lastOffsetToHighlightersMap,
      currentHighlighters, invalidMarkers);
  }

  //System.out.println("Updated highlighters 2/5 for "+ (System.currentTimeMillis() - started));
  for(RangeHighlighter rangeHighlighter:invalidMarkers) {
    editor.getMarkupModel().removeHighlighter(rangeHighlighter);
    currentHighlighters.remove(rangeHighlighter);
  }

  long doneFor = System.currentTimeMillis() - started;
  //System.out.println("Updated highlighters 2 for "+ doneFor);
  Communicator.debug("Updated highlighters 2 for "+ doneFor);
}
 
Example 18
Source File: LocalDependencies.java    From whyline with MIT License 2 votes vote down vote up
public List<SetLocal> getPotentialDefinitionsOfLocalIDBefore(Instruction instruction, int localID) {

		TIntObjectHashMap<List<SetLocal>> definitionsByInstruction = definitionsByInstructionIndexLocalID.get(localID);
		if(definitionsByInstruction == null) {
			definitionsByInstruction = new TIntObjectHashMap<List<SetLocal>>(4);
			definitionsByInstructionIndexLocalID.put(localID, definitionsByInstruction);
		}
		
		List<SetLocal> potentialDefs = definitionsByInstruction.get(instruction.getIndex());
		if(potentialDefs == null) {

			potentialDefs = new LinkedList<SetLocal>();
			definitionsByInstruction.put(instruction.getIndex(), potentialDefs);

			gnu.trove.TIntHashSet visited = new gnu.trove.TIntHashSet(64);

			Vector<Instruction> instructionsToAnalyze = new Vector<Instruction>(3);
			instructionsToAnalyze.add(instruction);

			while(!instructionsToAnalyze.isEmpty()) {

				Instruction instructionToAnalyze = instructionsToAnalyze.remove(instructionsToAnalyze.size() - 1);

				if(!visited.contains(instructionToAnalyze.getIndex())) {

					visited.add(instructionToAnalyze.getIndex());

					for(Instruction predecessor : instructionToAnalyze.getOrderedPredecessors())
						if(predecessor instanceof SetLocal && ((SetLocal)predecessor).getLocalID() == localID)
							potentialDefs.add((SetLocal)predecessor);
						else 
							instructionsToAnalyze.add(predecessor);
					
				}
				
			}
			
		}
			
		return potentialDefs;
		
	}