org.eclipse.xtext.util.ReplaceRegion Java Examples
The following examples show how to use
org.eclipse.xtext.util.ReplaceRegion.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaDocTypeReferenceProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testComputation_3() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append("* {@link java.util.ArrayList"); _builder.newLine(); _builder.append("*/"); _builder.newLine(); _builder.append("class Foo{}"); _builder.newLine(); final String input = _builder.toString(); Resource _eResource = this.clazz(input).eResource(); final XtextResource resource = ((XtextResource) _eResource); final ICompositeNode rootNode = resource.getParseResult().getRootNode(); final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode); Assert.assertEquals(0, regions.size()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #2
Source File: DefaultTextEditComposer.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected List<TextEdit> getObjectEdits() { final Collection<EObject> modifiedObjects = getModifiedObjects(); Collection<EObject> topLevelObjects = EcoreUtil.filterDescendants(modifiedObjects); Iterable<EObject> containedModifiedObjects = Collections.emptyList(); if (!resource.getContents().isEmpty()) { final EObject root = resource.getContents().get(0); containedModifiedObjects = Iterables.filter(topLevelObjects, new Predicate<EObject>() { @Override public boolean apply(EObject input) { return EcoreUtil.isAncestor(root, input); } }); } List<TextEdit> edits = Lists.newArrayListWithExpectedSize(Iterables.size(containedModifiedObjects)); for (EObject modifiedObject : containedModifiedObjects) { ReplaceRegion replaceRegion = serializer.serializeReplacement(modifiedObject, getSaveOptions()); TextEdit edit = new ReplaceEdit(replaceRegion.getOffset(), replaceRegion.getLength(), replaceRegion.getText()); edits.add(edit); } return edits; }
Example #3
Source File: JavaDocTypeReferenceProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testComputation_8() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append("* @see String"); _builder.newLine(); _builder.append("*/"); _builder.newLine(); _builder.append("class Foo{}"); _builder.newLine(); final String input = _builder.toString(); Resource _eResource = this.clazz(input).eResource(); final XtextResource resource = ((XtextResource) _eResource); final ICompositeNode rootNode = resource.getParseResult().getRootNode(); final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode); Assert.assertEquals(1, regions.size()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #4
Source File: JavaDocTypeReferenceProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testComputation_7() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append("* {@link String}"); _builder.newLine(); _builder.append("*/"); _builder.newLine(); _builder.append("class Foo{}"); _builder.newLine(); final String input = _builder.toString(); Resource _eResource = this.clazz(input).eResource(); final XtextResource resource = ((XtextResource) _eResource); final ICompositeNode rootNode = resource.getParseResult().getRootNode(); final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode); Assert.assertEquals(1, regions.size()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #5
Source File: XbaseReferenceUpdater.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override protected void processReferringResource(Resource referringResource, Iterable<IReferenceDescription> referenceDescriptions, ElementRenameArguments elementRenameArguments, IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) { ImportAwareUpdateAcceptor importAwareUpdateAcceptor = createUpdateAcceptor(referringResource, updateAcceptor); Iterable<IReferenceDescription> importTypeReferences = getImportTypeReferences(referenceDescriptions); super.processReferringResource(referringResource, importTypeReferences, elementRenameArguments, importAwareUpdateAcceptor, monitor); importAwareUpdateAcceptor.getImportSection().update(); Iterable<IReferenceDescription> notImportTypeReferences = getNotImportTypeReferences(referenceDescriptions); super.processReferringResource(referringResource, notImportTypeReferences, elementRenameArguments, importAwareUpdateAcceptor, monitor); List<ReplaceRegion> importChanges = importAwareUpdateAcceptor.getImportSection().rewrite(); TextEdit importChangeEdit = replaceConverter.convertToTextEdit(importChanges); if(importChangeEdit != null) updateAcceptor.accept(referringResource.getURI(), importChangeEdit); }
Example #6
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Fix(IssueCodes.OBSOLETE_CAST) public void fixObsoletCast(final Issue issue, IssueResolutionAcceptor acceptor) { String fixup = "Remove unnecessary cast"; acceptor.accept(issue, fixup, fixup, null, new IModification() { @Override public void apply(IModificationContext context) throws Exception { final IXtextDocument document = context.getXtextDocument(); ReplaceRegion replacement = document.tryReadOnly(new IUnitOfWork<ReplaceRegion, XtextResource>() { @Override public ReplaceRegion exec(XtextResource state) throws Exception { EObject type = state.getEObject(issue.getUriToProblem().fragment()); XCastedExpression cast = EcoreUtil2.getContainerOfType(type, XCastedExpression.class); INode castNode = NodeModelUtils.findActualNodeFor(cast); INode targetNode = NodeModelUtils.findActualNodeFor(cast.getTarget()); return new ReplaceRegion(castNode.getTotalTextRegion(), targetNode.getText()); } }); if (replacement != null) { document.replace(replacement.getOffset(), replacement.getLength(), replacement.getText()); } } }); }
Example #7
Source File: ImportOrganizer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
private ReplaceRegion getReplaceRegion(String nameToUse, String packageLocalName, JvmDeclaredType type, TypeUsage usage, RewritableImportSection importSection) { // if the resource contains two types with the same simple name, we don't add any import // but we can still use the package local name within the same package. // Except for inner types if (equal(usage.getContextPackageName(), type.getPackageName()) && type.getDeclaringType() == null) { if (type.eContainer() != null) { String declarationLocalName = getLocalName(type, usage.getContext()); nameToUse = declarationLocalName; } else if (importSection.getImportedTypes(packageLocalName) == null) { nameToUse = packageLocalName; } } String textToUse = getConcreteSyntax(nameToUse, type, usage); return new ReplaceRegion(usage.getTextRegion(), textToUse); }
Example #8
Source File: OrganizeImportsHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public void doOrganizeImports(final IXtextDocument document) { List<ReplaceRegion> result = document.priorityReadOnly(new IUnitOfWork<List<ReplaceRegion>, XtextResource>() { @Override public List<ReplaceRegion> exec(XtextResource state) throws Exception { return importOrganizer.getOrganizedImportChanges(state); } }); if (result == null || result.isEmpty()) return; try { DocumentRewriteSession session = null; if(document instanceof IDocumentExtension4) { session = ((IDocumentExtension4)document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); } replaceConverter.convertToTextEdit(result).apply(document); if(session != null) { ((IDocumentExtension4)document).stopRewriteSession(session); } } catch (BadLocationException e) { LOG.error(Messages.OrganizeImportsHandler_organizeImportsErrorMessage, e); } }
Example #9
Source File: JavaDocTypeReferenceProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testComputation_4() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append("* {@link java.util.ArrayList"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append("class Foo{}"); _builder.newLine(); final String input = _builder.toString(); Resource _eResource = this.clazz(input).eResource(); final XtextResource resource = ((XtextResource) _eResource); final ICompositeNode rootNode = resource.getParseResult().getRootNode(); final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode); Assert.assertEquals(0, regions.size()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #10
Source File: FixedPartialParsingHelper.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
private boolean isRangePartOfExceedingLookAhead(final CompositeNode node, final ReplaceRegion replaceRegion) { TreeIterator<AbstractNode> iterator = node.basicIterator(); int lookAhead = node.getLookAhead(); if (lookAhead == 0) { return false; } while (iterator.hasNext()) { AbstractNode child = iterator.next(); if (child instanceof CompositeNode) { if (child.getTotalOffset() < replaceRegion.getEndOffset()) { lookAhead = Math.max(((CompositeNode) child).getLookAhead(), lookAhead); } } else if (!((ILeafNode) child).isHidden()) { lookAhead--; if (lookAhead == 0) { if (child.getTotalOffset() >= replaceRegion.getEndOffset()) { return false; } } } } return lookAhead > 0; }
Example #11
Source File: PartialParsingHelper.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private boolean isRangePartOfExceedingLookAhead(CompositeNode node, ReplaceRegion replaceRegion) { TreeIterator<AbstractNode> iterator = node.basicIterator(); int lookAhead = node.getLookAhead(); if (lookAhead == 0) { return false; } while(iterator.hasNext()) { AbstractNode child = iterator.next(); if (child instanceof CompositeNode) { if (child.getTotalOffset() < replaceRegion.getEndOffset()) lookAhead = Math.max(((CompositeNode) child).getLookAhead(), lookAhead); } else if (!((ILeafNode) child).isHidden()) { lookAhead--; if (lookAhead == 0) { if (child.getTotalOffset() >= replaceRegion.getEndOffset()) return false; } } } return lookAhead > 0; }
Example #12
Source File: PartialParsingProcessor.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public String processFile(String completeData, String data, int offset, int len, String change) throws Exception { IParseResult initialParseResult = parser.parse(new StringReader(data)); String newData = applyDelta(data, offset, len, change); ReplaceRegion replaceRegion = new ReplaceRegion(offset, len, change); try { IParseResult reparsed = parser.reparse(initialParseResult, replaceRegion); IParseResult parsedFromScratch = parser.parse(new StringReader(newData)); assertEqual(data, newData, parsedFromScratch, reparsed); return newData; } catch(Throwable e) { ComparisonFailure throwMe = new ComparisonFailure(e.getMessage(), newData, replaceRegion + DELIM + data); throwMe.initCause(e); throw throwMe; } }
Example #13
Source File: AbstractPartialParserReplaceTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception { IParseResult parseResult = getParseResult(model); PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length); String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers .getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change)); assertEquals(expectedReparseRegion, reparseRegion); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); getPartialParser().setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); IParseResult partiallyReparse = reparse(parseResult, offset, length, change); assertTrue("unloaded", unloaded.get()); assertFalse(partiallyReparse.getRootNode().getText(), partiallyReparse.hasSyntaxErrors()); String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length); assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText()); }
Example #14
Source File: Bug419429Test.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception { IParseResult parseResult = getParseResultAndExpect(model, UNKNOWN_EXPECTATION); PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length); String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers .getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change)); assertEquals(expectedReparseRegion, reparseRegion); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); getPartialParser().setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); IParseResult partiallyReparse = reparse(parseResult, offset, length, change); assertTrue("unloaded", unloaded.get()); String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length); assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText()); compareWithFullParse(model, offset, length, change); }
Example #15
Source File: PartialParsingProcessor.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public String processFile(String completeData, String data, int offset, int len, String change) throws Exception { IParseResult initialParseResult = parser.parse(new StringReader(data)); String newData = applyDelta(data, offset, len, change); ReplaceRegion replaceRegion = new ReplaceRegion(offset, len, change); try { IParseResult reparsed = parser.reparse(initialParseResult, replaceRegion); IParseResult parsedFromScratch = parser.parse(new StringReader(newData)); assertEqual(data, newData, parsedFromScratch, reparsed); return newData; } catch(Throwable e) { ComparisonFailure throwMe = new ComparisonFailure(e.getMessage(), newData, replaceRegion + DELIM + data); throwMe.initCause(e); throw throwMe; } }
Example #16
Source File: ImportsAwareReferenceProposalCreator.java From n4js with Eclipse Public License 1.0 | 6 votes |
private ContentAssistEntry convertResolutionToContentAssistEntry(ReferenceResolution resolution, N4JSResource resource, ContentAssistContext context) { ContentAssistEntry cae = new ContentAssistEntry(); cae.setPrefix(context.getPrefix()); cae.setProposal(resolution.proposal); cae.setLabel(resolution.label); cae.setDescription(resolution.description); if (resolution.importToBeAdded != null) { ReplaceRegion textReplacement = importHelper.getReplacementForImport(resource.getScript(), resolution.importToBeAdded); cae.getTextReplacements().add(textReplacement); } cae.setSource(resolution.referencedElement); cae.setKind(getKind(resolution)); return cae; }
Example #17
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Check public void checkJavaDocRefs(XtendMember member){ if(isIgnored(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC)) return; List<INode> documentationNodes = ((IEObjectDocumentationProviderExtension) documentationProvider).getDocumentationNodes(member); for(INode node : documentationNodes){ for(ReplaceRegion region : javaDocTypeReferenceProvider.computeTypeRefRegions(node)){ String typeRefString = region.getText(); if(typeRefString != null && typeRefString.length() > 0){ IScope scope = scopeProvider.getScope(member, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE); IEObjectDescription candidate = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(typeRefString)); if(candidate == null){ Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC); if (severity != null) getChain().add(createDiagnostic(severity, "javaDoc: " + typeRefString + " cannot be resolved to a type", member, region.getOffset(), region.getLength(), IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC)); } } } } }
Example #18
Source File: TestLanguageProposalCreator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ContentAssistEntry createProposal(String proposal, String prefix, ContentAssistContext context, String kind, Procedure1<? super ContentAssistEntry> init) { ContentAssistEntry entry = super.createProposal(proposal, prefix, context, kind, init); if (entry != null && kind == ContentAssistEntry.KIND_KEYWORD && "{".equals(proposal)) { // just for testing purposes entry.getTextReplacements().add(new ReplaceRegion(context.getOffset() + 1, 0, "}")); } return entry; }
Example #19
Source File: Serializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ReplaceRegion serializeReplacement(EObject obj, SaveOptions options) { ICompositeNode node = NodeModelUtils.findActualNodeFor(obj); if (node == null) { throw new IllegalStateException("Cannot replace an obj that has no associated node"); } String text = serialize(obj, options); int replaceRegionLength = calculateReplaceRegionLength(node, text); return new ReplaceRegion(node.getTotalOffset(), replaceRegionLength, text); }
Example #20
Source File: Serializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ReplaceRegion serializeReplacement(EObject obj, SaveOptions options) { TokenStringBuffer tokenStringBuffer = new TokenStringBuffer(); try { TreeConstructionReport report = serialize(obj, tokenStringBuffer, options); return new ReplaceRegion(report.getPreviousLocation(), tokenStringBuffer.toString()); } catch (IOException e) { throw new RuntimeException(e); } }
Example #21
Source File: CommentAssociationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private void checkReplaceRegion(Element element, String expectedText, String completeModel) { Serializer serializer = get(Serializer.class); ReplaceRegion replacement = serializer.serializeReplacement(element, SaveOptions.defaultOptions()); assertEquals(expectedText, replacement.getText()); assertEquals(completeModel.indexOf(expectedText), replacement.getOffset()); assertEquals(expectedText.length(), replacement.getLength()); }
Example #22
Source File: FixedPartialParsingHelper.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
private boolean isNullEdit(final INode oldRootNode, final ReplaceRegion replaceRegion) { if (replaceRegion.getLength() == replaceRegion.getText().length()) { String replacedText = oldRootNode.getText().substring(replaceRegion.getOffset(), replaceRegion.getEndOffset()); if (replaceRegion.getText().equals(replacedText)) { return true; } } return false; }
Example #23
Source File: PartialParserTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testInsertSlashInSecondNode() throws Exception { IParseResult parseResult = resource.getParser().reparse(this.parseResult, new ReplaceRegion(model.indexOf('6'), 0, "/")); assertFalse(parseResult.hasSyntaxErrors()); assertEquals(0, parseResult.getRootNode().getTotalOffset()); assertSame(resource.getParseResult().getRootNode(), parseResult.getRootNode()); String newModel = "a.b.c.d: 123;\n" + "e.f.g.h: 45/6;"; EmfAssert.assertEObjectsEqual(getModel(newModel), resource.getParseResult().getRootASTElement()); }
Example #24
Source File: PartialParsingHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected IParseResult fullyReparse(IParser parser, IParseResult previousParseResult, ReplaceRegion replaceRegion) { unloadSemanticObject(previousParseResult.getRootASTElement()); ICompositeNode node = previousParseResult.getRootNode(); ParserRule parserRule = NodeModelUtils.getEntryParserRule(node); String reparseRegion = insertChangeIntoReplaceRegion(previousParseResult.getRootNode(), replaceRegion); return parser.parse(parserRule, new StringReader(reparseRegion)); }
Example #25
Source File: PartialParserTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testInsertSlashInFirstNode() throws Exception { IParseResult parseResult = resource.getParser().reparse(this.parseResult, new ReplaceRegion(model.indexOf('3'), 0, "/")); assertFalse(parseResult.hasSyntaxErrors()); assertEquals(0, parseResult.getRootNode().getTotalOffset()); assertSame(resource.getParseResult().getRootNode(), parseResult.getRootNode()); String newModel = "a.b.c.d: 12/3;\n" + "e.f.g.h: 456;"; EmfAssert.assertEObjectsEqual(getModel(newModel), resource.getParseResult().getRootASTElement()); }
Example #26
Source File: ContentAssistService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) { CompletionItem completionItem = new CompletionItem(); String label = entry.getLabel(); if (label == null) { label = entry.getProposal(); } completionItem.setLabel(label); completionItem.setDetail(entry.getDescription()); completionItem.setDocumentation(entry.getDocumentation()); String prefix = entry.getPrefix(); if (prefix == null) { prefix = ""; } int prefixOffset = caretOffset - prefix.length(); Position prefixPosition = document.getPosition(prefixOffset); completionItem.setTextEdit(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal())); completionItem.setKind(translateKind(entry)); if (!entry.getTextReplacements().isEmpty()) { if (completionItem.getAdditionalTextEdits() == null) { completionItem.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size())); } entry.getTextReplacements().forEach( (ReplaceRegion it) -> completionItem.getAdditionalTextEdits().add(toTextEdit(it, document))); } if (ContentAssistEntry.KIND_SNIPPET.equals(entry.getKind())) { completionItem.setInsertTextFormat(InsertTextFormat.Snippet); } return completionItem; }
Example #27
Source File: JavaDocTypeReferenceProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testComputation_6() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append("* {@link }"); _builder.newLine(); _builder.append("* @see"); _builder.newLine(); _builder.append("* @see"); _builder.newLine(); _builder.append("* {@link}"); _builder.newLine(); _builder.append("*/"); _builder.newLine(); _builder.append("class Foo{}"); _builder.newLine(); final String input = _builder.toString(); Resource _eResource = this.clazz(input).eResource(); final XtextResource resource = ((XtextResource) _eResource); final ICompositeNode rootNode = resource.getParseResult().getRootNode(); final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode); Assert.assertEquals(0, regions.size()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #28
Source File: JavaDocTypeReferenceProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testComputation() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append("* {@link List}"); _builder.newLine(); _builder.append("* {@link String}"); _builder.newLine(); _builder.append("* {@link Integer"); _builder.newLine(); _builder.append("* {@link ArrayList}"); _builder.newLine(); _builder.append("*/"); _builder.newLine(); _builder.append("class Foo{}"); _builder.newLine(); final String input = _builder.toString(); Resource _eResource = this.clazz(input).eResource(); final XtextResource resource = ((XtextResource) _eResource); final ICompositeNode rootNode = resource.getParseResult().getRootNode(); final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode); Assert.assertEquals(3, regions.size()); Assert.assertEquals("List", IterableExtensions.<ReplaceRegion>head(regions).getText()); Assert.assertEquals(input.indexOf("List"), IterableExtensions.<ReplaceRegion>head(regions).getOffset()); Assert.assertEquals("List".length(), IterableExtensions.<ReplaceRegion>head(regions).getLength()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #29
Source File: PartialParserPerformanceSuite.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void processFile(String data) throws Exception { IParseResult parseResult = parser.parse(new StringReader(data)); for (int i = 0; i < data.length() - chars; i++) { parseResult = parser.reparse(parseResult, new ReplaceRegion(i, chars, "")); parseResult = parser.reparse(parseResult, new ReplaceRegion(i, 0, data.substring(i, i + chars))); } }
Example #30
Source File: ExtractMethodRefactoring.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected String getMethodBodyWithRenamedParameters(ITextRegion expressionsRegion) throws BadLocationException { String expressionsAsString = document.get(expressionsRegion.getOffset(), expressionsRegion.getLength()); List<ReplaceRegion> parameterRenames = newArrayList(); for(final String parameterName: externalFeatureCalls.keySet()) { ParameterInfo parameter = find(parameterInfos, new Predicate<ParameterInfo>() { @Override public boolean apply(ParameterInfo info) { return equal(info.getOldName(), parameterName); } }); if(parameter.isRenamed()) { for(XFeatureCall featureCall: externalFeatureCalls.get(parameterName)) { ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1); parameterRenames.add(new ReplaceRegion(textRegion, parameter.getNewName())); } } } sort(parameterRenames, new Comparator<ReplaceRegion>() { @Override public int compare(ReplaceRegion o1, ReplaceRegion o2) { return o2.getOffset() - o1.getOffset(); } }); StringBuffer buffer = new StringBuffer(expressionsAsString); for(ReplaceRegion parameterRename: parameterRenames) { buffer.replace(parameterRename.getOffset() - expressionsRegion.getOffset(), parameterRename.getEndOffset() - expressionsRegion.getOffset(), parameterRename.getText()); } expressionsAsString = buffer.toString(); return expressionsAsString; }