private static CompletionData computeData(final Editor editor, final CharSequence charsSequence) { final int offset = editor.getCaretModel().getOffset(); final CompletionData data = new CompletionData(); IdTableBuilding.scanWords(new IdTableBuilding.ScanWordProcessor() { @Override public void run(final CharSequence chars, @Nullable char[] charsArray, final int start, final int end) { if (start <= offset && end >= offset) { data.myPrefix = charsSequence.subSequence(start, offset).toString(); data.myWordUnderCursor = charsSequence.subSequence(start, end).toString(); data.startOffset = start; } } }, charsSequence, 0, charsSequence.length()); if (data.myPrefix == null) { data.myPrefix = ""; data.myWordUnderCursor = ""; data.startOffset = offset; } return data; }
public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) { ScanContent data = content.getUserData(scanContentKey); if (data != null) { content.putUserData(scanContentKey, null); return data; } final boolean needTodo = content.getFile().isInLocalFileSystem(); // same as TodoIndex.getFilter().isAcceptable final boolean needIdIndex = IdTableBuilding.getFileTypeIndexer(content.getFileType()) instanceof LexerBasedIdIndexer; final IdDataConsumer consumer = needIdIndex? new IdDataConsumer():null; final OccurrenceConsumer todoOccurrenceConsumer = new OccurrenceConsumer(consumer, needTodo); final Lexer filterLexer = indexer.createLexer(todoOccurrenceConsumer); filterLexer.start(content.getContentAsText()); while (filterLexer.getTokenType() != null) filterLexer.advance(); Map<TodoIndexEntry,Integer> todoMap = null; if (needTodo) { for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) { final int count = todoOccurrenceConsumer.getOccurrenceCount(indexPattern); if (count > 0) { if (todoMap == null) todoMap = new THashMap<TodoIndexEntry, Integer>(); todoMap.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count); } } } data = new ScanContent( consumer != null? consumer.getResult():Collections.<IdIndexEntry, Integer>emptyMap(), todoMap != null ? todoMap: Collections.<TodoIndexEntry,Integer>emptyMap() ); if (needIdIndex && needTodo) content.putUserData(scanContentKey, data); return data; }
protected final void scanWordsInToken(final int occurrenceMask, boolean mayHaveFileRefs, final boolean mayHaveEscapes) { myOccurenceMask = occurrenceMask; final int start = getTokenStart(); final int end = getTokenEnd(); IdTableBuilding.scanWords(this, myCachedBufferSequence, myCachedArraySequence, start, end, mayHaveEscapes); if (mayHaveFileRefs) { processPossibleComplexFileName(myCachedBufferSequence, myCachedArraySequence, start, end); } }
private static boolean checkIfGivenXmlHasTheseWords(final String name, final XmlFile tldFileByUri) { if (name == null || name.isEmpty()) return true; final List<String> list = StringUtil.getWordsIn(name); final String[] words = ArrayUtil.toStringArray(list); final boolean[] wordsFound = new boolean[words.length]; final int[] wordsFoundCount = new int[1]; IdTableBuilding.ScanWordProcessor wordProcessor = new IdTableBuilding.ScanWordProcessor() { @Override public void run(final CharSequence chars, @Nullable char[] charsArray, int start, int end) { if (wordsFoundCount[0] == words.length) return; final int foundWordLen = end - start; Next: for (int i = 0; i < words.length; ++i) { final String localName = words[i]; if (wordsFound[i] || localName.length() != foundWordLen) continue; for (int j = 0; j < localName.length(); ++j) { if (chars.charAt(start + j) != localName.charAt(j)) continue Next; } wordsFound[i] = true; wordsFoundCount[0]++; break; } } }; final CharSequence contents = tldFileByUri.getViewProvider().getContents(); IdTableBuilding.scanWords(wordProcessor, contents, 0, contents.length()); return wordsFoundCount[0] == words.length; }
public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) { ScanContent data = content.getUserData(scanContentKey); if (data != null) { content.putUserData(scanContentKey, null); return data; } final boolean needTodo = content.getFile().getFileSystem().getProtocol().equals(StandardFileSystems.FILE_PROTOCOL); final boolean needIdIndex = IdTableBuilding.getFileTypeIndexer(content.getFileType()) instanceof LexerBasedIdIndexer; final IdDataConsumer consumer = needIdIndex? new IdDataConsumer():null; final OccurrenceConsumer todoOccurrenceConsumer = new OccurrenceConsumer(consumer, needTodo); final Lexer filterLexer = indexer.createLexer(todoOccurrenceConsumer); filterLexer.start(content.getContentAsText()); while (filterLexer.getTokenType() != null) filterLexer.advance(); Map<TodoIndexEntry,Integer> todoMap = null; if (needTodo) { for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) { final int count = todoOccurrenceConsumer.getOccurrenceCount(indexPattern); if (count > 0) { if (todoMap == null) todoMap = new THashMap<TodoIndexEntry, Integer>(); todoMap.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count); } } } data = new ScanContent( consumer != null? consumer.getResult():Collections.<IdIndexEntry, Integer>emptyMap(), todoMap != null ? todoMap: Collections.<TodoIndexEntry,Integer>emptyMap() ); if (needIdIndex && needTodo) content.putUserData(scanContentKey, data); return data; }
public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) { ScanContent data = content.getUserData(scanContentKey); if (data != null) { content.putUserData(scanContentKey, null); return data; } final boolean needTodo = content.getFile().getFileSystem() instanceof LocalFileSystem; final boolean needIdIndex = IdTableBuilding.getFileTypeIndexer(content.getFileType()) instanceof LexerBasedIdIndexer; final IdDataConsumer consumer = needIdIndex? new IdDataConsumer():null; final OccurrenceConsumer todoOccurrenceConsumer = new OccurrenceConsumer(consumer, needTodo); final Lexer filterLexer = indexer.createLexer(todoOccurrenceConsumer); filterLexer.start(content.getContentAsText()); while (filterLexer.getTokenType() != null) filterLexer.advance(); Map<TodoIndexEntry,Integer> todoMap = null; if (needTodo) { for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) { final int count = todoOccurrenceConsumer.getOccurrenceCount(indexPattern); if (count > 0) { if (todoMap == null) todoMap = new THashMap<TodoIndexEntry, Integer>(); todoMap.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count); } } } data = new ScanContent( consumer != null? consumer.getResult():Collections.<IdIndexEntry, Integer>emptyMap(), todoMap != null ? todoMap: Collections.<TodoIndexEntry,Integer>emptyMap() ); if (needIdIndex && needTodo) content.putUserData(scanContentKey, data); return data; }