Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil.resolveAll()

The following are Jave code examples for showing how to use resolveAll() of the org.eclipse.emf.ecore.util.EcoreUtil class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: n4js   File: ExceptionAnalyser.java   View Source Code Vote up 6 votes
@Override
protected List<Diagnostic> getScriptErrors(Script script) {
	EcoreUtil.resolveAll(script.eResource());
	List<Diagnostic> diagnostics = super.getScriptErrors(script);
	Iterator<Expression> expressions = Iterators.filter(EcoreUtil2.eAll(script), Expression.class);
	List<Diagnostic> result = Lists.<Diagnostic> newArrayList(Iterables.filter(diagnostics,
			ExceptionDiagnostic.class));
	while (expressions.hasNext()) {
		Expression expression = expressions.next();
		RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(expression);
		Result<TypeRef> type = typeSystem.type(ruleEnvironment, expression);
		if (type.getRuleFailedException() != null) {
			Throwable cause = Throwables.getRootCause(type.getRuleFailedException());
			if (!(cause instanceof RuleFailedException)) {
				if (cause instanceof Exception) {
					result.add(new ExceptionDiagnostic((Exception) cause));
				} else {
					throw new RuntimeException(cause);
				}
			}
		}
	}
	validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
	return result;
}
 
Example 2
Project: gemoc-studio-modeldebugging   File: SelectAnyEObjectDialog.java   View Source Code Vote up 6 votes
public SelectAnyEObjectDialog(Shell parent, ResourceSet resourceSet, ILabelProvider renderer) {
	super(parent, renderer);
	_searchedResourceSet = resourceSet;
	ArrayList<EObject> all = new ArrayList<EObject>();
	EcoreUtil.resolveAll(resourceSet);
	for (Resource r : _searchedResourceSet.getResources())
	{
		for (TreeIterator<EObject> iterator = r.getAllContents(); iterator.hasNext();) {
			EObject o =  iterator.next();
			if(select(o)) all.add(o);
		}
	}
	
	Object[] elements = all.toArray();
	this.setElements(elements);
}
 
