Search in sources :

Example 11 with IntArrayList

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);
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) IntArrayList(com.intellij.util.containers.IntArrayList) PsiElement(com.intellij.psi.PsiElement)

Example 12 with IntArrayList

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);
                }
            }
        }
    };
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) IntArrayList(com.intellij.util.containers.IntArrayList) ArrayList(java.util.ArrayList) IntArrayList(com.intellij.util.containers.IntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with IntArrayList

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);
        }
    }
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Example 14 with IntArrayList

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());
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with IntArrayList

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");
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList) TIntArrayList(gnu.trove.TIntArrayList)

Aggregations

IntArrayList (com.intellij.util.containers.IntArrayList)31 ArrayList (java.util.ArrayList)5 PsiFile (com.intellij.psi.PsiFile)3 NotNull (org.jetbrains.annotations.NotNull)3 TextRange (com.intellij.openapi.util.TextRange)2 Nullable (org.jetbrains.annotations.Nullable)2 ExceptionUtil (com.intellij.codeInsight.ExceptionUtil)1 RadComponent (com.intellij.designer.model.RadComponent)1 LighterASTNode (com.intellij.lang.LighterASTNode)1 Logger (com.intellij.openapi.diagnostic.Logger)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 Project (com.intellij.openapi.project.Project)1 com.intellij.psi (com.intellij.psi)1 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)1 PsiElement (com.intellij.psi.PsiElement)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 DummyHolder (com.intellij.psi.impl.source.DummyHolder)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 PsiUtil (com.intellij.psi.util.PsiUtil)1