|
|
Line 44: |
Line 44: |
| </source> | | </source> |
| | | |
− | === UI === | + | === UI === |
| | | |
| The rules are automatically added to the Syntax Coloring preference page: | | The rules are automatically added to the Syntax Coloring preference page: |
Line 54: |
Line 54: |
| [[Image:pdt_semantic_editor.png]] | | [[Image:pdt_semantic_editor.png]] |
| | | |
− | === References === | + | === Performances === |
− | jdt semantic highlighting
| + | Work in progress... |
− | | + | |
− | wtp semantic highlighting
| + | |
− | | + | |
− | === Component Requirements, Constraints, and Acceptance Criteria ===
| + | |
− | | + | |
− | i did some fundamental work and added some basic classes.
| + | |
− | | + | |
− | so add a semantic highlighting can be done by the following steps:
| + | |
− | | + | |
− | 1. add a SemanticHighlightingType type constant in class SemanticHighlightings. for example:
| + | |
− | <pre>
| + | |
− | public static final SemanticHighlightingType StaticFieldHighlightingType = new SemanticHighlightingType(STATIC_FIELD);
| + | |
− | </pre>
| + | |
− | SemanticHighlightingType have another constructor
| + | |
− | <pre>
| + | |
− | public SemanticHighlightingType(String preferenceKey,boolean boldByDefault,
| + | |
− | boolean italicByDefault,boolean strikethroughByDefault,boolean underlineByDefault,RGB defaultTextColor)
| + | |
− | </pre>
| + | |
− | so default values can be set using this constructor .
| + | |
− | if useing the first constructor.all the boolean value are setting to false.and the defaultTextColor depands on the findRGB mothed:
| + | |
− | | + | |
− | <pre>
| + | |
− | private static RGB findRGB(String key, RGB defaultRGB) {
| + | |
− | if (!PlatformUI.isWorkbenchRunning())
| + | |
− | return defaultRGB;
| + | |
− | | + | |
− | ColorRegistry registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
| + | |
− | RGB rgb = registry.getRGB(key);
| + | |
− | if (rgb != null)
| + | |
− | return rgb;
| + | |
− | return defaultRGB;
| + | |
− | }
| + | |
− | | + | |
− | private String getThemeColorKey() {
| + | |
− | return PHPUiPlugin.ID + "." + getPreferenceKey() + "Highlighting"; //$NON-NLS-1$//$NON-NLS-2$
| + | |
− | }
| + | |
− | | + | |
− | protected RGB getDefaultDefaultTextColor() {
| + | |
− | return new RGB(0, 0, 0);
| + | |
− | }
| + | |
− | </pre>
| + | |
− | of course,you can subclass SemanticHighlightingType class to get more flexible default values.
| + | |
− | | + | |
− | 2. in the method getSemanticHighlightingMap() of SemanticHighlightings,add the following statement.
| + | |
− | <pre>
| + | |
− | semanticHighlightingMap.put(StaticFieldHighlightingType.getPreferenceKey(), StaticFieldHighlightingType);
| + | |
− | </pre>
| + | |
− | 3. of course you have to extend the extension "org.eclipse.wst.sse.ui.semanticHighlighting" in your plugin.xml
| + | |
− | <pre>
| + | |
− | <extension point="org.eclipse.wst.sse.ui.semanticHighlighting">
| + | |
− | <highlighting
| + | |
− | class="org.eclipse.php.internal.ui.editor.highlighting.StaticFieldHighlighting"
| + | |
− | target="org.eclipse.php.core.phpsource">
| + | |
− | </highlighting>
| + | |
− | </extension>
| + | |
− | </pre>
| + | |
− | 4. the StaticFieldHighlighting class in plugin.xml, StaticFieldHighlighting is implemented as following:
| + | |
− | <pre>
| + | |
− | package org.eclipse.php.internal.ui.editor.highlighting;
| + | |
− | | + | |
− | import org.eclipse.php.internal.core.ast.nodes.*;
| + | |
− | import org.eclipse.php.internal.ui.editor.SemanticHighlightingType;
| + | |
− | import org.eclipse.php.internal.ui.editor.SemanticHighlightings;
| + | |
− | | + | |
− | public class StaticFieldHighlighting extends AbstractSemanticHighlighting {
| + | |
− | | + | |
− | protected class StaticFieldApply extends AbstractSemanticApply{
| + | |
− | @Override
| + | |
− | public boolean visit(Variable variable) {
| + | |
− | // TODO Auto-generated method stub
| + | |
− | if(variable.getParent() instanceof SingleFieldDeclaration){
| + | |
− | SingleFieldDeclaration singleFieldDeclaration = (SingleFieldDeclaration)variable.getParent();
| + | |
− | if(singleFieldDeclaration.getParent() instanceof FieldsDeclaration){
| + | |
− | FieldsDeclaration fieldsDeclaration = (FieldsDeclaration)
| + | |
− | | + | |
− | singleFieldDeclaration.getParent();
| + | |
− | if((fieldsDeclaration.getModifier() & Modifier.STATIC) != 0){
| + | |
− | addASTNode(variable);
| + | |
− | }
| + | |
− | }
| + | |
− | }else if(variable.getParent() instanceof StaticFieldAccess){
| + | |
− | addASTNode(variable);
| + | |
− | }else if(variable.getParent() instanceof ArrayAccess){
| + | |
− | if(((ArrayAccess)variable.getParent()).getName() == variable){
| + | |
− | addASTNode(variable);
| + | |
− | }
| + | |
− | }
| + | |
− | return super.visit(variable);
| + | |
− | }
| + | |
− | }
| + | |
− | | + | |
− | @Override
| + | |
− | public AbstractSemanticApply getSemanticApply() {
| + | |
− | return new StaticFieldApply();
| + | |
− | }
| + | |
− | | + | |
− | @Override
| + | |
− | public SemanticHighlightingType getSemanticHighlightingType() {
| + | |
− | // TODO Auto-generated method stub
| + | |
− | return SemanticHighlightings.StaticFieldHighlightingType;
| + | |
− | }
| + | |
− | }
| + | |
− | | + | |
− | </pre>
| + | |
− | in StaticFieldHighlighting ,you have to implement two methods,getSemanticHighlightingType() and getSemanticApply().
| + | |
− | getSemanticHighlightingType() returns what you just added in
| + | |
− | SemanticHighlightings class.
| + | |
− | getSemanticApply() return a subclass of AbstractSemanticApply .here is StaticFieldApply which you must implement yourself.and the stuff is done in StaticFieldApply ,override the corresponding visit methods to find out the ASTNode which will be highlighted,and call the method addASTNode(ASTNode node) defined in AbstractSemanticApply .
| + | |
− | | + | |
− | | + | |
− | so that is all.
| + | |
− | | + | |
− | | + | |
− | i will talk about the fundamental work and the basic classes i added soon.
| + | |
− | | + | |
− | and i have finished staticField and staticMethodInvocation highlighting.
| + | |
− | | + | |
− | ==== the following semantic elements highlighting will be finished soon! ====
| + | |
− | | + | |
− | | + | |
− | ConstantHighlighting
| + | |
− | | + | |
− | FieldHighlighting
| + | |
− | | + | |
− | MethodDeclarationHighlighting
| + | |
− | | + | |
− | AbstractMethodInvocationHighlighting
| + | |
− | | + | |
− | InheritedMethodInvocationHighlighting
| + | |
− | | + | |
− | ParameterVariableHighlighting
| + | |
− | | + | |
− | ClassHighlighting
| + | |
− | | + | |
− | InterfaceHighlighting
| + | |
− | | + | |
− | === Index Classes ===
| + | |
− | | + | |
− | | + | |
− | === API ===
| + | |
The PHP semantic highlighting API is used to define semantic rules for PHP coloring. It's also useful for plugin developpers who would like to extends PHP highlighting with specific semantic rules.
target. By using the PHP source target, PHP UI plugin is automatically registering this contributor as a semantic highlighter.
<extension point="org.eclipse.wst.sse.ui.semanticHighlighting">
<highlighting
class="org.eclipse.php.internal.ui.editor.highlighting.ParameterVariableHighlighting"
target="org.eclipse.php.core.phpsource">
</highlighting>
</extension>
.
public class ParameterVariableHighlighting extends AbstractSemanticHighlighting {
@Override
public AbstractSemanticApply getSemanticApply() {
return new ParameterVariableApply();
}
@Override
public void initDefaultPreferences() {
getStyle().setUnderlineByDefault(true)
.setDefaultTextColor(new RGB(102, 0, 0));
}
public String getDisplayName() {
return "Local variables";
}
}
Since some rules might be conflicting between each other, you can define the priority rules. For instance, the InternalClassHighlighting rule has to override the ClassHighlighting rule. You can use the
annotation to define the application order of the semantic rules.
@HighlightingPriority(Priority.HIGH)
public class InternalClassHighlighting extends AbstractSemanticHighlighting {
Work in progress...