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; } }
@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); } } } }
@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))); }
@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(); } } }
@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); }
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); }
@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); } }
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); }
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); }
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); }
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); }
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; }
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); } } } } } }
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()); }
/** * @since 2.5 */ @Override public ITextRegion getTextRegion() { int offset = getOffset(); int length = getEndOffset() - offset; return new TextRegion(offset, length); }
/** * @since 2.5 */ @Override public ITextRegion getTotalTextRegion() { int totalOffset = getTotalOffset(); int totalLength = getTotalLength(); return new TextRegion(totalOffset, totalLength); }
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())); }
/** * @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; }
@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); }
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(); }
@Test public void testTokenMerge() throws Exception { String model = " "; ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0)); assertEquals(0, tokenRegion.getOffset()); assertEquals(2, tokenRegion.getLength()); }
@Test public void testTokenMerge_1() throws Exception { String model = " ab "; ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 0)); assertEquals(1, tokenRegion.getOffset()); assertEquals(2, tokenRegion.getLength()); }
@Test public void testTokenSplit() throws Exception { String model = " a b "; ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1)); assertEquals(2, tokenRegion.getOffset()); assertEquals(1, tokenRegion.getLength()); }
@Test public void testTokenSplit_1() throws Exception { String model = " axb "; ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1)); assertEquals(1, tokenRegion.getOffset()); assertEquals(3, tokenRegion.getLength()); }
@Test public void testBug486454() throws Exception { String model = "t"; ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0)); assertEquals(0, tokenRegion.getOffset()); assertEquals(1, tokenRegion.getLength()); }
@Test public void twoFrame1() { final TraceRegionToStringTester tester = new TraceRegionToStringTester(); StringConcatenation _builder = new StringConcatenation(); _builder.append("foo bar"); _builder.newLine(); tester.setLocalText(_builder.toString()); TextRegion _textRegion = new TextRegion(1, 5); tester.setLocalFrame(_textRegion); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("baz buz"); _builder_1.newLine(); tester.setRemote1(_builder_1.toString()); SourceRelativeURI _uri1 = tester.getUri1(); TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(1, 5, _uri1); TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location))); final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> { TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(1, 5); it.addChild(2, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1))); TraceRegionToStringTester.Location _location_2 = new TraceRegionToStringTester.Location(1, 5); it.addChild(5, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_2))); }; TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function); tester.setTrace(_doubleArrow); StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("---- local1 ----- | ---- remote1 ----"); _builder_2.newLine(); _builder_2.append("o[1[o]1] b[2[a]2] | b[1,2[az bu]2,1]z"); _builder_2.newLine(); _builder_2.append("-------------------------------------"); _builder_2.newLine(); _builder_2.append("1: D 2-1 Region -> Location[1,5]"); _builder_2.newLine(); _builder_2.append("2: D 5-1 Region -> Location[1,5]"); _builder_2.newLine(); this.operator_tripleEquals(tester, _builder_2); }
@Test public void twoFrame2() { final TraceRegionToStringTester tester = new TraceRegionToStringTester(); StringConcatenation _builder = new StringConcatenation(); _builder.append("foo bar"); _builder.newLine(); tester.setLocalText(_builder.toString()); TextRegion _textRegion = new TextRegion(2, 4); tester.setLocalFrame(_textRegion); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("baz buz"); _builder_1.newLine(); tester.setRemote1(_builder_1.toString()); SourceRelativeURI _uri1 = tester.getUri1(); TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(1, 5, _uri1); TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location))); final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> { TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(1, 5); it.addChild(2, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1))); TraceRegionToStringTester.Location _location_2 = new TraceRegionToStringTester.Location(1, 5); it.addChild(5, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_2))); }; TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function); tester.setTrace(_doubleArrow); StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("---- local1 ---- | ---- remote1 ----"); _builder_2.newLine(); _builder_2.append("[1[o]1] b[2[a]2] | b[1,2[az bu]2,1]z"); _builder_2.newLine(); _builder_2.append("------------------------------------"); _builder_2.newLine(); _builder_2.append("1: D 2-1 Region -> Location[1,5]"); _builder_2.newLine(); _builder_2.append("2: D 5-1 Region -> Location[1,5]"); _builder_2.newLine(); this.operator_tripleEquals(tester, _builder_2); }
public ContentAssistContext.Builder doCreateContext( INode lastCompleteNode, EObject currentModel, EObject previousModel, INode currentNode, String prefix) { ContentAssistContext.Builder context = contentAssistContextProvider.get(); context.setRootNode(rootNode); context.setLastCompleteNode(lastCompleteNode); context.setCurrentNode(currentNode); context.setRootModel(parseResult.getRootASTElement()); context.setCurrentModel(currentModel); context.setPreviousModel(previousModel); context.setOffset(completionOffset); context.setPrefix(prefix); int regionLength = prefix.length(); if (selection.getLength() > 0) { regionLength = regionLength + selection.getLength(); } ITextRegion region = new TextRegion(completionOffset - prefix.length(), regionLength); if (selection.getOffset() >= 0 && selection.getLength() >= 0) { context.setSelectedText(document.substring(selection.getOffset(), selection.getOffset() + selection.getLength())); } context.setReplaceRegion(region); context.setResource(resource); return context; }
public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) { try { final CompletionList result = new CompletionList(); result.setIsIncomplete(true); final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get(); final int caretOffset = document.getOffSet(params.getPosition()); final Position caretPosition = params.getPosition(); final TextRegion position = new TextRegion(caretOffset, 0); try { this.createProposals(document.getContents(), position, caretOffset, resource, acceptor); } catch (final Throwable _t) { if (_t instanceof Throwable) { final Throwable t = (Throwable)_t; boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t); boolean _not = (!_isOperationCanceledException); if (_not) { throw t; } } else { throw Exceptions.sneakyThrow(_t); } } final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> { final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document); item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0')); List<CompletionItem> _items = result.getItems(); _items.add(item); }; IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected void createProposals(final String document, final TextRegion selection, final int caretOffset, final XtextResource resource, final IIdeContentProposalAcceptor acceptor) { int _length = document.length(); boolean _greaterThan = (caretOffset > _length); if (_greaterThan) { return; } final ContentAssistContextFactory contextFactory = this.contextFactoryProvider.get(); contextFactory.setPool(this.executorService); final ContentAssistContext[] contexts = contextFactory.create(document, selection, caretOffset, resource); this.proposalProvider.createProposals(((Collection<ContentAssistContext>)Conversions.doWrapArray(contexts)), acceptor); }
public List<TextEdit> format(final XtextResource resource, final Document document, final int offset, final int length) { if ((this.formatter2Provider != null)) { TextRegion _textRegion = new TextRegion(offset, length); final List<ITextReplacement> replacements = this.format2(resource, _textRegion, null); final Function1<ITextReplacement, TextEdit> _function = (ITextReplacement r) -> { return this.toTextEdit(document, r.getReplacementText(), r.getOffset(), r.getLength()); }; return IterableExtensions.<TextEdit>toList(ListExtensions.<ITextReplacement, TextEdit>map(replacements, _function)); } else { return CollectionLiterals.<TextEdit>newArrayList(); } }
protected void selectInTreeView(ISelection selection) { if (selection instanceof ITextSelection && !treeViewer.getTree().isDisposed()) { ITextSelection textSelection = (ITextSelection) selection; ITextRegion selectedTextRegion = new TextRegion(textSelection.getOffset(), textSelection.getLength()); Object input = treeViewer.getInput(); if (input instanceof IOutlineNode) { IOutlineNode nodeToBeSelected = findBestNode((IOutlineNode) input, selectedTextRegion); if (nodeToBeSelected != null) treeViewer.setSelection(new StructuredSelection(nodeToBeSelected)); } } }
/** * @since 2.1 */ protected EObjectNode createEObjectNode(IOutlineNode parentNode, EObject modelElement, Image image, Object text, boolean isLeaf) { EObjectNode eObjectNode = new EObjectNode(modelElement, parentNode, image, text, isLeaf); ICompositeNode parserNode = NodeModelUtils.getNode(modelElement); if (parserNode != null) eObjectNode.setTextRegion(new TextRegion(parserNode.getOffset(), parserNode.getLength())); if (isLocalElement(parentNode, modelElement)) eObjectNode.setShortTextRegion(locationInFileProvider.getSignificantTextRegion(modelElement)); return eObjectNode; }
public EObjectNode createEObjectNode(IOutlineNode parentNode, EObject modelElement, ImageDescriptor imageDescriptor, Object text, boolean isLeaf) { EObjectNode eObjectNode = new EObjectNode(modelElement, parentNode, imageDescriptor, text, isLeaf); ICompositeNode parserNode = NodeModelUtils.getNode(modelElement); if (parserNode != null) eObjectNode.setTextRegion(new TextRegion(parserNode.getOffset(), parserNode.getLength())); if(isLocalElement(parentNode, modelElement)) eObjectNode.setShortTextRegion(locationInFileProvider.getSignificantTextRegion(modelElement)); return eObjectNode; }
protected ITextRegion getRegion(Pair<EObject, EObject> selection) { final ITextRegion firstRegion = getTextRegion(selection.getFirst()); if (selection.getFirst() == selection.getSecond()) { return firstRegion; } ITextRegion secondRegion = getTextRegion(selection.getSecond()); return new TextRegion(firstRegion.getOffset(), getEndOffset(secondRegion) - firstRegion.getOffset()); }
protected ITextRegion computeInitialFineGrainedSelection(INode node, ITextRegion currentEditorSelection) { if (node.getText().trim().length() > 0 && currentEditorSelection.getOffset() >= node.getOffset() && getEndOffset(currentEditorSelection) < node.getOffset() + node.getLength()) { //TODO enhance to just select a single word in a comment or string literal. return new TextRegion(node.getOffset(), node.getLength()); } return null; }
@Override public void run() { ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection(); ITextRegion currentEditorSelection = new TextRegion(selection.getOffset(), selection.getLength()); ITextRegion nextSelection = xtextEditor.getDocument().readOnly(createTextSelectionWork(currentEditorSelection)); if (nextSelection == null || nextSelection == ITextRegion.EMPTY_REGION || nextSelection.equals(currentEditorSelection)) { return; } xtextEditor.selectAndReveal(nextSelection.getOffset(), nextSelection.getLength()); }
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { INode crossRefNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(offset, 0)); if (crossRefNode == null) return; EObject crossLinkedEObject = eObjectAtOffsetHelper.getCrossReferencedElement(crossRefNode); if (crossLinkedEObject != null && !crossLinkedEObject.eIsProxy()) { createHyperlinksTo(resource, crossRefNode, crossLinkedEObject, acceptor); } }
protected boolean isRefactoringEnabled(IRenameElementContext renameElementContext, XtextResource resource) { ResourceSet resourceSet = resource.getResourceSet(); if (renameElementContext != null && resourceSet != null) { EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true); if (targetElement != null && !targetElement.eIsProxy()) { if(targetElement.eResource() == resource && renameElementContext.getTriggeringEditorSelection() instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) renameElementContext.getTriggeringEditorSelection(); ITextRegion selectedRegion = new TextRegion(textSelection.getOffset(), textSelection.getLength()); INode crossReferenceNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, selectedRegion); if(crossReferenceNode == null) { // selection is on the declaration. make sure it's the name ITextRegion significantRegion = locationInFileProvider.getSignificantTextRegion(targetElement); if(!significantRegion.contains(selectedRegion)) return false; } } IRenameStrategy.Provider renameStrategyProvider = globalServiceProvider.findService(targetElement, IRenameStrategy.Provider.class); try { return renameStrategyProvider.get(targetElement, renameElementContext) != null; } catch (NoSuchStrategyException e) { MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Cannot rename element", e.getMessage()); } } } return false; }
@Override public ContentAssistEntry createProposal(final IEObjectDescription candidate, final CrossReference crossRef, final ContentAssistContext context) { boolean _hasIdRule = this.hasIdRule(crossRef); if (_hasIdRule) { final XbaseIdeCrossrefProposalProvider.ProposalBracketInfo bracketInfo = this.getProposalBracketInfo(candidate, context); String _string = this.getQualifiedNameConverter().toString(candidate.getName()); final String proposalString = (_string + bracketInfo.brackets); int _xifexpression = (int) 0; if ((candidate instanceof IIdentifiableElementDescription)) { _xifexpression = ((IIdentifiableElementDescription)candidate).getNumberOfIrrelevantParameters(); } else { _xifexpression = 0; } final int insignificantParameters = _xifexpression; final LightweightTypeReferenceFactory converter = this.getTypeConverter(context.getResource()); final EObject objectOrProxy = candidate.getEObjectOrProxy(); final Procedure1<ContentAssistEntry> _function = (ContentAssistEntry result) -> { if ((objectOrProxy instanceof JvmFeature)) { boolean _startsWith = bracketInfo.brackets.startsWith(" ="); if (_startsWith) { String _string_1 = this.getQualifiedNameConverter().toString(candidate.getName()); String _plus = (_string_1 + bracketInfo.brackets); this.addNameAndDescription(result, ((JvmFeature)objectOrProxy), false, insignificantParameters, _plus, converter); } else { boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(bracketInfo.brackets); boolean _not = (!_isNullOrEmpty); this.addNameAndDescription(result, ((JvmFeature)objectOrProxy), _not, insignificantParameters, this.getQualifiedNameConverter().toString(candidate.getName()), converter); } } else { this.addNameAndDescription(result, objectOrProxy, this.getQualifiedNameConverter().toString(candidate.getQualifiedName()), this.getQualifiedNameConverter().toString(candidate.getName())); } int _offset = context.getOffset(); int _length = context.getPrefix().length(); int _minus = (_offset - _length); int _length_1 = proposalString.length(); int offset = (_minus + _length_1); result.setEscapePosition(Integer.valueOf((offset + bracketInfo.caretOffset))); if ((bracketInfo.selectionOffset != 0)) { int _offset_1 = offset; offset = (_offset_1 + bracketInfo.selectionOffset); ArrayList<TextRegion> _editPositions = result.getEditPositions(); TextRegion _textRegion = new TextRegion(offset, bracketInfo.selectionLength); _editPositions.add(_textRegion); } if ((objectOrProxy instanceof JvmExecutable)) { final StringBuilder parameterList = new StringBuilder(); this.appendParameters(parameterList, ((JvmExecutable)objectOrProxy), insignificantParameters, converter); } }; return this.getProposalCreator().createProposal(proposalString, context, _function); } return super.createProposal(candidate, crossRef, context); }