Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Recommenders/Attic/Templates"

(New sequence diagram added)
Line 1: Line 1:
 
== Introduction to Templates Completion ==
 
== Introduction to Templates Completion ==
  
This page will soon contain in-detail information about the Code Recommenders Template Completion plugin and how it can be used, maintained and extended by developers.
+
This page contains in-detail information about the Code Recommenders Template Completion plug-in and how it can be used, maintained and extended by developers.
  
For the rest of this introduction we will present a short scenario which helps the developer to understand the major tasks and possible obstacles.
+
For the rest of this introduction we will present a short scenario which helps the developer to understand the major tasks and possible obstacles in generating templates.
In the following we will present the general [[#Architecture]] of the plugin by giving an overview of its components in [[#Components Overview]] and how they interact in [[#General Workflow]].
+
In the following we will present the general [[#Architecture]] of the plug-in by giving an overview of its components in [[#Components Overview]] and how they interact in [[#General Workflow]].
We will further explain the most [[#Important Concepts]] which further helps understanding the system and are vital to know for working on the plugin.
+
We will further explain the most [[#Important Concepts]] which further helps understanding the system and are vital to know for working on the plug-in.
  
 
=== Functionality ===
 
=== Functionality ===
  
Here we will give a short illustration about the main goals of this plugin.
+
Eclipse has a built-in templates engine which allows the user to define frequently used code snippets and to insert them with just a few clicks.
 +
For a better adaption several variables can be included for dynamical content. An overview is given by the [http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.user/concepts/concept-template-variables.htm Eclipse help pages].
 +
However, as the following example for creating an SWT button object illustrates, designing templates can be difficult and time-consuming.
  
 
; Default Eclipse SWT template for a new button:
 
; Default Eclipse SWT template for a new button:
Line 19: Line 21:
 
</source>
 
</source>
  
The task of this Plugin is to dynamically construct such templates depending on the context, i.e. depending on at which position completion was triggered (e.g. Button b<^Space>) and what has already been done with the observed variable, and the information about frequent patterns in such a context, as obtained from other [[Recommenders]] components.
+
Therefore the Eclipse Recommenders Templates plug-in aims to automatically create such templates for (a) providing useful shortcuts to frequently written code and (b) to populate common practices which help new users to learn how frameworks are used.
 +
However, much from the context of the completion request can influence the decision about how to (further) progress with an object, which is why presenting appropriate and well-adaptive templates is non-trivial.
 +
 
 +
The following illustrates several obstacles in one example.
 +
First, the declaration of b is not within the direct scope of the completion request, it's defined outside the method.
 +
Second, there has already been methods called, so we shouldn't, for example, include a new constructor (it's not common for this scenario).
 +
Third, "b" has not been qualified with a dot ("b.") when triggering the request.
 +
 
 +
; Default Eclipse SWT template for a new button:
 +
<source lang="java">
 +
private Button b;
 +
 
 +
private void doSomething(){
 +
  b = new Button(null, 0);
 +
  b.setText("...");
 +
  b<^Space>
 +
}
 +
</source>
  
 
== Architecture ==
 
== Architecture ==

Revision as of 07:20, 18 March 2011

Introduction to Templates Completion

This page contains in-detail information about the Code Recommenders Template Completion plug-in and how it can be used, maintained and extended by developers.

For the rest of this introduction we will present a short scenario which helps the developer to understand the major tasks and possible obstacles in generating templates. In the following we will present the general #Architecture of the plug-in by giving an overview of its components in #Components Overview and how they interact in #General Workflow. We will further explain the most #Important Concepts which further helps understanding the system and are vital to know for working on the plug-in.

Functionality

Eclipse has a built-in templates engine which allows the user to define frequently used code snippets and to insert them with just a few clicks. For a better adaption several variables can be included for dynamical content. An overview is given by the Eclipse help pages. However, as the following example for creating an SWT button object illustrates, designing templates can be difficult and time-consuming.

Default Eclipse SWT template for a new button
${buttonType:newType(org.eclipse.swt.widgets.Button)} ${button:newName(org.eclipse.swt.widgets.Button)}= new ${buttonType}(${parent:var(org.eclipse.swt.widgets.Composite)}, ${style:link(SWT.PUSH, SWT.TOGGLE, SWT.RADIO, SWT.CHECK, SWT.FLAT)});
${button}.setLayoutData(new ${type:newType(org.eclipse.swt.layout.GridData)}(SWT.${horizontal:link(BEGINNING, CENTER, END, FILL)}, SWT.${vertical:link(CENTER, TOP, BOTTOM, FILL)}, ${hex:link(false, true)}, ${vex:link(false, true)}));
${button}.setText(${word_selection}${});
${imp:import(org.eclipse.swt.SWT)}${cursor}

Therefore the Eclipse Recommenders Templates plug-in aims to automatically create such templates for (a) providing useful shortcuts to frequently written code and (b) to populate common practices which help new users to learn how frameworks are used. However, much from the context of the completion request can influence the decision about how to (further) progress with an object, which is why presenting appropriate and well-adaptive templates is non-trivial.

The following illustrates several obstacles in one example. First, the declaration of b is not within the direct scope of the completion request, it's defined outside the method. Second, there has already been methods called, so we shouldn't, for example, include a new constructor (it's not common for this scenario). Third, "b" has not been qualified with a dot ("b.") when triggering the request.

Default Eclipse SWT template for a new button
private Button b;
 
private void doSomething(){
   b = new Button(null, 0);
   b.setText("...");
   b<^Space>
}

Architecture

Dependencies between components

This section will contain a general overview about the whole plugin and how its components interact. First, a diagram describing the structure and the dependencies between the components is displayed on the right. Second, each component of the Plugin is given along with a short description. Finally, the default sequence of components interaction is displayed.

Components Overview

This subsection will give a short description of each component and display the dependencies between them.

Table of Plugin components and short description of their roles.
Package / Class Description
.templates Main components of the Plugins, control interaction.
CompletionProposalsBuilder Transforms PatternRecommendations into IJavaCompletionProposals which are applied on the editor content when the propoals is selected from the completion proposals menu.
CompletionTargetVariableBuilder Extracts the CompletionTargetVariable from an IIntelligentCompletionContext.
PatternRecommender Computes PatternRecommendations from the CallsModelStore.
TemplatesCompletionModule Prepares the Plugin by injecting dependencies.
TemplatesCompletionProposalComputer Controls the process of template recommendations.
TemplatesPlugin Stores the Plugin's instance while it is started.
.templates.code Components for transforming our information into Eclipse templates code.
CodeBuilder Builds Eclipse templates code from a list of method calls on a given variable name.
MethodCallFormatter Generates the String representation of a MethodCall.
MethodFormatter Generates the String representation of an IMethod.
.templates.types Encapsulates certain information. Only used by this Plugin.
CompletionTargetVariable Models the variable on which the completion was triggered.
JavaTemplateProposal Extends the TemplateProposal to customize the style of the template's entry in the completion popup.
MethodCall Models a call of a certain method on a given variable name.
PatternRecommendation Encapsulates one recommendation received from the models store.

General Workflow

In this subsection we will illustrate how the components interact when responding to a completion request.

Regular computation of templates

Important Concepts

This section will consider how the most important components work in detail.

Target Variables

This subsection will explain what information we need for template proposals in how it is encapsulated.

Pattern Recommender

Here we will explain how the pattern recommender communicates which other plugins of the code recommenders system to obtain relevant patterns.

Code Builder

This subsection will shortly illustrate how Eclipse templates work and how we generate them from our mined patterns.

Back to the top