use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class TemplateState method recalcSegment.
private void recalcSegment(int segmentNumber, boolean isQuick, Expression expressionNode, Expression defaultValue) {
if (isDisposed())
return;
String oldValue = getExpressionString(segmentNumber);
int start = mySegments.getSegmentStart(segmentNumber);
int end = mySegments.getSegmentEnd(segmentNumber);
PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
PsiFile psiFile = getPsiFile();
PsiElement element = psiFile != null ? psiFile.findElementAt(start) : null;
if (element != null) {
PsiUtilCore.ensureValid(element);
}
ExpressionContext context = createExpressionContext(start);
Result result = isQuick ? expressionNode.calculateQuickResult(context) : expressionNode.calculateResult(context);
if (isQuick && result == null) {
if (!oldValue.isEmpty()) {
return;
}
}
final boolean resultIsNullOrEmpty = result == null || result.equalsToText("", element);
// do not update default value of neighbour segment
if (resultIsNullOrEmpty && myCurrentSegmentNumber >= 0 && (mySegments.getSegmentStart(segmentNumber) == mySegments.getSegmentEnd(myCurrentSegmentNumber) || mySegments.getSegmentEnd(segmentNumber) == mySegments.getSegmentStart(myCurrentSegmentNumber))) {
return;
}
if (defaultValue != null && resultIsNullOrEmpty) {
result = defaultValue.calculateResult(context);
}
if (element != null) {
PsiUtilCore.ensureValid(element);
}
if (result == null || result.equalsToText(oldValue, element))
return;
replaceString(StringUtil.notNullize(result.toString()), start, end, segmentNumber);
if (result instanceof RecalculatableResult) {
IntArrayList indices = initEmptyVariables();
shortenReferences();
PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
((RecalculatableResult) result).handleRecalc(psiFile, myDocument, mySegments.getSegmentStart(segmentNumber), mySegments.getSegmentEnd(segmentNumber));
restoreEmptyVariables(indices);
}
}
use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class SuspiciousCollectionsMethodCallsInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
final List<PsiMethod> patternMethods = new ArrayList<>();
final IntArrayList indices = new IntArrayList();
return new JavaElementVisitor() {
@Override
public void visitMethodCallExpression(PsiMethodCallExpression methodCall) {
final String message = getSuspiciousMethodCallMessage(methodCall, REPORT_CONVERTIBLE_METHOD_CALLS, patternMethods, indices);
if (message != null) {
holder.registerProblem(methodCall.getArgumentList().getExpressions()[0], message);
}
}
@Override
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
final PsiClassType.ClassResolveResult functionalInterfaceResolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
if (interfaceMethod != null && interfaceMethod.getParameterList().getParametersCount() == 1) {
final PsiSubstitutor psiSubstitutor = LambdaUtil.getSubstitutor(interfaceMethod, functionalInterfaceResolveResult);
final MethodSignature signature = interfaceMethod.getSignature(psiSubstitutor);
String message = SuspiciousMethodCallUtil.getSuspiciousMethodCallMessage(expression, signature.getParameterTypes()[0], REPORT_CONVERTIBLE_METHOD_CALLS, patternMethods, indices);
if (message != null) {
holder.registerProblem(ObjectUtils.notNull(expression.getReferenceNameElement(), expression), message);
}
}
}
};
}
use of com.intellij.util.containers.IntArrayList in project intellij-plugins by JetBrains.
the class CucumberTableInspection method checkTable.
private static void checkTable(GherkinTable table, Collection<String> columnNames, ProblemsHolder holder) {
final GherkinTableRow row = table != null ? table.getHeaderRow() : null;
if (row == null) {
return;
}
final List<GherkinTableCell> cells = row.getPsiCells();
IntArrayList unusedIndices = new IntArrayList();
for (int i = 0, cellsSize = cells.size(); i < cellsSize; i++) {
String columnName = cells.get(i).getText().trim();
if (!columnNames.contains(columnName)) {
unusedIndices.add(i);
}
}
if (!unusedIndices.isEmpty()) {
highlightUnusedColumns(row, unusedIndices, holder);
for (GherkinTableRow tableRow : table.getDataRows()) {
highlightUnusedColumns(tableRow, unusedIndices, holder);
}
}
}
use of com.intellij.util.containers.IntArrayList in project intellij-plugins by JetBrains.
the class FileOffsetsManager method loadLineOffsets.
@NotNull
private static // similar to com.intellij.openapi.fileEditor.impl.LoadTextUtil.convertLineSeparators()
LineOffsets loadLineOffsets(@NotNull final CharBuffer buffer, final long modificationStamp) {
int dst = 0;
char prev = ' ';
int crlfCount = 0;
final IntArrayList originalLineOffsets = new IntArrayList();
final IntArrayList convertedLineOffsets = new IntArrayList();
// first line
originalLineOffsets.add(0);
convertedLineOffsets.add(0);
final int length = buffer.length();
final char[] bufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer);
for (int src = 0; src < length; src++) {
char c = bufferArray != null ? bufferArray[src] : buffer.charAt(src);
switch(c) {
case '\r':
if (bufferArray != null) {
bufferArray[dst++] = '\n';
} else {
buffer.put(dst++, '\n');
}
//crCount++;
originalLineOffsets.add(dst + crlfCount);
convertedLineOffsets.add(dst);
break;
case '\n':
if (prev == '\r') {
//crCount--;
crlfCount++;
originalLineOffsets.set(originalLineOffsets.size() - 1, dst + crlfCount);
} else {
if (bufferArray != null) {
bufferArray[dst++] = '\n';
} else {
buffer.put(dst++, '\n');
}
//lfCount++;
originalLineOffsets.add(dst + crlfCount);
convertedLineOffsets.add(dst);
}
break;
default:
if (bufferArray != null) {
bufferArray[dst++] = c;
} else {
buffer.put(dst++, c);
}
break;
}
prev = c;
}
return new LineOffsets(modificationStamp, originalLineOffsets.toArray(), convertedLineOffsets.toArray());
}
use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class FSRecords method checkSanity.
static void checkSanity() {
long t = System.currentTimeMillis();
r.lock();
try {
final int fileLength = length();
assert fileLength % RECORD_SIZE == 0;
int recordCount = fileLength / RECORD_SIZE;
IntArrayList usedAttributeRecordIds = new IntArrayList();
IntArrayList validAttributeIds = new IntArrayList();
for (int id = 2; id < recordCount; id++) {
int flags = getFlags(id);
LOG.assertTrue((flags & ~ALL_VALID_FLAGS) == 0, "Invalid flags: 0x" + Integer.toHexString(flags) + ", id: " + id);
if (BitUtil.isSet(flags, FREE_RECORD_FLAG)) {
LOG.assertTrue(DbConnection.myFreeRecords.contains(id), "Record, marked free, not in free list: " + id);
} else {
LOG.assertTrue(!DbConnection.myFreeRecords.contains(id), "Record, not marked free, in free list: " + id);
checkRecordSanity(id, recordCount, usedAttributeRecordIds, validAttributeIds);
}
}
} finally {
r.unlock();
}
t = System.currentTimeMillis() - t;
LOG.info("Sanity check took " + t + " ms");
}
Aggregations