Example 3
Project: greycat-idea-plugin   File: PrettyPrinter.java   View Source Code Vote up 6 votes
protected ResourceSet getEcoreModel(File ecorefile) {

        ResourceSetImpl rs = new ResourceSetImpl();
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
        try {
            URI fileUri = URI.createFileURI(ecorefile.getCanonicalPath());
            Resource resource = rs.createResource(fileUri);
            resource.load(null);
            EcoreUtil.resolveAll(resource);
            rs.getResources().add(resource);
            EcoreUtil.resolveAll(rs);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return rs;
    }
 
Example 4
Project: SurveyDSL   File: QueryITToXMIConverter.java   View Source Code Vote up 6 votes
public static void convertERDSLtoXMI(String inputM, String outputM) {
	Injector injector = new QueryITStandaloneSetup().createInjectorAndDoEMFRegistration();

	XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);


	URI uri = URI.createURI(inputM);
	

	Resource xtextResource = resourceSet.getResource(uri, true);

	EcoreUtil.resolveAll(xtextResource);

	Resource xmiResource = resourceSet.createResource(URI.createURI(outputM));
	xmiResource.getContents().add(xtextResource.getContents().get(0));
	try {
		xmiResource.save(null);
		System.out.println("Saved " + outputM);
    	System.out.println("QueryIT file converted successfully to XMI");
    	System.out.println("-------------------------------------");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 5
Project: n4js   File: XcoreReader.java   View Source Code Vote up 5 votes
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
		Issues issues) {
	ResourceSet resourceSet = getResourceSet();

	// due to some Xcore peculiarity we have to access the IAllContainerState here
	// to trigger some lazy init logic
	IAllContainersState allContainerState = (IAllContainersState) EcoreUtil.getAdapter(resourceSet.eAdapters(),
			IAllContainersState.class);
	allContainerState.isEmpty("");

	Multimap<String, URI> uris = getPathTraverser().resolvePathes(pathes,
			new Predicate<URI>() {
		@Override
		public boolean apply(URI input) {
			return input.fileExtension().equals(XCORE_FILE_EXT);
		}
	});
	List<Resource> resources = new ArrayList<>();
	for (URI uri : uris.values()) {
		LOGGER.info(uri);
		try {
			resources.add(parse(uri, resourceSet));
		} catch (Exception e) {
			LOGGER.error("Problem during loading of resource @ " + uri, e);
		}
	}
	installIndex(resourceSet);
	for (Resource r : resources) {
		EcoreUtil.resolveAll(r);
		for (Diagnostic x : r.getErrors()) {
			issues.addError(x.getMessage(), x);
		}

	}
	ctx.set(slot, resources);
}
 
Example 6
Project: n4js   File: BuiltInTypeScopeTest.java   View Source Code Vote up 5 votes
@SuppressWarnings("javadoc")
@Test
public void testResolveAllBuiltInTypes() {
	BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
	scope.getSingleElement(QualifiedName.create("any")); // trigger loading
	Assert.assertEquals(5, resourceSet.getResources().size());
	EcoreUtil.resolveAll(resourceSet);
	Assert.assertEquals(5, resourceSet.getResources().size());

	Map<EObject, Collection<Setting>> unresolvedProxies = EcoreUtil.UnresolvedProxyCrossReferencer
			.find(resourceSet);
	Assert.assertTrue(unresolvedProxies.toString(), unresolvedProxies.isEmpty());
}
 
Example 7
Project: n4js   File: N4JSPostProcessor.java   View Source Code Vote up 5 votes
private void postProcessN4JSResource(N4JSResource resource, CancelIndicator cancelIndicator) {
	// step 1: process the AST (resolve all proxies in AST, infer type of all typable AST nodes, etc.)
	astProcessor.processAST(resource, cancelIndicator);
	// step 2: expose internal types visible from outside
	// (i.e. if they are referenced from a type that is visible form the outside)
	exposeReferencedInternalTypes(resource);
	// step 3: resolve remaining proxies in TModule
	// (the TModule was created programmatically, so it usually does not contain proxies; however, in case of
	// explicitly declared types, the types builder copies type references from the AST to the corresponding
	// TModule element *without* resolving proxies, so the TModule might contain lazy-cross-ref proxies; most of
	// these should have been resolved during AST traversal and exposing internal types, but some can be left)
	EcoreUtil.resolveAll(resource.getModule());
}
 
Example 8
Project: n4js   File: InferredElementsTargetURICollector.java   View Source Code Vote up 5 votes
@Override
protected void doAdd(EObject primaryTarget, TargetURIs targetURIsAddHere) {
	Resource resource = primaryTarget.eResource();
	// If the target is not contained in a resource, we cannot do anything but return.
	if (resource == null)
		return;
	EcoreUtil.resolveAll(primaryTarget.eResource());

	// Special handling for composed members and TStructMember
	if (primaryTarget instanceof TMember && ((TMember) primaryTarget).isComposed()) {
		// In case of composed member, add the constituent members instead.
		List<TMember> constituentMembers = ((TMember) primaryTarget).getConstituentMembers();
		for (TMember constituentMember : constituentMembers) {
			super.doAdd(constituentMember, targetURIsAddHere);
		}
	} else {
		if (primaryTarget instanceof TStructMember) {
			TStructMember crossRefStructMember = ((TStructMember) primaryTarget).getDefinedMember();
			if (crossRefStructMember != null)
				// If this TStructMember is an AST, also add the defined member located in the TModule
				super.doAdd(((TStructMember) primaryTarget).getDefinedMember(), targetURIsAddHere);
		}
		super.doAdd(primaryTarget, targetURIsAddHere);
	}

	inferredElements.collectInferredElements(primaryTarget, (object) -> {
		if (object != null) {
			super.doAdd(object, targetURIsAddHere);
		}
	}, projectUtils);
}
 
Example 9
Project: lcdsl   File: LcDslHelper.java   View Source Code Vote up 5 votes
/**
 * Finds a launch configuration with the given name from the current EMF index. The index contains all
 * launch configurations from projects that have the Xtext nature. Launch configurations from projects
 * without the Xtext nature are not found. Use {@link #findLaunchConfig(String, IFile)} in this case.
 *
 * @param name the name of the configuration to find
 * @return the configuration or <code>null</code>
 */
public LaunchConfig findLaunchConfig(String name) {
    Iterable<IEObjectDescription> indexed = index.getExportedObjectsByType(LcDslPackage.eINSTANCE.getLaunchConfig());

    for (IEObjectDescription o : indexed) {
        if (o.getName().getLastSegment().equals(name)) {
            EObject obj = EcoreUtil.resolve(o.getEObjectOrProxy(), rsProvider.get());
            EcoreUtil.resolveAll(obj);
            return (LaunchConfig) obj;
        }
    }
    return null;
}
 
Example 10
Project: gemoc-studio   File: ResourceMerger.java   View Source Code Vote up 5 votes
private EList<Resource> getResources() {
	ResourceSet rs = new ResourceSetImpl();
	URI inputURI = URI.createPlatformResourceURI(_context.getInputFile().getFullPath().toString(), true);
	Resource r = rs.getResource(inputURI, true);
	EcoreUtil.resolveAll(r);
	EcoreUtil.resolveAll(rs); // result in the load of several resources
	return rs.getResources();
}
 
Example 11
Project: OCCI-Studio   File: OcciHelper.java   View Source Code Vote up 5 votes
public static EObject getRootElement(ResourceSet resourceSet, IFile file) {
	URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
	System.out.println("file " + file.getFullPath().toString());
	System.out.println("uri " + uri);
	org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(uri, true);
	EcoreUtil.resolveAll(resource);
	return resource.getContents().get(0);
}
 
Example 12
Project: OCCI-Studio   File: OCCIDocumentProvider.java   View Source Code Vote up 5 votes
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
		throws CoreException {
	try {
		//System.out.println("doSaveDocument ");
		ResourceSet resourceSet = createResourceSet();
		XtextResource xtextResource = (XtextResource) resourceSet.createResource(URI.createURI("temp.occi"));
		InputStream is = new ByteArrayInputStream(document.get().getBytes());
		xtextResource.load(is, Collections.EMPTY_MAP);
		is.close();
		URI uri = URI.createPlatformResourceURI(
				((org.eclipse.ui.part.FileEditorInput) element).getFile().getFullPath().toString(), true);
		//resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
		//System.out.println("uriii "+uri);
		Resource xmiResource = resourceSet.getResource(uri, true);
		((XMLResource) xmiResource).getDefaultSaveOptions().put(XMLResource.OPTION_URI_HANDLER,
				new URIHandlerImpl.PlatformSchemeAware());
		xmiResource.getContents().clear();
		xmiResource.getContents().addAll(xtextResource.getContents());
		// SUPER IMPORTANT to avoid to have references to temp.occi
		EcoreUtil.resolveAll(xmiResource);			
		xmiResource.save(Collections.EMPTY_MAP);
	} catch (IOException e) {
		throw new CoreException(
				new Status(IStatus.ERROR, "org.occiware.clouddesigner.occi.xtext.ui", "Failed to save", e));
	}
}
 
Example 13
Project: gemoc-studio-modeldebugging   File: EMFUtil.java   View Source Code Vote up 4 votes
public static Resource loadModelURI(URI uri, ResourceSet rs) throws IOException {
	Resource res = rs.createResource(uri);
	res.load(null);
	EcoreUtil.resolveAll(rs);// IMPORTANT
	return res;
}
 
Example 14
Project: gemoc-studio-modeldebugging   File: EMFUtil.java   View Source Code Vote up 4 votes
public static Resource loadModelURI(String uri, ResourceSet rs) throws IOException {
	Resource res = rs.createResource(URI.createURI(uri));
	res.load(null);
	EcoreUtil.resolveAll(rs);// IMPORTANT
	return res;
}
 
Example 15
Project: gemoc-studio-modeldebugging   File: EMFUtil.java   View Source Code Vote up 4 votes
public static Resource loadModelPath(String path, ResourceSet rs) throws IOException {
	Resource res = rs.createResource(EMFUtil.createFileURI(path));
	res.load(null);
	EcoreUtil.resolveAll(rs);// IMPORTANT
	return res;
}
 
Example 16
Project: OCCI-Studio   File: OcciHelper.java   View Source Code Vote up 4 votes
public static EObject getRootElement(ResourceSet resourceSet, String path) {
	org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(URI.createURI(path), true);
	EcoreUtil.resolveAll(resource);
	return resource.getContents().get(0);
}
 
Example 17
Project: gemoc-studio-modeldebugging   File: DefaultModelLoader.java   View Source Code Vote up 3 votes
private static Resource loadModelThenConfigureResourceSet(ResourceSet rs, URI modelURI, HashMap<String, String> nsURIMapping,
		SubMonitor subMonitor) {

	Resource resource = rs.getResource(modelURI, true);
	EcoreUtil.resolveAll(rs);
	configureResourceSet(rs,modelURI,nsURIMapping,subMonitor);

	return resource;

}
 
Example 18
Project: n4js   File: EObjectFeatureMerger.java   View Source Code Vote up 2 votes
/**
 * Merges the structural features from the {@code from} argument to the {@code to} argument.
 *
 * @param from
 *            the object to copy and merge the features from.
 * @param to
 *            the target of the merge operation.
 * @return the merged object.
 */
public EObject merge(final EObject from, final EObject to) {
	final EObject copy = EcoreUtil.copy(from);
	EcoreUtil.resolveAll(copy);
	return merge(copy, to, newHashSet());
}