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 "PDT/Dev2Dev/Semantic"

< PDT
(Component Requirements, Constraints, and Acceptance Criteria)
(Component Requirements, Constraints, and Acceptance Criteria)
Line 27: Line 27:
 
3. of course you have to extend the extension "org.eclipse.wst.sse.ui.semanticHighlighting" in your plugin.xml
 
3. of course you have to extend the extension "org.eclipse.wst.sse.ui.semanticHighlighting" in your plugin.xml
 
<pre>
 
<pre>
<extension point="org.eclipse.wst.sse.ui.semanticHighlighting">
+
<extension point="org.eclipse.wst.sse.ui.semanticHighlighting">
 
<highlighting
 
<highlighting
 
         class="org.eclipse.php.internal.ui.editor.highlighting.StaticFieldHighlighting"
 
         class="org.eclipse.php.internal.ui.editor.highlighting.StaticFieldHighlighting"
 
         target="org.eclipse.php.core.phpsource">
 
         target="org.eclipse.php.core.phpsource">
 
</highlighting>
 
</highlighting>
</extension>
+
</extension>
 
</pre>
 
</pre>
 
4. the StaticFieldHighlighting class in plugin.xml, StaticFieldHighlighting is implemented as following:
 
4. the StaticFieldHighlighting class in plugin.xml, StaticFieldHighlighting is implemented as following:

Revision as of 03:23, 16 April 2009

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);

2. in the method getSemanticHighlightingStrings() of SemanticHighlightings,add the following statement.

fgSemanticHighlightingStrings.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.

Index Classes

API

Back to the top