Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcjaun2010-07-13 21:14:28 +0000
committercjaun2010-07-13 21:14:28 +0000
commitf78645929b6f9d0cbb99167ab199fa4dfab6f2b1 (patch)
tree6b02ff62ea18404faf96db6abe0da45ee69815f3
parent668c78cd9b656418b60735116abd9801dc9cc485 (diff)
downloadwebtools.sourceediting-f78645929b6f9d0cbb99167ab199fa4dfab6f2b1.tar.gz
webtools.sourceediting-f78645929b6f9d0cbb99167ab199fa4dfab6f2b1.tar.xz
webtools.sourceediting-f78645929b6f9d0cbb99167ab199fa4dfab6f2b1.zip
Pulled 3.2.1 fixes into HEAD
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.support.jsp/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.support.jsp/plugin.xml4
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.support.jsp/src/org/eclipse/wst/jsdt/web/support/jsp/JSDTStructuredTextViewerConfigurationJSP.java35
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml16
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/StructuredTextViewerConfigurationJSDT.java29
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/autoedit/AutoEditStrategyForJs.java6
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java8
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/text/JsCharacterPairInserter.java293
10 files changed, 354 insertions, 43 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF
index 93a5e84343..c0700e35d0 100644
--- a/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.wst.jsdt.web.core;singleton:=true
-Bundle-Version: 1.0.300.qualifier
+Bundle-Version: 1.0.301.qualifier
Bundle-Activator: org.eclipse.wst.jsdt.web.core.internal.JsCorePlugin
Bundle-Vendor: %Bundle-Vendor.0
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.wst.jsdt.web.support.jsp/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.jsdt.web.support.jsp/META-INF/MANIFEST.MF
index ea4687285f..4f552a392e 100644
--- a/bundles/org.eclipse.wst.jsdt.web.support.jsp/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.jsdt.web.support.jsp/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.wst.jsdt.web.support.jsp;singleton:=true
-Bundle-Version: 1.0.300.qualifier
+Bundle-Version: 1.0.301.qualifier
Bundle-Activator: org.eclipse.wst.jsdt.web.support.jsp.Activator
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.wst.jsdt.web.ui;bundle-version="[1.0.200,2.0.0)",
diff --git a/bundles/org.eclipse.wst.jsdt.web.support.jsp/plugin.xml b/bundles/org.eclipse.wst.jsdt.web.support.jsp/plugin.xml
index 394f6f8031..ea1b7a6e53 100644
--- a/bundles/org.eclipse.wst.jsdt.web.support.jsp/plugin.xml
+++ b/bundles/org.eclipse.wst.jsdt.web.support.jsp/plugin.xml
@@ -17,6 +17,10 @@
type="org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor"
class="org.eclipse.wst.jsdt.web.ui.internal.java.search.JsFindOccurrencesProcessor"
target="org.eclipse.jst.jsp.SCRIPT,org.eclipse.jst.jsp.SCRIPT.EVENTHANDLER" />
+ <provisionalConfiguration
+ type="slaveformattingstrategy"
+ class="org.eclipse.wst.jsdt.web.ui.internal.format.FormattingStrategyJSDT"
+ target="org.eclipse.jst.jsp.SCRIPT.JAVASCRIPT" />
</extension>
<extension point="org.eclipse.wst.sse.ui.sourcevalidation">
diff --git a/bundles/org.eclipse.wst.jsdt.web.support.jsp/src/org/eclipse/wst/jsdt/web/support/jsp/JSDTStructuredTextViewerConfigurationJSP.java b/bundles/org.eclipse.wst.jsdt.web.support.jsp/src/org/eclipse/wst/jsdt/web/support/jsp/JSDTStructuredTextViewerConfigurationJSP.java
index cbf2df30b5..661e60d1b9 100644
--- a/bundles/org.eclipse.wst.jsdt.web.support.jsp/src/org/eclipse/wst/jsdt/web/support/jsp/JSDTStructuredTextViewerConfigurationJSP.java
+++ b/bundles/org.eclipse.wst.jsdt.web.support.jsp/src/org/eclipse/wst/jsdt/web/support/jsp/JSDTStructuredTextViewerConfigurationJSP.java
@@ -13,14 +13,13 @@
*/
package org.eclipse.wst.jsdt.web.support.jsp;
-import org.eclipse.jface.text.formatter.IContentFormatter;
-import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
+import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jst.jsp.core.text.IJSPPartitions;
import org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP;
import org.eclipse.wst.html.core.text.IHTMLPartitions;
import org.eclipse.wst.jsdt.web.ui.StructuredTextViewerConfigurationJSDT;
-import org.eclipse.wst.jsdt.web.ui.internal.format.FormattingStrategyJSDT;
+import org.eclipse.wst.jsdt.web.ui.internal.autoedit.AutoEditStrategyForJs;
import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider;
/**
@@ -41,23 +40,6 @@ public class JSDTStructuredTextViewerConfigurationJSP extends StructuredTextView
return fHTMLSourceViewerConfiguration;
}
- public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- final IContentFormatter formatter = super.getContentFormatter(sourceViewer);
- if(formatter instanceof MultiPassContentFormatter) {
- /*
- * Check for any externally supported auto edit strategies from EP.
- * [Bradley Childs - childsb@us.ibm.com]
- */
- String[] contentTypes = getConfiguredContentTypes(sourceViewer);
- for (int i = 0; i < contentTypes.length; i++) {
- if (IHTMLPartitions.SCRIPT.equals(contentTypes[i]) || IJSPPartitions.JSP_CONTENT_JAVASCRIPT.equals(contentTypes[i])) {
- ((MultiPassContentFormatter) formatter).setSlaveStrategy(new FormattingStrategyJSDT(), contentTypes[i]);
- }
- }
- }
- return formatter;
- }
-
public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
String[] indentations = null;
if (IHTMLPartitions.SCRIPT.equals(contentType) || IJSPPartitions.JSP_CONTENT_JAVASCRIPT.equals(contentType) || IHTMLPartitions.SCRIPT_EVENTHANDLER.equals(contentType))
@@ -78,4 +60,17 @@ public class JSDTStructuredTextViewerConfigurationJSP extends StructuredTextView
return providers;
}
+
+ /**
+ * @see org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
+ */
+ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
+ if(contentType.equals(IHTMLPartitions.SCRIPT) || contentType.equals(IHTMLPartitions.SCRIPT_EVENTHANDLER)) {
+ IAutoEditStrategy[] strategies = new IAutoEditStrategy[1];
+ strategies[0] = new AutoEditStrategyForJs();
+ return strategies;
+ } else {
+ return super.getAutoEditStrategies(sourceViewer, contentType);
+ }
+ }
}
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.jsdt.web.ui/META-INF/MANIFEST.MF
index 4f18a2696a..ec07f29588 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.wst.jsdt.web.ui; singleton:=true
-Bundle-Version: 1.0.300.qualifier
+Bundle-Version: 1.0.301.qualifier
Bundle-Activator: org.eclipse.wst.jsdt.web.ui.internal.JsUIPlugin
Bundle-Vendor: %Bundle-Vendor.0
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml b/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml
index 380b89606b..604fd98033 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml
@@ -28,6 +28,10 @@
type="org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor"
class="org.eclipse.wst.jsdt.web.ui.internal.java.search.JsFindOccurrencesProcessor"
target="org.eclipse.wst.html.SCRIPT,org.eclipse.wst.html.SCRIPT.EVENTHANDLER" />
+ <provisionalConfiguration
+ type="slaveformattingstrategy"
+ class="org.eclipse.wst.jsdt.web.ui.internal.format.FormattingStrategyJSDT"
+ target="org.eclipse.wst.html.SCRIPT" />
</extension>
<extension
@@ -716,4 +720,16 @@
</contentType>
</proposalComputer>
</extension>
+<extension point="org.eclipse.wst.sse.ui.characterPairing">
+ <inserter class="org.eclipse.wst.jsdt.web.ui.internal.text.JsCharacterPairInserter" id="org.eclipse.wst.jsdt.web.ui.inserter">
+ <contentTypeIdentifier
+ id="org.eclipse.wst.html.core.htmlsource"
+ partitions="org.eclipse.wst.html.SCRIPT, org.eclipse.wst.html.SCRIPT.EVENTHANDLER">
+ </contentTypeIdentifier>
+ <contentTypeIdentifier
+ id="org.eclipse.jst.jsp.core.jspsource"
+ partitions="org.eclipse.wst.html.SCRIPT, org.eclipse.wst.html.SCRIPT.EVENTHANDLER">
+ </contentTypeIdentifier>
+ </inserter>
+</extension>
</plugin>
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/StructuredTextViewerConfigurationJSDT.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/StructuredTextViewerConfigurationJSDT.java
index ec19c2073f..a1d8070fbf 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/StructuredTextViewerConfigurationJSDT.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/StructuredTextViewerConfigurationJSDT.java
@@ -10,12 +10,11 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.web.ui;
-import org.eclipse.jface.text.formatter.IContentFormatter;
-import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
+import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.wst.html.core.text.IHTMLPartitions;
import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
-import org.eclipse.wst.jsdt.web.ui.internal.format.FormattingStrategyJSDT;
+import org.eclipse.wst.jsdt.web.ui.internal.autoedit.AutoEditStrategyForJs;
/**
*
@@ -43,20 +42,16 @@ public class StructuredTextViewerConfigurationJSDT extends StructuredTextViewerC
super();
}
- public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- final IContentFormatter formatter = super.getContentFormatter(sourceViewer);
- if(formatter instanceof MultiPassContentFormatter) {
- /*
- * Check for any externally supported auto edit strategies from EP.
- * [Bradley Childs - childsb@us.ibm.com]
- */
- String[] contentTypes = getConfiguredContentTypes(sourceViewer);
- for (int i = 0; i < contentTypes.length; i++) {
- if (IHTMLPartitions.SCRIPT.equals(contentTypes[i])) {
- ((MultiPassContentFormatter) formatter).setSlaveStrategy(new FormattingStrategyJSDT(), contentTypes[i]);
- }
- }
+ /**
+ * @see org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
+ */
+ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
+ if(contentType.equals(IHTMLPartitions.SCRIPT) || contentType.equals(IHTMLPartitions.SCRIPT_EVENTHANDLER)) {
+ IAutoEditStrategy[] strategies = new IAutoEditStrategy[1];
+ strategies[0] = new AutoEditStrategyForJs();
+ return strategies;
+ } else {
+ return super.getAutoEditStrategies(sourceViewer, contentType);
}
- return formatter;
}
}
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/autoedit/AutoEditStrategyForJs.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/autoedit/AutoEditStrategyForJs.java
index b6622031b9..9c1f97c21f 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/autoedit/AutoEditStrategyForJs.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/autoedit/AutoEditStrategyForJs.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 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
@@ -53,8 +53,8 @@ public class AutoEditStrategyForJs implements IAutoEditStrategy {
return fStrategies;
}
String partitioning = IHTMLPartitions.SCRIPT;
- fStrategies = new IAutoEditStrategy[] { new JavaDocAutoIndentStrategy(partitioning), new SmartSemicolonAutoEditStrategy(partitioning),
- new JavaAutoIndentStrategy(partitioning, getJavaProject(document), null) };
+ fStrategies = new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning),
+ new JavaAutoIndentStrategy(partitioning, getJavaProject(document), null), new JavaDocAutoIndentStrategy(partitioning) };
/* new AutoEditStrategyForTabs() */
return fStrategies;
}
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java
index 3574844ce6..a42e3fded6 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java
@@ -18,6 +18,7 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.wst.jsdt.internal.ui.text.java.JavaCompletionProposal;
import org.eclipse.wst.jsdt.internal.ui.text.java.LazyJavaCompletionProposal;
+import org.eclipse.wst.jsdt.internal.ui.text.java.LazyJavaTypeCompletionProposal;
import org.eclipse.wst.jsdt.ui.text.java.IJavaCompletionProposal;
/**
@@ -94,4 +95,11 @@ public class JSDTCompletionProposal extends JavaCompletionProposal implements IJ
final public void setJavaCompletionProposal(ICompletionProposal javaCompletionProposal) {
fJavaCompletionProposal = javaCompletionProposal;
}
+
+ protected boolean isValidPrefix(String prefix) {
+ if (this.fJavaCompletionProposal instanceof LazyJavaTypeCompletionProposal) {
+ return ((LazyJavaTypeCompletionProposal) this.fJavaCompletionProposal).isValidTypePrefix(prefix);
+ }
+ return super.isValidPrefix(prefix);
+ }
}
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/text/JsCharacterPairInserter.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/text/JsCharacterPairInserter.java
new file mode 100644
index 0000000000..38d02d7ad7
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/text/JsCharacterPairInserter.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.jsdt.web.ui.internal.text;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.link.ILinkedModeListener;
+import org.eclipse.jface.text.link.LinkedModeModel;
+import org.eclipse.jface.text.link.LinkedModeUI.ExitFlags;
+import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.jsdt.core.JavaScriptCore;
+import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin;
+import org.eclipse.wst.jsdt.internal.ui.text.JavaHeuristicScanner;
+import org.eclipse.wst.jsdt.internal.ui.text.Symbols;
+import org.eclipse.wst.jsdt.ui.PreferenceConstants;
+import org.eclipse.wst.jsdt.web.ui.internal.Logger;
+import org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter;
+
+/**
+ * <p>Inserts character pairs in script regions in HTML and JSP documents based on the Javascript
+ * character pairing preferences.</p>
+ */
+public class JsCharacterPairInserter extends AbstractCharacterPairInserter implements IPropertyChangeListener{
+
+ private boolean fCloseStrings;
+ private boolean fCloseBrackets;
+ private boolean fCloseBraces;
+ private boolean fCloseAngularBrackets;
+
+ /**
+ * @see org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter#hasPair(char)
+ */
+ public boolean hasPair(char c) {
+ switch (c) {
+ case '(':
+ case '<':
+ case '[':
+ case '\'':
+ case '\"':
+ case '{':
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter#shouldPair(org.eclipse.jface.text.source.ISourceViewer, char)
+ */
+ protected boolean shouldPair(ISourceViewer viewer, char c) {
+ IDocument document= viewer.getDocument();
+
+ final Point selection= viewer.getSelectedRange();
+ final int offset= selection.x;
+ final int length= selection.y;
+
+ try {
+ IRegion startLine= document.getLineInformationOfOffset(offset);
+ IRegion endLine= document.getLineInformationOfOffset(offset + length);
+
+ JavaHeuristicScanner scanner= new JavaHeuristicScanner(document);
+ int nextToken= scanner.nextToken(offset + length, endLine.getOffset() + endLine.getLength());
+ String next= nextToken == Symbols.TokenEOF ? null : document.get(offset, scanner.getPosition() - offset).trim();
+ int prevToken= scanner.previousToken(offset - 1, startLine.getOffset());
+ int prevTokenOffset= scanner.getPosition() + 1;
+ String previous= prevToken == Symbols.TokenEOF ? null : document.get(prevTokenOffset, offset - prevTokenOffset).trim();
+
+ switch (c) {
+ case '(':
+ if (!fCloseBrackets
+ || nextToken == Symbols.TokenLPAREN
+ || nextToken == Symbols.TokenIDENT
+ || next != null && next.length() > 1)
+ return false;
+ break;
+
+ case '<':
+ if (!(fCloseAngularBrackets && fCloseBrackets)
+ || nextToken == Symbols.TokenLESSTHAN
+ || prevToken != Symbols.TokenLBRACE
+ && prevToken != Symbols.TokenRBRACE
+ && prevToken != Symbols.TokenSEMICOLON
+ && prevToken != Symbols.TokenSYNCHRONIZED
+ && prevToken != Symbols.TokenSTATIC
+ && (prevToken != Symbols.TokenIDENT || !isAngularIntroducer(previous))
+ && prevToken != Symbols.TokenEOF)
+ return false;
+ break;
+
+ case '{':
+ if (!fCloseBraces
+ || nextToken == Symbols.TokenIDENT
+ || next != null && next.length() > 1)
+ return false;
+ break;
+ case '[':
+ if (!fCloseBrackets
+ || nextToken == Symbols.TokenIDENT
+ || next != null && next.length() > 1)
+ return false;
+ break;
+
+ case '\'':
+ case '"':
+ if (!fCloseStrings
+ || nextToken == Symbols.TokenIDENT
+ || prevToken == Symbols.TokenIDENT
+ || next != null && next.length() > 1
+ || previous != null && previous.length() > 1)
+ return false;
+ break;
+
+ default:
+ return false;
+ }
+ } catch (BadLocationException e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter#getPair(char)
+ */
+ protected char getPair(char c) {
+ switch (c) {
+ case '(':
+ return ')';
+ case '<':
+ return '>';
+ case '[':
+ return ']';
+ case '{':
+ return '}';
+ case '\'':
+ return c;
+ case '\"':
+ return c;
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /**
+ * <p>Initialize the preference listener</p>
+ *
+ * @see org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter#initialize()
+ */
+ public void initialize() {
+ super.initialize();
+ IPreferenceStore preferenceStore = JavaScriptPlugin.getDefault().getPreferenceStore();
+ this.fCloseStrings = preferenceStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_STRINGS);
+ this.fCloseBrackets = preferenceStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACKETS);
+ this.fCloseBraces = preferenceStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACES);
+ this.fCloseAngularBrackets = JavaScriptCore.VERSION_1_5.compareTo(
+ preferenceStore.getString(JavaScriptCore.COMPILER_SOURCE)) <= 0;
+ preferenceStore.addPropertyChangeListener(this);
+ }
+
+ /**
+ * <p>Dispose the preference listener</p>
+ *
+ * @see org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter#dispose()
+ */
+ public void dispose() {
+ JavaScriptPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
+ super.dispose();
+ }
+
+ /**
+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if (PreferenceConstants.EDITOR_CLOSE_STRINGS.equals(event.getProperty())){
+ this.fCloseStrings = ((Boolean) event.getNewValue()).booleanValue();
+ } else if (PreferenceConstants.EDITOR_CLOSE_BRACKETS.equals(event.getProperty())) {
+ this.fCloseBrackets = ((Boolean) event.getNewValue()).booleanValue();
+ } else if (PreferenceConstants.EDITOR_CLOSE_BRACES.equals(event.getProperty())) {
+ this.fCloseBraces = ((Boolean) event.getNewValue()).booleanValue();
+ } else if (JavaScriptCore.COMPILER_SOURCE.equals(event.getProperty())) {
+ IPreferenceStore preferenceStore = JavaScriptPlugin.getDefault().getPreferenceStore();
+ this.fCloseAngularBrackets = JavaScriptCore.VERSION_1_5.compareTo(preferenceStore.getString(
+ JavaScriptCore.COMPILER_SOURCE)) <= 0;
+ }
+ }
+
+ /**
+ * TODO: IAN: comment me
+ * @param identifier
+ * @return
+ */
+ private boolean isAngularIntroducer(String identifier) {
+ return identifier.length() > 0
+ && (Character.isUpperCase(identifier.charAt(0))
+ || identifier.startsWith("final") //$NON-NLS-1$
+ || identifier.startsWith("public") //$NON-NLS-1$
+ || identifier.startsWith("public") //$NON-NLS-1$
+ || identifier.startsWith("protected") //$NON-NLS-1$
+ || identifier.startsWith("private")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter#getExitPolicy(char, char, org.eclipse.jface.text.IDocument)
+ */
+ protected IExitPolicy getExitPolicy(char exit, char escape, IDocument document) {
+ return new ExitPolicy(exit, escape, document);
+ }
+
+ /**
+ * <p>An exit policy that deals with a user adding a carriage return between {}.
+ * In that case rather then exiting to the exit position the linked mode is exited
+ * and the carriage return inserted.</p>
+ */
+ private static class ExitPolicy implements IExitPolicy {
+
+ /** exit character */
+ private char fExit;
+
+ /** escape character for the exit character */
+ private char fEscape;
+
+ /** document to execute this exit policy on */
+ private IDocument fDocument;
+
+ /**
+ * <p>Default constructor</p>
+ *
+ * @param exit exit character
+ * @param escape escape character for the exit character
+ * @param document document to execute this exit policy on
+ */
+ public ExitPolicy(char exit, char escape, IDocument document) {
+ fExit = exit;
+ fEscape = escape;
+ fDocument = document;
+ }
+
+ /**
+ * @see org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy#doExit(org.eclipse.jface.text.link.LinkedModeModel, org.eclipse.swt.events.VerifyEvent, int, int)
+ */
+ public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
+ if(!isMasked(offset)) {
+ // if exit character then exit to exit location
+ if (event.character == fExit) {
+ return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
+ }
+
+ // if carriage return and previous character is { then exit linked mode and insert return
+ if (event.character == SWT.CR && offset > 0) {
+ try {
+ if (this.fDocument.getChar(offset - 1) == '{') {
+ return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
+ }
+ } catch (BadLocationException e) {
+ Logger.logException("Error while trying to exit linked mode", e); //$NON-NLS-1$
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * <p>Determine if the exit character has been escaped.<p>
+ *
+ * @param offset current offset in the document
+ * @return <code>true</code> if exit character escaped, <code>false</code> otherwise
+ */
+ private boolean isMasked(int offset) {
+ try {
+ return fEscape == fDocument.getChar(offset - 1);
+ } catch (BadLocationException e) {
+ }
+ return false;
+ }
+ }
+}

Back to the top