Skip to content

Commit

Permalink
Rework IStorageEditorInput -> IJavaElement adapter into a type conver…
Browse files Browse the repository at this point in the history
…ter (#83)

The Eclipse Adapter Manager is a one-shot adapter, whereas the
Ferret TypesConversionManager cascades through the possible conversion
pipelines until one succeeds.
  • Loading branch information
briandealwis authored Nov 6, 2017
1 parent b19e34a commit c5ee530
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 66 deletions.
28 changes: 13 additions & 15 deletions ca.ubc.cs.ferret.pde/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,20 @@
fidelity="equivalent"
providedType="org.eclipse.pde.internal.core.text.bundle.PackageObject">
</converter>
<converter
class="ca.ubc.cs.ferret.pde.PdeTypeConverter"
providedType="org.eclipse.ui.IStorageEditorInput"
desiredType="org.eclipse.jdt.core.IJavaElement"
fidelity="equivalent">
</converter>
<converter
class="ca.ubc.cs.ferret.pde.PdeTypeConverter"
providedType="org.eclipse.ui.IStorageEditorInput"
desiredType="org.eclipse.jdt.core.IPackageFragmentRoot"
fidelity="equivalent">
</converter>

</extension>
</extension>
<extension point="ca.ubc.cs.clustering.classifiers">
<classifier
class="ca.ubc.cs.ferret.pde.classifiers.PluginObjectClassifier"
Expand All @@ -265,18 +277,4 @@
<extension point="org.eclipse.help.contexts">
<contexts file="helpContexts.xml" />
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.eclipse.ui.IStorageEditorInput"
class="ca.ubc.cs.ferret.pde.JarFileAdapterFactory">
<adapter
type="org.eclipse.jdt.core.IJavaElement">
</adapter>
<adapter
type="org.eclipse.jdt.core.IPackageFragmentRoot">
</adapter>
</factory>
</extension>

</plugin>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@
import ca.ubc.cs.ferret.types.ConversionResult;
import ca.ubc.cs.ferret.types.ConversionSpecification;
import ca.ubc.cs.ferret.types.ConversionSpecification.Fidelity;
import java.io.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.pde.core.IIdentifiable;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.plugin.IPluginImport;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
import org.eclipse.pde.internal.core.natures.PDE;
import org.eclipse.pde.internal.core.plugin.ImportObject;
import org.eclipse.pde.internal.core.text.bundle.PackageObject;
import org.eclipse.ui.IStorageEditorInput;

public class PdeTypeConverter extends AbstractTypeConverter {

Expand All @@ -43,7 +48,8 @@ public PdeTypeConverter() {}
public ConversionResult<?> convert(Object object,
ConversionSpecification spec, ISphere sphere) throws ConversionException {
try {
if(spec.getDesiredClass() == IPluginModelBase.class) {
Class<?> desiredClass = spec.getDesiredClass();
if (desiredClass == IPluginModelBase.class) {
if(object instanceof IPluginImport) {
return wrap(spec, Fidelity.Exact, IPluginModelBase.class,
PdeModelHelper.getDefault().findPluginModel(((IPluginImport)object).getId()));
Expand All @@ -63,13 +69,13 @@ public ConversionResult<?> convert(Object object,
((IIdentifiable)object).getId());
return wrap(spec, Fidelity.Exact, IPluginModelBase.class, plugin);
}
} else if(spec.getDesiredClass() == IPluginImport.class) {
} else if (desiredClass == IPluginImport.class) {
// This is more here for proof-of-concept
if(object instanceof ImportObject) {
return wrap(spec, Fidelity.Exact, IPluginImport.class,
((ImportObject)object).getImport());
}
} else if(spec.getDesiredClass() == PdeIdentifier.class) {
} else if (desiredClass == PdeIdentifier.class) {
// FIXME: PdeIdentifier should be a contextualized object, with JavaTypePdeIdentifier,
// ResourcePdeIdentifier, etc. The problem is that a resource is specified relative to
// to its defining project. Although I don't think there's a way to reference resources
Expand All @@ -94,14 +100,14 @@ public ConversionResult<?> convert(Object object,
new PdeIdentifier(relativePathname));
}
}
} else if(spec.getDesiredClass() == IFeatureModel.class) {
} else if (desiredClass == IFeatureModel.class) {
if(object instanceof IIdentifiable) {
IFeatureModel feature =
PdeModelHelper.getDefault().findFeatureModel(
((IIdentifiable)object).getId());
return wrap(spec, Fidelity.Exact, IFeatureModel.class, feature);
}
} else if(spec.getDesiredClass() == IModel.class) {
} else if (desiredClass == IModel.class) {
if(object instanceof IModel) {
return wrap(spec, Fidelity.Exact, IModel.class, (IModel)object);
} else if(object instanceof IIdentifiable) {
Expand All @@ -116,7 +122,7 @@ public ConversionResult<?> convert(Object object,
if(plugin != null) { return wrap(spec, Fidelity.Exact,
IPluginModelBase.class, plugin); }
}
} else if(spec.getDesiredClass() == JavaPackage.class) {
} else if (desiredClass == JavaPackage.class) {
if(object instanceof ImportPackageSpecification) {
return wrap(
spec,
Expand All @@ -133,6 +139,18 @@ public ConversionResult<?> convert(Object object,
} else if(object instanceof IPackageFragment) { return wrap(spec,
Fidelity.Equivalent, JavaPackage.class, new JavaPackage(
((IPackageFragment)object).getElementName())); }
} else if (desiredClass == IJavaElement.class || desiredClass == IPackageFragmentRoot.class) {
if (object instanceof IStorageEditorInput) {
IStorageEditorInput input = (IStorageEditorInput) object;
File file = input.getAdapter(File.class);
if (file != null) {
Object adapted = PDECore.getDefault().getSearchablePluginsManager().createAdapterChild(null,
file);
if (desiredClass.isInstance(adapted)) {
return wrap(spec, Fidelity.Equivalent, (Class<Object>) desiredClass, adapted);
}
}
}
}
} catch(ClassNotFoundException e) {
throw new ConversionException(e);
Expand Down

0 comments on commit c5ee530

Please sign in to comment.