Java Code Examples for com.intellij.util.containers.hash.HashMap#entrySet()

The following examples show how to use com.intellij.util.containers.hash.HashMap#entrySet() . 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: PhpHighlightPackParametersUsagesHandler.java    From idea-php-advanced-autocomplete with MIT License 6 votes vote down vote up
@NotNull
private static HashMap<Integer, RelativeRange> getRelativeSpecificationRanges(HashMap<Integer, PhpPackFormatSpecificationParser.PackSpecification> specifications, List<StringLiteralExpression> targets) {
    Map<TextRange, StringLiteralExpression> rangesInsideResultingFormatString = getRangesWithExpressionInsideResultingFormatString(targets);
    HashMap<Integer, RelativeRange> result = new HashMap<>();

    for (Map.Entry<Integer, PhpPackFormatSpecificationParser.PackSpecification> entry : specifications.entrySet()) {
        PhpPackFormatSpecificationParser.PackSpecification specification = entry.getValue();
        for (Map.Entry<TextRange, StringLiteralExpression> e : rangesInsideResultingFormatString.entrySet()) {
            TextRange expressionRangeInsideFormatString = e.getKey();
            TextRange specificationRangeInsideFormatString = expressionRangeInsideFormatString.intersection(specification.getRangeInElement());
            if (specificationRangeInsideFormatString != null && !specificationRangeInsideFormatString.isEmpty()) {
                result.put(entry.getKey(), new RelativeRange(e.getValue(), specificationRangeInsideFormatString.shiftLeft(expressionRangeInsideFormatString.getStartOffset())));
            }
        }
    }

    return result;
}
 
Example 2
Source File: PhpHighlightPackParametersUsagesHandler.java    From idea-php-advanced-autocomplete with MIT License 6 votes vote down vote up
private int resolveSpecificationIndexFromParameter(HashMap<Integer, PhpPackFormatSpecificationParser.PackSpecification> specifications) {
    int offset = 1;

    for (Map.Entry<Integer, PhpPackFormatSpecificationParser.PackSpecification> entry : specifications.entrySet()) {
        PhpPackFormatSpecificationParser.PackSpecification specification = entry.getValue();
        for (int r = 0; r < specification.getRepeater(); r++) {
            int parameterIndex = offset + r >= 0 ? this.myFormatExpressionIndex + offset + r : offset + r;
            if (parameterIndex == this.mySelectedParameterIndex) {
                return entry.getKey();
            }
        }
        offset += specification.getRepeater();
    }

    return -1;
}
 
Example 3
Source File: PhpHighlightPackParametersUsagesHandler.java    From idea-php-advanced-autocomplete with MIT License 5 votes vote down vote up
@Override
public void computeUsages(List<StringLiteralExpression> targets) {
    StringLiteralExpression formatExpression = ContainerUtil.getFirstItem(targets);
    if (formatExpression == null) {
        return;
    }

    String contents = PhpInterpolationStringRepresentationConverter.createExpressionContent(targets);
    HashMap<Integer, PhpPackFormatSpecificationParser.PackSpecification> specificationsWithIndices = PhpPackFormatSpecificationParser.parseFormat(contents, formatExpression.isSingleQuote() || PhpHeredocToStringIntention.isNowdoc(formatExpression), this.myParameters.length);
    HashMap<Integer, RelativeRange> relativeSpecificationRanges = getRelativeSpecificationRanges(specificationsWithIndices, targets);

    int specificationIndex = this.mySelectedParameterIndex == this.myFormatExpressionIndex
        ? resolveSpecificationIndexFromCaret(relativeSpecificationRanges)
        : resolveSpecificationIndexFromParameter(specificationsWithIndices);

    RelativeRange pair = relativeSpecificationRanges.get(specificationIndex);
    if (pair == null) {
        return;
    }

    this.myReadUsages.add(getRangeInsideDocument(pair.getContainingExpression(), pair.getRangeInsideExpression()));
    int offset = 1;

    for (Map.Entry<Integer, PhpPackFormatSpecificationParser.PackSpecification> entry : specificationsWithIndices.entrySet()) {
        PhpPackFormatSpecificationParser.PackSpecification specification = entry.getValue();
        if (entry.getKey() == specificationIndex) {
            for (int r = 0; r < specification.getRepeater(); r++) {
                int parameterIndex = offset + r >= 0 ? this.myFormatExpressionIndex + offset + r : offset + r;
                if (parameterIndex >= 0 && parameterIndex < this.myParameters.length) {
                    this.addOccurrence(this.myParameters[parameterIndex]);
                }
            }
            break;
        }
        offset += specification.getRepeater();
    }
}