• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TextRegion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.xtext.util.TextRegion的典型用法代码示例。如果您正苦于以下问题:Java TextRegion类的具体用法?Java TextRegion怎么用?Java TextRegion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TextRegion类属于org.eclipse.xtext.util包,在下文中一共展示了TextRegion类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: update

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
public void update(int offset, int replacedTextLength, String newText) {
	if (!isLoaded()) {
		throw new IllegalStateException("You can't update an unloaded resource.");
	}
	try {
		isUpdating = true;
		IParseResult oldParseResult = parseResult;
		ReplaceRegion replaceRegion = new ReplaceRegion(new TextRegion(offset, replacedTextLength), newText);
		IParseResult newParseResult;
		ParserRule oldEntryPoint = NodeModelUtils.getEntryParserRule(oldParseResult.getRootNode());
		if (entryPoint == null || entryPoint == oldEntryPoint) {
			newParseResult = parser.reparse(oldParseResult, replaceRegion);
		} else {
			StringBuilder builder = new StringBuilder(oldParseResult.getRootNode().getText());
			replaceRegion.applyTo(builder);
			newParseResult = parser.parse(entryPoint, new StringReader(builder.toString()));
		}
		updateInternalState(oldParseResult, newParseResult);
	} finally {
		isUpdating = false;
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:23,代码来源:XtextResource.java


示例2: testTokenRegionContainsRegion

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
@Test 
	public void testTokenRegionContainsRegion() throws Exception {
		String modelAsString = "a1 / /* comment */ b2";
		List<CommonToken> tokens = getTokens(modelAsString);
		for(int length=0; length < modelAsString.length(); ++length) {
			for(int offset = 0; offset + length < modelAsString.length(); ++offset) {
				ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(modelAsString, new TextRegion(offset, length));
//				System.out.println(offset + ":" + length + " -> " + tokenRegion);
				CommonToken firstToken = findTokenStartingAt(tokenRegion.getOffset(), tokens);
				assertTrue(firstToken.getStartIndex() <= offset);
				if(tokenRegion.getLength() != 0) {
					CommonToken lastToken = findTokenStopingAt(tokenRegion.getOffset() + tokenRegion.getLength()-1, tokens);
					assertTrue(lastToken.getStopIndex() >= offset + length -1);
				}
			}
		}
	}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:TokenRegionProviderTest.java


示例3: testGetCrossReferenceNode

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
@Test public void testGetCrossReferenceNode() throws Exception {
	String firstPart = "foo Foo1=X.Y foo Foo2=X.Y zonk bar Bar1 Foo1=X.Y";
	String modelAsString = firstPart+",Foo2=X.Y";
	XtextResource resource = getResourceFromString(modelAsString);
	
	INode node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length(), 0));
	assertEquals(firstPart.length()-8, node.getOffset());
	assertEquals(8, node.getLength());
	
	assertNull(eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length(), 1)));
	
	node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length()+1, 0));
	assertEquals(firstPart.length()+1, node.getOffset());
	assertEquals(8, node.getLength());
	
	node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length()+1, 5));
	assertEquals(firstPart.length()+1, node.getOffset());
	assertEquals(8, node.getLength());
	
	node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length()+1, 8));
	assertEquals(firstPart.length()+1, node.getOffset());
	assertEquals(8, node.getLength());
	
	assertNull(eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length()+1, 9)));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:EObjectAtOffsetTest.java


