本文整理匯總了Java中org.eclipse.xtext.resource.XtextResource.setURI方法的典型用法代碼示例。如果您正苦於以下問題:Java XtextResource.setURI方法的具體用法?Java XtextResource.setURI怎麽用?Java XtextResource.setURI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.xtext.resource.XtextResource
的用法示例。
在下文中一共展示了XtextResource.setURI方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testResourcesAreInMap_03
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreInMap_03() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
EList<Resource> _resources = rs.getResources();
_resources.add(resource);
Assert.assertEquals(1, rs.getURIResourceMap().size());
Assert.assertEquals(resource, rs.getURIResourceMap().get(null));
resource.setURI(URI.createFileURI(new File("foo").getAbsolutePath()));
Assert.assertEquals(1, rs.getURIResourceMap().size());
Assert.assertFalse(rs.getURIResourceMap().containsKey(null));
Assert.assertEquals(resource, rs.getURIResourceMap().get(resource.getURI()));
Assert.assertEquals(resource, rs.getURIResourceMap().get(rs.getURIConverter().normalize(resource.getURI())));
resource.setURI(URI.createFileURI(new File("bar").getAbsolutePath()));
Assert.assertEquals(1, rs.getURIResourceMap().size());
Assert.assertFalse(rs.getURIResourceMap().containsKey(null));
Assert.assertEquals(resource, rs.getURIResourceMap().get(resource.getURI()));
Assert.assertEquals(resource, rs.getURIResourceMap().get(rs.getURIConverter().normalize(resource.getURI())));
resource.setURI(null);
Assert.assertEquals(1, rs.getURIResourceMap().size());
Assert.assertEquals(resource, rs.getURIResourceMap().get(null));
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例2: getNewResource
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
private XtextResource getNewResource(String content, URI uri) {
IParseResult parseResult = parser.parse(new StringReader(content));
ResourceSet resourceSet2 = resourceSetProvider.get();
XtextResource newXtextResource = resourceProvider.get();
newXtextResource.setURI(uri);
resourceSet2.getResources().add(newXtextResource);
newXtextResource.setParseResult(parseResult);
return newXtextResource;
}
示例3: prettyPrint
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/**
* @since 2.7
*/
protected void prettyPrint(String absoluteGrammarFileName, Charset encoding) {
try {
String content = readFileIntoString(absoluteGrammarFileName, encoding);
final ILineSeparatorInformation lineSeparatorInformation = new ILineSeparatorInformation() {
@Override
public String getLineSeparator() {
return DebugAntlrGeneratorFragment.this.getLineDelimiter();
}
};
Injector injector = new SimpleAntlrStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(new SimpleAntlrRuntimeModule() {
@Override
public void configure(Binder binder) {
super.configure(binder);
binder.bind(ILineSeparatorInformation.class).toInstance(lineSeparatorInformation);
}
});
}
}.createInjectorAndDoEMFRegistration();
XtextResource resource = injector.getInstance(XtextResource.class);
resource.setURI(URI.createFileURI(absoluteGrammarFileName));
resource.load(new StringInputStream(content, encoding.name()),
Collections.singletonMap(XtextResource.OPTION_ENCODING, encoding.name()));
if (!resource.getErrors().isEmpty()) {
String errors = Joiner.on(getLineDelimiter()).join(resource.getErrors());
throw new GeneratorWarning("Non fatal problem: Debug grammar could not be formatted due to:" + getLineDelimiter() + errors);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(content.length());
resource.save(outputStream, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
String toBeWritten = new NewlineNormalizer(getLineDelimiter()).normalizeLineDelimiters(
new String(outputStream.toByteArray(), encoding.name()));
writeStringIntoFile(absoluteGrammarFileName, toBeWritten, encoding);
} catch(IOException e) {
throw new GeneratorWarning(e.getMessage());
}
}
示例4: setUp
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public void setUp() throws Exception {
super.setUp();
factory = new ResourceFactoryImpl(){
@Override
public Resource createResource(URI uri) {
XtextResource resource = new XtextResource();
injectMembers(resource);
resource.setLinker(get(Linker.class));
resource.setURI(uri);
return resource;
}
};
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug287988testlanguage", factory);
}
示例5: getModel
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
public Grammar getModel(final String model, final boolean dropUnreachable) throws Exception {
EObject _model = super.getModel(model);
Grammar grammar = ((Grammar) _model);
RuleNames ruleNames = RuleNames.getRuleNames(grammar, false);
RuleFilter filter = new RuleFilter();
filter.setDiscardUnreachableRules(dropUnreachable);
Grammar result = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar();
XtextResource resource = this.<XtextResource>get(XtextResource.class);
resource.getContents().add(result);
resource.setURI(URI.createURI("synthetic://flattened.xtext"));
return result;
}
示例6: testResourcesAreInMap
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreInMap() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createFileURI(new File("foo").getAbsolutePath()));
EList<Resource> _resources = rs.getResources();
_resources.add(resource);
Assert.assertEquals(1, rs.getURIResourceMap().size());
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例7: testResourcesAreInMap_02
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreInMap_02() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createFileURI(new File("foo").getAbsolutePath()));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(1, rs.getURIResourceMap().size());
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例8: testResourcesAreCleared_01
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreCleared_01() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createFileURI(new File("foo").getAbsolutePath()));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(1, rs.getURIResourceMap().size());
rs.getResources().clear();
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例9: testResourcesAreClearedWithDeliverFalse_01
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreClearedWithDeliverFalse_01() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createFileURI(new File("foo").getAbsolutePath()));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(1, rs.getURIResourceMap().size());
rs.eSetDeliver(false);
rs.getResources().clear();
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例10: testResourcesAreInMapWithNormalizedURI_01
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreInMapWithNormalizedURI_01() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createURI("/a/../foo"));
EList<Resource> _resources = rs.getResources();
_resources.add(resource);
Assert.assertEquals(2, rs.getURIResourceMap().size());
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例11: testResourcesAreInMapWithNormalizedURI_02
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreInMapWithNormalizedURI_02() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createURI("/a/../foo"));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(2, rs.getURIResourceMap().size());
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例12: testResourcesAreInMapWithNormalizedURI_03
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreInMapWithNormalizedURI_03() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
EList<Resource> _resources = rs.getResources();
_resources.add(resource);
Assert.assertEquals(1, rs.getURIResourceMap().size());
Assert.assertEquals(resource, rs.getURIResourceMap().get(null));
Assert.assertEquals(0, rs.getNormalizationMap().size());
resource.setURI(URI.createURI("/a/../foo"));
Assert.assertEquals(2, rs.getURIResourceMap().size());
Assert.assertFalse(rs.getURIResourceMap().containsKey(null));
Assert.assertEquals(resource, rs.getURIResourceMap().get(resource.getURI()));
Assert.assertEquals(resource, rs.getURIResourceMap().get(rs.getURIConverter().normalize(resource.getURI())));
Assert.assertEquals(1, rs.getNormalizationMap().size());
Assert.assertEquals(rs.getURIConverter().normalize(resource.getURI()), rs.getNormalizationMap().get(resource.getURI()));
resource.setURI(URI.createURI("/a/../bar"));
Assert.assertEquals(2, rs.getURIResourceMap().size());
Assert.assertFalse(rs.getURIResourceMap().containsKey(null));
Assert.assertEquals(resource, rs.getURIResourceMap().get(resource.getURI()));
Assert.assertEquals(resource, rs.getURIResourceMap().get(rs.getURIConverter().normalize(resource.getURI())));
Assert.assertEquals(1, rs.getNormalizationMap().size());
Assert.assertEquals(rs.getURIConverter().normalize(resource.getURI()), rs.getNormalizationMap().get(resource.getURI()));
resource.setURI(null);
Assert.assertEquals(1, rs.getURIResourceMap().size());
Assert.assertEquals(resource, rs.getURIResourceMap().get(null));
Assert.assertEquals(0, rs.getNormalizationMap().size());
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
Assert.assertEquals(0, rs.getNormalizationMap().size());
}
示例13: testResourcesAreClearedWithNormalizedURI_01
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreClearedWithNormalizedURI_01() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createURI("/a/../foo"));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(2, rs.getURIResourceMap().size());
rs.getResources().clear();
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
示例14: testResourcesAreClearedWithDeliverFalseWithNormalizedURI_01
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Test
public void testResourcesAreClearedWithDeliverFalseWithNormalizedURI_01() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createURI("//a/../foo"));
EList<Resource> _resources = rs.getResources();
ArrayList<Resource> _newArrayList = CollectionLiterals.<Resource>newArrayList(resource);
Iterables.<Resource>addAll(_resources, _newArrayList);
Assert.assertEquals(2, rs.getURIResourceMap().size());
rs.eSetDeliver(false);
rs.getResources().clear();
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}