private static int[] getPathPos(PathNameCS pathNameCS) { EList<SimpleNameCS> sequenceOfNames = pathNameCS.getSimpleNames(); if (sequenceOfNames.size() == 1) { return null; } int size = sequenceOfNames.size() - 1; int[] positions = new int[size]; Arrays.fill(positions, -1); IToken startToken = pathNameCS.getStartToken(); IToken endToken = pathNameCS.getEndToken(); IPrsStream prsStream = startToken.getIPrsStream(); IToken nextToken = startToken; int tokenIndex = 1; int i = 0; while (nextToken != endToken) { nextToken = prsStream.getIToken(startToken.getTokenIndex() + tokenIndex++); if (nextToken.getKind() == QVTOParsersym.TK_IDENTIFIER) { positions[i++] = nextToken.getStartOffset(); if (i == positions.length) { // safety exit in case we have inconsistent start end token break; } } } return positions; }
@Override public void parserProblem( Severity problemSeverity, String problemMessage, String processingContext, int startOffset, int endOffset) { IPrsStream prsStream = getIPrsStream(); int leftToken = prsStream.getTokenIndexAtCharacter(startOffset); int rightToken = prsStream.getTokenIndexAtCharacter(endOffset); int leftTokenLoc = (leftToken > rightToken ? rightToken : leftToken); int rightTokenLoc = rightToken; int line = prsStream.getLine(leftTokenLoc) + getErrorReportLineOffset(); CustomDiagnostic diagnostic = new CustomDiagnostic( problemSeverity.getDiagnosticSeverity(), "org.eclipse.ocl", 1, problemMessage, new Object[] {processingContext}); if (line > 0) { diagnostic.setStartLine(prsStream.getLine(leftTokenLoc) + getErrorReportLineOffset()); diagnostic.setStartPosition(prsStream.getColumn(leftTokenLoc)); diagnostic.setEndPosition(prsStream.getEndColumn(rightTokenLoc)); diagnostic.setEndLine(prsStream.getEndLine(rightTokenLoc) + getErrorReportLineOffset()); } if (diagnostics == null) { diagnostics = diagnostic; } else { diagnostics.add(diagnostic); } }