org.openxma.dsl.common.jdt.JdtEObjectDescription Maven / Gradle / Ivy
package org.openxma.dsl.common.jdt;
import java.io.IOException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.XtextResource;
public class JdtEObjectDescription {
protected final IEObjectDescription selectedObjectDescription;
private String plattformString;
private IResource iResource;
private IJavaProject javaProject;
private String classPathString;
private String packageString;
private XtextResource xtextResource;
public JdtEObjectDescription(IEObjectDescription selectedObjectDescription) {
super();
this.selectedObjectDescription = selectedObjectDescription;
}
public IEObjectDescription getIEObjectDescription() {
return selectedObjectDescription;
}
public String getPlattformString() {
if (plattformString == null) {
URI objectURI = selectedObjectDescription.getEObjectURI();
plattformString = objectURI.toPlatformString(true);
}
return plattformString;
}
public IResource getResource() {
if (iResource == null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
iResource = root.findMember(getPlattformString());
}
return iResource;
}
public IJavaProject getJavaProject() throws CoreException {
if (javaProject == null) {
if (getResource() != null && getResource().getProject() != null) {
IProject iProject = getResource().getProject();
javaProject = (IJavaProject) iProject.getNature(JavaCore.NATURE_ID);
}
}
return javaProject;
}
public String getClassPathString() throws JavaModelException, CoreException {
if (classPathString == null) {
if (getJavaProject() != null) {
IPackageFragmentRoot[] packageFragmentRoots = getJavaProject().getPackageFragmentRoots();
for (int i=0;i