diff options
author | nitind | 2005-09-07 23:49:25 +0000 |
---|---|---|
committer | nitind | 2005-09-07 23:49:25 +0000 |
commit | f8e7763d515e5c136b08181f43823d983cc1822d (patch) | |
tree | 7e9d5daa765fa3c88f6ec822030403fd9256f7ed /bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst | |
parent | 40dcdbd55ddd1bf99a48f007a73cbe31e0baed4a (diff) | |
download | webtools.sourceediting-f8e7763d515e5c136b08181f43823d983cc1822d.tar.gz webtools.sourceediting-f8e7763d515e5c136b08181f43823d983cc1822d.tar.xz webtools.sourceediting-f8e7763d515e5c136b08181f43823d983cc1822d.zip |
[108683] StructuredTextViewerConfiguration and editorConfiguration extension point API
Diffstat (limited to 'bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst')
10 files changed, 1067 insertions, 254 deletions
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentassist/HTMLContentAssistProcessor.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentassist/HTMLContentAssistProcessor.java index f543fc0bf9..ff35669301 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentassist/HTMLContentAssistProcessor.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentassist/HTMLContentAssistProcessor.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.eclipse.core.resources.IResource; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.contentassist.ICompletionProposal; @@ -65,7 +64,6 @@ public class HTMLContentAssistProcessor extends AbstractContentAssistProcessor i private INodeAdapterFactory factoryForCSS = null; protected IPreferenceStore fPreferenceStore = null; protected boolean isXHTML = false; - protected IResource fResource = null; private HTMLTemplateCompletionProcessor fTemplateProcessor = null; private List fTemplateContexts = new ArrayList(); diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/HTML2TextReader.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/HTML2TextReader.java new file mode 100644 index 0000000000..55689a6b01 --- /dev/null +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/HTML2TextReader.java @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Jens Lukowski/Innoopract - initial renaming/restructuring + * + */ +package org.eclipse.wst.html.ui.internal.derived; + +import java.io.IOException; +import java.io.PushbackReader; +import java.io.Reader; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.wst.xml.ui.internal.derived.SubstitutionTextReader; + +/* + * Copied from org.eclipse.jdt.internal.ui.text.HTML2TextReader Modifications + * were made to add br/ tag and fix warnings + */ +/** + * Reads the text contents from a reader of HTML contents and translates the + * tags or cut them out. + */ +public class HTML2TextReader extends SubstitutionTextReader { + + private static final String EMPTY_STRING= ""; //$NON-NLS-1$ + private static final Map fgEntityLookup; + private static final Set fgTags; + + static { + + fgTags= new HashSet(); + fgTags.add("b"); //$NON-NLS-1$ + fgTags.add("br"); //$NON-NLS-1$ + fgTags.add("br/");//$NON-NLS-1$ + fgTags.add("h5"); //$NON-NLS-1$ + fgTags.add("p"); //$NON-NLS-1$ + fgTags.add("dl"); //$NON-NLS-1$ + fgTags.add("dt"); //$NON-NLS-1$ + fgTags.add("dd"); //$NON-NLS-1$ + fgTags.add("li"); //$NON-NLS-1$ + fgTags.add("ul"); //$NON-NLS-1$ + fgTags.add("pre"); //$NON-NLS-1$ + + fgEntityLookup= new HashMap(7); + fgEntityLookup.put("lt", "<"); //$NON-NLS-1$ //$NON-NLS-2$ + fgEntityLookup.put("gt", ">"); //$NON-NLS-1$ //$NON-NLS-2$ + fgEntityLookup.put("nbsp", " "); //$NON-NLS-1$ //$NON-NLS-2$ + fgEntityLookup.put("amp", "&"); //$NON-NLS-1$ //$NON-NLS-2$ + fgEntityLookup.put("circ", "^"); //$NON-NLS-1$ //$NON-NLS-2$ + fgEntityLookup.put("tilde", "~"); //$NON-NLS-2$ //$NON-NLS-1$ + fgEntityLookup.put("quot", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } + + private int fCounter= 0; + private TextPresentation fTextPresentation; + private int fBold= 0; + private int fStartOffset= -1; + private boolean fInParagraph= false; + private boolean fIsPreformattedText= false; + + /** + * Transforms the html text from the reader to formatted text. + * @param presentation If not <code>null</code>, formattings will be applied to + * the presentation. + */ + public HTML2TextReader(Reader reader, TextPresentation presentation) { + super(new PushbackReader(reader)); + fTextPresentation= presentation; + } + + public int read() throws IOException { + int c= super.read(); + if (c != -1) + ++ fCounter; + return c; + } + + protected void startBold() { + if (fBold == 0) + fStartOffset= fCounter; + ++ fBold; + } + + protected void startPreformattedText() { + fIsPreformattedText= true; + setSkipWhitespace(false); + } + + protected void stopPreformattedText() { + fIsPreformattedText= false; + setSkipWhitespace(true); + } + + protected void stopBold() { + -- fBold; + if (fBold == 0) { + if (fTextPresentation != null) { + fTextPresentation.addStyleRange(new StyleRange(fStartOffset, fCounter - fStartOffset, null, null, SWT.BOLD)); + } + fStartOffset= -1; + } + } + + /* + * @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader#computeSubstitution(int) + */ + protected String computeSubstitution(int c) throws IOException { + + if (c == '<') + return processHTMLTag(); + else if (c == '&') + return processEntity(); + else if (fIsPreformattedText) + return processPreformattedText(c); + + return null; + } + + private String html2Text(String html) { + + if (html == null || html.length() == 0) + return EMPTY_STRING; + + String tag= html; + if ('/' == tag.charAt(0)) + tag= tag.substring(1); + + if (!fgTags.contains(tag)) + return EMPTY_STRING; + + + if ("pre".equals(html)) { //$NON-NLS-1$ + startPreformattedText(); + return EMPTY_STRING; + } + + if ("/pre".equals(html)) { //$NON-NLS-1$ + stopPreformattedText(); + return EMPTY_STRING; + } + + if (fIsPreformattedText) + return EMPTY_STRING; + + if ("b".equals(html)) { //$NON-NLS-1$ + startBold(); + return EMPTY_STRING; + } + + if ("h5".equals(html) || "dt".equals(html)) { //$NON-NLS-1$ //$NON-NLS-2$ + startBold(); + return EMPTY_STRING; + } + + if ("dl".equals(html)) //$NON-NLS-1$ + return LINE_DELIM; + + if ("dd".equals(html)) //$NON-NLS-1$ + return "\t"; //$NON-NLS-1$ + + if ("li".equals(html)) //$NON-NLS-1$ + return LINE_DELIM + "\t" + "- "; //$NON-NLS-1$ //$NON-NLS-2$ + + if ("/b".equals(html)) { //$NON-NLS-1$ + stopBold(); + return EMPTY_STRING; + } + + if ("p".equals(html)) { //$NON-NLS-1$ + fInParagraph= true; + return LINE_DELIM; + } + + if ("br".equals(html) || "br/".equals(html)) //$NON-NLS-1$ //$NON-NLS-2$ + return LINE_DELIM; + + if ("/p".equals(html)) { //$NON-NLS-1$ + boolean inParagraph= fInParagraph; + fInParagraph= false; + return inParagraph ? EMPTY_STRING : LINE_DELIM; + } + + if ("/h5".equals(html) || "/dt".equals(html)) { //$NON-NLS-1$ //$NON-NLS-2$ + stopBold(); + return LINE_DELIM; + } + + if ("/dd".equals(html)) //$NON-NLS-1$ + return LINE_DELIM; + + return EMPTY_STRING; + } + + /* + * A '<' has been read. Process a html tag + */ + private String processHTMLTag() throws IOException { + + StringBuffer buf= new StringBuffer(); + int ch; + do { + + ch= nextChar(); + + while (ch != -1 && ch != '>') { + buf.append(Character.toLowerCase((char) ch)); + ch= nextChar(); + if (ch == '"'){ + buf.append(Character.toLowerCase((char) ch)); + ch= nextChar(); + while (ch != -1 && ch != '"'){ + buf.append(Character.toLowerCase((char) ch)); + ch= nextChar(); + } + } + if (ch == '<'){ + unread(ch); + return '<' + buf.toString(); + } + } + + if (ch == -1) + return null; + + int tagLen= buf.length(); + // needs special treatment for comments + if ((tagLen >= 3 && "!--".equals(buf.substring(0, 3))) //$NON-NLS-1$ + && !(tagLen >= 5 && "--".equals(buf.substring(tagLen - 2)))) { //$NON-NLS-1$ + // unfinished comment + buf.append(ch); + } else { + break; + } + } while (true); + + return html2Text(buf.toString()); + } + + private String processPreformattedText(int c) { + if (c == '\r' || c == '\n') + fCounter++; + return null; + } + + + private void unread(int ch) throws IOException { + ((PushbackReader) getReader()).unread(ch); + } + + protected String entity2Text(String symbol) { + if (symbol.length() > 1 && symbol.charAt(0) == '#') { + int ch; + try { + if (symbol.charAt(1) == 'x') { + ch= Integer.parseInt(symbol.substring(2), 16); + } else { + ch= Integer.parseInt(symbol.substring(1), 10); + } + return EMPTY_STRING + (char)ch; + } catch (NumberFormatException e) { + // log problem? + } + } else { + String str= (String) fgEntityLookup.get(symbol); + if (str != null) { + return str; + } + } + return "&" + symbol; // not found //$NON-NLS-1$ + } + + /* + * A '&' has been read. Process a entity + */ + private String processEntity() throws IOException { + StringBuffer buf= new StringBuffer(); + int ch= nextChar(); + while (Character.isLetterOrDigit((char)ch) || ch == '#') { + buf.append((char) ch); + ch= nextChar(); + } + + if (ch == ';') + return entity2Text(buf.toString()); + + buf.insert(0, '&'); + if (ch != -1) + buf.append((char) ch); + return buf.toString(); + } +} diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/HTMLTextPresenter.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/HTMLTextPresenter.java new file mode 100644 index 0000000000..95a56c200e --- /dev/null +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/HTMLTextPresenter.java @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Jens Lukowski/Innoopract - initial renaming/restructuring + * + */ +package org.eclipse.wst.html.ui.internal.derived; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.Iterator; + +import org.eclipse.jface.text.DefaultInformationControl; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.widgets.Display; +import org.eclipse.wst.xml.ui.internal.Logger; +import org.eclipse.wst.xml.ui.internal.derived.HTML2TextReader; +import org.eclipse.wst.xml.ui.internal.derived.LineBreakingReader; + +/* + * Copied from org.eclipse.jdt.internal.ui.text.HTMLTextPresenter + * Modifications were made to use own Logger to log exception, and the + * ellipses constant + */ +public class HTMLTextPresenter implements DefaultInformationControl.IInformationPresenter { + private static final String ELLIPSES = "..."; //$NON-NLS-1$ + private static final String LINE_DELIM = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + + private int fCounter; + private boolean fEnforceUpperLineLimit; + + public HTMLTextPresenter(boolean enforceUpperLineLimit) { + super(); + fEnforceUpperLineLimit = enforceUpperLineLimit; + } + + public HTMLTextPresenter() { + this(true); + } + + protected Reader createReader(String hoverInfo, TextPresentation presentation) { + return new HTML2TextReader(new StringReader(hoverInfo), presentation); + } + + protected void adaptTextPresentation(TextPresentation presentation, int offset, int insertLength) { + + int yoursStart = offset; + int yoursEnd = offset + insertLength - 1; + yoursEnd = Math.max(yoursStart, yoursEnd); + + Iterator e = presentation.getAllStyleRangeIterator(); + while (e.hasNext()) { + + StyleRange range = (StyleRange) e.next(); + + int myStart = range.start; + int myEnd = range.start + range.length - 1; + myEnd = Math.max(myStart, myEnd); + + if (myEnd < yoursStart) + continue; + + if (myStart < yoursStart) + range.length += insertLength; + else + range.start += insertLength; + } + } + + private void append(StringBuffer buffer, String string, TextPresentation presentation) { + + int length = string.length(); + buffer.append(string); + + if (presentation != null) + adaptTextPresentation(presentation, fCounter, length); + + fCounter += length; + } + + private String getIndent(String line) { + int length = line.length(); + + int i = 0; + while (i < length && Character.isWhitespace(line.charAt(i))) + ++i; + + return (i == length ? line : line.substring(0, i)) + " "; //$NON-NLS-1$ + } + + /* + * @see IHoverInformationPresenter#updatePresentation(Display display, + * String, TextPresentation, int, int) + */ + public String updatePresentation(Display display, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight) { + + if (hoverInfo == null) + return null; + + GC gc = new GC(display); + try { + + StringBuffer buffer = new StringBuffer(); + int maxNumberOfLines = Math.round(maxHeight / gc.getFontMetrics().getHeight()); + + fCounter = 0; + LineBreakingReader reader = new LineBreakingReader(createReader(hoverInfo, presentation), gc, maxWidth); + + boolean lastLineFormatted = false; + String lastLineIndent = null; + + String line = reader.readLine(); + boolean lineFormatted = reader.isFormattedLine(); + boolean firstLineProcessed = false; + + while (line != null) { + + if (fEnforceUpperLineLimit && maxNumberOfLines <= 0) + break; + + if (firstLineProcessed) { + if (!lastLineFormatted) + append(buffer, LINE_DELIM, null); + else { + append(buffer, LINE_DELIM, presentation); + if (lastLineIndent != null) + append(buffer, lastLineIndent, presentation); + } + } + + append(buffer, line, null); + firstLineProcessed = true; + + lastLineFormatted = lineFormatted; + if (!lineFormatted) + lastLineIndent = null; + else if (lastLineIndent == null) + lastLineIndent = getIndent(line); + + line = reader.readLine(); + lineFormatted = reader.isFormattedLine(); + + maxNumberOfLines--; + } + + if (line != null && buffer.length() > 0) { + append(buffer, LINE_DELIM, lineFormatted ? presentation : null); + append(buffer, ELLIPSES, presentation); + } + + return trim(buffer, presentation); + + } catch (IOException e) { + Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); + return null; + + } finally { + gc.dispose(); + } + } + + private String trim(StringBuffer buffer, TextPresentation presentation) { + + int length = buffer.length(); + + int end = length - 1; + while (end >= 0 && Character.isWhitespace(buffer.charAt(end))) + --end; + + if (end == -1) + return ""; //$NON-NLS-1$ + + if (end < length - 1) + buffer.delete(end + 1, length); + else + end = length; + + int start = 0; + while (start < end && Character.isWhitespace(buffer.charAt(start))) + ++start; + + buffer.delete(0, start); + presentation.setResultWindow(new Region(start, buffer.length())); + return buffer.toString(); + } +} diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/LineBreakingReader.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/LineBreakingReader.java new file mode 100644 index 0000000000..9e6b9a7de0 --- /dev/null +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/LineBreakingReader.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Jens Lukowski/Innoopract - initial renaming/restructuring + * + */ +package org.eclipse.wst.html.ui.internal.derived; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.text.BreakIterator; + +import org.eclipse.swt.graphics.GC; + +/** + * Copied from org.eclipse.jdt.internal.ui.text.LineBreakingReader. + * Modifications were made to fix warnings. + */ +/* + * Not a real reader. Could change if requested + */ +public class LineBreakingReader { + private GC fGC; + + private String fLine; + + private BreakIterator fLineBreakIterator; + private int fMaxWidth; + private int fOffset; + + + private BufferedReader fReader; + + /** + * Creates a reader that breaks an input text to fit in a given width. + * + * @param reader + * Reader of the input text + * @param gc + * The graphic context that defines the currently used font + * sizes + * @param maxLineWidth + * The max width (pixes) where the text has to fit in + */ + public LineBreakingReader(Reader reader, GC gc, int maxLineWidth) { + fReader = new BufferedReader(reader); + fGC = gc; + fMaxWidth = maxLineWidth; + fOffset = 0; + fLine = null; + fLineBreakIterator = BreakIterator.getLineInstance(); + } + + private int findNextBreakOffset(int currOffset) { + int currWidth = 0; + int nextOffset = fLineBreakIterator.following(currOffset); + while (nextOffset != BreakIterator.DONE) { + String word = fLine.substring(currOffset, nextOffset); + int wordWidth = fGC.textExtent(word).x; + int nextWidth = wordWidth + currWidth; + if (nextWidth > fMaxWidth) { + if (currWidth > 0) { + return currOffset; + } + return nextOffset; + } + currWidth = nextWidth; + currOffset = nextOffset; + nextOffset = fLineBreakIterator.next(); + } + return nextOffset; + } + + private int findWordBegin(int idx) { + while (idx < fLine.length() && Character.isWhitespace(fLine.charAt(idx))) { + idx++; + } + return idx; + } + + public boolean isFormattedLine() { + return fLine != null; + } + + /** + * Reads the next line. The lengths of the line will not exceed the gived + * maximum width. + */ + public String readLine() throws IOException { + if (fLine == null) { + String line = fReader.readLine(); + if (line == null) + return null; + + int lineLen = fGC.textExtent(line).x; + if (lineLen < fMaxWidth) { + return line; + } + fLine = line; + fLineBreakIterator.setText(line); + fOffset = 0; + } + int breakOffset = findNextBreakOffset(fOffset); + String res; + if (breakOffset != BreakIterator.DONE) { + res = fLine.substring(fOffset, breakOffset); + fOffset = findWordBegin(breakOffset); + if (fOffset == fLine.length()) { + fLine = null; + } + } else { + res = fLine.substring(fOffset); + fLine = null; + } + return res; + } +} diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/text/SingleCharReader.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/SingleCharReader.java index 914fde4c31..6425ba34f2 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/text/SingleCharReader.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/SingleCharReader.java @@ -1,22 +1,26 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 +/* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.html.ui.internal.text; - -// taken from package org.eclipse.jdt.ui.text; + * IBM - Initial API and implementation + * Jens Lukowski/Innoopract - initial renaming/restructuring + * + */ +package org.eclipse.wst.html.ui.internal.derived; import java.io.IOException; import java.io.Reader; -abstract class SingleCharReader extends Reader { +/* + * Copied from org.eclipse.jdt.internal.corext.javadoc.SingleCharReader. + * Modification was made to fix statement unnecessarily nested within else + * clause warning in read(..). + */ +public abstract class SingleCharReader extends Reader { /** * @see Reader#read() @@ -34,9 +38,7 @@ abstract class SingleCharReader extends Reader { if (i == off) { return -1; } - else { - return i - off; - } + return i - off; } cbuf[i] = (char) ch; } @@ -61,4 +63,4 @@ abstract class SingleCharReader extends Reader { } return buf.toString(); } -}
\ No newline at end of file +} diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/SubstitutionTextReader.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/SubstitutionTextReader.java new file mode 100644 index 0000000000..e4deaa9637 --- /dev/null +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/derived/SubstitutionTextReader.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Jens Lukowski/Innoopract - initial renaming/restructuring + * + */ +package org.eclipse.wst.html.ui.internal.derived; + +import java.io.IOException; +import java.io.Reader; + +import org.eclipse.wst.xml.ui.internal.derived.SingleCharReader; + +/* + * Copied from org.eclipse.jdt.internal.ui.text.SubstitutionTextReader. + * Modifications were made to read() to allow whitespaces and fixed statement + * unnecessarily nested within else clause warning in nextChar() + */ +/** + * Reads the text contents from a reader and computes for each character a + * potential substitution. The substitution may eat more characters than only + * the one passed into the computation routine. + */ +public abstract class SubstitutionTextReader extends SingleCharReader { + + protected static final String LINE_DELIM = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + + private Reader fReader; + protected boolean fWasWhiteSpace; + private int fCharAfterWhiteSpace; + + /** + * Tells whether white space characters are skipped. + */ + private boolean fSkipWhiteSpace = true; + + private boolean fReadFromBuffer; + private StringBuffer fBuffer; + private int fIndex; + + + protected SubstitutionTextReader(Reader reader) { + fReader = reader; + fBuffer = new StringBuffer(); + fIndex = 0; + fReadFromBuffer = false; + fCharAfterWhiteSpace = -1; + fWasWhiteSpace = true; + } + + /** + * Implement to compute the substitution for the given character and if + * necessary subsequent characters. Use <code>nextChar</code> to read + * subsequent characters. + */ + protected abstract String computeSubstitution(int c) throws IOException; + + /** + * Returns the internal reader. + */ + protected Reader getReader() { + return fReader; + } + + /** + * Returns the next character. + */ + protected int nextChar() throws IOException { + fReadFromBuffer = (fBuffer.length() > 0); + if (fReadFromBuffer) { + char ch = fBuffer.charAt(fIndex++); + if (fIndex >= fBuffer.length()) { + fBuffer.setLength(0); + fIndex = 0; + } + return ch; + } + int ch = fCharAfterWhiteSpace; + if (ch == -1) { + ch = fReader.read(); + } + if (fSkipWhiteSpace && Character.isWhitespace((char) ch)) { + do { + ch = fReader.read(); + } while (Character.isWhitespace((char) ch)); + if (ch != -1) { + fCharAfterWhiteSpace = ch; + return ' '; + } + } else { + fCharAfterWhiteSpace = -1; + } + return ch; + } + + /** + * @see Reader#read() + */ + public int read() throws IOException { + int c; + do { + + c = nextChar(); + while (!fReadFromBuffer) { + String s = computeSubstitution(c); + if (s == null) + break; + if (s.length() > 0) + fBuffer.insert(0, s); + c = nextChar(); + } + + } while (fSkipWhiteSpace && fWasWhiteSpace && ((c == ' ') && !fReadFromBuffer)); + /* + * SSE: For above and below check, if whitespace is read from buffer, + * do not skip + */ + fWasWhiteSpace = ((c == ' ' && !fReadFromBuffer) || c == '\r' || c == '\n'); + return c; + } + + /** + * @see Reader#ready() + */ + public boolean ready() throws IOException { + return fReader.ready(); + } + + /** + * @see Reader#close() + */ + public void close() throws IOException { + fReader.close(); + } + + /** + * @see Reader#reset() + */ + public void reset() throws IOException { + fReader.reset(); + fWasWhiteSpace = true; + fCharAfterWhiteSpace = -1; + fBuffer.setLength(0); + fIndex = 0; + } + + protected final void setSkipWhitespace(boolean state) { + fSkipWhiteSpace = state; + } + + protected final boolean isSkippingWhitespace() { + return fSkipWhiteSpace; + } +} diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java index 81aff17b52..1e8f56e91f 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java @@ -15,9 +15,10 @@ import java.util.List; import java.util.Vector; import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.DefaultInformationControl; import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.ITextDoubleClickStrategy; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.contentassist.ContentAssistant; @@ -32,8 +33,9 @@ import org.eclipse.jface.text.information.InformationPresenter; import org.eclipse.jface.text.reconciler.IReconciler; import org.eclipse.jface.text.reconciler.IReconcilingStrategy; import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; -import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.wst.css.core.internal.provisional.text.ICSSPartitionTypes; import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor; import org.eclipse.wst.css.ui.internal.style.LineStyleProviderForEmbeddedCSS; @@ -45,28 +47,22 @@ import org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML; import org.eclipse.wst.html.ui.internal.autoedit.AutoEditStrategyForTabs; import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor; import org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML; +import org.eclipse.wst.html.ui.internal.derived.HTMLTextPresenter; import org.eclipse.wst.html.ui.internal.hyperlink.XMLHyperlinkDetector; import org.eclipse.wst.html.ui.internal.style.LineStyleProviderForHTML; -import org.eclipse.wst.html.ui.internal.taginfo.HTMLBestMatchHoverProcessor; import org.eclipse.wst.html.ui.internal.taginfo.HTMLInformationProvider; import org.eclipse.wst.html.ui.internal.taginfo.HTMLTagInfoHoverProcessor; import org.eclipse.wst.javascript.ui.internal.common.contentassist.JavaScriptContentAssistProcessor; import org.eclipse.wst.javascript.ui.internal.common.style.LineStyleProviderForJavaScript; -import org.eclipse.wst.javascript.ui.internal.common.taginfo.JavaScriptBestMatchHoverProcessor; import org.eclipse.wst.javascript.ui.internal.common.taginfo.JavaScriptInformationProvider; import org.eclipse.wst.javascript.ui.internal.common.taginfo.JavaScriptTagInfoHoverProcessor; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitionTypes; -import org.eclipse.wst.sse.ui.internal.StructuredTextEditor; +import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; import org.eclipse.wst.sse.ui.internal.format.StructuredFormattingStrategy; import org.eclipse.wst.sse.ui.internal.provisional.StructuredTextViewerConfiguration; import org.eclipse.wst.sse.ui.internal.provisional.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.internal.provisional.style.IHighlighter; import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; import org.eclipse.wst.sse.ui.internal.reconcile.StructuredRegionProcessor; -import org.eclipse.wst.sse.ui.internal.taginfo.AnnotationHoverProcessor; -import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor; import org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager; import org.eclipse.wst.sse.ui.internal.util.EditorUtility; import org.eclipse.wst.xml.core.internal.provisional.text.IXMLPartitions; @@ -77,24 +73,33 @@ import org.eclipse.wst.xml.ui.internal.doubleclick.XMLDoubleClickStrategy; import org.eclipse.wst.xml.ui.internal.validation.StructuredTextReconcilingStrategyForMarkup; public class StructuredTextViewerConfigurationHTML extends StructuredTextViewerConfiguration { - - InformationPresenter fInformationPresenter = null; - - public StructuredTextViewerConfigurationHTML() { - super(); - } - - public StructuredTextViewerConfigurationHTML(IPreferenceStore store) { - super(store); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, - * java.lang.String) + * One instance per configuration because not sourceviewer-specific and + * it's a String array + */ + private String[] fConfiguredContentTypes; + /* + * One instance per configuration because not sourceviewer-specific and + * requires special uninstall + */ + private IContentAssistant fCorrectionAssistant; + /* + * One instance per configuration + */ + private LineStyleProvider fLineStyleProviderForEmbeddedCSS; + /* + * One instance per configuration */ + private LineStyleProvider fLineStyleProviderForHTML; + /* + * One instance per configuration + */ + private LineStyleProvider fLineStyleProviderForJavascript; + /* + * One instance per configuration + */ + private IReconciler fReconciler; + public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { List allStrategies = new ArrayList(0); @@ -102,12 +107,12 @@ public class StructuredTextViewerConfigurationHTML extends StructuredTextViewerC for (int i = 0; i < superStrategies.length; i++) { allStrategies.add(superStrategies[i]); } - + if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) { allStrategies.add(new StructuredAutoEditStrategyXML()); } - - // be sure this is added last in list, so it has a change to modify + + // be sure this is added last in list, so it has a change to modify // previous results. // add auto edit strategy that handles when tab key is pressed allStrategies.add(new AutoEditStrategyForTabs()); @@ -116,50 +121,65 @@ public class StructuredTextViewerConfigurationHTML extends StructuredTextViewerC } public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - if (configuredContentTypes == null) { + if (fConfiguredContentTypes == null) { String[] xmlTypes = StructuredTextPartitionerForXML.getConfiguredContentTypes(); String[] htmlTypes = StructuredTextPartitionerForHTML.getConfiguredContentTypes(); - configuredContentTypes = new String[2 + xmlTypes.length + htmlTypes.length]; + fConfiguredContentTypes = new String[2 + xmlTypes.length + htmlTypes.length]; - configuredContentTypes[0] = IStructuredPartitionTypes.DEFAULT_PARTITION; - configuredContentTypes[1] = IStructuredPartitionTypes.UNKNOWN_PARTITION; + fConfiguredContentTypes[0] = IStructuredPartitionTypes.DEFAULT_PARTITION; + fConfiguredContentTypes[1] = IStructuredPartitionTypes.UNKNOWN_PARTITION; int index = 0; - System.arraycopy(xmlTypes, 0, configuredContentTypes, index += 2, xmlTypes.length); - System.arraycopy(htmlTypes, 0, configuredContentTypes, index += xmlTypes.length, htmlTypes.length); + System.arraycopy(xmlTypes, 0, fConfiguredContentTypes, index += 2, xmlTypes.length); + System.arraycopy(htmlTypes, 0, fConfiguredContentTypes, index += xmlTypes.length, htmlTypes.length); } - return configuredContentTypes; + return fConfiguredContentTypes; } + /** + * Returns the content assistant ready to be used with the given source + * viewer. + * + * @param sourceViewer + * the source viewer to be configured by this configuration + * @return a content assistant or <code>null</code> if content assist + * should not be supported + */ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { - IContentAssistant ca = super.getContentAssistant(sourceViewer); + ContentAssistant assistant = (ContentAssistant) super.getContentAssistant(sourceViewer); - if (ca != null && ca instanceof ContentAssistant) { - ContentAssistant contentAssistant = (ContentAssistant) ca; + // create content assist processors to be used + IContentAssistProcessor htmlContentAssistProcessor = new HTMLContentAssistProcessor(); + IContentAssistProcessor jsContentAssistProcessor = new JavaScriptContentAssistProcessor(); + IContentAssistProcessor cssContentAssistProcessor = new CSSContentAssistProcessor(); + IContentAssistProcessor noRegionProcessorForHTML = new NoRegionContentAssistProcessorForHTML(); - IContentAssistProcessor htmlContentAssistProcessor = new HTMLContentAssistProcessor(); - IContentAssistProcessor jsContentAssistProcessor = new JavaScriptContentAssistProcessor(); - IContentAssistProcessor cssContentAssistProcessor = new CSSContentAssistProcessor(); - IContentAssistProcessor noRegionProcessorForHTML = new NoRegionContentAssistProcessorForHTML(); + // add processors to content assistant + // HTML + assistant.setContentAssistProcessor(htmlContentAssistProcessor, IHTMLPartitionTypes.HTML_DEFAULT); + assistant.setContentAssistProcessor(htmlContentAssistProcessor, IHTMLPartitionTypes.HTML_COMMENT); - // HTML - setContentAssistProcessor(contentAssistant, htmlContentAssistProcessor, IHTMLPartitionTypes.HTML_DEFAULT); - setContentAssistProcessor(contentAssistant, htmlContentAssistProcessor, IHTMLPartitionTypes.HTML_COMMENT); - - // JavaScript - setContentAssistProcessor(contentAssistant, jsContentAssistProcessor, IHTMLPartitionTypes.SCRIPT); + // JavaScript + assistant.setContentAssistProcessor(jsContentAssistProcessor, IHTMLPartitionTypes.SCRIPT); - // CSS - setContentAssistProcessor(contentAssistant, cssContentAssistProcessor, ICSSPartitionTypes.STYLE); + // CSS + assistant.setContentAssistProcessor(cssContentAssistProcessor, ICSSPartitionTypes.STYLE); - // unknown - setContentAssistProcessor(contentAssistant, noRegionProcessorForHTML, IStructuredPartitionTypes.UNKNOWN_PARTITION); - } - - return ca; + // unknown + assistant.setContentAssistProcessor(noRegionProcessorForHTML, IStructuredPartitionTypes.UNKNOWN_PARTITION); + return assistant; } + /** + * Returns the content formatter ready to be used with the given source + * viewer. + * + * @param sourceViewer + * the source viewer to be configured by this configuration + * @return a content formatter or <code>null</code> if formatting should + * not be supported + */ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { final MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IHTMLPartitionTypes.HTML_DEFAULT); @@ -169,23 +189,30 @@ public class StructuredTextViewerConfigurationHTML extends StructuredTextViewerC } public IContentAssistant getCorrectionAssistant(ISourceViewer sourceViewer) { - IContentAssistant ca = super.getCorrectionAssistant(sourceViewer); - - if (ca != null && ca instanceof ContentAssistant) { - ContentAssistant correctionAssistant = (ContentAssistant) ca; - ITextEditor editor = getTextEditor(); - if (editor != null) { - IContentAssistProcessor correctionProcessor = new CorrectionProcessorXML(editor); - correctionAssistant.setContentAssistProcessor(correctionProcessor, IHTMLPartitionTypes.HTML_DEFAULT); - correctionAssistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_CDATA); - correctionAssistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_COMMENT); - correctionAssistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_DECLARATION); - correctionAssistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_PI); - correctionAssistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.DTD_SUBSET); + /* + * Ensure that only one assistant is ever returned. Creating a second + * assistant that is added to a viewer can cause odd key-eating by the + * wrong one. Also do not create correction assistant if sourceviewer + * is null. + */ + if (fCorrectionAssistant == null && sourceViewer != null) { + ContentAssistant assistant = new ContentAssistant(); + + // content assistant configurations + assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + + if (sourceViewer != null) { + IContentAssistProcessor correctionProcessor = new CorrectionProcessorXML(sourceViewer); + assistant.setContentAssistProcessor(correctionProcessor, IHTMLPartitionTypes.HTML_DEFAULT); + assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_CDATA); + assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_COMMENT); + assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_DECLARATION); + assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_PI); + assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.DTD_SUBSET); } + fCorrectionAssistant = assistant; } - - return ca; + return fCorrectionAssistant; } public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { @@ -196,28 +223,6 @@ public class StructuredTextViewerConfigurationHTML extends StructuredTextViewerC return super.getDoubleClickStrategy(sourceViewer, contentType); } - public IHighlighter getHighlighter(ISourceViewer sourceViewer) { - IHighlighter highlighter = super.getHighlighter(sourceViewer); - - if (highlighter != null) { - // HTML - LineStyleProvider htmlLineStyleProvider = new LineStyleProviderForHTML(); - highlighter.addProvider(IHTMLPartitionTypes.HTML_DEFAULT, htmlLineStyleProvider); - highlighter.addProvider(IHTMLPartitionTypes.HTML_COMMENT, htmlLineStyleProvider); - highlighter.addProvider(IHTMLPartitionTypes.HTML_DECLARATION, htmlLineStyleProvider); - - // JavaScript - LineStyleProvider jsLineStyleProvider = new LineStyleProviderForJavaScript(); - highlighter.addProvider(IHTMLPartitionTypes.SCRIPT, jsLineStyleProvider); - - // CSS - LineStyleProvider cssLineStyleProvider = new LineStyleProviderForEmbeddedCSS(); - highlighter.addProvider(ICSSPartitionTypes.STYLE, cssLineStyleProvider); - } - - return highlighter; - } - /* * (non-Javadoc) * @@ -240,155 +245,207 @@ public class StructuredTextViewerConfigurationHTML extends StructuredTextViewerC return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]); } - public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { - if (fInformationPresenter == null) { - fInformationPresenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer)); + public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { + Vector vector = new Vector(); - // HTML - IInformationProvider htmlInformationProvider = new HTMLInformationProvider(); - fInformationPresenter.setInformationProvider(htmlInformationProvider, IHTMLPartitionTypes.HTML_DEFAULT); + // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference + Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences(); + int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE); + String indentCharPref = preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR); + boolean useSpaces = HTMLCorePreferenceNames.SPACE.equals(indentCharPref); + + for (int i = 0; i <= indentationWidth; i++) { + StringBuffer prefix = new StringBuffer(); + boolean appendTab = false; - // JavaScript - IInformationProvider javascriptInformationProvider = new JavaScriptInformationProvider(); - fInformationPresenter.setInformationProvider(javascriptInformationProvider, IHTMLPartitionTypes.SCRIPT); + if (useSpaces) { + for (int j = 0; j + i < indentationWidth; j++) + prefix.append(' '); - fInformationPresenter.setSizeConstraints(60, 10, true, true); - fInformationPresenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + if (i != 0) + appendTab = true; + } + else { + for (int j = 0; j < i; j++) + prefix.append(' '); + + if (i != indentationWidth) + appendTab = true; + } + + if (appendTab) { + prefix.append('\t'); + vector.add(prefix.toString()); + // remove the tab so that indentation - tab is also an indent + // prefix + prefix.deleteCharAt(prefix.length() - 1); + } + vector.add(prefix.toString()); } - return fInformationPresenter; + vector.add(""); //$NON-NLS-1$ + + return (String[]) vector.toArray(new String[vector.size()]); } /** - * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconcilerg(org.eclipse.jface.text.source.ISourceViewer) + * Returns the information control creator. The creator is a factory + * creating information controls for the given source viewer. + * + * @param sourceViewer + * the source viewer to be configured by this configuration + * @return the information control creator or <code>null</code> if no + * information support should be installed + * @since 2.0 */ - public IReconciler getReconciler(ISourceViewer sourceViewer) { - if (fReconciler != null) { - // a reconciler should always either be installed or disposed of - if (!fReconciler.isInstalled()) { - fReconciler = null; + public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) { + // used by hover help + return new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell parent) { + return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(false)); + } + }; + } + + public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { + InformationPresenter presenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer)); + + // information presenter configurations + presenter.setSizeConstraints(60, 10, true, true); + presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + + // information providers to be used + IInformationProvider htmlInformationProvider = new HTMLInformationProvider(); + IInformationProvider javascriptInformationProvider = new JavaScriptInformationProvider(); + + // add information providers to information presenter + // HTML + presenter.setInformationProvider(htmlInformationProvider, IHTMLPartitionTypes.HTML_DEFAULT); + + // JavaScript + presenter.setInformationProvider(javascriptInformationProvider, IHTMLPartitionTypes.SCRIPT); + + return presenter; + } + + /** + * Returns the information presenter control creator. The creator is a + * factory creating the presenter controls for the given source viewer. + * + * @param sourceViewer + * the source viewer to be configured by this configuration + * @return an information control creator + */ + private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) { + return new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell parent) { + int shellStyle = SWT.RESIZE | SWT.TOOL; + int style = SWT.V_SCROLL | SWT.H_SCROLL; + return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false)); } + }; + } + + public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { + LineStyleProvider[] providers = null; + + if (partitionType == IHTMLPartitionTypes.HTML_DEFAULT || partitionType == IHTMLPartitionTypes.HTML_COMMENT || partitionType == IHTMLPartitionTypes.HTML_DECLARATION) { + providers = new LineStyleProvider[]{getLineStyleProviderForHTML()}; + } + else if (partitionType == IHTMLPartitionTypes.SCRIPT) { + providers = new LineStyleProvider[]{getLineStyleProviderForJavascript()}; + } + else if (partitionType == ICSSPartitionTypes.STYLE) { + providers = new LineStyleProvider[]{getLineStyleProviderForEmbeddedCSS()}; } - if (fReconciler == null) { - // create one - fReconciler = new StructuredRegionProcessor(); - fReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + return providers; + } + + private LineStyleProvider getLineStyleProviderForEmbeddedCSS() { + if (fLineStyleProviderForEmbeddedCSS == null) { + fLineStyleProviderForEmbeddedCSS = new LineStyleProviderForEmbeddedCSS(); } + return fLineStyleProviderForEmbeddedCSS; + } - boolean reconcilingEnabled = fPreferenceStore.getBoolean(CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS); + private LineStyleProvider getLineStyleProviderForHTML() { + if (fLineStyleProviderForHTML == null) { + fLineStyleProviderForHTML = new LineStyleProviderForHTML(); + } + return fLineStyleProviderForHTML; + } - if (!reconcilingEnabled) - return fReconciler; + private LineStyleProvider getLineStyleProviderForJavascript() { + if (fLineStyleProviderForJavascript == null) { + fLineStyleProviderForJavascript = new LineStyleProviderForJavaScript(); + } + return fLineStyleProviderForJavascript; + } - if (fReconciler != null) { - IDocument doc = ((StructuredTextEditor) editorPart).getDocumentProvider().getDocument(editorPart.getEditorInput()); - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - try { - if (sModel != null) { + public IReconciler getReconciler(ISourceViewer sourceViewer) { + boolean reconcilingEnabled = fPreferenceStore.getBoolean(CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS); + if (sourceViewer == null || !reconcilingEnabled) + return null; - String contentTypeId = sModel.getContentTypeIdentifier(); + /* + * Only create reconciler if sourceviewer is present + */ + if (fReconciler == null && sourceViewer != null) { + StructuredRegionProcessor reconciler = new StructuredRegionProcessor(); - IReconcilingStrategy markupStrategy = new StructuredTextReconcilingStrategyForMarkup((ITextEditor) editorPart); + // reconciler configurations + reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); - fReconciler.setReconcilingStrategy(markupStrategy, IStructuredPartitionTypes.DEFAULT_PARTITION); - fReconciler.setReconcilingStrategy(markupStrategy, IXMLPartitions.XML_DEFAULT); + // reconciling strategies for reconciler + IReconcilingStrategy markupStrategy = new StructuredTextReconcilingStrategyForMarkup(sourceViewer); - fReconciler.setDefaultStrategy(markupStrategy); + // add reconciling strategies + reconciler.setReconcilingStrategy(markupStrategy, IStructuredPartitionTypes.DEFAULT_PARTITION); + reconciler.setReconcilingStrategy(markupStrategy, IXMLPartitions.XML_DEFAULT); + reconciler.setDefaultStrategy(markupStrategy); - if (contentTypeId != null) - fReconciler.setValidatorStrategy(createValidatorStrategy(contentTypeId)); - } - } finally { - if (sModel != null) - sModel.releaseFromRead(); - } + fReconciler = reconciler; } return fReconciler; } public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { - ITextHover hover = null; - TextHoverManager.TextHoverDescriptor[] hoverDescs = getTextHovers(); + ITextHover textHover = null; + + // look for appropriate text hover processor to return based on + // content type and state mask + TextHoverManager manager = SSEUIPlugin.getDefault().getTextHoverManager(); + TextHoverManager.TextHoverDescriptor[] hoverDescs = manager.getTextHovers(); int i = 0; - while (i < hoverDescs.length && hover == null) { + while (i < hoverDescs.length && textHover == null) { if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) { String hoverType = hoverDescs[i].getId(); if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) { // check if script or html is needed if (contentType == IHTMLPartitionTypes.SCRIPT) { - hover = new JavaScriptBestMatchHoverProcessor(); - } else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) { - hover = new HTMLBestMatchHoverProcessor(); + textHover = manager.createBestMatchHover(new JavaScriptTagInfoHoverProcessor()); + } + else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) { + textHover = manager.createBestMatchHover(new HTMLTagInfoHoverProcessor()); } - } else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) { - hover = new ProblemAnnotationHoverProcessor(); - } else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) { - hover = new AnnotationHoverProcessor(); - } else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) { + } + else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) // check if script or html is needed if (contentType == IHTMLPartitionTypes.SCRIPT) { - hover = new JavaScriptTagInfoHoverProcessor(); - } else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) { - hover = new HTMLTagInfoHoverProcessor(); + textHover = new JavaScriptTagInfoHoverProcessor(); + } + else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) { + textHover = new HTMLTagInfoHoverProcessor(); } - } } i++; } - if (hover == null) { - hover = super.getTextHover(sourceViewer, contentType, stateMask); - } - return hover; - } - public void unConfigure(ISourceViewer viewer) { - super.unConfigure(viewer); - - // InformationPresenters - if (fInformationPresenter != null) - fInformationPresenter.uninstall(); - } - - public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { - Vector vector = new Vector(); - - // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference - Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences(); - int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE); - String indentCharPref = preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR); - boolean useSpaces = HTMLCorePreferenceNames.SPACE.equals(indentCharPref); - - for (int i = 0; i <= indentationWidth; i++) { - StringBuffer prefix = new StringBuffer(); - boolean appendTab = false; - - if (useSpaces) { - for (int j = 0; j + i < indentationWidth; j++) - prefix.append(' '); - - if (i != 0) - appendTab = true; - } else { - for (int j = 0; j < i; j++) - prefix.append(' '); - - if (i != indentationWidth) - appendTab = true; - } - - if (appendTab) { - prefix.append('\t'); - vector.add(prefix.toString()); - // remove the tab so that indentation - tab is also an indent - // prefix - prefix.deleteCharAt(prefix.length() - 1); - } - vector.add(prefix.toString()); + // no appropriate text hovers found, try super + if (textHover == null) { + textHover = super.getTextHover(sourceViewer, contentType, stateMask); } - - vector.add(""); //$NON-NLS-1$ - - return (String[]) vector.toArray(new String[vector.size()]); + return textHover; } }
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/taginfo/HTMLBestMatchHoverProcessor.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/taginfo/HTMLBestMatchHoverProcessor.java deleted file mode 100644 index d5516a833e..0000000000 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/taginfo/HTMLBestMatchHoverProcessor.java +++ /dev/null @@ -1,31 +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.wst.html.ui.internal.taginfo; - -import org.eclipse.jface.text.ITextHover; -import org.eclipse.wst.sse.ui.internal.taginfo.AbstractBestMatchHoverProcessor; - -/** - * Provides the best html hover help documentation (by using other hover help processors) - * Priority of hover help processors is: - * ProblemHoverProcessor, HTMLTagInfoHoverProcessor, AnnotationHoverProcessor - */ -public class HTMLBestMatchHoverProcessor extends AbstractBestMatchHoverProcessor { - HTMLTagInfoHoverProcessor fTagInfoHover; - - protected ITextHover getTagInfoHover() { - if (fTagInfoHover == null) { - fTagInfoHover = new HTMLTagInfoHoverProcessor(); - } - return fTagInfoHover; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/taginfo/HTMLInformationProvider.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/taginfo/HTMLInformationProvider.java index 26ecebfed4..9c85f32685 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/taginfo/HTMLInformationProvider.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/taginfo/HTMLInformationProvider.java @@ -13,9 +13,11 @@ package org.eclipse.wst.html.ui.internal.taginfo; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.information.IInformationProvider; import org.eclipse.jface.text.information.IInformationProviderExtension; +import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; /** * Provides context information for HTML tags (Shows tooltip description) @@ -24,10 +26,10 @@ import org.eclipse.jface.text.information.IInformationProviderExtension; */ public class HTMLInformationProvider implements IInformationProvider, IInformationProviderExtension { - private HTMLBestMatchHoverProcessor fTextHover = null; + private ITextHover fTextHover = null; public HTMLInformationProvider() { - fTextHover = new HTMLBestMatchHoverProcessor(); + fTextHover = SSEUIPlugin.getDefault().getTextHoverManager().createBestMatchHover(new HTMLTagInfoHoverProcessor()); } /* (non-Javadoc) diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/text/JavaCodeReader.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/text/JavaCodeReader.java index 196b9f3d82..e3cace3005 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/text/JavaCodeReader.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/text/JavaCodeReader.java @@ -17,6 +17,7 @@ import java.io.IOException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; +import org.eclipse.wst.html.ui.internal.derived.SingleCharReader; /** * Reads from a document either forwards or backwards. May be configured to |