@Override public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) { if (!documentPartitioningChanged) { try { IRegion info = fDocument.getLineInformationOfOffset(event.getOffset()); int start = Math.max(partition.getOffset(), info.getOffset()); int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length()); if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) { // optimize the case of the same line end = info.getOffset() + info.getLength(); } else{ end = endOfLineOf(end); } end = Math.min(partition.getOffset() + partition.getLength(), end); return new Region(start, end - start); } catch (BadLocationException x) { } } return partition; }
private Region getMatchingLocation(String text, String filter, Pattern regExPattern) { if (filter != null && !filter.isEmpty() && text != null) { String textLc = text.toLowerCase(); int offset = -1; int length = 0; if (regExPattern != null) { Matcher matcher = regExPattern.matcher(textLc); if (matcher.find()) { offset = matcher.start(); length = matcher.end() - offset; } } else { offset = textLc.indexOf(filter); length = filter.length(); } if (offset >= 0) { return new Region(offset, length); } } return null; }
@Override public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { SQLEditor editor = getAdapter(SQLEditor.class); PgDbParser parser = editor.getParser(); int offset = region.getOffset(); List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput()); for (PgObjLocation obj : refs) { if (offset > obj.getOffset() && offset < (obj.getOffset() + obj.getObjLength())) { IHyperlink[] links = parser.getDefinitionsForObj(obj) .map(def -> new SQLEditorHyperLink( new Region(def.getOffset(), def.getObjLength()), new Region(obj.getOffset(), obj.getObjLength()), obj.getObjName(), def.getFilePath(), def.getLineNumber())) .toArray(IHyperlink[]::new); if (links.length != 0) { return links; } } } return null; }
@Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { PgDbParser parser = editor.getParser(); List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput()); for (PgObjLocation obj : refs) { if (offset > obj.getOffset() && offset < (obj.getOffset() + obj.getObjLength())) { Optional<PgObjLocation> loc = parser.getDefinitionsForObj(obj).findAny(); if (loc.isPresent()) { SQLEditorMyRegion region = new SQLEditorMyRegion(obj.getOffset(), obj.getObjLength()); region.setComment(loc.get().getComment()); return region; } } } return new Region(offset, 0); }
@Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { IDocument document = textViewer.getDocument(); /* Vérifie qu'on est dans une String de KSP */ boolean isSqlString = DocumentUtils.isContentType(document, offset, KspRegionType.STRING); if (!isSqlString) { return null; } /* Extrait le mot courant. */ ITextSelection selection = new TextSelection(document, offset, 0); ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE); if (currentWordSelection == null) { return null; } String currentWord = currentWordSelection.getText(); if (currentWord == null) { return null; } /* Renvoie la région du mot. */ return new Region(currentWordSelection.getOffset(), currentWordSelection.getLength()); }
private IHyperlink[] handleFileLink(IRegion lineInfo, GradleHyperLinkResult result) { try { File folder = editorFile.getParentFile(); String fileName = result.linkContent; File target = new File(folder, fileName); if (!target.exists()) { target = new File(fileName); } if (!target.exists()) { return null; } IFileStore fileStore = EFS.getLocalFileSystem().getStore(target.toURI()); if (fileStore==null){ return null; } IRegion urlRegion = new Region(lineInfo.getOffset() + result.linkOffsetInLine, result.linkLength); GradleFileHyperlink gradleFileHyperlink = new GradleFileHyperlink(urlRegion, fileStore); return new IHyperlink[] { gradleFileHyperlink }; } catch (RuntimeException e) { return null; } }
/** * Returns the first mandatory argument of the command * * @param input * @param index The index at or after the beginning of the command and before the * argument * @return The argument without braces, null if there is no valid argument * @throws BadLocationException if index is out of bounds */ public static IRegion getCommandArgument(String input, int index){ int pos = index; final int length = input.length(); if (input.charAt(index) == '\\') pos++; while (pos < length && Character.isLetter(input.charAt(pos))) pos++; while (pos < length && Character.isWhitespace(input.charAt(pos))) pos++; if (pos == length) return null; if (input.charAt(pos) == '{') { int end = findPeerChar(input, pos + 1, LEFT, '{', '}'); if (end == -1) return null; return new Region (pos + 1, end - pos - 1); } return null; }
private static IRegion findEnvironment(String input, String envName, String command, int fromIndex) { int pos = input.indexOf("{" + envName + "}", fromIndex + command.length()); while (pos != -1) { int end = pos + envName.length() + 2; // Search for the command int beginStart = findLastCommand(input, command, pos); if (beginStart != -1 && beginStart >= fromIndex) { // Check for whitespaces between \begin and {...} while (pos != beginStart + command.length() && Character.isWhitespace(input.charAt(--pos))) ; if (pos == beginStart + command.length()) { return new Region(beginStart, end - beginStart); } } pos = input.indexOf("{" + envName + "}", pos + envName.length() + 2); } return null; }
private static IRegion findLastEnvironment(String input, String envName, String command, int fromIndex) { int pos = input.lastIndexOf("{" + envName + "}", fromIndex); while (pos != -1) { int end = pos + envName.length() + 2; // Search for the command int beginStart = findLastCommand(input, command, pos); if (beginStart != -1 && beginStart <= fromIndex) { // Check for whitespaces between \command and {...} while (pos != beginStart + command.length() && Character.isWhitespace(input.charAt(--pos))) ; if (pos == beginStart + command.length()) { return new Region(beginStart, end - beginStart); } } pos = input.lastIndexOf("{" + envName + "}", pos-1); } return null; }
/** * Creates and returns a background job which searches and highlights all \label and \*ref. * @param document * @param model * @param refName The name of the reference * @return The job */ private Job createMatchReferenceJob(final IDocument document, final IAnnotationModel model, final String refName) { return new Job("Update Annotations") { public IStatus run(IProgressMonitor monitor) { String text = document.get(); String refNameRegExp = refName.replaceAll("\\*", "\\\\*"); final String simpleRefRegExp = "\\\\([a-zA-Z]*ref|label)\\s*\\{" + refNameRegExp + "\\}"; Matcher m = (Pattern.compile(simpleRefRegExp)).matcher(text); while (m.find()) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; IRegion match = LatexParserUtils.getCommand(text, m.start()); //Test if it is a real LaTeX command if (match != null) { IRegion fi = new Region(m.start(), m.end()-m.start()); createNewAnnotation(fi, "References", model); } } return Status.OK_STATUS; } }; }
/** {@inheritDoc} */ @Override public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) { final IParseResult parseResult = resource.getParseResult(); if (parseResult == null || parseResult.getRootNode() == null) { return; // Return, no need to call in super.createAdditionalHyperlinks } // Check if the current parse tree node represents an override keyword, in which case we want to link // to the overridden rule INode node = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset); if (node != null && isOverrideKeyword(node.getGrammarElement())) { Rule rule = (Rule) eObjectAtOffsetHelper.resolveElementAt(resource, offset); Region region = new Region(node.getOffset(), node.getLength()); List<Rule> extendedRules = getExtendedRules(rule); for (Rule extendedRule : extendedRules) { createHyperlinksTo(resource, region, extendedRule, acceptor); } } super.createHyperlinksByOffset(resource, offset, acceptor); }
public static pcal.Region jumptToPCal(TLAtoPCalMapping mapping, Location location, IDocument document) throws BadLocationException { /* * Get the best guess of the line number in the * current contents of the editor that corresponds to what was line * mapping.tlaStartLine when the algorithm was translated. * It is computed by assuming that neither the algorithm nor the translation * have changed, but they both may have been moved down by the same * number delta of lines (possibly negative). A more sophisticated approach * using fingerprints of lines could be used, requiring that the necessary * fingerprint information be put in TLAtoPCalMapping. */ int beginAlgorithmLine = AdapterFactory.GetLineOfPCalAlgorithm(document); if (beginAlgorithmLine == -1) { throw new BadLocationException("The algorithm is no longer in the module."); } // Translate editor location to pcal.Region final pcal.Region tlaRegion = location.toRegion(); // Do actual mapping return mapping.mapTLAtoPCalRegion(tlaRegion, beginAlgorithmLine); }
public void selectAndReveal(final pcal.Region aRegion) throws BadLocationException { final IDocument document = getDocumentProvider().getDocument( getEditorInput()); // Translate pcal.Region coordinates into Java IDocument coordinates final PCalLocation begin = aRegion.getBegin(); final int startLineOffset = document.getLineOffset(begin.getLine()); final int startOffset = startLineOffset + begin.getColumn(); final PCalLocation end = aRegion.getEnd(); final int endLineOffset = document.getLineOffset(end.getLine()); final int endOffset = endLineOffset + end.getColumn(); final int length = endOffset - startOffset; selectAndReveal(startOffset, length); }
public void gotoMarker(final IMarker marker) { // if the given marker happens to be of instance TLAtoPCalMarker, it // indicates that the user wants to go to the PCal equivalent of the // current TLA+ marker if (marker instanceof TLAtoPCalMarker) { final TLAtoPCalMarker tlaToPCalMarker = (TLAtoPCalMarker) marker; try { final pcal.Region region = tlaToPCalMarker.getRegion(); if (region != null) { selectAndReveal(region); return; } else { UIHelper.setStatusLineMessage("No valid TLA to PCal mapping found for current selection"); } } catch (BadLocationException e) { // not expected to happen e.printStackTrace(); } } // fall back to original marker if the TLAtoPCalMarker didn't work or no // TLAtoPCalMarker super.gotoMarker(marker); }
/** * Creates a region describing the text block (something that starts at * the beginning of a line) completely containing the current selection. * * @param selection The selection to use * @param document The document * @return the region describing the text block comprising the given selection */ private IRegion getTextBlockFromSelection(ITextSelection selection, IDocument document) { try { IRegion line = document.getLineInformationOfOffset(selection.getOffset()); int length = selection.getLength() == 0 ? line.getLength() : selection.getLength() + (selection.getOffset() - line.getOffset()); return new Region(line.getOffset(), length); } catch (BadLocationException x) { // should not happen // TODO } return null; }
/** * Returns a new region that ends at the end of the input region and begins * at the first character of the line before the line containing the offset * of the input region. If the input region's offset is on the first * line of the document, this method does nothing. * * @param document * @param region * @return * @throws BadLocationException */ public static IRegion getRegionWithPreviousLine(IDocument document, IRegion region) throws BadLocationException { // the first line of the region int currentFirstLine = document.getLineOfOffset(region.getOffset()); if (currentFirstLine > 0) { int newOffset = document.getLineOffset(currentFirstLine - 1); return new Region(newOffset, region.getLength() + (region.getOffset() - newOffset)); } else { // no previous line so do nothing return region; } }
/** * Find the IDs in the given text and return the array of * regions pointing to those or an empty array, if no IDs were found. * An ID is scheme_timestamp, created by {@link ModelWriter#getValidIdentifier(String)} e.G. next_125195338522638000 * @param text text containing IDs (error text) * @return array of regions or empty array */ public static IRegion[] findIds(String text) { if (text == null || text.length() == 0) { return new IRegion[0]; } Matcher matcher = ModelWriter.ID_MATCHER.matcher(text); Vector<Region> regions = new Vector<Region>(); while (matcher.find()) { regions.add(new Region(matcher.start(), matcher.end() - matcher.start())); } return regions.toArray(new IRegion[regions.size()]); }
/** * Finds the locations in the given text and return the array of * regions pointing to those or an empty array, if no location were found. * A location is a pointer in the TLA file, e.G. "line 11, col 8 to line 14, col 26 of module Foo" * @param text text containing locations (error text) * @return array of regions or empty array */ public static IRegion[] findLocations(String text) { if (text == null || text.length() == 0) { return new IRegion[0]; } Matcher matcher = Location.LOCATION_MATCHER.matcher(text); Vector<IRegion> regions = new Vector<IRegion>(); while (matcher.find()) { regions.add(new Region(matcher.start(), matcher.end() - matcher.start())); } // look for this pattern also // this pattern appears when there // is an error evaluating a nested expression matcher = Location.LOCATION_MATCHER4.matcher(text); while (matcher.find()) { regions.add(new Region(matcher.start(), matcher.end() - matcher.start())); } return regions.toArray(new IRegion[regions.size()]); }
/** * searches backwards for the given string within the same partition type * @return the region of the match or <code>null</code> if no match were found * @since 2.4 */ public IRegion searchBackwardsInSamePartition(String toFind, String documentText, IDocument document, int endOffset) throws BadLocationException { if (endOffset < 0) { return null; } int length = toFind.length(); String text = preProcessSearchString(documentText); ITypedRegion partition = document.getPartition(endOffset); int indexOf = text.lastIndexOf(toFind, endOffset - length); while (indexOf >= 0) { ITypedRegion partition2 = document.getPartition(indexOf); if (partition2.getType().equals(partition.getType())) { return new Region(indexOf, length); } indexOf = text.lastIndexOf(toFind, partition2.getOffset() - length); } String trimmed = toFind.trim(); if (trimmed.length() > 0 && trimmed.length() != length) { return searchBackwardsInSamePartition(trimmed, documentText, document, endOffset); } return null; }
/** * searches for the given string within the same partition type * * @return the region of the match or <code>null</code> if no match were found * @since 2.4 */ public IRegion searchInSamePartition(String toFind, String documentText, IDocument document, int startOffset) throws BadLocationException { if (startOffset >= document.getLength()) { return null; } String text = preProcessSearchString(documentText); ITypedRegion partition = document.getPartition(startOffset); int indexOf = text.indexOf(toFind, getOffset(toFind, startOffset)); while (indexOf >= 0 && indexOf < document.getLength()) { ITypedRegion partition2 = document.getPartition(indexOf); if (partition2.getType().equals(partition.getType())) { return new Region(indexOf, toFind.length()); } indexOf = text.indexOf(toFind, partition2.getOffset() + partition2.getLength()); } String trimmed = toFind.trim(); if (trimmed.length() > 0 && trimmed.length() != toFind.length()) { return searchInSamePartition(trimmed, documentText, document, startOffset); } return null; }
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) { if (!documentPartitioningChanged) { try { IRegion info= document.getLineInformationOfOffset(event.getOffset()); int start= Math.max(partition.getOffset(), info.getOffset()); int end= event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length()); if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) { // optimize the case of the same line end= info.getOffset() + info.getLength(); } else end= endOfLineOf(end); end= Math.min(partition.getOffset() + partition.getLength(), end); return new Region(start, end - start); } catch (BadLocationException x) { logger.logInfo("unable to find location in document to repair a given region",x); //$NON-NLS-1$ } } return partition; }
public IRegion getHoverRegion(ITextViewer textViewer, int offset) { IParseNode activeNode = getActiveNode(textViewer, offset); if (activeNode instanceof CSSSimpleSelectorNode) { CSSSimpleSelectorNode node = (CSSSimpleSelectorNode) activeNode; // Verify that this is an HTML element selector String typeSelector = node.getTypeSelector(); if (!StringUtil.isEmpty(typeSelector)) { ElementElement element = new HTMLIndexQueryHelper().getElement(typeSelector.toLowerCase()); if (element != null) { return new Region(node.getStartingOffset(), node.getLength()); } } } return null; }
public static void collect( ASTNode node, IJavaProject project, Region rangeLimit, boolean skipMethodBodies, Collection<SimpleName> resultingTypeImports, Collection<SimpleName> resultingStaticImports) { ASTNode root = node.getRoot(); CompilationUnit astRoot = root instanceof CompilationUnit ? (CompilationUnit) root : null; node.accept( new ImportReferencesCollector( project, astRoot, rangeLimit, skipMethodBodies, resultingTypeImports, resultingStaticImports)); }
private ImportReferencesCollector( IJavaProject project, CompilationUnit astRoot, Region rangeLimit, boolean skipMethodBodies, Collection<SimpleName> resultingTypeImports, Collection<SimpleName> resultingStaticImports) { super(processJavadocComments(astRoot)); fTypeImports = resultingTypeImports; fStaticImports = resultingStaticImports; fSubRange = rangeLimit; if (project == null || !JavaModelUtil.is50OrHigher(project)) { fStaticImports = null; // do not collect } fASTRoot = astRoot; // can be null fSkipMethodBodies = skipMethodBodies; }
/** * Exclude specified regions */ public void remove(IRegion... region) { for (IRegion r : region) { Assert.isLegal(r.getLength() >= 0, "Negative region length"); //$NON-NLS-1$ IRegion from = new Region(r.getOffset(), Integer.MAX_VALUE); IRegion floor = NavigableSetFloor(regions, from); List<IRegion> list = new ArrayList<IRegion>(NavigableSetTailSet(regions, floor != null ? floor : from, true)); for (IRegion current : list) { if (overlap(current, r)) { regions.remove(current); IRegion[] parts = substruct(current, r); if (parts.length > 0) { regions.addAll(Arrays.asList(parts)); } else { break; } } } } validate(); }
@Override public boolean visit(SimpleName node) { VariableDeclaration decl = getVariableDeclaration(node); if (decl == null) return super.visit(node); IVariableBinding binding = decl.resolveBinding(); if (binding == null) return super.visit(node); boolean keysEqual = fKey.equals(binding.getKey()); boolean rangeInSet = fRanges.contains(new Region(node.getStartPosition(), node.getLength())); if (keysEqual && !rangeInSet) fProblemNodes.add(node); if (!keysEqual && rangeInSet) fProblemNodes.add(node); /* * if (!keyEquals && !rangeInSet) * ok, different local variable. * * if (keyEquals && rangeInSet) * ok, renamed local variable & has been renamed. */ return super.visit(node); }
/** * Gets a region for the attribute's value (without the quotes). */ public static IRegion getAttributeValueRegion(IDOMAttr attribute) { String attrValue = attribute.getValueRegionText(); if (attrValue == null) { return null; } int offset = attribute.getValueRegionStartOffset(); int length = attrValue.length(); // Strip off the quotes if (isXmlQuote(attrValue.charAt(0))) { offset++; length--; } if (isXmlQuote(attrValue.charAt(attrValue.length() - 1))) { length--; } return new Region(offset, length); }
private void tryParseCssElExpression(IDOMElement styleElement, String remainingFragments, int remainingFragmentsOffsetInDoc, IRegion fieldRefRegion) { CssExtractor extractor = UiBinderXmlModelUtilities.createCssExtractorForStyleElement( styleElement, javaProject); if (extractor != null) { for (String selector : CssSelectorNameCollector.getValidSelectorNames(extractor.getCssDocument())) { if (selector.equals(remainingFragments)) { return; } } } if (remainingFragments.length() > 0) { problemMarkerManager.setCssSelectorFragmentUndefinedError(new Region( remainingFragmentsOffsetInDoc, remainingFragments.length()), remainingFragments); } else { problemMarkerManager.setCssSelectorFragmentUnspecifiedError(fieldRefRegion); } }
public void run() { VelocityEditor editor = (VelocityEditor) getTextEditor(); if (editor.fMouseListener.fActiveRegion != null) { // If the user is using the ctrl-alt mouse click feature, then // goto the definition under the mouse, and not under the current cursor location editor.gotoDefinition(editor.fMouseListener.fActiveRegion); return; } ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); if (!selection.isEmpty()) { editor.gotoDefinition(new Region(selection.getOffset(), selection.getLength())); } }
/** * Creates a region describing the text block (something that starts at the * beginning of a line) completely containing the current selection. * * @param selection * The selection to use * @param document * The document * @return the region describing the text block comprising the given * selection */ private IRegion getTextBlockFromSelection(ITextSelection selection, IDocument document) { try { IRegion line = document.getLineInformationOfOffset(selection.getOffset()); int length = selection.getLength() == 0 ? line.getLength() : selection.getLength() + (selection.getOffset() - line.getOffset()); return new Region(line.getOffset(), length); } catch (BadLocationException x) { // should not happen // JavaPlugin.log(x); } return null; }
public void documentChanged(DocumentEvent event) { if ((fRememberedPosition != null) && !fRememberedPosition.isDeleted()) { event.getDocument().removePosition(fRememberedPosition); fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength()); } fRememberedPosition = null; ISourceViewer viewer = getSourceViewer(); if (viewer != null) { StyledText widget = viewer.getTextWidget(); if ((widget != null) && !widget.isDisposed()) { widget.getDisplay().asyncExec(new Runnable() { public void run() { deactivate(); } }); } } }
@Override public IRegion processFix(IDocument document, IMarker marker) throws CoreException { int line = (int) marker.getAttribute(IMarker.LINE_NUMBER); try { String indent = getIndent(document, line); // getLineOffset() is zero-based, and imarkerLine is one-based. int endOfCurrLine = document.getLineInformation(line - 1).getOffset() + document.getLineInformation(line - 1).getLength(); // should be fine for first and last lines in the doc as well String replacementText = indent + "type: object"; String delim = TextUtilities.getDefaultLineDelimiter(document); document.replace(endOfCurrLine, 0, delim + replacementText); return new Region(endOfCurrLine + delim.length(), replacementText.length()); } catch (BadLocationException e) { throw new CoreException(createStatus(e, "Cannot process the IMarker")); } }
@Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { IRegion region = new Region(offset, 0); try { IDocument doc = textViewer.getDocument(); if (doc instanceof IDocumentExtension3) { IDocumentExtension3 ext3 = (IDocumentExtension3) doc; region = ext3.getPartition(EditorConstants.BF_PARTITIONING, offset, true); } else { region = doc.getPartition(offset); } } catch (BadPartitioningException | BadLocationException ex) { BfActivator.getDefault().logError("Partitioning Problem", ex); } return region; }
/** * @see msi.gama.lang.gaml.ui.editor.IGamlEditor#applyTemplate(org.eclipse.jface.text.templates.Template) */ public void applyTemplateAtTheEnd(final Template t) { try { final IDocument doc = getDocument(); int offset = doc.getLineOffset(doc.getNumberOfLines() - 1); doc.replace(offset, 0, "\n\n"); offset += 2; final int length = 0; final Position pos = new Position(offset, length); final XtextTemplateContextType ct = new XtextTemplateContextType(); final DocumentTemplateContext dtc = new DocumentTemplateContext(ct, doc, pos); final IRegion r = new Region(offset, length); final TemplateProposal tp = new TemplateProposal(t, dtc, r, null); tp.apply(getInternalSourceViewer(), (char) 0, 0, offset); } catch (final BadLocationException e) { e.printStackTrace(); } }
/** * Get the partition type for the specified offset. The offset must be within * this line. * @param offset The offset relative to the beginning of the document. * @return The partition that the offset is in, or null if it is outside the * range of this line. */ public Partition getRegionType( int offset ) { if( offset >= start && offset <= commentStart ) { for( Region region : stringAreas ) { if( offset > region.getOffset() && offset <= region.getOffset() + region.getLength() ) { return Partition.STRING; } } return Partition.CODE; } if( offset > commentStart ) { return Partition.COMMENT; } ZDebug.dumpStackTrace( "Offset out of range? ", offset ); return null; }
/** * Open the declaration if possible. */ @Override public void run() { ITextEditor textEditor = getTextEditor(); if (textEditor instanceof JSSourceEditor) { ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection(); IRegion region = new Region(selection.getOffset(), 1); JSHyperlinkDetector detector = new JSHyperlinkDetector(); IHyperlink[] hyperlinks = detector.detectHyperlinks((AbstractThemeableEditor) textEditor, region, true); if (!ArrayUtil.isEmpty(hyperlinks)) { // give first link highest precedence hyperlinks[0].open(); } } }
public IRegion[] selectValidRanges(int start, int end) { final List<Region> result = new ArrayList<Region>(); for (final IRegion region : excludes) { final int regionEnd = region.getOffset() + region.getLength(); if (start <= regionEnd && region.getOffset() <= end) { if (start < region.getOffset()) { int validEnd = Math.min(end, region.getOffset()); result.add(new Region(start, validEnd - start)); } start = regionEnd; if (start > end) { break; } } } if (start < end) { result.add(new Region(start, end - start)); } return result.toArray(new IRegion[result.size()]); }
/** * getFunctionRegionInfo * * @param node * @return */ private RegionInfo getFunctionRegionInfo(CSSFunctionNode node) { RegionInfo result = null; Matcher m = RGB_CHANNELS.matcher(node.toString()); if (m.matches()) { int red = Integer.parseInt(m.group(1)); int green = Integer.parseInt(m.group(2)); int blue = Integer.parseInt(m.group(3)); // @formatter:off result = new RegionInfo(new Region(node.getStartingOffset(), node.getLength()), new RGB(red, green, blue)); // @formatter:on } return result; }