当前位置: 首页>>代码示例>>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;未经允许,请勿转载。