本文整理匯總了Java中org.eclipse.xtext.resource.XtextResource類的典型用法代碼示例。如果您正苦於以下問題:Java XtextResource類的具體用法?Java XtextResource怎麽用?Java XtextResource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XtextResource類屬於org.eclipse.xtext.resource包,在下文中一共展示了XtextResource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: elementKeyword
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
/**
* Test the element keyword of an element. Examples of element keyword are getter, setter, field etc.
*/
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
@Xpect
public void elementKeyword(
@StringExpectation IStringExpectation expectation,
IEObjectCoveringRegion offset) {
EObject context = offset.getEObject();
// Identical behavior as in hover in the IDE! See class N4JSHoverProvider
// Get the cross-referenced element at the offset.
EObject element = offsetHelper
.resolveCrossReferencedElementAt((XtextResource) context.eResource(), offset.getOffset());
// If not a cross-reference element, use context instead
if (element == null)
element = context;
String actual = calculateElementKeyword(element);
expectation.assertEquals(actual);
}
示例2: quickFixList
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
/**
* Example: {@code // XPECT quickFixList at 'a.<|>method' --> 'import A','do other things' }
*
* @param expectation
* comma separated strings, which are proposed as quick fix
* @param resource
* injected xtext-file
* @param offset
* cursor position at '<|>'
* @param checkType
* 'display': verify list of provided proposals comparing their user-displayed strings.
* @param selected
* which proposal to pick
* @param mode
* modus of operation
* @param offset2issue
* mapping of offset(!) to issues.
* @throws Exception
* if failing
*/
@Xpect
@ParameterParser(syntax = "('at' (arg2=STRING (arg3=ID (arg4=STRING)? (arg5=ID)? )? )? )?")
@ConsumedIssues({ Severity.INFO, Severity.ERROR, Severity.WARNING })
public void quickFixList(
@CommaSeparatedValuesExpectation(quoted = true, ordered = true) ICommaSeparatedValuesExpectation expectation, // arg0
@ThisResource XtextResource resource, // arg1
RegionWithCursor offset, // arg2
String checkType, // arg3
String selected, // arg4
String mode, // arg5
@IssuesByLine Multimap<Integer, Issue> offset2issue) throws Exception {
List<IssueResolution> resolutions = collectAllResolutions(resource, offset, offset2issue);
List<String> resolutionNames = Lists.newArrayList();
for (IssueResolution resolution : resolutions) {
resolutionNames.add(resolution.getLabel());
}
expectation.assertEquals(resolutionNames);
}
示例3: collectAllResolutions
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
/**
* CollectAll resolutions under the cursor at offset.
*
*/
List<IssueResolution> collectAllResolutions(XtextResource resource, RegionWithCursor offset,
Multimap<Integer, Issue> offset2issue) {
EObject script = resource.getContents().get(0);
ICompositeNode scriptNode = NodeModelUtils.getNode(script);
ILeafNode offsetNode = NodeModelUtils.findLeafNodeAtOffset(scriptNode, offset.getGlobalCursorOffset());
int offStartLine = offsetNode.getTotalStartLine();
List<Issue> allIssues = QuickFixTestHelper.extractAllIssuesInLine(offStartLine, offset2issue);
List<IssueResolution> resolutions = Lists.newArrayList();
for (Issue issue : allIssues) {
if (issue.getLineNumber() == offsetNode.getStartLine()
&& issue.getLineNumber() <= offsetNode.getEndLine()) {
Display.getDefault().syncExec(() -> resolutions.addAll(quickfixProvider.getResolutions(issue)));
}
}
return resolutions;
}
示例4: cleanXtextResource
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
/**
* Remove OutdatedStateAdapter from provided{@link XtextResource} and return it.
*
* @return {@link XtextResource}
*/
public static XtextResource cleanXtextResource(XtextResource xtextResource) {
// Since here we are reusing the same xtextresource and not reparsing the stream,
// we must take care that stale Xtext-documents associated with this resource do not effect us.
// An assertion looks for org.eclipse.xtext.ui.editor.model.XtextDocument.OutdatedStateAdapter
// in org.eclipse.xtext.ui.editor.model.XtextDocument.setInput(XtextResource)
// To reuse the resource we remove it here:
// Adapter toBeRemoved = null;
// for (Adapter a : xtextResource.eAdapters()) {
// if (a instanceof OutdatedStateAdapter)
// toBeRemoved = a;
// }
// if (toBeRemoved != null)
// xtextResource.eAdapters().remove(toBeRemoved);
return xtextResource;
}
示例5: readOnly
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
/***
* This method modifies the super method to handle NullPointerException when state is null.
*/
@Override
public <R> R readOnly(final URI targetURI, final IUnitOfWork<R, ResourceSet> work) {
IXtextDocument document = openDocumentTracker.getOpenDocument(targetURI.trimFragment());
if (document != null) {
return document.readOnly(new IUnitOfWork<R, XtextResource>() {
@Override
public R exec(XtextResource state) throws Exception {
// For some reason, sometimes state can be null at this point,
// The resource set must be retrieved by other means in delegate.readOnly
if (state == null) {
return delegate.readOnly(targetURI, work);
}
ResourceSet localContext = state.getResourceSet();
if (localContext != null)
return work.exec(localContext);
return null;
}
});
} else
{
return delegate.readOnly(targetURI, work);
}
}
示例6: 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;
}
示例7: apply
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
@Override
public final void apply(IModificationContext context) throws Exception {
context.getXtextDocument().modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
final IMarker marker = issue instanceof N4JSIssue ? ((N4JSIssue) issue).getMarker() : null;
final EObject element = resource.getEObject(issue.getUriToProblem().fragment());
final Collection<? extends IChange> changes = modification.computeChanges(
context,
marker,
issue.getOffset(),
issue.getLength(),
element);
modification.computeFinalChanges();
changeManager.applyAll(changes);
}
});
}
示例8: buildMap
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
@Override
protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) {
IDefaultResourceDescriptionStrategy strategy = ((XtextResource) resource).getResourceServiceProvider()
.get(IDefaultResourceDescriptionStrategy.class);
TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(resource, false);
IAcceptor<IEObjectDescription> acceptor = new IAcceptor<IEObjectDescription>() {
@Override
public void accept(IEObjectDescription description) {
elements.put(description.getQualifiedName(), description);
}
};
while (allProperContents.hasNext()) {
EObject content = allProperContents.next();
if (!strategy.createEObjectDescriptions(content, acceptor)) {
allProperContents.prune();
}
}
}
示例9: getLaunchConfigFromEditor
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
protected LaunchConfig getLaunchConfigFromEditor(ExecutionEvent event) {
XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event);
if (activeXtextEditor == null) {
return null;
}
final ITextSelection selection = (ITextSelection) activeXtextEditor.getSelectionProvider().getSelection();
return activeXtextEditor.getDocument().priorityReadOnly(new IUnitOfWork<LaunchConfig, XtextResource>() {
@Override
public LaunchConfig exec(XtextResource xTextResource) throws Exception {
EObject lc = eObjectAtOffsetHelper.resolveContainedElementAt(xTextResource, selection.getOffset());
return findParentLaunchConfig(lc);
}
});
}
示例10: loadGexpressionTestFile
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
public static void loadGexpressionTestFile() {
// Getting the serializer
GExpressionsStandaloneSetup setup = new GExpressionsStandaloneSetup();
Injector injector = setup.createInjectorAndDoEMFRegistration();
GexpressionsPackage.eINSTANCE.eClass();
Serializer serializer = injector.getInstance(Serializer.class);
// Load the model
URI modelURI = URI
.createFileURI("/home/flatombe/thesis/gemoc/git/gemoc-dev/org/eclipse/gemoc/GEL/org.eclipse.gemoc.gel.gexpressions.test/model/test.gexpressions");
XtextResourceSet resSet = injector.getInstance(XtextResourceSet.class);
resSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resSet.getResource(modelURI, true);
GProgram program = (GProgram) resource.getContents().get(0);
List<GExpression> exps = program.getExpressions();
for (GExpression exp : exps) {
// Serializing
String s = serializer.serialize(exp);
System.out.println(s);
}
}
示例11: provideHighlightingFor
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
@Override
public void provideHighlightingFor(XtextResource resource,
org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor acceptor) {
TreeIterator<EObject> allContents = resource.getAllContents();
while (allContents.hasNext()) {
EObject next = allContents.next();
if (next.eIsProxy()) {
continue;
}
if (next instanceof ElementReferenceExpression) {
if (next instanceof ElementReferenceExpression) {
ElementReferenceExpression expression = (ElementReferenceExpression) next;
provideHighligtingFor(expression, acceptor);
}
}
}
}
示例12: format
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
public void format(final Object restaurante, final IFormattableDocument document) {
if (restaurante instanceof XtextResource) {
_format((XtextResource)restaurante, document);
return;
} else if (restaurante instanceof Restaurante) {
_format((Restaurante)restaurante, document);
return;
} else if (restaurante instanceof EObject) {
_format((EObject)restaurante, document);
return;
} else if (restaurante == null) {
_format((Void)null, document);
return;
} else if (restaurante != null) {
_format(restaurante, document);
return;
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(restaurante, document).toString());
}
}
示例13: isDocumentHighlightAvailableFor
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
/**
* Returns with {@code true} if the AST element selected from the resource
* can provide document highlights, otherwise returns with {@code false}.
*
* <p>
* Clients may override this method to change the default behavior.
*
* @param selectedElemnt
* the selected element resolved via the offset from the
* resource. Can be {@code null}.
* @param resource
* the resource for the document.
* @param offset
* the offset of the selection.
*
* @return {@code true} if the document highlight is available for the
* selected element, otherwise {@code false}.
*
*/
protected boolean isDocumentHighlightAvailableFor(final EObject selectedElemnt, final XtextResource resource,
final int offset) {
if (selectedElemnt == null || !getSelectedElementFilter().apply(selectedElemnt)) {
return false;
}
final EObject containedElement = offsetHelper.resolveContainedElementAt(resource, offset);
// Special handling to avoid such cases when the selection is not
// exactly on the desired element.
if (selectedElemnt == containedElement) {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(containedElement);
return !isNullOrEmpty(region)
// Region is comparable to a selection in an editor,
// therefore the end position is exclusive.
&& (region.contains(offset) || (region.getOffset() + region.getLength()) == offset);
}
return true;
}
示例14: doValidation
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
protected void doValidation() {
if (allErrorsAndWarnings == null) {
doLinking();
allErrorsAndWarnings = newArrayList();
// validation
for (Resource resource : sources) {
if (resource instanceof XtextResource) {
XtextResource xtextResource = (XtextResource) resource;
List<Issue> issues = xtextResource.getResourceServiceProvider().getResourceValidator().validate(xtextResource, checkMode, CancelIndicator.NullImpl);
for (Issue issue : issues) {
allErrorsAndWarnings.add(issue);
}
}
}
}
}
示例15: compareWithFullParse
import org.eclipse.xtext.resource.XtextResource; //導入依賴的package包/類
protected void compareWithFullParse(String model, int offset, int length, String newText) throws Exception {
XtextResource resource = getResourceFromStringAndExpect(model, UNKNOWN_EXPECTATION);
resource.update(offset, length, newText);
String text = resource.getParseResult().getRootNode().getText();
XtextResource newResource = getResourceFromStringAndExpect(text, UNKNOWN_EXPECTATION);
assertEquals(text, resource.getContents().size(), newResource.getContents().size());
EcoreUtil.resolveAll(resource);
EcoreUtil.resolveAll(newResource);
for(int i = 0; i < resource.getContents().size(); i++) {
assertEquals(text, EmfFormatter.objToStr(newResource.getContents().get(i)), EmfFormatter.objToStr(resource.getContents().get(i)));
}
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ICompositeNode newRootNode = newResource.getParseResult().getRootNode();
Iterator<INode> iterator = rootNode.getAsTreeIterable().iterator();
Iterator<INode> newIterator = newRootNode.getAsTreeIterable().iterator();
while(iterator.hasNext()) {
assertTrue(newIterator.hasNext());
assertEqualNodes(text, iterator.next(), newIterator.next());
}
assertFalse(iterator.hasNext());
assertFalse(newIterator.hasNext());
}