Author: vrubezhny
Date: 2009-12-11 09:46:35 -0500 (Fri, 11 Dec 2009)
New Revision: 19210
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java
Log:
JBIDE-4553: JSF EL inserted w/o closed } using CA on xhtml page if it was called w/o
closed } and " .
Issue is fixed
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-12-11
14:40:28 UTC (rev 19209)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-12-11
14:46:35 UTC (rev 19210)
@@ -938,10 +938,68 @@
}
/**
- * Returns URI for the current/parent tag
+ * Returns EL Prefix Text Region Information Object
+ *
* @return
*/
- @SuppressWarnings("deprecation")
+ protected TextRegion getELPrefix(ContentAssistRequest request) {
+ if (!DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(request.getRegion().getType())
&&
+ !DOMRegionContext.XML_CONTENT.equals(request.getRegion().getType()))
+ return null;
+
+ String text = request.getDocumentRegion().getFullText(request.getRegion());
+ int startOffset = request.getDocumentRegion().getStartOffset() +
request.getRegion().getStart();
+
+ boolean isAttributeValue = false;
+ boolean hasOpenQuote = false;
+ boolean hasCloseQuote = false;
+ char quoteChar = (char)0;
+ if (DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(request.getRegion().getType())) {
+ isAttributeValue = true;
+ if (text.startsWith("\"") || text.startsWith("'"))
{//$NON-NLS-1$ //$NON-NLS-2$
+ quoteChar = text.charAt(0);
+ hasOpenQuote = true;
+ }
+ if (hasOpenQuote && text.endsWith(String.valueOf(quoteChar))) {
+ hasCloseQuote = true;
+ }
+ }
+
+ int inValueOffset = getOffset() - startOffset;
+ if (text != null && text.length() < inValueOffset) { // probably, the
attribute value ends before the document position
+ return null;
+ }
+ if (inValueOffset<0) {
+ return null;
+ }
+
+// String matchString = text.substring(0, inValueOffset);
+
+ ELParser p = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = p.parse(text);
+
+ ELInstance is = ELUtil.findInstance(model, inValueOffset);// ELInstance
+ ELInvocationExpression ie = ELUtil.findExpression(model, inValueOffset);//
ELExpression
+
+ boolean isELStarted = (model != null && is != null &&
(model.toString().startsWith("#{") || //$NON-NLS-1$
+ model.toString().startsWith("${"))); //$NON-NLS-1$
+ boolean isELClosed = (model != null && is != null &&
model.toString().endsWith("}")); //$NON-NLS-1$
+
+// boolean insideEL = startOffset + model.toString().length()
+ TextRegion tr = new TextRegion(startOffset, ie == null ? inValueOffset :
ie.getStartPosition(),
+ ie == null ? 0 : inValueOffset - ie.getStartPosition(), ie == null ? "" :
ie.getText(), //$NON-NLS-1$
+ isELStarted, isELClosed,
+ isAttributeValue, hasOpenQuote, hasCloseQuote, quoteChar);
+
+ return tr;
+ }
+
+ /**
+ * Returns EL Prefix Text Region Information Object
+ *
+ * @deprecated
+ * @return
+ */
protected TextRegion getELPrefix() {
IStructuredModel sModel = StructuredModelManager
.getModelManager()
@@ -1038,14 +1096,27 @@
private String text;
private boolean isELStarted;
private boolean isELClosed;
+ private boolean isAttributeValue;
+ private boolean hasOpenQuote;
+ private boolean hasCloseQuote;
+ private char quoteChar;
TextRegion(int startOffset, int offset, int length, String text, boolean isELStarted,
boolean isELClosed) {
+ this(startOffset, offset, length, text, isELStarted, isELClosed, false, false, false,
(char)0);
+ }
+
+ TextRegion(int startOffset, int offset, int length, String text, boolean isELStarted,
boolean isELClosed,
+ boolean isAttributeValue, boolean hasOpenQuote, boolean hasCloseQuote, char
quoteChar) {
this.startOffset = startOffset;
this.offset = offset;
this.length = length;
this.text = text;
this.isELStarted = isELStarted;
this.isELClosed = isELClosed;
+ this.isAttributeValue = isAttributeValue;
+ this.hasOpenQuote = hasOpenQuote;
+ this.hasCloseQuote = hasCloseQuote;
+ this.quoteChar = quoteChar;
}
public int getStartOffset() {
@@ -1074,5 +1145,21 @@
public boolean isELClosed() {
return isELClosed;
}
+
+ public boolean isAttributeValue() {
+ return isAttributeValue;
+ }
+
+ public char getQuoteChar() {
+ return quoteChar;
+ }
+
+ public boolean hasOpenQuote() {
+ return hasOpenQuote;
+ }
+
+ public boolean hasCloseQuote() {
+ return hasCloseQuote;
+ }
}
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-12-11
14:40:28 UTC (rev 19209)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-12-11
14:46:35 UTC (rev 19210)
@@ -49,12 +49,12 @@
*/
@Override
protected void addTextELProposals(ContentAssistRequest contentAssistRequest) {
- TextRegion prefix = getELPrefix();
+ TextRegion prefix = getELPrefix(contentAssistRequest);
if (prefix == null || !prefix.isELStarted()) {
AutoContentAssistantProposal proposal = new AutoContentAssistantProposal(true,
"#{}", //$NON-NLS-1$
contentAssistRequest.getReplacementBeginPosition(),
0, 2, JSF_EL_PROPOSAL_IMAGE,
JstUIMessages.JspContentAssistProcessor_NewELExpression, null,
- JstUIMessages.FaceletPageContectAssistProcessor_NewELExpressionTextInfo,
TextProposal.R_XML_ATTRIBUTE_VALUE_TEMPLATE);
+ JstUIMessages.FaceletPageContectAssistProcessor_NewELExpressionTextInfo,
TextProposal.R_TAG_INSERTION + 1);
contentAssistRequest.addProposal(proposal);
return;
@@ -77,6 +77,11 @@
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString();
int cursorPosition = replacementString.length();
+
+ if (!prefix.isELClosed()) {
+ replacementString += "}"; //$NON-NLS-1$
+ }
+
Image image = textProposal.getImage();
// JBIDE-512, JBIDE-2541 related changes ===>>>
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java 2009-12-11
14:40:28 UTC (rev 19209)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java 2009-12-11
14:46:35 UTC (rev 19210)
@@ -97,7 +97,7 @@
// Need to check if an EL Expression is opened here.
// If it is true we don't need to start any new tag proposals
- TextRegion prefix = getELPrefix();
+ TextRegion prefix = getELPrefix(contentAssistRequest);
if (prefix != null && prefix.isELStarted()) {
return;
}
@@ -237,7 +237,7 @@
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) {
// Need to check if an EL Expression is opened here.
// If it is true we don't need to start any new tag proposals
- TextRegion prefix = getELPrefix();
+ TextRegion prefix = getELPrefix(contentAssistRequest);
if (prefix != null && prefix.isELStarted()) {
return;
}
@@ -285,13 +285,14 @@
@Override
protected void addAttributeValueELProposals(ContentAssistRequest contentAssistRequest)
{
- TextRegion prefix = getELPrefix();
+ TextRegion prefix = getELPrefix(contentAssistRequest);
if (prefix == null) {
return;
}
if(!prefix.isELStarted()) {
- AutoContentAssistantProposal proposal = new AutoContentAssistantProposal(true,
"#{}", //$NON-NLS-1$
+ AutoContentAssistantProposal proposal = new AutoContentAssistantProposal(true,
+ "#{}" + (prefix.isAttributeValue() && prefix.hasOpenQuote()
&& !prefix.hasCloseQuote() ? String.valueOf(prefix.getQuoteChar()) :
""), //$NON-NLS-1$ //$NON-NLS-2$
getOffset(), 0, 2, JSF_EL_PROPOSAL_IMAGE,
JstUIMessages.JspContentAssistProcessor_NewELExpression,
null, JstUIMessages.JspContentAssistProcessor_NewELExpressionAttrInfo,
TextProposal.R_XML_ATTRIBUTE_VALUE_TEMPLATE);
@@ -315,7 +316,21 @@
int replacementOffset = beginChangeOffset;
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString();
+
+ char quoteChar = prefix.isAttributeValue() && prefix.hasOpenQuote() ?
prefix.getQuoteChar() : '"';
+// if (prefix.isAttributeValue() && !prefix.hasOpenQuote()) {
+// replacementString = String.valueOf(quoteChar) + replacementString;
+// }
int cursorPosition = replacementString.length();
+
+ if (!prefix.isELClosed()) {
+ replacementString += "}"; //$NON-NLS-1$
+ }
+
+ if (prefix.isAttributeValue() && prefix.hasOpenQuote() &&
!prefix.hasCloseQuote()) {
+ replacementString += String.valueOf(quoteChar);
+ }
+
Image image = textProposal.getImage();
// JBIDE-512, JBIDE-2541 related changes ===>>>
@@ -340,9 +355,10 @@
}
if (prefix.isELStarted() && !prefix.isELClosed()) {
- AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal("}", //$NON-NLS-1$
- getOffset(), 0, 1, JSF_EL_PROPOSAL_IMAGE,
JstUIMessages.JspContentAssistProcessor_CloseELExpression,
- null, JstUIMessages.JspContentAssistProcessor_CloseELExpressionInfo,
TextProposal.R_XML_ATTRIBUTE_VALUE_TEMPLATE);
+ AutoContentAssistantProposal proposal = new AutoContentAssistantProposal(
+ "}" + (prefix.isAttributeValue() && prefix.hasOpenQuote()
&& !prefix.hasCloseQuote() ? String.valueOf(prefix.getQuoteChar()) :
""), //$NON-NLS-1$ //$NON-NLS-2$
+ getOffset(), 0, 0, JSF_EL_PROPOSAL_IMAGE,
JstUIMessages.JspContentAssistProcessor_CloseELExpression,
+ null, JstUIMessages.JspContentAssistProcessor_CloseELExpressionInfo,
TextProposal.R_XML_ATTRIBUTE_VALUE + 1); //
contentAssistRequest.addProposal(proposal);
}
@@ -350,12 +366,12 @@
@Override
protected void addTextELProposals(ContentAssistRequest contentAssistRequest) {
- TextRegion prefix = getELPrefix();
+ TextRegion prefix = getELPrefix(contentAssistRequest);
if (prefix == null || !prefix.isELStarted()) {
AutoContentAssistantProposal proposal = new AutoContentAssistantProposal(true,
"#{}", //$NON-NLS-1$
contentAssistRequest.getReplacementBeginPosition(),
0, 2, JSF_EL_PROPOSAL_IMAGE,
JstUIMessages.JspContentAssistProcessor_NewELExpression, null,
- JstUIMessages.FaceletPageContectAssistProcessor_NewELExpressionTextInfo,
TextProposal.R_XML_ATTRIBUTE_VALUE_TEMPLATE);
+ JstUIMessages.FaceletPageContectAssistProcessor_NewELExpressionTextInfo,
TextProposal.R_TAG_INSERTION + 1);
contentAssistRequest.addProposal(proposal);
return;
@@ -378,6 +394,11 @@
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString();
int cursorPosition = replacementString.length();
+
+ if (!prefix.isELClosed()) {
+ replacementString += "}"; //$NON-NLS-1$
+ }
+
Image image = textProposal.getImage();
// JBIDE-512, JBIDE-2541 related changes ===>>>