Skip to content

Instantly share code, notes, and snippets.

View nbhusare's full-sized avatar
🏠
Working from home

Neeraj Bhusare nbhusare

🏠
Working from home
View GitHub Profile
@nbhusare
nbhusare / Recursing_Through_Parents.java
Created October 3, 2020 17:04
Scope provider implementation to demonstrate how you can created a nested scope with elements in it.
/**
* In the implementation of the scope provider, we create a nested scope, where each scope contains the fields from the given Clazz.
**/
override IScope getScope(EObject context, EReference eReference) {
if (reference == MyDslPackage.Literals.REF_TO_FIELD_FIELD) {
return clazzScope(context.getContainerOfType(Clazz));
}
return super.getScope(context, eReference);
@nbhusare
nbhusare / EMFTVM_from_Java.java
Last active September 4, 2020 14:41
EMFTVM from Java
// https://wiki.eclipse.org/ATL/EMFTVM#API
ExecEnv env = EmftvmFactory.eINSTANCE.createExecEnv();
ResourceSet rs = new ResourceSetImpl();
// Load metamodels
Metamodel metaModel = EmftvmFactory.eINSTANCE.createMetamodel();
metaModel.setResource(rs.getResource(URI.createURI("http://www.eclipse.org/m2m/atl/2011/EMFTVM"), true));
env.registerMetaModel("METAMODEL", metaModel);
@nbhusare
nbhusare / NewVMShutdownHook.java
Last active December 27, 2019 12:57
Add a new Virtual Machine Shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
// Your code comes here...
}));
/* addShutdownHook() - A shutdown hook is simply an initialized but unstarted thread. When the virtual machine begins its
shutdown sequence it will start all registered shutdown hooks in some unspecified order and let them run concurrently. When all the
hooks have finished it will then run all uninvoked finalizers if finalization-on-exit has been enabled. Finally, the virtual machine
will halt. Note that daemon threads will continue to run during the shutdown sequence, as will non-daemon threads if shutdown was
initiated by invoking the exitmethod. */
@nbhusare
nbhusare / Data_Race_Vs_Race_condition.txt
Last active November 19, 2019 07:00
Data Race Vs Race condition
Data race: It occurs when synchronization is not used to coordinate access to the shared state. You risk data race whenever you write to a shared variable that might next be read by another thread, or read a variable that might have last been written by another thread, if both threads do not use synchronization
Race condition: It occurs when the correctness of a computation depends on the relative timing of interlaving of multiple threads by the runtime; in other words, when getting the right answer relies on the lucky timing.
private static ClassLoader getBundleClassLoader(String name) {
Bundle bundle = Platform.getBundle(name);
BundleWiring wiring = bundle.adapt(BundleWiring.class);
wiring != null : String.format("Should not happen; current state of bundle %s is %s",
bundle.getSymbolicName(), bundle.getState());
return wiring.getClassLoader();
}
@nbhusare
nbhusare / CompareDoubleApprox
Created May 4, 2019 13:30
Comparing two double values are approx. equal
https://stackoverflow.com/questions/9090500/how-to-compare-that-sequence-of-doubles-are-all-approximately-equal-in-java
@nbhusare
nbhusare / EMF Containment proxies
Created May 1, 2019 17:42
EMF Containment proxies
Behavior of EMF when proxy resolution is turned on - It is only when proxy resolution is enabled on a containment reference that the container and contained objects can reside in different resources. In this situation, adding an object to a resource’s contents does not automatically remove it from its existing container. this behavior is only available beginning in EMF 2.2.
Also, when generating a model, "containment proxies "must be enabled explicitly for the whole model, or else all containment references will be considered non-proxy-resolving, completely disabling cross-resource containment.
Previous to EMF 2.2, you could always be sure that the resource of an EObject in a containment tree would also be the resource of its container. Enabling cross-resource containment breaks this assumption, which could impact existing applications. For example, saving an object’s resource does not guarantee that its contents are saved.
@nbhusare
nbhusare / EMFURIConvertor
Created May 1, 2019 10:35
EMF URI Convertor - Storing and converting URI's from one format to another
final URIConverter converter = new URIConverterImpl();
final URI uri1 = URI.createURI("http://www.example.com/epo2.ecore");
final URI uri2 = URI.createURI("platform:/resource/models/epo2.ecore");
// Maintain mapping between the two URI's
converter.getURIMap().put(uri1, uri2);
// Normalize/Convert the URI from one format into another
final URI normalized = converter.normalize(uri1);
System.out.println(normalized);
@nbhusare
nbhusare / ReadImageFromBundle
Created April 24, 2019 23:58
Reading image from an bundle
final Bundle bundle = Platform.getBundle("org.eclipse.ui.editors");
final URL url = FileLocator.find(bundle, new Path("icons/full/obj16/quick_fix_warning_obj.png"), null);
final ImageDescriptor imageDesc = ImageDescriptor.createFromURL(url);
final Image image = imageDesc.createImage();
return image;
@nbhusare
nbhusare / gist:741a10b6cc6dcecc721d636baf66d55f
Created March 8, 2019 07:43
Delete all local branch which have been merged
https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged