diff options
Diffstat (limited to 'bundles')
11 files changed, 419 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/.classpath b/bundles/org.eclipse.e4.tools.jdt.templates/.classpath new file mode 100644 index 00000000..64c5e31b --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/.project b/bundles/org.eclipse.e4.tools.jdt.templates/.project new file mode 100644 index 00000000..e0303cd3 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.e4.tools.jdt.templates</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.e4.tools.jdt.templates/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..5a797383 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Sat Mar 06 23:33:15 EST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.jdt.templates/META-INF/MANIFEST.MF new file mode 100644 index 00000000..1a967cb3 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: e4 Templates +Bundle-SymbolicName: org.eclipse.e4.tools.jdt.templates;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.eclipse.jdt.ui;bundle-version="3.6.0", + org.eclipse.ui.editors;bundle-version="3.6.0", + org.eclipse.jface.text;bundle-version="3.6.0", + org.eclipse.jdt.core;bundle-version="3.6.0", + org.eclipse.core.runtime;bundle-version="3.6.0" +Export-Package: org.eclipse.e4.internal.tools.jdt.templates diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/build.properties b/bundles/org.eclipse.e4.tools.jdt.templates/build.properties new file mode 100644 index 00000000..3337a4a3 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + templates/,\ + icons/ diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/icons/full/elcl16/e4assist_co.gif b/bundles/org.eclipse.e4.tools.jdt.templates/icons/full/elcl16/e4assist_co.gif Binary files differnew file mode 100644 index 00000000..150a1f7e --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/icons/full/elcl16/e4assist_co.gif diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/plugin.xml b/bundles/org.eclipse.e4.tools.jdt.templates/plugin.xml new file mode 100644 index 00000000..b3ed8606 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/plugin.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.jdt.ui.javaCompletionProposalComputer" + id="e4ProposalCategory" + name="e4 proposals"> + <proposalCategory + icon="$nl$/icons/full/elcl16/e4assist_co.gif"/> + </extension> + <extension + point="org.eclipse.jdt.ui.javaCompletionProposalComputer" + id="e4BuilderCompletionProposalComputer"> + <javaCompletionProposalComputer + activate="true" + categoryId="org.eclipse.e4.tools.jdt.templates.e4ProposalCategory" + class="org.eclipse.e4.internal.tools.jdt.templates.E4TemplateCompletionProposalComputer"> + <partition type="__dftl_partition_content_type"/> + </javaCompletionProposalComputer> + </extension> + <extension + point="org.eclipse.ui.editors.templates"> + <contextType + name="e4" + class="org.eclipse.e4.internal.tools.jdt.templates.E4ContextType" + id="e4" + registryId="org.eclipse.jdt.ui.CompilationUnitEditor"> + </contextType> + <contextType + name="e4 statements" + class="org.eclipse.e4.internal.tools.jdt.templates.E4ContextType" + id="e4-statements" + registryId="org.eclipse.jdt.ui.CompilationUnitEditor"> + </contextType> + <contextType + name="e4 members" + class="org.eclipse.e4.internal.tools.jdt.templates.E4ContextType" + id="e4-members" + registryId="org.eclipse.jdt.ui.CompilationUnitEditor"> + </contextType> + <include + file="templates/default-e4templates.xml" + translations="$nl$/templates/default-e4templates.properties"> + </include> + </extension> + +</plugin> diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/src/org/eclipse/e4/internal/tools/jdt/templates/E4ContextType.java b/bundles/org.eclipse.e4.tools.jdt.templates/src/org/eclipse/e4/internal/tools/jdt/templates/E4ContextType.java new file mode 100644 index 00000000..1fdf5ff9 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/src/org/eclipse/e4/internal/tools/jdt/templates/E4ContextType.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 IBM Corporation 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: + * IBM Corporation - initial API and implementation (adapted from JDT's SWTContextType) + *******************************************************************************/ +package org.eclipse.e4.internal.tools.jdt.templates; + +import org.eclipse.jdt.internal.corext.template.java.AbstractJavaContextType; +import org.eclipse.jdt.internal.corext.template.java.JavaContext; + +/** + * The context type for templates inside e4 code. + * The same class is used for several context types: + * <dl> + * <li>templates for all Java code locations</li> + * <li>templates for member locations</li> + * <li>templates for statement locations</li> + * </dl> + */ +public class E4ContextType extends AbstractJavaContextType { + + /** + * The context type id for templates working on all Java code locations in e4 projects + */ + public static final String ID_ALL= "e4"; //$NON-NLS-1$ + + /** + * The context type id for templates working on member locations in e4 projects + */ + public static final String ID_MEMBERS= "e4-members"; //$NON-NLS-1$ + + /** + * The context type id for templates working on statement locations in e4 projects + */ + public static final String ID_STATEMENTS= "e4-statements"; //$NON-NLS-1$ + + protected void initializeContext(JavaContext context) { + if (!getId().equals(E4ContextType.ID_ALL)) { // a specific context must also allow the templates that work everywhere + context.addCompatibleContextType(E4ContextType.ID_ALL); + } + } +} diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/src/org/eclipse/e4/internal/tools/jdt/templates/E4TemplateCompletionProposalComputer.java b/bundles/org.eclipse.e4.tools.jdt.templates/src/org/eclipse/e4/internal/tools/jdt/templates/E4TemplateCompletionProposalComputer.java new file mode 100644 index 00000000..cadf6bfc --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/src/org/eclipse/e4/internal/tools/jdt/templates/E4TemplateCompletionProposalComputer.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 IBM Corporation 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: + * IBM Corporation - initial API and implementation (adapted from JDT's SWTTemplateCompletionProposalComputer) + *******************************************************************************/ +package org.eclipse.e4.internal.tools.jdt.templates; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jdt.core.CompletionContext; +import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IElementChangedListener; +import org.eclipse.jdt.core.IJavaElementDelta; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.text.java.AbstractTemplateCompletionProposalComputer; +import org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateEngine; +import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; +import org.eclipse.jface.text.templates.ContextTypeRegistry; +import org.eclipse.jface.text.templates.TemplateContextType; + +/** + * Computer that computes the template proposals for the E4 context type. + * + */ +public class E4TemplateCompletionProposalComputer extends AbstractTemplateCompletionProposalComputer { + + /** + * The name of <code>org.eclipse.e4.core.services.IDisposable</code> used to detect + * if a project uses e4. + */ + private static final String E4_TYPE_NAME= "org.eclipse.e4.core.services.IDisposable"; //$NON-NLS-1$ + + + /** + * Listener that resets the cached java project if its build path changes. + */ + private final class BuildPathChangeListener implements IElementChangedListener { + + public void elementChanged(ElementChangedEvent event) { + IJavaProject javaProject= getCachedJavaProject(); + if (javaProject == null) + return; + + IJavaElementDelta[] children= event.getDelta().getChangedChildren(); + for (int i= 0; i < children.length; i++) { + IJavaElementDelta child= children[i]; + if (javaProject.equals(child.getElement())) { + if (isClasspathChange(child)) { + setCachedJavaProject(null); + } + } + } + } + + /** + * Does the delta indicate a classpath change? + * @param delta the delta to inspect + * @return true if classpath has changed + */ + private boolean isClasspathChange(IJavaElementDelta delta) { + int flags= delta.getFlags(); + if (isClasspathChangeFlag(flags)) + return true; + + if ((flags & IJavaElementDelta.F_CHILDREN) != 0) { + IJavaElementDelta[] children= delta.getAffectedChildren(); + for (int i= 0; i < children.length; i++) { + if (isClasspathChangeFlag(children[i].getFlags())) + return true; + } + } + + return false; + } + + /** + * Do the flags indicate a classpath change? + * @param flags the flags to inspect + * @return true if the flag flags a classpath change + */ + private boolean isClasspathChangeFlag(int flags) { + if ((flags & IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED) != 0) + return true; + + if ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0) + return true; + + if ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) + return true; + + if ((flags & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0) + return true; + + return false; + } + } + + + /** + * Engine used to compute the proposals for this computer + */ + private final TemplateEngine fE4TemplateEngine; + private final TemplateEngine fE4MembersTemplateEngine; + private final TemplateEngine fE4StatementsTemplateEngine; + + /** + * The Java project of the compilation unit for which a template + * engine has been computed last time if any + */ + private IJavaProject fCachedJavaProject; + /** + * Is org.eclipse.e4.core.services.IDisposable on class path of <code>fJavaProject</code>. Invalid + * if <code>fJavaProject</code> is <code>false</code>. + */ + private boolean fIsE4OnClasspath; + + public E4TemplateCompletionProposalComputer() { + ContextTypeRegistry templateContextRegistry= JavaPlugin.getDefault().getTemplateContextRegistry(); + fE4TemplateEngine= createTemplateEngine(templateContextRegistry, E4ContextType.ID_ALL); + fE4MembersTemplateEngine= createTemplateEngine(templateContextRegistry, E4ContextType.ID_MEMBERS); + fE4StatementsTemplateEngine= createTemplateEngine(templateContextRegistry, E4ContextType.ID_STATEMENTS); + + JavaCore.addElementChangedListener(new BuildPathChangeListener()); + } + + private static TemplateEngine createTemplateEngine(ContextTypeRegistry templateContextRegistry, String contextTypeId) { + TemplateContextType contextType= templateContextRegistry.getContextType(contextTypeId); + Assert.isNotNull(contextType); + return new TemplateEngine(contextType); + } + + protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) { + ICompilationUnit unit= context.getCompilationUnit(); + if (unit == null) + return null; + + IJavaProject javaProject= unit.getJavaProject(); + if (javaProject == null) + return null; + + if (isE4OnClasspath(javaProject)) { + CompletionContext coreContext= context.getCoreContext(); + if (coreContext != null) { + int tokenLocation= coreContext.getTokenLocation(); + if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) { + return fE4MembersTemplateEngine; + } + if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) { + return fE4StatementsTemplateEngine; + } + } + return fE4TemplateEngine; + } + + return null; + } + + /** + * Tells whether E4 is on the given project's class path. + * + * @param javaProject the Java project + * @return <code>true</code> if the given project's class path + */ + private synchronized boolean isE4OnClasspath(IJavaProject javaProject) { + if (!javaProject.equals(fCachedJavaProject)) { + fCachedJavaProject= javaProject; + try { + IType type= javaProject.findType(E4_TYPE_NAME); + fIsE4OnClasspath= type != null; + } catch (JavaModelException e) { + fIsE4OnClasspath= false; + } + } + return fIsE4OnClasspath; + } + + /** + * Returns the cached Java project. + * + * @return the cached Java project or <code>null</code> if none + */ + private synchronized IJavaProject getCachedJavaProject() { + return fCachedJavaProject; + } + + /** + * Set the cached Java project. + * + * @param project or <code>null</code> to reset the cache + */ + private synchronized void setCachedJavaProject(IJavaProject project) { + fCachedJavaProject= project; + } + +} diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/templates/default-e4templates.properties b/bundles/org.eclipse.e4.tools.jdt.templates/templates/default-e4templates.properties new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/templates/default-e4templates.properties diff --git a/bundles/org.eclipse.e4.tools.jdt.templates/templates/default-e4templates.xml b/bundles/org.eclipse.e4.tools.jdt.templates/templates/default-e4templates.xml new file mode 100644 index 00000000..33dd0808 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.jdt.templates/templates/default-e4templates.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation 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: + * Boris Bokowski, IBM Corporation - initial API and implementation + *******************************************************************************/ +--> + +<templates> + +<template name="e4-parent" description="Injected Parent Composite" id="org.eclipse.e4.tools.jdt.templates.parent" context="e4-members" enabled="true" autoinsert="false">@Inject +Composite parent;</template> + +<template name="e4-preference" description="Injected Preference Value" id="org.eclipse.e4.tools.jdt.templates.preference" context="e4-members" enabled="true" autoinsert="false">@Inject +void setPreferenceValue(@Named("preference-PREFERENCE_KEY") String preferenceValue) { + ${cursor} +}</template> + +<template name="e4-adapter" description="Injected Adapter Service" id="org.eclipse.e4.tools.jdt.templates.adapter" context="e4-members" enabled="true" autoinsert="false">@Inject +Adapter adapter;</template> + +<template name="e4-preferences" description="Injected Preferences Service" id="org.eclipse.e4.tools.jdt.templates.preferences" context="e4-members" enabled="true" autoinsert="false">@Inject +IEclipsePreferences preferences;</template> + +<template name="e4-statushandler" description="Injected Status Handler" id="org.eclipse.e4.tools.jdt.templates.statushandler" context="e4-members" enabled="true" autoinsert="false">@Inject +IStatusHandler statusHandler;</template> + +<template name="e4-logger" description="Injected Logger" id="org.eclipse.e4.tools.jdt.templates.logger" context="e4-members" enabled="true" autoinsert="false">@Inject +Logger logger;</template> + +<template name="e4-eventbroker" description="Injected Event Broker" id="org.eclipse.e4.tools.jdt.templates.eventbroker" context="e4-members" enabled="true" autoinsert="false">@Inject +IEventBroker eventBroker;</template> + +<template name="e4-stylingengine" description="Injected Styling Engine" id="org.eclipse.e4.tools.jdt.templates.stylingengine" context="e4-members" enabled="true" autoinsert="false">@Inject +IStylingEngine stylingEngine;</template> + +<template name="e4-event" description="Event Handler Method" id="org.eclipse.e4.tools.jdt.templates.eventhandler" context="e4-members" enabled="true" autoinsert="false">@EventHandler("some/event/topic") +void handleSomeEvent(Payload payloadObject) { + ${cursor} +}</template> + +<template name="e4-init" description="Initialization Method" id="org.eclipse.e4.tools.jdt.templates.init" context="e4-members" enabled="true" autoinsert="false">@PostConstruct +void init() { + ${cursor} +}</template> + +<template name="e4-dispose" description="Dispose Method" id="org.eclipse.e4.tools.jdt.templates.dispose" context="e4-members" enabled="true" autoinsert="false">@PreDestroy +void dispose() { + ${cursor} +}</template> + +</templates> |