示例4: getStringRepresentation

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
@Override
protected String getStringRepresentation(final Object object) {
  if ((object instanceof AbstractIdeTemplateProposalProvider.Variable)) {
    final String varName = ((AbstractIdeTemplateProposalProvider.Variable)object).name;
    int _offset = this.context.getReplaceRegion().getOffset();
    int _currentOffset = this.getCurrentOffset();
    final int offset = (_offset + _currentOffset);
    int _length = varName.length();
    TextRegion _textRegion = new TextRegion(offset, _length);
    this.entry.getEditPositions().add(_textRegion);
    return varName;
  } else {
    if ((object instanceof AbstractIdeTemplateProposalProvider.Cursor)) {
      int _offset_1 = this.context.getReplaceRegion().getOffset();
      int _currentOffset_1 = this.getCurrentOffset();
      final int offset_1 = (_offset_1 + _currentOffset_1);
      this.entry.setEscapePosition(Integer.valueOf(offset_1));
      return null;
    } else {
      return object.toString();
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:AbstractIdeTemplateProposalProvider.java


示例5: createHyperlinksByOffset

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
@Override
public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
  IEditorPart activeEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
  if (activeEditor.getEditorInput() instanceof XtextReadonlyEditorInput) {
    INode crossRefNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(offset, 0));
    if (crossRefNode == null) {
      return;
    }
    EObject crossLinkedEObject = eObjectAtOffsetHelper.getCrossReferencedElement(crossRefNode);
    if (crossLinkedEObject != null && crossLinkedEObject.eClass().getEPackage() != CheckPackage.eINSTANCE) {
      return;
    }
    // if EPackage of referenced object is CheckPackage, try to provide hyperlinks: works for included catalogs
  }
  super.createHyperlinksByOffset(resource, offset, acceptor);
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:17,代码来源:CheckHyperlinkHelper.java


示例6: getTextRegion

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
protected ITextRegion getTextRegion(EObject eObject) {
	if (eObject == null)
		return null;
	IParseResult parseResult = ((XtextResource)eObject.eResource()).getParseResult();
	if (parseResult == null)
		return null;
	ICompositeNode rootNode = parseResult.getRootNode();
	Map<ILeafNode, EObject> comments = commentAssociater.associateCommentsWithSemanticEObjects(eObject, singleton(rootNode));
	final ITextRegion result = locationProvider.getFullTextRegion(eObject);
	int start = result.getOffset();
	int end = result.getOffset() + result.getLength();
	for (Entry<ILeafNode, EObject> entry : comments.entrySet()) {
		if (entry.getValue() == eObject) {
			ILeafNode node = entry.getKey();
			if (node.getTotalOffset() < start) {
				start = node.getTotalOffset();
			}
			if (node.getTotalEndOffset() > end) {
				end = node.getTotalEndOffset();
			}
		}
	}
	return new TextRegion(start, end-start);
}
 
开发者ID:cplutte,项目名称:bts,代码行数:25,代码来源:AstSelectionProvider.java


示例7: computeCommentFolding

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
@Override
protected void computeCommentFolding(final IXtextDocument xtextDocument,
		final IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor, final ITypedRegion typedRegion,
		final boolean initiallyFolded) throws BadLocationException {
	final int offset = typedRegion.getOffset();
	final int length = typedRegion.getLength();
	final Matcher matcher = getTextPatternInComment().matcher(xtextDocument.get(offset, length));
	((GamaFoldingRegionAcceptor) foldingRegionAcceptor).type = typedRegion.getType();
	if (matcher.find()) {
		final TextRegion significant = new TextRegion(offset + matcher.start(), 0);
		((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(offset, length,
				initiallyFolded, significant);
	} else {
		((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(offset, length,
				initiallyFolded);
	}
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:18,代码来源:GamaFoldingRegionProvider.java


示例8: addSectionToAppend

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
protected void addSectionToAppend(IAcceptor<ReplaceRegion> acceptor) {
	StringBuilder importDeclarationsToAppend = getImportDeclarationsToAppend();
	if (importDeclarationsToAppend.length() == 0)
		return;
	importRegion = regionUtil.addLeadingWhitespace(importRegion, resource);
	importRegion = regionUtil.addTrailingSingleWhitespace(importRegion, lineSeparator, resource);
	int insertOffset = importRegion.getOffset() + importRegion.getLength();
	if (insertOffset != 0 && originalImportDeclarations.isEmpty())
		importDeclarationsToAppend.insert(0, lineSeparator);
	importDeclarationsToAppend.append(lineSeparator);
	int insertLength = -importRegion.getLength();
	insertLength += regionUtil.addTrailingWhitespace(importRegion, resource).getLength();
	ReplaceRegion appendDeclarations = new ReplaceRegion(new TextRegion(insertOffset, insertLength), importDeclarationsToAppend.toString());
	acceptor.accept(appendDeclarations);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:16,代码来源:RewritableImportSection.java


示例9: computeRegion

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
public ITextRegion computeRegion(XtextResource resource) {
	XImportSection xImportSection = config.getImportSection(resource);
	// try to obtain the region from the text if it is not a synthetic region.
	if (xImportSection != null && xImportSection.eResource() != null) {
		INode node = NodeModelUtils.findActualNodeFor(xImportSection);
		if(node == null) 
			LOG.error("Cannot detect node for original import section");
		else 
			return node.getTextRegion();
	} 
	return new TextRegion(config.getImportSectionOffset(resource), 0);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:13,代码来源:ImportSectionRegionUtil.java


示例10: addLeadingWhitespace

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
public ITextRegion addLeadingWhitespace(ITextRegion textRegion, XtextResource resource) {
	String text = resource.getParseResult().getRootNode().getText();
	int offset = textRegion.getOffset();
	int length = textRegion.getLength();
	while(offset > 0 && Character.isWhitespace(text.charAt(offset-1)) ){
		--offset;
		++length;
	}
	return new TextRegion(offset, length);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:ImportSectionRegionUtil.java


示例11: addTrailingWhitespace

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
public ITextRegion addTrailingWhitespace(ITextRegion textRegion, XtextResource resource) {
	String text = resource.getParseResult().getRootNode().getText();
	int offset = textRegion.getOffset();
	int length = textRegion.getLength();
	while(offset + length < text.length() && Character.isWhitespace(text.charAt(offset+length))) {
		++length;
	}
	return new TextRegion(offset, length);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:10,代码来源:ImportSectionRegionUtil.java


示例12: addTrailingSingleWhitespace

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
public ITextRegion addTrailingSingleWhitespace(ITextRegion textRegion, String lineSeparator, XtextResource resource) {
	String text = resource.getParseResult().getRootNode().getText();
	String theFollowing = text.substring(textRegion.getOffset() + textRegion.getLength());
	if(!isEmpty(theFollowing)) { 
		if(theFollowing.startsWith(lineSeparator)) 
			return new TextRegion(textRegion.getOffset(), textRegion.getLength() + lineSeparator.length());
		else if(Character.isWhitespace(theFollowing.charAt(0)))
			return new TextRegion(textRegion.getOffset(), textRegion.getLength() + 1);
	}
	return textRegion;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:12,代码来源:ImportSectionRegionUtil.java


示例13: addJavaDocReferences

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
private void addJavaDocReferences(final INode documentationNode, final ITextRegion selectedRegion, final ImportsAcceptor acceptor) {
  List<ReplaceRegion> _computeTypeRefRegions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(documentationNode);
  for (final ReplaceRegion docTypeReference : _computeTypeRefRegions) {
    {
      int _offset = docTypeReference.getOffset();
      int _length = docTypeReference.getLength();
      final TextRegion referenceRange = new TextRegion(_offset, _length);
      boolean _contains = selectedRegion.contains(referenceRange);
      if (_contains) {
        String docTypeText = docTypeReference.getText();
        final EObject element = NodeModelUtils.findActualSemanticObjectFor(documentationNode);
        IScope scope = this.scopeProvider.getScope(element, 
          TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
        IEObjectDescription singleElement = scope.getSingleElement(QualifiedName.create(docTypeText));
        JvmType referencedType = null;
        if ((singleElement != null)) {
          EObject _eObjectOrProxy = singleElement.getEObjectOrProxy();
          referencedType = ((JvmType) _eObjectOrProxy);
        }
        if (((referencedType instanceof JvmDeclaredType) && (!referencedType.eIsProxy()))) {
          JvmDeclaredType casted = ((JvmDeclaredType) referencedType);
          boolean _equals = casted.getQualifiedName().equals(docTypeText);
          boolean _not = (!_equals);
          if (_not) {
            acceptor.acceptTypeImport(casted);
          }
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:32,代码来源:ImportsCollector.java


示例14: assertTrace

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
protected void assertTrace(final String javaCodeWithMarker, String xbaseCodeWithMarker) throws Exception {
	xbaseCodeWithMarker = " " + xbaseCodeWithMarker + " ";
	Matcher xbaseMatcher = p.matcher(xbaseCodeWithMarker);
	assertTrue(xbaseMatcher.matches());
	String xbaseGroup1 = xbaseMatcher.group(1);
	String xbaseGroup2 = xbaseMatcher.group(2);
	String xbaseGroup3 = xbaseMatcher.group(3);
	String actualCode = xbaseGroup1 + xbaseGroup2 + xbaseGroup3; 
	XExpression model = expression(actualCode,true);
	TreeAppendable appendable = new TreeAppendable(new ImportManager(true), converter, locationProvider, jvmModelAssociations, model, "  ", "\n");
	XbaseCompiler compiler = get(XbaseCompiler.class);
	LightweightTypeReference returnType = typeResolver.resolveTypes(model).getReturnType(model);
	if (returnType == null) {
		throw new IllegalStateException();
	}
	compiler.compile(model, appendable, returnType);
	String compiledJavaCode = appendable.getContent();
	Matcher javaMatcher = p.matcher(javaCodeWithMarker);
	assertTrue(javaMatcher.matches());
	String javaGroup1 = javaMatcher.group(1);
	String javaGroup2 = javaMatcher.group(2);
	String javaGroup3 = javaMatcher.group(3);
	String actualExpectation = javaGroup1 + javaGroup2 + javaGroup3;
	assertEquals(actualExpectation, compiledJavaCode);
	ITrace trace = new SimpleTrace(appendable.getTraceRegion());
	ILocationInResource location = trace.getBestAssociatedLocation(new TextRegion(javaGroup1.length(), javaGroup2.length()));
	if (location == null) {
		throw new IllegalStateException("location may not be null");
	}
	assertEquals(new TextRegion(xbaseGroup1.length(), xbaseGroup2.length()), location.getTextRegion());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:32,代码来源:CompilerTraceTest.java


示例15: getTextRegion

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
/**
 * @since 2.5
 */
@Override
public ITextRegion getTextRegion() {
	int offset = getOffset();
	int length = getEndOffset() - offset;
	return new TextRegion(offset, length);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:AbstractNode.java


示例16: getTotalTextRegion

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
/**
 * @since 2.5
 */
@Override
public ITextRegion getTotalTextRegion() {
	int totalOffset = getTotalOffset();
	int totalLength = getTotalLength();
	return new TextRegion(totalOffset, totalLength);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:AbstractNode.java


示例17: getTokenReplaceRegion

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
public ReplaceRegion getTokenReplaceRegion(String changedText, ReplaceRegion replaceRegion) {
	int lengthDelta = replaceRegion.getText().length() - replaceRegion.getLength();
	ITextRegion tokenRegion = getTokenRegion(changedText, new TextRegion(replaceRegion.getOffset(), replaceRegion
			.getText().length()));
	if (tokenRegion.getOffset() == replaceRegion.getOffset()
			&& tokenRegion.getLength() == replaceRegion.getText().length())
		return replaceRegion;
	else 
		return new ReplaceRegion(tokenRegion.getOffset(), tokenRegion.getLength() - lengthDelta,
				changedText.substring(tokenRegion.getOffset(), tokenRegion.getOffset() + tokenRegion.getLength()));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:TokenRegionProvider.java


示例18: resolveCrossReferencedElementAt

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
/**
 * @return the cross referenced EObject under, right or left to the cursor (in that order) or
 *         <code>null</code> if there is no cross referenced object next to the offset.
 */
public EObject resolveCrossReferencedElementAt(XtextResource resource, int offset) {
	INode node = getCrossReferenceNode(resource, new TextRegion(offset, 0));
	if (node != null)
		return getCrossReferencedElement(node);
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:11,代码来源:EObjectAtOffsetHelper.java


示例19: feedTokenStream

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
@Override
public ITextRegion feedTokenStream(ITokenStream out, ICompositeNode in, int offset, int length) throws IOException {
	List<INode> nodes = getLeafs(in, offset, offset + length);
	if (nodes.isEmpty())
		return new TextRegion(in.getOffset(), 0);
	if (out instanceof ITokenStreamExtension)
		((ITokenStreamExtension) out).init(findRootRuleForRegion(nodes.get(0)));
	boolean lastIsTokenOrComment = false;
	for (INode node : nodes) {
		boolean currentIsTokenOrComment = tokenUtil.isCommentNode(node) || tokenUtil.isToken(node);
		if (lastIsTokenOrComment && currentIsTokenOrComment)
			writeHiddenEmpty(out);
		lastIsTokenOrComment = currentIsTokenOrComment;
		if (node instanceof ILeafNode) {
			ILeafNode leaf = (ILeafNode) node;
			if (leaf.isHidden())
				writeHidden(out, leaf);
			else
				writeSemantic(out, leaf);
		} else if (node instanceof ICompositeNode)
			writeSemantic(out, (ICompositeNode) node);
	}
	out.flush();
	int rStart = nodes.get(0).getOffset();
	int rLength = nodes.get(nodes.size() - 1).getEndOffset() - rStart;
	return new TextRegion(rStart, rLength);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:28,代码来源:NodeModelStreamer.java


示例20: firstSetGrammarElementsToString

import org.eclipse.xtext.util.TextRegion; //导入依赖的package包/类
public String firstSetGrammarElementsToString(final ContentAssistContextFactory factory) {
  final int offset = this.document.indexOf(this.cursor);
  Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor");
  final String doc = this.document.replace(this.cursor, "");
  final XtextResource res = this.parse(doc);
  factory.setPool(Executors.newCachedThreadPool());
  TextRegion _textRegion = new TextRegion(0, 0);
  final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res);
  final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule();
  StringConcatenation _builder = new StringConcatenation();
  {
    Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>)Conversions.doWrapArray(ctxs)));
    for(final Pair<Integer, ContentAssistContext> ctx : _indexed) {
      _builder.append("context");
      Integer _key = ctx.getKey();
      _builder.append(_key);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      {
        ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements();
        for(final AbstractElement ele : _firstSetGrammarElements) {
          _builder.append("\t");
          String _name = ele.eClass().getName();
          _builder.append(_name, "\t");
          _builder.append(": ");
          String _apply = f.apply(ele);
          _builder.append(_apply, "\t");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("}");
      _builder.newLine();
    }
  }
  return _builder.toString();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:37,代码来源:ContentAssistContextTestHelper.java



注:本文中的org.eclipse.xtext.util.TextRegion类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StringNameHelper类代码示例发布时间:2022-05-23
下一篇:
Java StaxSerializer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap