blob: 0e924016ef0641e4a7f941504a33f216d92e2c23 [file] [log] [blame]
<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<h1 id="Java_Discoverer_API">Java Discoverer API</h1>
<p>First, add the following plug-in dependencies to your project (
<b>Require-Bundle</b> in your Manifest.MF):
<p>There are several Java discoverer classes that do the same discovery but on different inputs:</p>
<li>DiscoverJavaModelFromJavaProject : from an IJavaProject (defined in jdt.core)</li>
<li>DiscoverJavaModelFromProject : from an IProject</li>
<li>DiscoverJavaModelFromClassFile : from an IClassFile (defined in jdt.core)</li>
<li>DiscoverJavaModelFromLibrary : from an IPackageFragmentRoot (for jars; defined in jdt.core)</li>
<p>You can easily discover a Java model programmatically. For example, to discover a Java model from a Java project:</p>
DiscoverJavaModelFromJavaProject discoverer = new DiscoverJavaModelFromJavaProject();
javaDiscoverer.discoverElement(javaProject, monitor);
Resource javaResource = javaDiscoverer.getTargetModel();
<p>To have a monitor to pass to the <code>discoverElement</code> method, you can either call the discoverer in an Eclipse Job, or pass a new NullProgressMonitor if you don't need progress reporting.</p>
<p>Once you have the Java Resource, you can use the standard EMF API to read model elements. For example, to get the root:</p>
Model javaModel = (Model) javaResource.getContents().get(0);
<p>To print the list of Java classes in the model:</p>
EList&lt;ClassFile&gt; classFiles = javaModel.getClassFiles();
for (ClassFile classFile : classFiles) {