private void assertValidState() { if (myDocument.isInBulkUpdate() || myDirty) return; if (myLineWidths.size() != myEditor.getVisibleLineCount()) { LOG.error("Inconsistent state", new Attachment("editor.txt", myEditor.dumpState())); reset(); } assert myLineWidths.size() == myEditor.getVisibleLineCount(); }
@Nullable private VirtualFileSystemEntry findFileById( int id, boolean cachedOnly, TIntArrayList visited, int mask) { VirtualFileSystemEntry cached = myIdToDirCache.get(id); if (cached != null) return cached; if (visited != null && (visited.size() >= DEPTH_LIMIT || (mask & id) == id && visited.contains(id))) { @NonNls String sb = "Dead loop detected in persistent FS (id=" + id + " cached-only=" + cachedOnly + "):"; for (int i = 0; i < visited.size(); i++) { int _id = visited.get(i); sb += "\n " + _id + " '" + getName(_id) + "' " + String.format("%02x", getFileAttributes(_id)) + ' ' + myIdToDirCache.containsKey(_id); } LOG.error(sb); return null; } int parentId = getParent(id); if (parentId >= id) { if (visited == null) visited = new TIntArrayList(DEPTH_LIMIT); } if (visited != null) visited.add(id); VirtualFileSystemEntry result; if (parentId == 0) { myRootsLock.readLock().lock(); try { result = myRootsById.get(id); } finally { myRootsLock.readLock().unlock(); } } else { VirtualFileSystemEntry parentFile = findFileById(parentId, cachedOnly, visited, mask | id); if (parentFile instanceof VirtualDirectoryImpl) { result = ((VirtualDirectoryImpl) parentFile).findChildById(id, cachedOnly); } else { result = null; } } if (result != null && result.isDirectory()) { VirtualFileSystemEntry old = myIdToDirCache.put(id, result); if (old != null) result = old; } return result; }
void invalidateRange(int startOffset, int endOffset) { myWidthInPixels = -1; int startVisualLine = myView.offsetToVisualLine(startOffset, false); int endVisualLine = myView.offsetToVisualLine(endOffset, true); int lineDiff = myEditor.getVisibleLineCount() - myLineWidths.size(); if (lineDiff > 0) { int[] newEntries = new int[lineDiff]; myLineWidths.insert(startVisualLine, newEntries); } else if (lineDiff < 0) { myLineWidths.remove(startVisualLine, -lineDiff); } for (int i = startVisualLine; i <= endVisualLine && i < myLineWidths.size(); i++) { myLineWidths.set(i, UNKNOWN_WIDTH); } }
public SelectionData selectTests(String methodName, Edge[] dangerousEdges) throws MethodNotFoundException { TestHistory th = thHandler.getTestHistory(methodName); int maxTestID = th.getHighestTestID(); TIntArrayList testList = new TIntArrayList(); for (int i = 0; i < dangerousEdges.length; i++) { // int predBlockID = dangerousEdges[i].getPredNodeID(); int succBlockID = dangerousEdges[i].getSuccNodeID(); for (int j = 0; j < maxTestID; j++) { if ( /*th.query(predBlockID, j) &&*/ th.query(succBlockID, j)) { testList.add(j + 1); } } } SelectionData sd = new SelectionData(); if (testList.size() > 0) { sd.tests = testList.toNativeArray(); } else { sd.tests = new int[0]; } return sd; }
private void refreshTable() { IDevice[] devices = myDetectedDevicesRef.get(); myDisplayedDevices = devices; final IDevice[] selectedDevices = getSelectedDevices(); final TIntArrayList selectedRows = new TIntArrayList(); for (int i = 0; i < devices.length; i++) { if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) { selectedRows.add(i); } } myProcessSelectionFlag = false; myDeviceTable.setModel(new MyDeviceTableModel(devices)); if (selectedRows.size() == 0 && devices.length > 0) { myDeviceTable.getSelectionModel().setSelectionInterval(0, 0); } for (int selectedRow : selectedRows.toNativeArray()) { if (selectedRow < devices.length) { myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow); } } fireSelectedDevicesChanged(); myProcessSelectionFlag = true; updatePreviouslySelectedSerials(); }
@Override public void save(@NotNull DataOutput out, TIntArrayList list) throws IOException { if (list.size() == 2) { DataInputOutputUtil.writeINT(out, list.getQuick(0)); DataInputOutputUtil.writeINT(out, list.getQuick(1)); } else { DataInputOutputUtil.writeINT(out, -list.size()); int prev = 0; for (int i = 0, len = list.size(); i < len; i += 2) { int value = list.getQuick(i); DataInputOutputUtil.writeINT(out, value - prev); prev = value; DataInputOutputUtil.writeINT(out, list.getQuick(i + 1)); } } }
/** Get/allocate spaceNeeded entries for the designated float-based attribute */ private int getFloatSpace(int attrId, int spaceNeeded) { int sequence = AttrDefinitionMgr.getAttrIndex(attrId); // this should be unique across all attributes if (sequence < indicesPlusOne.size()) { int indexPlusOne = indicesPlusOne.getQuick(sequence); if (indexPlusOne > 0) { Assert.state( getLength(attrId) == spaceNeeded, "getLength = " + getLength(attrId) + ", requested = " + spaceNeeded); // dumbo check to ensure not asking for diff size return indexPlusOne - 1; } } else { padSpace(indicesPlusOne, sequence); } // okay, it's not been allocated so ... int index = nextFloatsIndex; nextFloatsIndex += spaceNeeded; indicesPlusOne.set(sequence, index + 1); // Add to list of attrIds for iterator Assert.state(attrIds.contains(attrId) == false); attrIds.add(attrId); setLength(sequence, spaceNeeded); syncToStore(); // we sync here as we've modified return index; }
private void process(BasicBlock bb, TIntArrayList locks) { int n = bb.size(); int k = locks.size(); for (int i = 0; i < n; i++) { Quad q = bb.getQuad(i); Operator op = q.getOperator(); if (op instanceof Monitor) { if (op instanceof MONITORENTER) { TIntArrayList locks2 = new TIntArrayList(k + 1); for (int j = 0; j < k; j++) locks2.add(locks.get(j)); int lIdx = domL.indexOf(q); assert (lIdx >= 0); locks2.add(lIdx); locks = locks2; k++; } else { k--; TIntArrayList locks2 = new TIntArrayList(k); for (int j = 0; j < k; j++) locks2.add(locks.get(j)); locks = locks2; } } else if (op.isHeapInst() && k > 0) { int eIdx = domE.indexOf(q); assert (eIdx >= 0); add(locks.get(k - 1), eIdx); } } for (Object o : bb.getSuccessors()) { BasicBlock bb2 = (BasicBlock) o; if (!visited.contains(bb2)) { visited.add(bb2); process(bb2, locks); } } }
public void act() { Message message_NF; Message message_LFF; Message message_LFS; // Link failure handling if (failure_type == Link_F) { message_LFF = new Message(Values.interruptMessage, Values.ReachLoss, second_node); kernel.schedule( new ArrivalEventV2(first_node, message_LFF, kernel, GetTime.getNextSchedule(kernel))); message_LFS = new Message(Values.interruptMessage, Values.ReachLoss, first_node); kernel.schedule( new ArrivalEventV2(second_node, message_LFS, kernel, GetTime.getNextSchedule(kernel))); } // Node failure handling else { if (failure_type == Node_F) { NodeV2 Failed_Node = Topology.getNodeByAddressV2(failed_node); adjacenes = (TIntArrayList) (Failed_Node.getAdjacenes().clone()); Failed_Node.eraseState(); message_NF = new Message(Values.interruptMessage, Values.ReachLoss, failed_node); for (int i = 0; i < adjacenes.size(); i++) { kernel.schedule( new ArrivalEventV2( adjacenes.get(i), message_NF, kernel, GetTime.getNextSchedule(kernel))); } } else { } } }
private void setLength(int sequence, int length) { if (sequence >= lengths.size()) { padSpace(lengths, sequence); } lengths.set(sequence, length); }
public static boolean checkParametersNumber( @NotNull List<CandidateInfo> conflicts, final int argumentsCount, boolean ignoreIfStaticsProblem) { boolean atLeastOneMatch = false; TIntArrayList unmatchedIndices = null; for (int i = 0; i < conflicts.size(); i++) { ProgressManager.checkCanceled(); CandidateInfo info = conflicts.get(i); if (ignoreIfStaticsProblem && !info.isStaticsScopeCorrect()) return true; if (!(info instanceof MethodCandidateInfo)) continue; PsiMethod method = ((MethodCandidateInfo) info).getElement(); if (method.isVarArgs()) return true; if (method.getParameterList().getParametersCount() == argumentsCount) { // remove all unmatched before if (unmatchedIndices != null) { for (int u = unmatchedIndices.size() - 1; u >= 0; u--) { int index = unmatchedIndices.get(u); conflicts.remove(index); i--; } unmatchedIndices = null; } atLeastOneMatch = true; } else if (atLeastOneMatch) { conflicts.remove(i); i--; } else { if (unmatchedIndices == null) unmatchedIndices = new TIntArrayList(conflicts.size() - i); unmatchedIndices.add(i); } } return atLeastOneMatch; }
private void applyChildrenChangeEvents(VirtualFile parent, List<VFileEvent> events) { final NewVirtualFileSystem delegate = getDelegate(parent); TIntArrayList childrenIdsUpdated = new TIntArrayList(); List<VirtualFile> childrenToBeUpdated = new SmartList<VirtualFile>(); assert parent != null && parent != mySuperRoot; final int parentId = getFileId(parent); assert parentId != 0; TIntHashSet parentChildrenIds = new TIntHashSet(FSRecords.list(parentId)); boolean hasRemovedChildren = false; for (VFileEvent event : events) { if (event instanceof VFileCreateEvent) { String name = ((VFileCreateEvent) event).getChildName(); final VirtualFile fake = new FakeVirtualFile(parent, name); final FileAttributes attributes = delegate.getAttributes(fake); if (attributes != null) { final int childId = createAndFillRecord(delegate, fake, parentId, attributes); assert parent instanceof VirtualDirectoryImpl : parent; final VirtualDirectoryImpl dir = (VirtualDirectoryImpl) parent; VirtualFileSystemEntry child = dir.createChild(name, childId, dir.getFileSystem()); childrenToBeUpdated.add(child); childrenIdsUpdated.add(childId); parentChildrenIds.add(childId); } } else if (event instanceof VFileDeleteEvent) { VirtualFile file = ((VFileDeleteEvent) event).getFile(); if (!file.exists()) { LOG.error("Deleting a file, which does not exist: " + file.getPath()); continue; } hasRemovedChildren = true; int id = getFileId(file); childrenToBeUpdated.add(file); childrenIdsUpdated.add(-id); parentChildrenIds.remove(id); } } FSRecords.updateList(parentId, parentChildrenIds.toArray()); if (hasRemovedChildren) clearIdCache(); VirtualDirectoryImpl parentImpl = (VirtualDirectoryImpl) parent; for (int i = 0, len = childrenIdsUpdated.size(); i < len; ++i) { final int childId = childrenIdsUpdated.get(i); final VirtualFile childFile = childrenToBeUpdated.get(i); if (childId > 0) { parentImpl.addChild((VirtualFileSystemEntry) childFile); } else { FSRecords.deleteRecordRecursively(-childId); parentImpl.removeChild(childFile); invalidateSubtree(childFile); } } }
@Override public String getInstalledPluginNameByPath(Project project, @NotNull VirtualFile pluginPath) { String nameFromPluginXml = super.getInstalledPluginNameByPath(project, pluginPath); if (nameFromPluginXml != null) { return nameFromPluginXml; } VirtualFile pluginJson = pluginPath.findChild("plugin.json"); if (pluginJson != null) { String pluginAndVersion = pluginPath.getName(); // pluginName-version TIntArrayList separatorIndexes = new TIntArrayList(); int start = -1; while (true) { start = pluginAndVersion.indexOf('-', start + 1); if (start == -1) break; separatorIndexes.add(start); } if (separatorIndexes.size() == 1) { return pluginAndVersion.substring(0, separatorIndexes.get(0)); } if (separatorIndexes.size() > 0) { String json; try { json = VfsUtil.loadText(pluginJson); } catch (IOException e) { return null; } for (int i = 0; i < separatorIndexes.size(); i++) { int idx = separatorIndexes.get(i); String name = pluginAndVersion.substring(0, idx); String version = pluginAndVersion.substring(idx + 1); if (hasValue(PLUGIN_NAME_JSON_PATTERN, json, name) && hasValue(PLUGIN_VERSION_JSON_PATTERN, json, version)) { return name; } } } } return null; }
@Override public void save(final DataOutput out, final TIntArrayList value) throws IOException { int size = value.size(); if (size == 0) { DataInputOutputUtil.writeSINT(out, Integer.MAX_VALUE); } else if (size == 1) { DataInputOutputUtil.writeSINT(out, -value.get(0)); } else { DataInputOutputUtil.writeSINT(out, size); for (int i = 0; i < size; i++) { DataInputOutputUtil.writeINT(out, value.get(i)); } } }
private boolean checkDirty() { if (myEditor.getSoftWrapModel().isDirty()) { myDirty = true; return true; } if (myDirty) { int visibleLineCount = myEditor.getVisibleLineCount(); int lineDiff = visibleLineCount - myLineWidths.size(); if (lineDiff > 0) myLineWidths.add(new int[lineDiff]); else if (lineDiff < 0) myLineWidths.remove(visibleLineCount, -lineDiff); for (int i = 0; i < visibleLineCount; i++) { myLineWidths.set(i, UNKNOWN_WIDTH); } myDirty = false; } return false; }
private List index(int numEvents, EventStream es, TObjectIntHashMap predicateIndex) { TObjectIntHashMap omap = new TObjectIntHashMap(); int outcomeCount = 0; List eventsToCompare = new ArrayList(numEvents); TIntArrayList indexedContext = new TIntArrayList(); while (es.hasNext()) { Event ev = es.nextEvent(); String[] econtext = ev.getContext(); ComparableEvent ce; int ocID; String oc = ev.getOutcome(); if (omap.containsKey(oc)) { ocID = omap.get(oc); } else { ocID = outcomeCount++; omap.put(oc, ocID); } for (int i = 0; i < econtext.length; i++) { String pred = econtext[i]; if (predicateIndex.containsKey(pred)) { indexedContext.add(predicateIndex.get(pred)); } } // drop events with no active features if (indexedContext.size() > 0) { ce = new ComparableEvent(ocID, indexedContext.toNativeArray()); eventsToCompare.add(ce); } else { System.err.println( "Dropped event " + ev.getOutcome() + ":" + Arrays.asList(ev.getContext())); } // recycle the TIntArrayList indexedContext.resetQuick(); } outcomeLabels = toIndexedStringArray(omap); predLabels = toIndexedStringArray(predicateIndex); return eventsToCompare; }
private int calculatePreferredWidth() { int lineCount = myLineWidths.size(); int maxWidth = 0; for (int i = 0; i < lineCount; i++) { int width = myLineWidths.get(i); if (width == UNKNOWN_WIDTH) { myApproximateWidthCalculated = false; myView.getTextLayoutCache().enableQuickLayouts(true); try { width = myView.getMaxWidthInLineRange(i, i); } finally { myView.getTextLayoutCache().enableQuickLayouts(false); } if (myApproximateWidthCalculated) width = -width; myLineWidths.set(i, width); } maxWidth = Math.max(maxWidth, Math.abs(width)); } return maxWidth; }
public static int getFreeRecord() { if (myFreeRecords.isEmpty()) return 0; return myFreeRecords.remove(myFreeRecords.size() - 1); }
/** * Pad the supplied array, cos Trove doesn't supply the capability * * @param array * @param sequence */ private void padSpace(TIntArrayList array, int sequence) { Assert.state(array.size() <= sequence); // e.g. 0 <= 0, on first add while (array.size() <= sequence) { // ensures we add including then value we want to then set array.add(-1); } }