diff options
author | Ed Willink | 2017-04-03 11:00:22 +0000 |
---|---|---|
committer | Ed Willink | 2017-04-05 12:29:06 +0000 |
commit | 469d1f44df4461de65b66f5bb5afb982e9b55f0e (patch) | |
tree | db7ef06a84761e0130799edfb1a16ab52779c15f | |
parent | 600a6aaf6a6d66892badf22bc7fc6cd5837be8b8 (diff) | |
download | org.eclipse.ocl-469d1f44df4461de65b66f5bb5afb982e9b55f0e.tar.gz org.eclipse.ocl-469d1f44df4461de65b66f5bb5afb982e9b55f0e.tar.xz org.eclipse.ocl-469d1f44df4461de65b66f5bb5afb982e9b55f0e.zip |
[unrelated] Add Class/File/ResourceLabelGenerator
5 files changed, 129 insertions, 18 deletions
diff --git a/plugins/org.eclipse.ocl.pivot/plugin.xml b/plugins/org.eclipse.ocl.pivot/plugin.xml index 6a1abc4aad..ae16957361 100644 --- a/plugins/org.eclipse.ocl.pivot/plugin.xml +++ b/plugins/org.eclipse.ocl.pivot/plugin.xml @@ -134,12 +134,14 @@ <extension point="org.eclipse.ocl.pivot.label_generator"> <generator for="java.lang.Boolean" class="org.eclipse.ocl.pivot.internal.labels.BooleanLabelGenerator"/> + <generator for="java.lang.Class" + class="org.eclipse.ocl.pivot.internal.labels.ClassLabelGenerator"/> <generator for="org.eclipse.emf.ecore.impl.DynamicEObjectImpl" class="org.eclipse.ocl.pivot.internal.labels.DynamicEObjectImplLabelGenerator"/> <generator for="org.eclipse.emf.ecore.EAnnotation" class="org.eclipse.ocl.pivot.internal.labels.EAnnotationLabelGenerator"/> - <generator for="org.eclipse.emf.common.util.URI" - class="org.eclipse.ocl.pivot.internal.labels.EcoreURILabelGenerator"/> + <generator for="java.io.File" + class="org.eclipse.ocl.pivot.internal.labels.FileLabelGenerator"/> <generator for="org.eclipse.emf.ecore.EGenericType" class="org.eclipse.ocl.pivot.internal.labels.EGenericTypeLabelGenerator"/> <generator for="org.eclipse.ocl.pivot.ids.ElementId" @@ -156,8 +158,12 @@ class="org.eclipse.ocl.pivot.internal.labels.NameableLabelGenerator"/> <generator for="java.lang.Number" class="org.eclipse.ocl.pivot.internal.labels.NumberLabelGenerator"/> + <generator for="org.eclipse.emf.ecore.resource.Resource" + class="org.eclipse.ocl.pivot.internal.labels.ResourceLabelGenerator"/> <generator for="java.lang.String" class="org.eclipse.ocl.pivot.internal.labels.StringLabelGenerator"/> + <generator for="org.eclipse.emf.common.util.URI" + class="org.eclipse.ocl.pivot.internal.labels.EcoreURILabelGenerator"/> <generator for="org.eclipse.ocl.pivot.values.Value" class="org.eclipse.ocl.pivot.internal.labels.ValueLabelGenerator"/> </extension> diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/ClassLabelGenerator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/ClassLabelGenerator.java new file mode 100644 index 0000000000..a4bdc6f3bd --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/ClassLabelGenerator.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2017 Willink Transformations and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * E.D.Willink - initial API and implementation + *******************************************************************************/ +package org.eclipse.ocl.pivot.internal.labels; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.ocl.pivot.labels.AbstractLabelGenerator; + +public final class ClassLabelGenerator extends AbstractLabelGenerator<Class<?>> +{ + public static void initialize(@NonNull Registry registry) { + registry.install(Class.class, new ClassLabelGenerator()); + } + + @SuppressWarnings("unchecked") + public ClassLabelGenerator() { + super((Class<? extends Class<?>>) Class.class); + } + + @Override + public void buildLabelFor(@NonNull Builder labelBuilder, @NonNull Class<?> object) { + labelBuilder.appendObject(object.getName()); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/FileLabelGenerator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/FileLabelGenerator.java new file mode 100644 index 0000000000..9b8505a95c --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/FileLabelGenerator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2017 Willink Transformations and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * E.D.Willink - initial API and implementation + *******************************************************************************/ +package org.eclipse.ocl.pivot.internal.labels; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.ocl.pivot.labels.AbstractLabelGenerator; + +public final class FileLabelGenerator extends AbstractLabelGenerator<File> +{ + public static void initialize(@NonNull Registry registry) { + registry.install(File.class, new FileLabelGenerator()); + } + + public FileLabelGenerator() { + super(File.class); + } + + @Override + public void buildLabelFor(@NonNull Builder labelBuilder, @NonNull File object) { + try { + labelBuilder.appendObject(object.getCanonicalPath()); + } catch (IOException e) { + labelBuilder.appendObject(object.toString()); + } + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/ResourceLabelGenerator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/ResourceLabelGenerator.java new file mode 100644 index 0000000000..e25ef2f280 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/labels/ResourceLabelGenerator.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2017 Willink Transformations and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * E.D.Willink - initial API and implementation + *******************************************************************************/ +package org.eclipse.ocl.pivot.internal.labels; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.ocl.pivot.labels.AbstractLabelGenerator; + +public final class ResourceLabelGenerator extends AbstractLabelGenerator<Resource> +{ + public static void initialize(@NonNull Registry registry) { + registry.install(Resource.class, new ResourceLabelGenerator()); + } + + public ResourceLabelGenerator() { + super(Resource.class); + } + + @Override + public void buildLabelFor(@NonNull Builder labelBuilder, @NonNull Resource object) { + labelBuilder.appendObject(object.getURI()); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/labels/LabelGeneratorRegistry.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/labels/LabelGeneratorRegistry.java index 4cefcf5aea..4e0c77c35a 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/labels/LabelGeneratorRegistry.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/labels/LabelGeneratorRegistry.java @@ -19,6 +19,7 @@ import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ocl.pivot.internal.labels.BooleanLabelGenerator; +import org.eclipse.ocl.pivot.internal.labels.ClassLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.DynamicEObjectImplLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.EAnnotationLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.EGenericTypeLabelGenerator; @@ -27,9 +28,11 @@ import org.eclipse.ocl.pivot.internal.labels.EObjectLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.EcoreURILabelGenerator; import org.eclipse.ocl.pivot.internal.labels.ElementIdLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.ExpressionInOCLLabelGenerator; +import org.eclipse.ocl.pivot.internal.labels.FileLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.ModelLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.NameableLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.NumberLabelGenerator; +import org.eclipse.ocl.pivot.internal.labels.ResourceLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.StringLabelGenerator; import org.eclipse.ocl.pivot.internal.labels.ValueLabelGenerator; import org.eclipse.ocl.pivot.internal.plugin.LabelGeneratorRegistryReader; @@ -57,13 +60,13 @@ import org.eclipse.ocl.pivot.labels.ILabelGenerator.Descriptor; * registration. */ public class LabelGeneratorRegistry implements ILabelGenerator.Registry -{ +{ public static class Global extends LabelGeneratorRegistry { private boolean initialized = false; - + public Global() {} - + public void initialize() { initialized = true; if (EcorePlugin.IS_ECLIPSE_RUNNING) { @@ -106,7 +109,7 @@ public class LabelGeneratorRegistry implements ILabelGenerator.Registry super.uninstall(labelledClass); } } - + public static @NonNull String debugLabelFor(@NonNull Object object) { Map<ILabelGenerator.Option<?>, Object> options = new HashMap<ILabelGenerator.Option<?>, Object>(); options.put(ILabelGenerator.Builder.SHOW_CLASS_SIMPLE_NAME, Boolean.TRUE); @@ -121,6 +124,7 @@ public class LabelGeneratorRegistry implements ILabelGenerator.Registry public static void initialize(ILabelGenerator.@NonNull Registry registry) { BooleanLabelGenerator.initialize(registry); + ClassLabelGenerator.initialize(registry); DynamicEObjectImplLabelGenerator.initialize(registry); EAnnotationLabelGenerator.initialize(registry); EGenericTypeLabelGenerator.initialize(registry); @@ -129,23 +133,25 @@ public class LabelGeneratorRegistry implements ILabelGenerator.Registry EcoreURILabelGenerator.initialize(registry); ElementIdLabelGenerator.initialize(registry); ExpressionInOCLLabelGenerator.initialize(registry); + FileLabelGenerator.initialize(registry); ModelLabelGenerator.initialize(registry); NameableLabelGenerator.initialize(registry); NumberLabelGenerator.initialize(registry); + ResourceLabelGenerator.initialize(registry); StringLabelGenerator.initialize(registry); ValueLabelGenerator.initialize(registry); } protected final ILabelGenerator.@Nullable Registry delegate; private final @NonNull Map<Class<?>, Object> map = new HashMap<Class<?>, Object>(); - + /** * Construct a registry that resolves label generators locally. */ private LabelGeneratorRegistry() { this.delegate = null; } - + /** * Construct a registry that resolves label generators locally when possible * but which delegates to delegate otherwise. @@ -170,7 +176,7 @@ public class LabelGeneratorRegistry implements ILabelGenerator.Registry if ((showClassSimpleName != null) && (showClassSimpleName == Boolean.TRUE)) { s.appendString(labelledObject.getClass().getSimpleName()); s.appendString(" "); - } + } } if (labelledObject instanceof EObject) { EObject eContainer = ((EObject)labelledObject).eContainer(); @@ -219,11 +225,11 @@ public class LabelGeneratorRegistry implements ILabelGenerator.Registry labelBuilder.appendString(labelledObject.toString()); labelBuilder.appendString(">"); } - - public ILabelGenerator.@NonNull Builder createDefaultLabelBuilder(@Nullable Object labelledObject, @Nullable Map<ILabelGenerator.Option<?>, Object> options) { - return new DefaultLabelGeneratorBuilder(this, labelledObject, options); - } - + + public ILabelGenerator.@NonNull Builder createDefaultLabelBuilder(@Nullable Object labelledObject, @Nullable Map<ILabelGenerator.Option<?>, Object> options) { + return new DefaultLabelGeneratorBuilder(this, labelledObject, options); + } + @Override public @Nullable ILabelGenerator<?> get(@NonNull Class<?> labelledClass) { Object object; @@ -238,7 +244,7 @@ public class LabelGeneratorRegistry implements ILabelGenerator.Registry return (ILabelGenerator<?>)object; } else if (delegate != null) { - return delegate.get(labelledClass); + return delegate.get(labelledClass); } else { return null; @@ -249,17 +255,17 @@ public class LabelGeneratorRegistry implements ILabelGenerator.Registry for (Class<?> sCls = cls; sCls != null; sCls = sCls.getSuperclass()) { ILabelGenerator<?> labelGenerator = get(sCls); if (labelGenerator != null) - return labelGenerator; + return labelGenerator; } for (@SuppressWarnings("null")@NonNull Class<?> iCls : cls.getInterfaces()) { ILabelGenerator<?> labelGenerator = get(iCls); if (labelGenerator != null) - return labelGenerator; + return labelGenerator; } for (@SuppressWarnings("null")@NonNull Class<?> iCls : cls.getInterfaces()) { ILabelGenerator<?> labelGenerator = getLabelGenerator(iCls); if (labelGenerator != null) - return labelGenerator; + return labelGenerator; } Class<?> sCls = cls.getSuperclass(); if (sCls != null) |