diff options
Diffstat (limited to 'bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style')
15 files changed, 0 insertions, 1524 deletions
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/IStyleConstantsJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/IStyleConstantsJSP.java deleted file mode 100644 index 2b81bf80d4..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/IStyleConstantsJSP.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.style; - -public interface IStyleConstantsJSP { - public static final String JSP_CONTENT = "jsp_content"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/LineStyleProviderForJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/LineStyleProviderForJSP.java deleted file mode 100644 index 68e8e3de3c..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/LineStyleProviderForJSP.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 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 - * Frits Jalvingh - contributions for bug 150794 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.html.ui.internal.style.IStyleConstantsHTML; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -public class LineStyleProviderForJSP extends AbstractLineStyleProvider implements LineStyleProvider{ - - private String fLanguage = null; - - // private static final String JAVA = "java"; //$NON-NLS-1$ - // private static final String[] JAVASCRIPT_LANGUAGE_KEYS = new String[] { - // "javascript", "javascript1.0", "javascript1.1_3", "javascript1.2", - // "javascript1.3", "javascript1.4", "javascript1.5", "javascript1.6", - // "jscript", "sashscript" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ - // //$NON-NLS-9$ //$NON-NLS-10$ - - public LineStyleProviderForJSP() { - super(); - } - - protected TextAttribute getAttributeFor(ITextRegion region) { - /** - * a method to centralize all the "sytle rules" for regions - */ - TextAttribute result = null; - // not sure why this is coming through null, but just to catch it - if (region == null) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } - else { - - if (result == null) { - String type = region.getType(); - if ((type == DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN) || (type == DOMJSPRegionContexts.JSP_DECLARATION_OPEN) || (type == DOMJSPRegionContexts.JSP_EXPRESSION_OPEN) || (type == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) || (type == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE) || (type == DOMJSPRegionContexts.JSP_CLOSE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - } - else if (type == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME || type == DOMJSPRegionContexts.JSP_ROOT_TAG_NAME) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } - else if ((type == DOMJSPRegionContexts.JSP_COMMENT_OPEN) || (type == DOMJSPRegionContexts.JSP_COMMENT_CLOSE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_BORDER); - } - else if (type == DOMJSPRegionContexts.JSP_COMMENT_TEXT) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_TEXT); - } - // ============ These are in common with XML --- (for XML form - // of tags) - // Note: this assume's this provider is only called for - // true JSP Nodes. If its called for others, then this will - // cause their tag names to be highlighted too! - // Further checks could be done to prevent that, but doesn't - // seem worth it, since if adpaters factories are working - // right, - // then wouldn't be needed. - else if (type == DOMRegionContext.XML_TAG_NAME) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } - else if ((type == DOMRegionContext.XML_TAG_OPEN) || (type == DOMRegionContext.XML_END_TAG_OPEN) || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_BORDER); - } - else if (type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - } - else if ((type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) || (type == DOMJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_DQUOTE) || (type == DOMJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_SQUOTE)|| (type == DOMJSPRegionContexts.JSP_TAG_ATTRIBUTE_VALUE_DQUOTE) || (type == DOMJSPRegionContexts.JSP_TAG_ATTRIBUTE_VALUE_SQUOTE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - } - else if (type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS); - } - - // DMW: added 9/1/2002 Undefined color may need addjustment :) - else if (type == DOMRegionContext.UNDEFINED) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - - else if (type == DOMRegionContext.WHITE_SPACE) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - // DMW added 8/30/2002 -- should provide JSP specific - // preference for "custom tag content" (both tag dependent, - // BLOCKED_TEXT, and not, XML CONTENT) - else if (type == DOMRegionContext.XML_CONTENT) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - else if (type == DOMRegionContext.BLOCK_TEXT) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } - } - // default, return null to signal "not handled" - // in which case, other factories should be tried - return result; - } - - - protected IPreferenceStore getColorPreferences() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } - - protected void loadColors() { - addTextAttribute(IStyleConstantsXML.TAG_NAME); - addTextAttribute(IStyleConstantsXML.TAG_BORDER); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS); - addTextAttribute(IStyleConstantsXML.COMMENT_BORDER); - addTextAttribute(IStyleConstantsXML.COMMENT_TEXT); - addTextAttribute(IStyleConstantsXML.CDATA_BORDER); - addTextAttribute(IStyleConstantsXML.CDATA_TEXT); - addTextAttribute(IStyleConstantsXML.DECL_BORDER); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - addTextAttribute(IStyleConstantsXML.DOCTYPE_NAME); - addTextAttribute(IStyleConstantsXML.PI_CONTENT); - addTextAttribute(IStyleConstantsXML.PI_BORDER); - addTextAttribute(IStyleConstantsXML.XML_CONTENT); - addTextAttribute(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - String styleKey = null; - - if (event != null) { - String prefKey = event.getProperty(); - // check if preference changed is a style preference - if (IStyleConstantsXML.TAG_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_NAME; - } - else if (IStyleConstantsXML.TAG_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_BORDER; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_NAME; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_VALUE.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_VALUE; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS; - } - else if (IStyleConstantsXML.COMMENT_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_BORDER; - } - else if (IStyleConstantsXML.COMMENT_TEXT.equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_TEXT; - } - else if (IStyleConstantsXML.CDATA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_BORDER; - } - else if (IStyleConstantsXML.CDATA_TEXT.equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_TEXT; - } - else if (IStyleConstantsXML.DECL_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.DECL_BORDER; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF; - } - else if (IStyleConstantsXML.DOCTYPE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_NAME; - } - else if (IStyleConstantsXML.PI_CONTENT.equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_CONTENT; - } - else if (IStyleConstantsXML.PI_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_BORDER; - } - else if (IStyleConstantsXML.XML_CONTENT.equals(prefKey)) { - styleKey = IStyleConstantsXML.XML_CONTENT; - } - else if (IStyleConstantsHTML.SCRIPT_AREA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsHTML.SCRIPT_AREA_BORDER; - } - } - - if (styleKey != null) { - // overwrite style preference with new value - addTextAttribute(styleKey); - super.handlePropertyChange(event); - } - } - - /** - * Returns the language. - * - * @return String - */ - public String getLanguage() { - return fLanguage; - } - - /** - * Sets the language. - * - * @param language - * The language to set - */ - public void setLanguage(String language) { - this.fLanguage = language; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/DoubleQuotedStringRule.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/DoubleQuotedStringRule.java deleted file mode 100644 index eabb960039..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/DoubleQuotedStringRule.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Frits Jalvingh 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: - * Frits Jalvingh - initial version (bugfix for 150794) - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.java; - -import org.eclipse.jface.text.rules.ICharacterScanner; -import org.eclipse.jface.text.rules.IPredicateRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; - -/** - * This rule matches the double-quoted strings present in JSP tag attributes. A double-quoted - * strings starts with \" (two characters!) and ends with \" (two characters!) too. The sequence - * \" is escaped by the horror \\\" (4 chars!?) as per the JSP spec. - * - * @author <a href="mailto:jal@etc.to">Frits Jalvingh</a> - * Created on Aug 5, 2007 - */ -public class DoubleQuotedStringRule implements IPredicateRule { - private IToken fToken; - private int m_qc; - - public DoubleQuotedStringRule(IToken tok) { - fToken = tok; - } - public IToken evaluate(ICharacterScanner scanner, boolean resume) { - if(resume) { - if(findEnd(scanner, m_qc)) - return fToken; - } else { - int c= scanner.read(); - if(c == '\\') { - c = scanner.read(); - if(c == '"' || c == '\'') { - if(findEnd(scanner, c)) - return fToken; - } - scanner.unread(); - } - scanner.unread(); - } - return Token.UNDEFINED; - } - - private boolean findEnd(ICharacterScanner scanner, int qc) { - m_qc = qc; - int count = 0; - int c; - int nsl = 0; - while((c= scanner.read()) != ICharacterScanner.EOF) { - count++; - if(c == '\\') { - nsl++; - if(nsl >= 4) - nsl = 0; - } else if(c == qc) { - if(nsl == 1) - return true; - nsl = 0; - } else - nsl= 0; - } - while(--count >= 0) - scanner.unread(); - return false; - } - - public IToken getSuccessToken() { - return fToken; - } - - public IToken evaluate(ICharacterScanner scanner) { - return evaluate(scanner, false); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/IStyleConstantsJSPJava.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/IStyleConstantsJSPJava.java deleted file mode 100644 index 9725028f04..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/IStyleConstantsJSPJava.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - *******************************************************************************/ - -package org.eclipse.jst.jsp.ui.internal.style.java; - -public interface IStyleConstantsJSPJava { - String JAVA_KEYWORD = "keyword"; //$NON-NLS-1$ - String JAVA_SINGLE_LINE_COMMENT = "single_line_comment"; //$NON-NLS-1$ - String JAVA_STRING = "string"; //$NON-NLS-1$ - String JAVA_DEFAULT = "default"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaCodeScanner.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaCodeScanner.java deleted file mode 100644 index 9d6c26eb60..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaCodeScanner.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 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 - * Frits Jalvingh - contributions for bug 150794 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.java; - - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.rules.EndOfLineRule; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.MultiLineRule; -import org.eclipse.jface.text.rules.SingleLineRule; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.rules.WordRule; - -/** - * A Java code scanner. - */ -class JavaCodeScanner extends org.eclipse.jface.text.rules.RuleBasedScanner { - private IToken fKeywordToken; - private IToken fTypeToken; - private IToken fStringToken; - private IToken fSingleLineCommentToken; - private IToken fDefaultToken; - - private static String[] fgKeywords = {"abstract", //$NON-NLS-1$ - "break", //$NON-NLS-1$ - "case", "catch", "class", "continue", //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "default", "do", //$NON-NLS-2$//$NON-NLS-1$ - "else", "extends", //$NON-NLS-2$//$NON-NLS-1$ - "final", "finally", "for", //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "if", "implements", "import", "instanceof", "interface", //$NON-NLS-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "native", "new", //$NON-NLS-2$//$NON-NLS-1$ - "package", "private", "protected", "public", //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "return", //$NON-NLS-1$ - "static", "super", "switch", "synchronized", //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "this", "throw", "throws", "transient", "try", //$NON-NLS-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "volatile", //$NON-NLS-1$ - "while", //$NON-NLS-1$ - "strictfp",//$NON-NLS-1$ - }; - private static String[] fgTypes = {"void", "boolean", "char", "byte", "short", "int", "long", "float", "double"};//$NON-NLS-9$//$NON-NLS-8$//$NON-NLS-7$//$NON-NLS-6$//$NON-NLS-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - private static String[] fgConstants = {"false", "null", "true"};//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - - /** - * Creates a Java code scanner - */ - public JavaCodeScanner() { - super(); - } - - public void initializeRules() { - List rules = new ArrayList(); - - // Add rule for multiple line comments. - rules.add(new MultiLineRule("/*", "*/", fSingleLineCommentToken));//$NON-NLS-1$ //$NON-NLS-2$ - - // Add rule for single line comments. - rules.add(new EndOfLineRule("//", fSingleLineCommentToken));//$NON-NLS-1$ - - // Add rule for strings and character constants. - rules.add(new SingleLineRule("\"", "\"", fStringToken, '\\'));//$NON-NLS-2$//$NON-NLS-1$ - rules.add(new SingleLineRule("'", "'", fStringToken, '\\'));//$NON-NLS-2$//$NON-NLS-1$ - - // Add generic whitespace rule. - //rules.add(new WhitespaceRule(new JavaWhitespaceDetector())); - - // Add word rule for keywords, types, and constants. - WordRule wordRule = new WordRule(new JavaWordDetector(), fDefaultToken); - for (int i = 0; i < fgKeywords.length; i++) - wordRule.addWord(fgKeywords[i], fKeywordToken); - for (int i = 0; i < fgTypes.length; i++) - wordRule.addWord(fgTypes[i], fTypeToken); - for (int i = 0; i < fgConstants.length; i++) - wordRule.addWord(fgConstants[i], fTypeToken); - rules.add(wordRule); - - // Add the double-quoted string rule - rules.add(new DoubleQuotedStringRule(fStringToken)); - - IRule[] result = new IRule[rules.size()]; - rules.toArray(result); - setRules(result); - } - - public void setTokenData(String tokenKey, Object data) { - if (tokenKey == IStyleConstantsJSPJava.JAVA_KEYWORD) { - fKeywordToken = new Token(data); - fTypeToken = new Token(data); - } else if (tokenKey == IStyleConstantsJSPJava.JAVA_STRING) { - fStringToken = new Token(data); - } else if (tokenKey == IStyleConstantsJSPJava.JAVA_SINGLE_LINE_COMMENT) { - fSingleLineCommentToken = new Token(data); - } else if (tokenKey == IStyleConstantsJSPJava.JAVA_DEFAULT) { - fDefaultToken = new Token(data); - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaColorProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaColorProvider.java deleted file mode 100644 index d943561425..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaColorProvider.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.java; - -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.RGB; - -/** - * Colors used in the Java editor - */ -public class JavaColorProvider { - - // people should not be setting these, even though they are currently not final - public static RGB MULTI_LINE_COMMENT = new RGB(128, 0, 0); - public static RGB SINGLE_LINE_COMMENT = new RGB(128, 128, 0); - public static RGB KEYWORD = new RGB(0, 0, 128); - public static RGB TYPE = new RGB(0, 0, 128); - public static RGB STRING = new RGB(0, 128, 0); - public static RGB DEFAULT = new RGB(0, 0, 0); - public static RGB JAVADOC_KEYWORD = new RGB(0, 128, 0); - public static RGB JAVADOC_TAG = new RGB(128, 128, 128); - public static RGB JAVADOC_LINK = new RGB(128, 128, 128); - public static RGB JAVADOC_DEFAULT = new RGB(0, 128, 128); - - public static int MULTI_LINE_COMMENT_BOLD = SWT.NORMAL; - public static int SINGLE_LINE_COMMENT_BOLD = SWT.NORMAL; - public static int KEYWORD_BOLD = SWT.BOLD; - public static int TYPE_BOLD = SWT.BOLD; - public static int STRING_BOLD = SWT.NORMAL; - public static int DEFAULT_BOLD = SWT.NORMAL; - public static int JAVADOC_KEYWORD_BOLD = SWT.BOLD; - public static int JAVADOC_TAG_BOLD = SWT.NORMAL; - public static int JAVADOC_LINK_BOLD = SWT.NORMAL; - public static int JAVADOC_DEFAULT_BOLD = SWT.NORMAL; - - private static JavaColorProvider fInstance = null; - - public static JavaColorProvider getInstance() { - if (fInstance == null) { - fInstance = new JavaColorProvider(); - } - return fInstance; - } - - /** - * Use colors from JDT plugin - */ - public void loadJavaColors() { - IPreferenceStore jdtStore = PreferenceConstants.getPreferenceStore(); - MULTI_LINE_COMMENT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR); - SINGLE_LINE_COMMENT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR); - KEYWORD = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR); - TYPE = KEYWORD; - STRING = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_STRING_COLOR); - DEFAULT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR); - JAVADOC_KEYWORD = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR); - JAVADOC_TAG = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR); - JAVADOC_LINK = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR); - JAVADOC_DEFAULT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR); - - MULTI_LINE_COMMENT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD) ? SWT.BOLD : SWT.NORMAL; - SINGLE_LINE_COMMENT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD) ? SWT.BOLD : SWT.NORMAL; - KEYWORD_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD) ? SWT.BOLD : SWT.NORMAL; - TYPE_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD) ? SWT.BOLD : SWT.NORMAL; - STRING_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_STRING_BOLD) ? SWT.BOLD : SWT.NORMAL; - DEFAULT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_TAG_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_TAG_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_LINK_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_LINKS_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_DEFAULT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_DEFAULT_BOLD) ? SWT.BOLD : SWT.NORMAL; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaWhitespaceDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaWhitespaceDetector.java deleted file mode 100644 index 381893e74d..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaWhitespaceDetector.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.java; - - - -/** - * A java aware white space detector. - */ -public class JavaWhitespaceDetector implements org.eclipse.jface.text.rules.IWhitespaceDetector { - - /** - * @see org.eclipse.jface.text.rules.IWhitespaceDetector#isWhitespace - */ - public boolean isWhitespace(char c) { - return Character.isWhitespace(c); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaWordDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaWordDetector.java deleted file mode 100644 index 77fe762368..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/JavaWordDetector.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.java; - - -/** - * A Java aware word detector. - */ -public class JavaWordDetector implements org.eclipse.jface.text.rules.IWordDetector { - - /** - * @see org.eclipse.jface.text.rules.IWordDetector#isWordIdentifierPart - */ - public boolean isWordPart(char c) { - return Character.isJavaIdentifierPart(c); - } - - /** - * @see org.eclipse.jface.text.rules.IWordDetector#isWordIdentifierStart - */ - public boolean isWordStart(char c) { - return Character.isJavaIdentifierStart(c); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/LineStyleProviderForJava.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/LineStyleProviderForJava.java deleted file mode 100644 index a41e055d7b..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/java/LineStyleProviderForJava.java +++ /dev/null @@ -1,349 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 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 - * Frits Jalvingh - contributions for bug 150794 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.java; - -import java.util.Collection; -import java.util.HashMap; - -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.style.IStyleConstantsJSP; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; -import org.eclipse.wst.html.ui.internal.style.IStyleConstantsHTML; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; -import org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.sse.ui.internal.util.EditorUtility; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -// Note: many of the methods in this class were based on (or copied from) those -// found in the example Java Editor -public class LineStyleProviderForJava implements LineStyleProvider{ - private class PropertyChangeListener implements IPropertyChangeListener { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) - */ - public void propertyChange(PropertyChangeEvent event) { - // have to do it this way so others can override the method - handlePropertyChange(event); - } - } - - private IDocument fDocument; - private Highlighter fHighlighter; - private boolean fIsInitialized = false; - private PropertyChangeListener fPreferenceListener = new PropertyChangeListener(); - /** The scanner it uses */ - private JavaCodeScanner fScanner; - /** Contains all text attributes pretaining to this line style provider */ - private HashMap fTextAttributes = null; - - public LineStyleProviderForJava() { - super(); - fScanner = new JavaCodeScanner(); - loadColors(); // Make sure we have rules before we start parsing - } - - /** - * Adds style information to the given text presentation. - * - * @param presentation the text presentation to be extended - * @param offset the offset of the range to be styled - * @param length the length of the range to be styled - * @param attr the attribute describing the style of the range to be styled - */ - private void addRange(Collection presentation, int offset, int length, TextAttribute attr) { - // support for user defined backgroud for JSP scriptlet regions - String styleString = JSPUIPlugin.getDefault().getPreferenceStore().getString(IStyleConstantsJSP.JSP_CONTENT); - String[] prefs = ColorHelper.unpackStylePreferences(styleString); - Color bgColor = (prefs != null && prefs.length == 3 && prefs[1].startsWith("#") && Display.getCurrent() != null) //$NON-NLS-1$ - ? new Color(Display.getCurrent(), ColorHelper.toRGB(prefs[1])) - : attr.getBackground(); - - presentation.add(new StyleRange(offset, length, attr.getForeground(), bgColor, attr.getStyle())); - } - - /** - * Looks up the colorKey in the preference store and adds the style - * information to list of TextAttributes - * - * @param colorKey - */ - private void addTextAttribute(String colorKey) { - if (getColorPreferences() != null) { - String prefString = getColorPreferences().getString(colorKey); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - RGB foreground = ColorHelper.toRGB(stylePrefs[0]); - RGB background = ColorHelper.toRGB(stylePrefs[1]); - boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue(); - getTextAttributes().put(colorKey, createTextAttribute(foreground, background, bold)); - } - } - } - - /** - * Looks up the colorKey in the preference store and adds the style - * information to list of TextAttributes - * - * @param colorKey - */ - private void addJavaTextAttribute(String colorKey) { - IPreferenceStore store = getJavaColorPreferences(); - if (store != null && colorKey != null) { - TextAttribute ta = null; - if (colorKey == IStyleConstantsJSPJava.JAVA_KEYWORD) { - // keyword - RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR); - boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD); - boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC); - ta = createTextAttribute(foreground, null, bold, italics); - } else if (colorKey == IStyleConstantsJSPJava.JAVA_STRING) { - // string - RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_STRING_COLOR); - boolean bold = store.getBoolean(PreferenceConstants.EDITOR_STRING_BOLD); - boolean italics = store.getBoolean(PreferenceConstants.EDITOR_STRING_ITALIC); - ta = createTextAttribute(foreground, null, bold, italics); - } else if (colorKey == IStyleConstantsJSPJava.JAVA_SINGLE_LINE_COMMENT) { - // single line comment - RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR); - boolean bold = store.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD); - boolean italics = store.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_ITALIC); - ta = createTextAttribute(foreground, null, bold, italics); - } else if (colorKey == IStyleConstantsJSPJava.JAVA_DEFAULT) { - // default - RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR); - boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD); - boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_ITALIC); - ta = createTextAttribute(foreground, null, bold, italics); - } - if (ta != null) { - getTextAttributes().put(colorKey, ta); - fScanner.setTokenData(colorKey, ta); - } - } - } - - private TextAttribute createTextAttribute(RGB foreground, RGB background, boolean bold) { - return new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, bold ? SWT.BOLD : SWT.NORMAL); - } - - private TextAttribute createTextAttribute(RGB foreground, RGB background, boolean bold, boolean italics) { - int style = bold ? SWT.BOLD : SWT.NORMAL; - if (italics) - style |= SWT.ITALIC; - - return new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, style); - } - - /** - * Returns the hashtable containing all the text attributes for this line - * style provider. Lazily creates a hashtable if one has not already been - * created. - * - * @return - */ - private HashMap getTextAttributes() { - if (fTextAttributes == null) { - fTextAttributes = new HashMap(); - loadColors(); - } - return fTextAttributes; - } - - /** - * Returns a text attribute encoded in the given token. If the token's - * data is not <code>null</code> and a text attribute it is assumed that - * it is the encoded text attribute. It returns the default text attribute - * if there is no encoded text attribute found. - * - * @param token the token whose text attribute is to be determined - * @return the token's text attribute - */ - private TextAttribute getTokenTextAttribute(IToken token) { - TextAttribute ta = null; - - Object data = token.getData(); - if (data instanceof TextAttribute) - ta = (TextAttribute)data; - else { - ta = (TextAttribute)getTextAttributes().get(IStyleConstantsJSPJava.JAVA_DEFAULT); - } - return ta; - } - - public void init(IStructuredDocument document, Highlighter highlighter) { - fDocument = document; - fHighlighter = highlighter; - - if (fIsInitialized) - return; - - registerPreferenceListener(); - - fIsInitialized = true; - } - - private void loadColors() { - addTextAttribute(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - - addJavaTextAttribute(IStyleConstantsJSPJava.JAVA_KEYWORD); - addJavaTextAttribute(IStyleConstantsJSPJava.JAVA_STRING); - addJavaTextAttribute(IStyleConstantsJSPJava.JAVA_SINGLE_LINE_COMMENT); - addJavaTextAttribute(IStyleConstantsJSPJava.JAVA_DEFAULT); - - fScanner.initializeRules(); - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - String styleKey = null; - String javaStyleKey = null; - - if (event != null) { - String prefKey = event.getProperty(); - // check if preference changed is a style preference - if (IStyleConstantsHTML.SCRIPT_AREA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsHTML.SCRIPT_AREA_BORDER; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_NAME; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_VALUE.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_VALUE; - } else if (PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR.equals(prefKey) || (PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD.equals(prefKey))|| (PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC.equals(prefKey))) { - javaStyleKey = IStyleConstantsJSPJava.JAVA_KEYWORD; - } else if (PreferenceConstants.EDITOR_STRING_COLOR.equals(prefKey) || (PreferenceConstants.EDITOR_STRING_BOLD.equals(prefKey))|| (PreferenceConstants.EDITOR_STRING_ITALIC.equals(prefKey))) { - javaStyleKey = IStyleConstantsJSPJava.JAVA_STRING; - } else if (PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR.equals(prefKey) || (PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD.equals(prefKey))|| (PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_ITALIC.equals(prefKey))) { - javaStyleKey = IStyleConstantsJSPJava.JAVA_SINGLE_LINE_COMMENT; - } else if (PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR.equals(prefKey) || (PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD.equals(prefKey))|| (PreferenceConstants.EDITOR_JAVA_DEFAULT_ITALIC.equals(prefKey))) { - javaStyleKey = IStyleConstantsJSPJava.JAVA_DEFAULT; - } - } - - if (styleKey != null) { - // overwrite style preference with new value - addTextAttribute(styleKey); - } - if (javaStyleKey != null) { - // overwrite style preference with new value - addJavaTextAttribute(javaStyleKey); - fScanner.initializeRules(); - } - if (styleKey != null || javaStyleKey != null) { - // force a full update of the text viewer - fHighlighter.refreshDisplay(); - } - } - - public boolean prepareRegions(ITypedRegion typedRegion, int ssssrequestedStart, int ssssrequestedLength, Collection holdResults) { - boolean result = true; - try { - // ideally, eventually, we'll have a "virtualDocument" we can - // refer to, but for now ... we'll simple rescan the one region. - // use simple adjustment (since "sub-content" starts at 0 - int offsetAdjustment = typedRegion.getOffset(); - String content = fDocument.get(typedRegion.getOffset(), typedRegion.getLength()); - IDocument document = new Document(content); - - int lastStart = 0; - int length = 0; - IToken lastToken = Token.UNDEFINED; - - int remainingLength = typedRegion.getLength(); - fScanner.setRange(document, lastStart, remainingLength); - - while (true) { - - IToken token = fScanner.nextToken(); - - if (token.isEOF()) { - if (!lastToken.isUndefined() && length != 0) - addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken)); - break; - } - - if (token.isWhitespace()) { - length += fScanner.getTokenLength(); - continue; - } - - if (lastToken.isUndefined()) { - lastToken = token; - length += fScanner.getTokenLength(); - continue; - } - - if (token != lastToken) { - addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken)); - lastToken = token; - lastStart = fScanner.getTokenOffset(); - length = fScanner.getTokenLength(); - continue; - } - - length += fScanner.getTokenLength(); - } - } - catch (BadLocationException e) { - // shouldn't happen, but we don't want it to stop other highlighting, if it does. - result = false; - } - return result; - } - - private void registerPreferenceListener() { - getColorPreferences().addPropertyChangeListener(fPreferenceListener); - getJavaColorPreferences().addPropertyChangeListener(fPreferenceListener); - } - - public void release() { - unregisterPreferenceManager(); - if (fTextAttributes != null) { - fTextAttributes.clear(); - fTextAttributes = null; - } - } - - private void unregisterPreferenceManager() { - getColorPreferences().removePropertyChangeListener(fPreferenceListener); - getJavaColorPreferences().removePropertyChangeListener(fPreferenceListener); - } - - private IPreferenceStore getColorPreferences() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } - - private IPreferenceStore getJavaColorPreferences() { - return PreferenceConstants.getPreferenceStore(); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/IStyleConstantsJSPEL.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/IStyleConstantsJSPEL.java deleted file mode 100644 index 5198842524..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/IStyleConstantsJSPEL.java +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - *******************************************************************************/ - -package org.eclipse.jst.jsp.ui.internal.style.jspel; - -public interface IStyleConstantsJSPEL { - String EL_KEYWORD = "keyword"; //$NON-NLS-1$ - String EL_DEFAULT = "default"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELCodeScanner.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELCodeScanner.java deleted file mode 100644 index e7f7cc9f9a..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELCodeScanner.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.jspel; - - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.rules.WhitespaceRule; -import org.eclipse.jface.text.rules.WordRule; - -/** - * A Java code scanner. - */ -public class JSPELCodeScanner extends org.eclipse.jface.text.rules.RuleBasedScanner { - private IToken fKeywordToken; - private IToken fTypeToken; - private IToken fDefaultToken; - - private static String[] fgKeywords = { - "and", //$NON-NLS-1$ - "did", //$NON-NLS-1$ - "div", //$NON-NLS-1$ - "empty", //$NON-NLS-1$ - "eq", //$NON-NLS-1$ - "ge", //$NON-NLS-1$ - "gt", //$NON-NLS-1$ - "or", //$NON-NLS-1$ - "le", //$NON-NLS-1$ - "lt", //$NON-NLS-1$ - "mod", //$NON-NLS-1$ - "ne", //$NON-NLS-1$ - "not" //$NON-NLS-1$ - }; - private static String[] fgConstants = {"false", "true"};//$NON-NLS-2$//$NON-NLS-1$ - - /** - * Creates a Java code scanner - */ - public JSPELCodeScanner() { - super(); - } - - public void initializeRules() { - List rules = new ArrayList(); - - // Add generic whitespace rule. - rules.add(new WhitespaceRule(new JSPELWhitespaceDetector())); - - // Add word rule for keywords, types, and constants. - WordRule wordRule = new WordRule(new JSPELWordDetector(), fDefaultToken); - for (int i = 0; i < fgKeywords.length; i++) - wordRule.addWord(fgKeywords[i], fKeywordToken); - for (int i = 0; i < fgConstants.length; i++) - wordRule.addWord(fgConstants[i], fTypeToken); - rules.add(wordRule); - - IRule[] result = new IRule[rules.size()]; - rules.toArray(result); - setRules(result); - } - - public void setTokenData(String tokenKey, Object data) { - if (tokenKey == IStyleConstantsJSPEL.EL_KEYWORD) { - fKeywordToken = new Token(data); - fTypeToken = new Token(data); - } else if (tokenKey == IStyleConstantsJSPEL.EL_DEFAULT) { - fDefaultToken = new Token(data); - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELColorProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELColorProvider.java deleted file mode 100644 index 716071ffea..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELColorProvider.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.jspel; - -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.RGB; - -/** - * Colors used in the Java editor - */ -public class JSPELColorProvider { - - // people should not be setting these, even though they are currently not final - public static RGB MULTI_LINE_COMMENT = new RGB(128, 0, 0); - public static RGB SINGLE_LINE_COMMENT = new RGB(128, 128, 0); - public static RGB KEYWORD = new RGB(0, 0, 128); - public static RGB TYPE = new RGB(0, 0, 128); - public static RGB STRING = new RGB(0, 128, 0); - public static RGB DEFAULT = new RGB(0, 0, 0); - public static RGB JAVADOC_KEYWORD = new RGB(0, 128, 0); - public static RGB JAVADOC_TAG = new RGB(128, 128, 128); - public static RGB JAVADOC_LINK = new RGB(128, 128, 128); - public static RGB JAVADOC_DEFAULT = new RGB(0, 128, 128); - - public static int MULTI_LINE_COMMENT_BOLD = SWT.NORMAL; - public static int SINGLE_LINE_COMMENT_BOLD = SWT.NORMAL; - public static int KEYWORD_BOLD = SWT.BOLD; - public static int TYPE_BOLD = SWT.BOLD; - public static int STRING_BOLD = SWT.NORMAL; - public static int DEFAULT_BOLD = SWT.NORMAL; - public static int JAVADOC_KEYWORD_BOLD = SWT.BOLD; - public static int JAVADOC_TAG_BOLD = SWT.NORMAL; - public static int JAVADOC_LINK_BOLD = SWT.NORMAL; - public static int JAVADOC_DEFAULT_BOLD = SWT.NORMAL; - - /** - * @deprecated all editors use same - */ - public static RGB EDITOR_BACKGROUND = new RGB(255, 255, 255); - /** - * @deprecated all editors use same - */ - public static boolean EDITOR_CURRENT_LINE = true; - /** - * @deprecated all editors use same - */ - public static RGB EDITOR_CURRENT_LINE_COLOR = new RGB(128, 128, 128); - - private static JSPELColorProvider fInstance = null; - - public static JSPELColorProvider getInstance() { - if (fInstance == null) { - fInstance = new JSPELColorProvider(); - } - return fInstance; - } - - /** - * Use colors from JDT plugin - */ - public void loadJavaColors() { - - IPreferenceStore jdtStore = PreferenceConstants.getPreferenceStore(); - MULTI_LINE_COMMENT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR); - SINGLE_LINE_COMMENT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR); - KEYWORD = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR); - TYPE = KEYWORD; - STRING = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_STRING_COLOR); - DEFAULT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR); - JAVADOC_KEYWORD = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR); - JAVADOC_TAG = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR); - JAVADOC_LINK = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR); - JAVADOC_DEFAULT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR); - - MULTI_LINE_COMMENT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD) ? SWT.BOLD : SWT.NORMAL; - SINGLE_LINE_COMMENT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD) ? SWT.BOLD : SWT.NORMAL; - KEYWORD_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD) ? SWT.BOLD : SWT.NORMAL; - TYPE_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD) ? SWT.BOLD : SWT.NORMAL; - STRING_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_STRING_BOLD) ? SWT.BOLD : SWT.NORMAL; - DEFAULT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_TAG_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_TAG_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_LINK_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_LINKS_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_DEFAULT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_DEFAULT_BOLD) ? SWT.BOLD : SWT.NORMAL; - -// EDITOR_BACKGROUND = new RGB(255, 255, 255); - -// IPreferenceStore sseStore = SSEUIPlugin.getDefault().getPreferenceStore(); -// EDITOR_CURRENT_LINE = sseStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE); -// EDITOR_CURRENT_LINE_COLOR = PreferenceConverter.getColor(sseStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELWhitespaceDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELWhitespaceDetector.java deleted file mode 100644 index 5c2345d7e9..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELWhitespaceDetector.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.jspel; - - - -/** - * A java aware white space detector. - */ -public class JSPELWhitespaceDetector implements org.eclipse.jface.text.rules.IWhitespaceDetector { - - /** - * @see org.eclipse.jface.text.rules.IWhitespaceDetector#isWhitespace - */ - public boolean isWhitespace(char c) { - return Character.isWhitespace(c); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELWordDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELWordDetector.java deleted file mode 100644 index 4676e239bf..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/JSPELWordDetector.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.jspel; - - -/** - * A Java aware word detector. - */ -public class JSPELWordDetector implements org.eclipse.jface.text.rules.IWordDetector { - - /** - * @see org.eclipse.jface.text.rules.IWordDetector#isWordIdentifierPart - */ - public boolean isWordPart(char c) { - return Character.isJavaIdentifierPart(c); - } - - /** - * @see org.eclipse.jface.text.rules.IWordDetector#isWordIdentifierStart - */ - public boolean isWordStart(char c) { - return Character.isJavaIdentifierStart(c); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/LineStyleProviderForJSPEL.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/LineStyleProviderForJSPEL.java deleted file mode 100644 index 8f000a0069..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/style/jspel/LineStyleProviderForJSPEL.java +++ /dev/null @@ -1,333 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.style.jspel; - -import java.util.Collection; -import java.util.HashMap; - -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.style.IStyleConstantsJSP; -import org.eclipse.jst.jsp.ui.internal.style.java.IStyleConstantsJSPJava; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; -import org.eclipse.wst.html.ui.internal.style.IStyleConstantsHTML; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; -import org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.sse.ui.internal.util.EditorUtility; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -// Note: many of the methods in this class were based on (or copied from) -// those -// found in the example Java Editor -public class LineStyleProviderForJSPEL implements LineStyleProvider { - private class PropertyChangeListener implements IPropertyChangeListener { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) - */ - public void propertyChange(PropertyChangeEvent event) { - // have to do it this way so others can override the method - handlePropertyChange(event); - } - } - - private IDocument fDocument; - private Highlighter fHighlighter; - private boolean fIsInitialized = false; - private PropertyChangeListener fPreferenceListener = new PropertyChangeListener(); - /** The scanner it uses */ - private JSPELCodeScanner fScanner; - /** Contains all text attributes pretaining to this line style provider */ - private HashMap fTextAttributes = null; - - public LineStyleProviderForJSPEL() { - super(); - fScanner = new JSPELCodeScanner(); - } - - /** - * Adds style information to the given text presentation. - * - * @param presentation - * the text presentation to be extended - * @param offset - * the offset of the range to be styled - * @param length - * the length of the range to be styled - * @param attr - * the attribute describing the style of the range to be styled - */ - private void addRange(Collection presentation, int offset, int length, TextAttribute attr) { - // support for user defined backgroud for JSP scriptlet regions - String styleString = JSPUIPlugin.getDefault().getPreferenceStore().getString(IStyleConstantsJSP.JSP_CONTENT); - String[] prefs = ColorHelper.unpackStylePreferences(styleString); - Color bgColor = (prefs != null && prefs.length == 3 && prefs[1].startsWith("#") && Display.getCurrent() != null) //$NON-NLS-1$ - ? new Color(Display.getCurrent(), ColorHelper.toRGB(prefs[1])) : attr.getBackground(); - - presentation.add(new StyleRange(offset, length, attr.getForeground(), bgColor, attr.getStyle())); - } - - /** - * Looks up the colorKey in the preference store and adds the style - * information to list of TextAttributes - * - * @param colorKey - */ - private void addTextAttribute(String colorKey) { - if (getColorPreferences() != null) { - String prefString = getColorPreferences().getString(colorKey); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - RGB foreground = ColorHelper.toRGB(stylePrefs[0]); - RGB background = ColorHelper.toRGB(stylePrefs[1]); - boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue(); - getTextAttributes().put(colorKey, createTextAttribute(foreground, background, bold)); - } - } - } - - /** - * Looks up the colorKey in the preference store and adds the style - * information to list of TextAttributes - * - * @param colorKey - */ - private void addJavaTextAttribute(String colorKey) { - IPreferenceStore store = getJavaColorPreferences(); - if (store != null && colorKey != null) { - TextAttribute ta = null; - if (colorKey == IStyleConstantsJSPEL.EL_KEYWORD) { - // keyword - RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR); - boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD); - boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC); - ta = createTextAttribute(foreground, null, bold, italics); - } else if (colorKey == IStyleConstantsJSPEL.EL_DEFAULT) { - // default - RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR); - boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD); - boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_ITALIC); - ta = createTextAttribute(foreground, null, bold, italics); - } - if (ta != null) { - getTextAttributes().put(colorKey, ta); - fScanner.setTokenData(colorKey, ta); - } - } - } - - private TextAttribute createTextAttribute(RGB foreground, RGB background, boolean bold) { - return new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, bold ? SWT.BOLD : SWT.NORMAL); - } - - private TextAttribute createTextAttribute(RGB foreground, RGB background, boolean bold, boolean italics) { - int style = bold ? SWT.BOLD : SWT.NORMAL; - if (italics) - style |= SWT.ITALIC; - - return new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, style); - } - - /** - * Returns the hashtable containing all the text attributes for this line - * style provider. Lazily creates a hashtable if one has not already been - * created. - * - * @return - */ - private HashMap getTextAttributes() { - if (fTextAttributes == null) { - fTextAttributes = new HashMap(); - loadColors(); - } - return fTextAttributes; - } - - /** - * Returns a text attribute encoded in the given token. If the token's - * data is not <code>null</code> and a text attribute it is assumed that - * it is the encoded text attribute. It returns the default text attribute - * if there is no encoded text attribute found. - * - * @param token - * the token whose text attribute is to be determined - * @return the token's text attribute - */ - private TextAttribute getTokenTextAttribute(IToken token) { - TextAttribute ta = null; - - Object data = token.getData(); - if (data instanceof TextAttribute) - ta = (TextAttribute) data; - else { - ta = (TextAttribute) getTextAttributes().get(IStyleConstantsJSPJava.JAVA_DEFAULT); - } - return ta; - } - - public void init(IStructuredDocument document, Highlighter highlighter) { - fDocument = document; - fHighlighter = highlighter; - - if (fIsInitialized) - return; - - registerPreferenceListener(); - - fIsInitialized = true; - } - - private void loadColors() { - addTextAttribute(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - - addJavaTextAttribute(IStyleConstantsJSPJava.JAVA_KEYWORD); - addJavaTextAttribute(IStyleConstantsJSPJava.JAVA_DEFAULT); - - fScanner.initializeRules(); - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - String styleKey = null; - String javaStyleKey = null; - - if (event != null) { - String prefKey = event.getProperty(); - // check if preference changed is a style preference - if (IStyleConstantsHTML.SCRIPT_AREA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsHTML.SCRIPT_AREA_BORDER; - } else if (IStyleConstantsXML.TAG_ATTRIBUTE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_NAME; - } else if (IStyleConstantsXML.TAG_ATTRIBUTE_VALUE.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_VALUE; - } else if (PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR.equals(prefKey) || (PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD.equals(prefKey)) || (PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC.equals(prefKey))) { - javaStyleKey = IStyleConstantsJSPEL.EL_KEYWORD; - } else if (PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR.equals(prefKey) || (PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD.equals(prefKey)) || (PreferenceConstants.EDITOR_JAVA_DEFAULT_ITALIC.equals(prefKey))) { - javaStyleKey = IStyleConstantsJSPEL.EL_DEFAULT; - } - } - - if (styleKey != null) { - // overwrite style preference with new value - addTextAttribute(styleKey); - } - if (javaStyleKey != null) { - // overwrite style preference with new value - addJavaTextAttribute(javaStyleKey); - fScanner.initializeRules(); - } - if (styleKey != null || javaStyleKey != null) { - // force a full update of the text viewer - fHighlighter.refreshDisplay(); - } - } - - public boolean prepareRegions(ITypedRegion typedRegion, int ssssrequestedStart, int ssssrequestedLength, Collection holdResults) { - boolean result = true; - try { - // ideally, eventually, we'll have a "virtualDocument" we can - // refer to, but for now ... we'll simple rescan the one region. - // use simple adjustment (since "sub-content" starts at 0 - int offsetAdjustment = typedRegion.getOffset(); - String content = fDocument.get(typedRegion.getOffset(), typedRegion.getLength()); - IDocument document = new Document(content); - - int lastStart = 0; - int length = 0; - IToken lastToken = Token.UNDEFINED; - - int remainingLength = typedRegion.getLength(); - fScanner.setRange(document, lastStart, remainingLength); - - while (true) { - - IToken token = fScanner.nextToken(); - - if (token.isEOF()) { - if (!lastToken.isUndefined() && length != 0) - addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken)); - break; - } - - if (token.isWhitespace()) { - length += fScanner.getTokenLength(); - continue; - } - - if (lastToken.isUndefined()) { - lastToken = token; - length += fScanner.getTokenLength(); - continue; - } - - if (token != lastToken) { - addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken)); - lastToken = token; - lastStart = fScanner.getTokenOffset(); - length = fScanner.getTokenLength(); - continue; - } - - length += fScanner.getTokenLength(); - } - } catch (BadLocationException e) { - // shouldn't happen, but we don't want it to stop other - // highlighting, if it does. - result = false; - } - return result; - } - - private void registerPreferenceListener() { - getColorPreferences().addPropertyChangeListener(fPreferenceListener); - getJavaColorPreferences().addPropertyChangeListener(fPreferenceListener); - } - - public void release() { - unRegisterPreferenceManager(); - if (fTextAttributes != null) { - fTextAttributes.clear(); - fTextAttributes = null; - } - } - - private void unRegisterPreferenceManager() { - getColorPreferences().removePropertyChangeListener(fPreferenceListener); - getJavaColorPreferences().removePropertyChangeListener(fPreferenceListener); - } - - private IPreferenceStore getColorPreferences() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } - - private IPreferenceStore getJavaColorPreferences() { - return PreferenceConstants.getPreferenceStore(); - } -} |