项目:n4js
文件:BuilderUtil.java
/***/
public static Set<IReferenceDescription> getIncomingReferences(URI uri) {
Set<IReferenceDescription> desc = Sets.newHashSet();
Iterable<IResourceDescription> descriptions = getAllResourceDescriptions();
for (IResourceDescription res : descriptions) {
Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
for (IReferenceDescription ref : descriptions2) {
if (uri.hasFragment()) {
if (ref.getTargetEObjectUri().equals(uri))
desc.add(ref);
} else {
if (ref.getTargetEObjectUri().trimFragment().equals(uri.trimFragment()))
desc.add(ref);
}
}
}
return desc;
}
项目:n4js
文件:BuilderUtil.java
/***/
public static Set<IReferenceDescription> getContainedReferences(URI uri) {
Set<IReferenceDescription> desc = Sets.newHashSet();
Iterable<IResourceDescription> descriptions = getAllResourceDescriptions();
for (IResourceDescription res : descriptions) {
Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
for (IReferenceDescription ref : descriptions2) {
if (uri.hasFragment()) {
if (ref.getSourceEObjectUri().equals(uri))
desc.add(ref);
} else {
if (ref.getSourceEObjectUri().trimFragment().equals(uri.trimFragment()))
desc.add(ref);
}
}
}
return desc;
}
项目:n4js
文件:N4HeadlessCompiler.java
/**
* Install the given resource's description into the given index. Raw JavaScript files will not be indexed. Note
* that when this method is called for the given resource,it is not yet fully processed and therefore the
* serialized type model is not added to the index.
* <p>
* This is due to the fact that we keep a common resource set for all projects that contains the resources of all
* projects with unprocessed dependencies,unlike in the IDE case where we have one resource set per open document
* and load the type models from the index.
* </p>
* <p>
* Since the type models are available in the resource set as long as they may still be referenced,they need not be
* serialized and stored into the index.
* </p>
*
* @param resource
* the resource to be indexed
* @param index
* the index to add the given resource to
*/
private void indexResource(Resource resource,ResourceDescriptionsData index) {
if (!shouldindexResource(resource))
return;
final URI uri = resource.getURI();
IResourceServiceProvider serviceProvider = IResourceServiceProvider.Registry.INSTANCE
.getResourceServiceProvider(uri);
if (serviceProvider != null) {
if (logger.isCreateDebugOutput()) {
logger.debug(" Indexing resource " + uri);
}
IResourceDescription.Manager resourceDescriptionManager = serviceProvider.getResourceDescriptionManager();
IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource);
if (resourceDescription != null) {
index.addDescription(uri,resourceDescription);
}
}
}
项目:n4js
文件:N4JSDirtyStateEditorSupport.java
private boolean isSignificantChange(IResourceDescription.Delta delta) {
if (delta.haveEObjectDescriptionsChanged()) {
IResourceDescription newDescription = delta.getNew();
IResourceDescription oldDescription = delta.getold();
if ((newDescription != null) != (oldDescription != null)) {
return true;
}
if (newDescription == null || oldDescription == null) {
throw new IllegalStateException();
}
List<IEObjectDescription> newDescriptions = Lists.newArrayList(newDescription.getExportedobjects());
List<IEObjectDescription> oldDescriptions = Lists.newArrayList(oldDescription.getExportedobjects());
if (newDescriptions.size() != oldDescriptions.size()) {
return true;
}
URI resourceURI = delta.getUri();
for (int i = 0; i < newDescriptions.size(); i++) {
if (!equalDescriptions(newDescriptions.get(i),oldDescriptions.get(i),resourceURI)) {
return true;
}
}
}
return false;
}
private IResourceDescription extractOldDescription(final IDirtyResource dirtyResource) {
IDirtyResource myDirtyResource = reflectiveGetInnerResource(dirtyResource);
if (myDirtyResource instanceof PrevstateAwareDocumentBasedDirtyResource) {
return ((PrevstateAwareDocumentBasedDirtyResource) myDirtyResource).getPrevDescription();
}
return null;
}
项目:n4js
文件:N4JSResourceDescriptionManager.java
/**
* {@inheritDoc}
*
* This marks {@code n4js} as affected if the manifest of the project changes. In turn,they will be revalidated and
* taken into consideration for the code generation step.
*/
@Override
public boolean isAffected(Collection<IResourceDescription.Delta> deltas,IResourceDescription candidate,IResourceDescriptions context) {
boolean result = basicIsAffected(deltas,candidate);
if (!result) {
for (IResourceDescription.Delta delta : deltas) {
URI uri = delta.getUri();
if (IN4JSProject.N4MF_MANIFEST.equalsIgnoreCase(uri.lastSegment())) {
URI prefixURI = uri.trimsegments(1).appendSegment("");
if (candidate.getURI().replacePrefix(prefixURI,prefixURI) != null) {
return true;
}
}
}
}
return result;
}
项目:n4js
文件:OrderedResourceDescriptionsData.java
@SuppressWarnings("unchecked")
@Override
protected void registerDescription(final IResourceDescription description,final Map<Qualifiedname,Object> target) {
for (final IEObjectDescription object : description.getExportedobjects()) {
final Qualifiedname lowerCase = object.getName().toLowerCase();
final Object existing = target.put(lowerCase,description);
if (existing != null && existing != description) {
Set<IResourceDescription> set = null;
if (existing instanceof IResourceDescription) {
// The linked hash set is the difference comparing to the super class.
set = Sets.newLinkedHashSetWithExpectedSize(2);
set.add((IResourceDescription) existing);
} else {
set = (Set<IResourceDescription>) existing;
}
set.add(description);
target.put(lowerCase,set);
}
}
}
@Override
public void build(IBuildContext context,IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor);
if (!prefs.isCompilerEnabled()) {
return;
}
final List<IResourceDescription.Delta> deltas = getRelevantDeltas(context);
if (deltas.isEmpty()) {
return;
}
if (progress.isCanceled()) {
throw new OperationCanceledException();
}
progress.beginTask("Compiling solidity...",deltas.size());
List<URI> uris = deltas.stream().map(delta -> delta.getUri()).collect(Collectors.toList());
compiler.compile(uris,progress);
context.getBuiltProject().refreshLocal(IProject.DEPTH_INFINITE,progress);
progress.done();
}
项目:xtext-extras
文件:ResourceDescriptionProviderTest.java
@Test
public void testStubGeneration_02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public interface MyTest {");
_builder.newLine();
_builder.append("\t");
_builder.append("public String helloWorld();");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
Assert.assertEquals("MyTest",IterableExtensions.<IEObjectDescription>head(it.getExportedobjects()).getQualifiedname().toString());
EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedobjects()).getEObjectOrProxy();
Assert.assertTrue(((JvmGenericType) _eObjectOrProxy).isInterface());
Assert.assertEquals(1,IterableExtensions.size(it.getExportedobjects()));
};
this.resultsIn(_builder,_function);
}
项目:xtext-extras
文件:ResourceDescriptionProviderTest.java
@Test
public void testStubGeneration_04() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public @interface MyTest {");
_builder.newLine();
_builder.append("\t");
_builder.append("String value();");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
Assert.assertEquals("MyTest",IterableExtensions.<IEObjectDescription>head(it.getExportedobjects()).getQualifiedname().toString());
EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedobjects()).getEObjectOrProxy();
Assert.assertTrue((_eObjectOrProxy instanceof JvmAnnotationType));
Assert.assertEquals(1,_function);
}
项目:xtext-extras
文件:ResourceDescriptionProviderTest.java
@Test
public void testStubGeneration_05() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package my.pack;");
_builder.newLine();
_builder.newLine();
_builder.append("public abstract class MyTest {");
_builder.newLine();
_builder.append("\t");
_builder.append("abstract String value();");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
Assert.assertEquals("my.pack.MyTest",IterableExtensions.<IEObjectDescription>head(it.getExportedobjects()).getQualifiedname().toString());
Assert.assertEquals(1,_function);
}
项目:xtext-core
文件:WorkspaceSymbolService.java
public List<? extends Symbolinformation> getSymbols(final String query,final IReferenceFinder.IResourceAccess resourceAccess,final IResourceDescriptions indexData,final CancelIndicator cancelIndicator) {
final LinkedList<Symbolinformation> result = CollectionLiterals.<Symbolinformation>newLinkedList();
Iterable<IResourceDescription> _allResourceDescriptions = indexData.getAllResourceDescriptions();
for (final IResourceDescription resourceDescription : _allResourceDescriptions) {
{
this.operationCanceledManager.checkCanceled(cancelIndicator);
final IResourceServiceProvider resourceServiceProvider = this._registry.getResourceServiceProvider(resourceDescription.getURI());
DocumentSymbolService _get = null;
if (resourceServiceProvider!=null) {
_get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class);
}
final DocumentSymbolService documentSymbolService = _get;
if ((documentSymbolService != null)) {
List<? extends Symbolinformation> _symbols = documentSymbolService.getSymbols(resourceDescription,query,resourceAccess,cancelIndicator);
Iterables.<Symbolinformation>addAll(result,_symbols);
}
}
}
return result;
}
项目:xtext-extras
文件:XbaseResourceDescriptionStrategyTest.java
@Test
public void testnoreferenceDescriptionsForPackageFragments() {
try {
final XExpression expression = this.expression("java::lang::String::valueOf(\"\")");
final Resource resource = expression.eResource();
final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(resource);
final Function1<IReferenceDescription,String> _function = (IReferenceDescription it) -> {
return it.getTargetEObjectUri().toString();
};
final Set<String> referenceDescriptions = IterableExtensions.<String>toSet(IterableExtensions.<IReferenceDescription,String>map(description.getReferenceDescriptions(),_function));
Assert.assertEquals(2,referenceDescriptions.size());
final Set<String> expectation = Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("java:/Objects/java.lang.String#java.lang.String","java:/Objects/java.lang.String#java.lang.String.valueOf(java.lang.Object)"));
Assert.assertEquals(expectation,referenceDescriptions);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
项目:xtext-extras
文件:EObjectDescriptionBasedStubGenerator.java
public String getJavaStubSource(IEObjectDescription description,IResourceDescription resourceDescription) {
if(isnestedType(description) || !isJvmDeclaredType(description)) {
return null;
}
Multimap<Qualifiedname,IEObjectDescription> owner2nested = LinkedHashMultimap.create();
for(IEObjectDescription other: resourceDescription.getExportedobjects()) {
if(isJvmDeclaredType(other) && isnestedType(other))
owner2nested.put(getownerClassName(other.getQualifiedname()),other);
}
StringBuilder classSignatureBuilder = new StringBuilder();
Qualifiedname qualifiedname = description.getQualifiedname();
if (qualifiedname.getSegments().size() > 1) {
String string = qualifiedname.toString();
classSignatureBuilder.append("package " + string.substring(0,string.lastIndexOf('.')) + ";");
}
appendType(description,owner2nested,classSignatureBuilder);
return classSignatureBuilder.toString();
}
项目:xtext-core
文件:AbstractLiveContainerTest.java
@Test
public void testContainerAddRemove() throws Exception {
ResourceSet resourceSet = new XtextResourceSet();
Resource res = parse("local",resourceSet).eResource();
parse("other",resourceSet);
IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
IResourceDescriptions resourceDescriptions = descriptionsprovider.getResourceDescriptions(res);
List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription,resourceDescriptions);
assertEquals(1,containers.size());
IContainer container = containers.get(0);
assertEquals("local,other",format(container.getExportedobjects()));
Resource foo = parse("foo",resourceSet).eResource();
assertEquals("foo,local,format(container.getExportedobjects()));
resourceSet.getResources().remove(foo);
assertEquals("local,format(container.getExportedobjects()));
}
项目:xtext-extras
文件:EcoreResourceDescriptionManagerTest.java
@Test public void testPerformance() throws Exception {
GenericResourceDescriptionManager manager = getEmfResourceDescriptionsManager();
Collection<String> uris = ImmutableList.copyOf(EPackage.Registry.INSTANCE.keySet());
for(String uri: uris) {
EPackage pack = EPackage.Registry.INSTANCE.getEPackage(uri);
IResourceDescription description = manager.getResourceDescription(pack.eResource());
assertNotNull(description);
for(int i = 0; i < 10; i++) {
Iterator<EObject> iter = EcoreUtil.getAllProperContents(pack,true);
while(iter.hasNext()) {
EObject next = iter.next();
if (next instanceof ENamedElement) {
String name = ((ENamedElement) next).getName();
// Iterable<IEObjectDescription> objects =
description.getExportedobjects(EcorePackage.Literals.EOBJECT,Qualifiedname.create(name),false);
// assertFalse(name + " - " + uri + " - " + next,Iterables.isEmpty(objects));
}
}
}
}
}
项目:xtext-core
文件:StateBasedContainerManager.java
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc,IResourceDescriptions resourceDescriptions) {
if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
return delegate.getVisibleContainers(desc,resourceDescriptions);
}
String root = internalGetContainerHandle(desc,resourceDescriptions);
if (root == null) {
if (log.isDebugEnabled())
log.debug("Cannot find IContainer for: " + desc.getURI());
return Collections.emptyList();
}
List<String> handles = getState(resourceDescriptions).getVisibleContainerHandles(root);
List<IContainer> result = getVisibleContainers(handles,resourceDescriptions);
if (!result.isEmpty()) {
IContainer first = result.get(0);
if (!first.hasResourceDescription(desc.getURI())) {
first = new DescriptionAddingContainer(desc,first);
result.set(0,first);
}
}
return result;
}
项目:dsl-devkit
文件:AbstractUtilTest.java
/**
* Prepare mocks for all tests.
*/
public static void prepareMocksBase() {
oldDesc = mock(IResourceDescription.class);
newDesc = mock(IResourceDescription.class);
delta = mock(Delta.class);
resource = mock(Resource.class);
uriCorrect = mock(URI.class);
when(uriCorrect.isPlatformResource()).thenReturn(true);
when(uriCorrect.isFile()).thenReturn(true);
when(uriCorrect.toFileString()).thenReturn(DUMMY_PATH);
when(uriCorrect.toPlatformString(true)).thenReturn(DUMMY_PATH);
when(delta.getNew()).thenReturn(newDesc);
when(delta.getold()).thenReturn(oldDesc);
when(delta.getUri()).thenReturn(uriCorrect);
when(resource.getURI()).thenReturn(uriCorrect);
file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uriCorrect.toPlatformString(true)));
Iterable<Pair<IStorage,IProject>> storages = singleton(Tuples.<IStorage,IProject> create(file,file.getProject()));
mapperCorrect = mock(Storage2UriMapperImpl.class);
when(mapperCorrect.getStorages(uriCorrect)).thenReturn(storages);
}
项目:xtext-core
文件:ResourceDescriptionsData.java
@Override
public Iterable<IEObjectDescription> getExportedobjects(final EClass type,final Qualifiedname qualifiedname,final boolean ignoreCase) {
Object existing = lookupMap.get(qualifiedname.toLowerCase());
if (existing instanceof IResourceDescription) {
return ((IResourceDescription) existing).getExportedobjects(type,qualifiedname,ignoreCase);
} else if (existing instanceof Set<?>) {
@SuppressWarnings("unchecked")
Set<IResourceDescription> casted = (Set<IResourceDescription>) existing;
return Iterables.concat(Iterables.transform(casted,new Function<IResourceDescription,Iterable<IEObjectDescription>>() {
@Override
public Iterable<IEObjectDescription> apply(IResourceDescription from) {
if (from != null) {
return from.getExportedobjects(type,ignoreCase);
}
return Collections.emptyList();
}
}));
}
return Collections.emptyList();
}
项目:dsl-devkit
文件:ResourceDescriptionDeltaTest.java
@Test
public void testOldReconstruction() {
IResourceDescription oldRes = createDescription("a");
IResourceDescription newRes = createDescription("a","b");
ResourceDescriptionDelta delta = new ResourceDescriptionDelta(oldRes,createDescription("a"),null);
assertFalse(delta.haveEObjectDescriptionsChanged());
assertSame(delta.getNew(),delta.getold());
delta = new ResourceDescriptionDelta(oldRes,null);
assertDeltaEquals(0,delta);
assertSame(delta.getNew(),newRes,null);
assertTrue(delta.haveEObjectDescriptionsChanged());
assertDeltaEquals(1,delta);
assertDeltaEquals(0,new ResourceDescriptionDelta(oldRes,delta.getold(),null));
delta = new ResourceDescriptionDelta(newRes,oldRes,null);
assertTrue(delta.haveEObjectDescriptionsChanged());
assertDeltaEquals(0,1,new ResourceDescriptionDelta(newRes,null));
}
项目:xtext-core
文件:ResourceSetBasedResourceDescriptions.java
@Override
public IResourceDescription getResourceDescription(URI uri) {
if (data != null) {
return data.getResourceDescription(uri);
}
Resource resource = resourceSet.getResource(uri,false);
if (resource == null)
return null;
IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
if (resourceServiceProvider == null)
return null;
Manager manager = resourceServiceProvider.getResourceDescriptionManager();
if (manager == null)
return null;
return manager.getResourceDescription(resource);
}
项目:dsl-devkit
文件:ResourceDescriptionDelta.java
/**
* Create a new delta from an old and a new resource description.
*
* @param oldDesc
* The old description
* @param newDesc
* The new description
* @param index
* index
*/
public ResourceDescriptionDelta(final IResourceDescription oldDesc,final IResourceDescription newDesc,final IResourceDescriptions index) {
super();
if (oldDesc == newDesc) {
throw new AssertionError("'old != new' constraint violated"); //$NON-NLS-1$
}
if (newDesc != null && oldDesc != null && !oldDesc.getURI().equals(newDesc.getURI())) {
URI oldURI = oldDesc.getURI();
URI newURI = newDesc.getURI();
throw new AssertionError("'new != null && old != null && !old.getURI().equals(new.getURI())' constraint violated,old was " + oldURI + " new was: " //$NON-NLS-1$ //$NON-NLS-2$
+ newURI);
}
this.uri = oldDesc == null ? newDesc.getURI() : oldDesc.getURI();
this.oldDesc = oldDesc;
if (newDesc != null) {
this.newDesc = new SoftReference<IResourceDescription>(newDesc);
}
this.index = index;
}
项目:xtext-core
文件:ReferenceFinder.java
@Override
public void findReferences(final TargetURIs targetURIs,IResourceDescription resourceDescription,IResourceAccess resourceAccess,final Acceptor acceptor,final IProgressMonitor monitor) {
final URI resourceURI = resourceDescription.getURI();
if (resourceAccess != null && targetURIs.containsResource(resourceURI)) {
IUnitOfWork.Void<ResourceSet> finder = new IUnitOfWork.Void<ResourceSet>() {
@Override
public void process(final ResourceSet state) throws Exception {
Resource resource = state.getResource(resourceURI,true);
findReferences(targetURIs,resource,acceptor,monitor);
}
};
resourceAccess.readOnly(resourceURI,finder);
} else {
findReferencesInDescription(targetURIs,resourceDescription,monitor);
}
}
public FixedcopiedResourceDescription(final IResourceDescription original) {
super();
this.uri = original.getURI();
this.exported = ImmutableList.copyOf(Iterables.transform(original.getExportedobjects(),new Function<IEObjectDescription,IEObjectDescription>() {
@Override
@SuppressWarnings("unchecked")
public IEObjectDescription apply(final IEObjectDescription from) {
if (from.getEObjectOrProxy().eIsProxy()) {
return from;
} else if (from instanceof IDetachableDescription) {
return ((IDetachableDescription<IEObjectDescription>) from).detach();
}
InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass());
result.eSetProxyURI(from.getEObjectURI());
ImmutableMap.Builder<String,String> userData = ImmutableMap.builder();
for (final String key : from.getUserDataKeys()) {
userData.put(key,from.getUserData(key));
}
return EObjectDescription.create(from.getName(),result,userData.build());
}
}));
}
项目:xtext-core
文件:ProjectDescriptionBasedContainerManager.java
@Override
public List<IContainer> getVisibleContainers(final IResourceDescription desc,final IResourceDescriptions resourceDescriptions) {
final ChunkedResourceDescriptions chunkedResourceDescriptions = this.getChunkedResourceDescriptions(resourceDescriptions);
if ((chunkedResourceDescriptions == null)) {
String _name = ChunkedResourceDescriptions.class.getName();
String _plus = ("expected " + _name);
throw new IllegalArgumentException(_plus);
}
final ResourceSet resourceSet = chunkedResourceDescriptions.getResourceSet();
final ProjectDescription projectDescription = ProjectDescription.findInEmfObject(resourceSet);
final ArrayList<IContainer> allContainers = CollectionLiterals.<IContainer>newArrayList();
allContainers.add(this.createContainer(resourceDescriptions,chunkedResourceDescriptions,projectDescription.getName()));
List<String> _dependencies = projectDescription.getDependencies();
for (final String name : _dependencies) {
allContainers.add(this.createContainer(resourceDescriptions,name));
}
return allContainers;
}
项目:xtext-core
文件:ProjectDescriptionBasedContainerManager.java
protected IContainer createContainer(final IResourceDescriptions resourceDescriptions,final ChunkedResourceDescriptions chunkedResourceDescriptions,final String projectName) {
IContainer _xifexpression = null;
if ((resourceDescriptions instanceof LiveShadowedChunkedResourceDescriptions)) {
_xifexpression = new LiveShadowedChunkedContainer(((LiveShadowedChunkedResourceDescriptions)resourceDescriptions),projectName);
} else {
ResourceDescriptionsData _elvis = null;
ResourceDescriptionsData _container = chunkedResourceDescriptions.getContainer(projectName);
if (_container != null) {
_elvis = _container;
} else {
Set<IResourceDescription> _emptySet = CollectionLiterals.<IResourceDescription>emptySet();
ResourceDescriptionsData _resourceDescriptionsData = new ResourceDescriptionsData(_emptySet);
_elvis = _resourceDescriptionsData;
}
_xifexpression = new ResourceDescriptionsBasedContainer(_elvis);
}
return _xifexpression;
}
项目:n4js
文件:AbstractBuilderTest.java
private void assertXtextIndexIsValidInternal() {
final IResourceDescriptions index = getXtextIndex();
final StringBuilder sb = new StringBuilder();
for (IResourceDescription desc : index.getAllResourceDescriptions()) {
if (desc instanceof ResourceDescriptionWithoutModuleUserData) {
sb.append("\n");
sb.append(IResourceDescription.class.getSimpleName());
sb.append(" in index must not be an instance of ");
sb.append(ResourceDescriptionWithoutModuleUserData.class.getSimpleName());
sb.append(" but it was. URI: ");
sb.append(desc.getURI());
}
}
assertTrue(sb.toString(),0 == sb.length());
}
项目:n4js
文件:TestEventListener.java
@Override
public void descriptionsChanged(Event event) {
URI expectedURI = URI.createPlatformResourceURI(file.getFullPath().toString(),true);
for (IResourceDescription.Delta delta : event.getDeltas()) {
URI deltaURI = delta.getUri();
if (expectedURI.equals(deltaURI)) {
eventFired = true;
}
}
}
项目:n4js
文件:BuilderUtil.java
/***/
public static String toString(IResourceDescriptions index) {
StringBuffer buff = new StringBuffer();
for (IResourceDescription desc : index.getAllResourceDescriptions()) {
buff.append(EmfFormatter.objToStr(desc,new EStructuralFeature[0]));
}
return buff.toString();
}
项目:n4js
文件:BuilderUtil.java
/***/
public static boolean indexContainsElement(final String fileUri,final String eObjectName) {
IResourceDescriptions descriptions = getBuilderState();
URI uri = URI.createURI("platform:/resource" + fileUri);
IResourceDescription description = descriptions.getResourceDescription(uri);
if (description != null) {
return description
.getExportedobjects(EcorePackage.Literals.EOBJECT,Qualifiedname.create(eObjectName),false)
.iterator().hasNext();
}
return false;
}
项目:n4js
文件:EagerResourceSetBasedResourceDescriptions.java
private Map<URI,IResourceDescription> getDescriptionsMap() {
Descriptions descriptions = getDescriptions(getResourceSet());
if (descriptions == null) {
descriptions = new Descriptions();
getResourceSet().eAdapters().add(descriptions);
List<Resource> list = new ArrayList<>(getResourceSet().getResources());
for (Resource resource : list) {
IResourceDescription description = computeResourceDescription(resource.getURI());
if (description != null) {
descriptions.map.put(resource.getURI(),description);
}
}
}
return descriptions.map;
}
项目:n4js
文件:EagerResourceSetBasedResourceDescriptions.java
private IResourceDescription computeResourceDescription(URI uri) {
Resource resource = resourceSet.getResource(uri,false);
if (resource == null)
return null;
IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
if (resourceServiceProvider == null)
return null;
IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
if (manager == null)
return null;
return manager.getResourceDescription(resource);
}
项目:n4js
文件:ExternalPackagesPluginTest.java
/**
* Checks if expected list of stringified file locations matches
*
* @param expected
* collection of entries
* @param actual
* collection of entries
*/
public void assertResourceDescriptions(Collection<String> expected,Iterable<IResourceDescription> actual) {
Set<String> exTradescriptions = new HashSet<>();
Set<String> missingDescriptions = new HashSet<>(expected);
for (IResourceDescription iResourceDescription : actual) {
URI uri = iResourceDescription.getURI();
String stringUri = uri.isPlatform() ? uri.toPlatformString(false) : uri.toFileString();
if (!missingDescriptions.contains(stringUri)) {
exTradescriptions.add(stringUri);
} else {
missingDescriptions.remove(stringUri);
}
}
if (missingDescriptions.isEmpty() && exTradescriptions.isEmpty()) {
return;
}
StringBuilder msg = new StringBuilder("unexpected actual resources" + "\n");
if (!exTradescriptions.isEmpty()) {
msg.append("actual contains " + exTradescriptions.size() + " extra resources" + "\n");
}
if (!missingDescriptions.isEmpty()) {
msg.append("actual is missing " + missingDescriptions.size() + " expected resources" + "\n");
}
for (String extra : exTradescriptions) {
msg.append("[extra] " + extra + "\n");
}
for (String missing : missingDescriptions) {
msg.append("[missing] " + missing + "\n");
}
fail(msg.toString());
}
private Map<URI,TModule> loadModules(final Iterable<URI> moduleUris,final IResourceDescriptions index,final ResourceSet resSet) {
final Map<URI,TModule> uri2Modules = newHashMap();
for (final URI moduleUri : moduleUris) {
final IResourceDescription resDesc = index.getResourceDescription(moduleUri);
uri2Modules.put(moduleUri,n4jscore.loadModuleFromIndex(resSet,resDesc,false));
}
return uri2Modules;
}
项目:n4js
文件:XpectN4JSES5transpilerHelper.java
/**
* @return the resources retrieved from the Xpect resource set configuration
*/
@Override
public List<Resource> getResources() {
final List<Resource> configuredResources = newArrayList();
if (configuredWorkspace != null && fileSetupCtx != null) {
for (IResourceDescription res : index.getAllResourceDescriptions()) {
if (fileExtensionProvider.isValid(res.getURI().fileExtension())) {
configuredResources.add(resourceSet.getResource(res.getURI(),true));
}
}
}
return configuredResources;
}
项目:n4js
文件:OpenTypeSelectionDialog.java
@Override
public String getText(final Object element) {
if (element instanceof IEObjectDescription) {
final IEObjectDescription description = (IEObjectDescription) element;
final StringBuilder sb = new StringBuilder(getFqn(description));
if (description instanceof EObject && null != ((EObject) description).eContainer()) {
final EObject container = ((EObject) description).eContainer();
if (container instanceof IResourceDescription) {
final URI uri = ((IResourceDescription) container).getURI();
final IN4JSEclipseProject project = core.findProject(uri).orNull();
if (null != project && project.exists()) {
sb.append(" [");
sb.append(project.getProjectId());
sb.append("]");
if (project.isExternal()) {
final IProject resourceProject = project.getProject();
sb.append(" External library: ");
sb.append(resourceProject.getLocation().toFile().getAbsolutePath());
}
}
}
}
return sb.toString();
} else {
return "";
}
}
@Override
public boolean removeStorage(ToBeBuilt toBeBuilt,IStorage storage,IProgressMonitor monitor) {
if (IN4JSArchive.NFAR_FILE_EXTENSION.equals(storage.getFullPath().getFileExtension())
&& storage instanceof IFile) {
IProject project = ((IFile) storage).getProject();
String key = project.getName() + "|" + storage.getFullPath().toPortableString();
Set<URI> cachedURIs = kNownEntries.remove(key);
if (cachedURIs != null) {
toBeBuilt.getTobedeleted().addAll(cachedURIs);
} else {
// cache not populated,use the index to find the URIs that shall be removed,e.g.
// can happen after a restart of Eclipse
Iterable<IResourceDescription> descriptions = builderState.getAllResourceDescriptions();
String expectedAuthority = "platform:/resource" + storage.getFullPath() + "!";
Set<URI> tobedeleted = toBeBuilt.getTobedeleted();
for (IResourceDescription description : descriptions) {
URI kNownURI = description.getURI();
if (kNownURI.isArchive()) {
String authority = kNownURI.authority();
if (expectedAuthority.equals(authority)) {
tobedeleted.add(kNownURI);
}
}
}
}
return true;
}
return false;
}
项目:n4js
文件:N4JSDirtyStateEditorSupport.java
@Override
public void scheduleUpdateEditorJob(final IResourceDescription.Event event) {
N4JSUpdateEditorStateJob job = updateEditorStateJob;
if (job == null) {
job = createUpdateEditorJob();
updateEditorStateJob = job;
}
job.scheduleFor(event);
}
项目:n4js
文件:N4JSDirtyStateEditorSupport.java
private Set<URI> collectDeltaURIs(Event event) {
Set<URI> deltaURIs = Sets.newHashSet();
for (IResourceDescription.Delta delta : event.getDeltas()) {
deltaURIs.add(delta.getUri());
}
return deltaURIs;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。