本文整理匯總了Java中org.eclipse.xtext.resource.XtextResource.getResourceSet方法的典型用法代碼示例。如果您正苦於以下問題:Java XtextResource.getResourceSet方法的具體用法?Java XtextResource.getResourceSet怎麽用?Java XtextResource.getResourceSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.xtext.resource.XtextResource
的用法示例。
在下文中一共展示了XtextResource.getResourceSet方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: collectTransitivelyDependentResources
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
private List<Resource> collectTransitivelyDependentResources(XtextResource resource,
Set<URI> deltaURIs) {
List<Resource> result = Lists.newArrayList();
ResourceSet resourceSet = resource.getResourceSet();
for (Resource candidate : resourceSet.getResources()) {
if (candidate != resource) {
URI uri = candidate.getURI();
if (deltaURIs.contains(uri)) {
// the candidate is contained in the delta list
// schedule it for unloading
result.add(candidate);
} else if (candidate instanceof N4JSResource) {
// the candidate does depend on one of the changed resources
// schedule it for unloading
if (canLoadFromDescriptionHelper.dependsOnAny(candidate, deltaURIs)) {
result.add(candidate);
}
}
}
}
return result;
}
示例2: getCompleteContent
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
public static String getCompleteContent(XtextResource xr) throws IOException, UnsupportedEncodingException {
XtextResourceSet resourceSet = (XtextResourceSet) xr.getResourceSet();
URIConverter uriConverter = resourceSet.getURIConverter();
URI uri = xr.getURI();
String encoding = xr.getEncoding();
InputStream inputStream = null;
try {
inputStream = uriConverter.createInputStream(uri);
return getCompleteContent(encoding, inputStream);
} finally {
tryClose(inputStream, null);
}
}
示例3: getTarget
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
private EObject getTarget(XtextResource resource, IHyperlink hyperlink) {
final ResourceSet resourceSet = resource != null ? resource.getResourceSet() : null;
final URI uri = hyperlink instanceof XtextHyperlink ? ((XtextHyperlink) hyperlink).getURI() : null;
final EObject target = resourceSet != null && uri != null ? resourceSet.getEObject(uri, true) : null;
if (target instanceof SyntaxRelatedTElement)
return ((SyntaxRelatedTElement) target).getAstElement();
return target;
}
示例4: setCrossResourceContainer
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
protected void setCrossResourceContainer(XtextResource resource) {
ResourceSet resourceSet = resource.getResourceSet();
Resource containerResource = resourceSet.createResource(URI.createFileURI("sample.xmi"));
CrossResourceContainerOneChild container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerOneChild();
containerResource.getContents().add(container);
assertEquals(1, resource.getContents().size());
container.setChild(resource.getContents().get(0));
}
示例5: setCrossResourceContainer
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
protected void setCrossResourceContainer(XtextResource resource) {
ResourceSet resourceSet = resource.getResourceSet();
Resource containerResource = resourceSet.createResource(URI.createFileURI("sample.xmi"));
CrossResourceContainerManyChildren container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerManyChildren();
containerResource.getContents().add(container);
container.getChildren().addAll(resource.getContents());
}
示例6: applyChange
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) {
XtextResource res = (XtextResource) lifecycleManager.openAndApplyReferences(getResourceSet(), getResource());
if (!referenceUpdater.isAffected(deltas, getResource())) {
return;
}
ITextRegionAccess base = textRegionBuilderProvider.get().forNodeModel(res).create();
ITextRegionDiffBuilder rewriter = new StringBasedTextRegionAccessDiffBuilder(base);
ReferenceUpdaterContext context = new ReferenceUpdaterContext(deltas, rewriter);
referenceUpdater.update(context);
if (!context.getModifications().isEmpty()) {
ChangeRecorder rec = new ChangeRecorder(res);
for (Runnable run : context.getModifications()) {
run.run();
}
ChangeDescription recording = rec.endRecording();
ResourceSet rs = res.getResourceSet();
ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, Collections.emptyList(), recording);
ResourceRecording recordedResource = tree.getRecordedResource(res);
serializer.serializeChanges(recordedResource, rewriter);
}
for (IUpdatableReference upd : context.getUpdatableReferences()) {
referenceUpdater.updateReference(rewriter, upd);
}
ITextRegionAccessDiff rewritten = rewriter.create();
List<ITextReplacement> rep = formatter.format(rewritten);
TextDocumentChange change = new TextDocumentChange(rewritten, getResource().getUri(), rep);
changeAcceptor.accept(change);
}
示例7: organizeImports
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/**
* Give the result as a multiline diff. If cancellation due to multiple possible resolution is expected, provide the
* expected Exception with 'XPECT organizeImports ambiguous "Exception-Message" -->'.
*
* If the parameter is not provided, always the first computed solution in the list will be taken
*
* @param ambiguous
* - String Expectation in {@link BreakException}
*/
@ParameterParser(syntax = "('ambiguous' arg0=STRING)?")
@Xpect
@ConsumedIssues({ Severity.INFO, Severity.ERROR, Severity.WARNING })
public void organizeImports(
String ambiguous, // arg0
@StringDiffExpectation(whitespaceSensitive = false, allowSingleSegmentDiff = false, allowSingleLineDiff = false) IStringDiffExpectation expectation,
@ThisResource XtextResource resource) throws Exception {
logger.info("organize imports ...");
boolean bAmbiguityCheck = ambiguous != null && ambiguous.trim().length() > 0;
Interaction iaMode = bAmbiguityCheck ? Interaction.breakBuild : Interaction.takeFirst;
try {
if (expectation == null /* || expectation.isEmpty() */) {
// TODO throw exception if empty.
// Hey, I want to ask the expectation if it's empty.
// Cannot access the region which could be asked for it's length.
throw new AssertionFailedError(
"The test is missing a diff: // XPECT organizeImports --> [old string replaced|new string expected] ");
}
// capture text for comparison:
String beforeApplication = resource.getParseResult().getRootNode().getText();
N4ContentAssistProcessorTestBuilder fixture = n4ContentAssistProcessorTestBuilderHelper
.createTestBuilderForResource(resource);
IXtextDocument xtextDoc = fixture.getDocument(resource, beforeApplication);
// in case of cross-file hyperlinks, we have to make sure the target resources are fully resolved
final ResourceSet resSet = resource.getResourceSet();
for (Resource currRes : new ArrayList<>(resSet.getResources())) {
N4JSResource.postProcess(currRes);
}
// Calling organize imports
Display.getDefault().syncExec(
() -> imortsOrganizer.unsafeOrganizeDocument(xtextDoc, iaMode));
if (bAmbiguityCheck) {
// should fail if here
assertEquals("Expected ambiguous resolution to break the organize import command.", ambiguous, "");
}
// checking that no errors are left.
String textAfterApplication = xtextDoc.get();
// compare with expectation, it's a multiline-diff expectation.
String before = XpectCommentRemovalUtil.removeAllXpectComments(beforeApplication);
String after = XpectCommentRemovalUtil.removeAllXpectComments(textAfterApplication);
expectation.assertDiffEquals(before, after);
} catch (Exception exc) {
if (exc instanceof RuntimeException && exc.getCause() instanceof BreakException) {
String breakMessage = exc.getCause().getMessage();
assertEquals(ambiguous, breakMessage);
} else {
throw exc;
}
}
}