當前位置: 首頁>>代碼示例>>Java>>正文


Java Region類代碼示例

本文整理匯總了Java中org.eclipse.jface.text.Region的典型用法代碼示例。如果您正苦於以下問題:Java Region類的具體用法?Java Region怎麽用?Java Region使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Region類屬於org.eclipse.jface.text包,在下文中一共展示了Region類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDamageRegion

import org.eclipse.jface.text.Region; //導入依賴的package包/類
@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;
}
 
開發者ID:de-jcup,項目名稱:eclipse-batch-editor,代碼行數:27,代碼來源:PresentationSupport.java

示例2: getMatchingLocation

import org.eclipse.jface.text.Region; //導入依賴的package包/類
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;
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:22,代碼來源:DiffTableViewer.java

示例3: detectHyperlinks

import org.eclipse.jface.text.Region; //導入依賴的package包/類
@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;
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:25,代碼來源:SQLEditorHyperLinkDetector.java

示例4: getHoverRegion

import org.eclipse.jface.text.Region; //導入依賴的package包/類
@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);
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:18,代碼來源:SQLEditorTextHover.java

示例5: getHoverRegion

import org.eclipse.jface.text.Region; //導入依賴的package包/類
@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());
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:26,代碼來源:KspTextHover.java

示例6: handleFileLink

import org.eclipse.jface.text.Region; //導入依賴的package包/類
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;
	}
}
 
開發者ID:de-jcup,項目名稱:egradle,代碼行數:25,代碼來源:GradleHyperlinkDetector.java

示例7: getCommandArgument

import org.eclipse.jface.text.Region; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:eclipse,項目名稱:texlipse,代碼行數:28,代碼來源:LatexParserUtils.java

示例8: findEnvironment

import org.eclipse.jface.text.Region; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:texlipse,代碼行數:19,代碼來源:LatexParserUtils.java

示例9: findLastEnvironment

import org.eclipse.jface.text.Region; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:texlipse,代碼行數:19,代碼來源:LatexParserUtils.java

示例10: createMatchReferenceJob

import org.eclipse.jface.text.Region; //導入依賴的package包/類
/**
 * 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;
            }
    };
}
 
開發者ID:eclipse,項目名稱:texlipse,代碼行數:29,代碼來源:TexlipseAnnotationUpdater.java

示例11: createHyperlinksByOffset

import org.eclipse.jface.text.Region; //導入依賴的package包/類
/** {@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);
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:22,代碼來源:FormatHyperlinkHelper.java

示例12: jumptToPCal

import org.eclipse.jface.text.Region; //導入依賴的package包/類
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);
  }
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:24,代碼來源:AdapterFactory.java

示例13: selectAndReveal

import org.eclipse.jface.text.Region; //導入依賴的package包/類
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);
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:18,代碼來源:TLAEditor.java

示例14: gotoMarker

import org.eclipse.jface.text.Region; //導入依賴的package包/類
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);
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:25,代碼來源:TLAEditor.java

示例15: getTextBlockFromSelection

import org.eclipse.jface.text.Region; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:27,代碼來源:ToggleCommentAction.java


注:本文中的org.eclipse.jface.text.Region類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。