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.
Difference between revisions of "PDT/Dev2Dev/Semantic"
(→Component Requirements, Constraints, and Acceptance Criteria) |
(→the following semantic elements highlighting will be finished soon!) |
||
Line 125: | Line 125: | ||
and i have finished staticField and staticMethodInvocation highlighting. | and i have finished staticField and staticMethodInvocation highlighting. | ||
− | = the following semantic elements highlighting will be finished soon! = | + | ==== the following semantic elements highlighting will be finished soon! ==== |
StaticFinalFieldHighlighting | StaticFinalFieldHighlighting |
Revision as of 07:41, 16 April 2009
Contents
Semantic Highlighting
Overview
Following the improvements done by the Web tools project (232752) on semantic highlighting, the PHP Source Editor can now set semantic rules for better coloring techniques that will improve its performance and functionality. For example, currently, all variables are highlighted in the same color. Although members / static / constants variables should be colored in separate colors just like the Java editor does.
Each semantic rule should have a preference page which describes its rule color and functionality.
References
jdt semantic highlighting
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:
public static final SemanticHighlightingType StaticFieldHighlightingType = new SemanticHighlightingType(STATIC_FIELD);
SemanticHighlightingType have another constructor
public SemanticHighlightingType(String preferenceKey,boolean boldByDefault, boolean italicByDefault,boolean strikethroughByDefault,boolean underlineByDefault,RGB defaultTextColor)
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:
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); }
of course,you can subclass SemanticHighlightingType class to get more flexible default values.
2. in the method getSemanticHighlightingMap() of SemanticHighlightings,add the following statement.
semanticHighlightingMap.put(StaticFieldHighlightingType.getPreferenceKey(), StaticFieldHighlightingType);
3. of course you have to extend the extension "org.eclipse.wst.sse.ui.semanticHighlighting" in your plugin.xml
<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>
4. the StaticFieldHighlighting class in plugin.xml, StaticFieldHighlighting is implemented as following:
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; } }
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!
StaticFinalFieldHighlighting
FieldHighlighting
MethodDeclarationHighlighting
AbstractMethodInvocationHighlighting
InheritedMethodInvocationHighlighting
ParameterVariableHighlighting
LocalVariableDeclarationHighlighting
LocalVariableHighlighting
MethodHighlighting
ClassHighlighting
InterfaceHighlighting
NumberHighlighting