|
Lines 43-48
Link Here
|
| 43 |
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; |
43 |
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; |
| 44 |
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; |
44 |
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; |
| 45 |
import org.eclipse.jst.jsp.ui.internal.templates.TemplateContextTypeIdsJSP; |
45 |
import org.eclipse.jst.jsp.ui.internal.templates.TemplateContextTypeIdsJSP; |
|
|
46 |
import org.eclipse.swt.graphics.Image; |
| 46 |
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor; |
47 |
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor; |
| 47 |
import org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument; |
48 |
import org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument; |
| 48 |
import org.eclipse.wst.html.core.text.IHTMLPartitions; |
49 |
import org.eclipse.wst.html.core.text.IHTMLPartitions; |
|
Lines 72-77
Link Here
|
| 72 |
import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry; |
73 |
import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry; |
| 73 |
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; |
74 |
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; |
| 74 |
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; |
75 |
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; |
|
|
76 |
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; |
| 75 |
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; |
77 |
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; |
| 76 |
import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; |
78 |
import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; |
| 77 |
import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; |
79 |
import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; |
|
Lines 89-94
Link Here
|
| 89 |
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistUtilities; |
91 |
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistUtilities; |
| 90 |
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator; |
92 |
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator; |
| 91 |
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants; |
93 |
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants; |
|
|
94 |
import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil; |
| 95 |
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; |
| 96 |
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; |
| 92 |
import org.w3c.dom.Attr; |
97 |
import org.w3c.dom.Attr; |
| 93 |
import org.w3c.dom.Document; |
98 |
import org.w3c.dom.Document; |
| 94 |
import org.w3c.dom.Element; |
99 |
import org.w3c.dom.Element; |
|
Lines 246-278
Link Here
|
| 246 |
ITextRegion nameRegion = null; |
251 |
ITextRegion nameRegion = null; |
| 247 |
while (i >= 0) { |
252 |
while (i >= 0) { |
| 248 |
nameRegion = openRegions.get(i--); |
253 |
nameRegion = openRegions.get(i--); |
| 249 |
if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) |
254 |
if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { |
| 250 |
break; |
255 |
break; |
|
|
256 |
} |
| 251 |
} |
257 |
} |
| 252 |
|
258 |
|
| 253 |
// on an empty value, add all the JSP and taglib tags |
|
|
| 254 |
CMElementDeclaration elementDecl = getCMElementDeclaration(node); |
259 |
CMElementDeclaration elementDecl = getCMElementDeclaration(node); |
| 255 |
if (nameRegion != null && elementDecl != null) { |
260 |
if (nameRegion != null && elementDecl != null) { |
| 256 |
String attributeName = open.getText(nameRegion); |
261 |
String attributeName = open.getText(nameRegion); |
| 257 |
if (attributeName != null) { |
262 |
if (attributeName != null) { |
| 258 |
String currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue(); |
263 |
Node parent = contentAssistRequest.getParent(); |
|
|
264 |
|
| 265 |
//ignore starte quote in match string |
| 266 |
String matchString = contentAssistRequest.getMatchString().trim(); |
| 267 |
if(matchString.startsWith("'") || matchString.startsWith("\"")) { |
| 268 |
matchString = matchString.substring(1); |
| 269 |
} |
| 259 |
|
270 |
|
| 260 |
if(currentValue == null || currentValue.length() == 0) { //$NON-NLS-1$ |
271 |
//get all the proposals |
| 261 |
List additionalElements = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES); |
272 |
List additionalElements = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ALL); |
| 262 |
for (i = 0; i < additionalElements.size(); i++) { |
273 |
Iterator nodeIterator = additionalElements.iterator(); |
| 263 |
Object additionalElement = additionalElements.get(i); |
274 |
|
| 264 |
if(additionalElement instanceof CMElementDeclaration) { |
275 |
//check each suggestion |
| 265 |
CMElementDeclaration ed = (CMElementDeclaration) additionalElement; |
276 |
while (nodeIterator.hasNext()) { |
| 266 |
|
277 |
CMNode additionalElementDecl = (CMNode) nodeIterator.next(); |
|
|
278 |
if (additionalElementDecl != null && additionalElementDecl instanceof CMElementDeclaration) { |
| 279 |
CMElementDeclaration ed = (CMElementDeclaration) additionalElementDecl; |
| 280 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811 |
| 281 |
StringBuffer sb = new StringBuffer(); |
| 282 |
getContentGenerator().generateTag(parent, ed, sb); |
| 283 |
|
| 284 |
String proposedText = sb.toString(); |
| 285 |
|
| 286 |
//filter out any proposals that dont match matchString |
| 287 |
if (beginsWith(proposedText, matchString)) { |
| 288 |
//wrap with ' because JSP attributes are warped with " |
| 289 |
proposedText = "'" + proposedText; |
| 290 |
|
| 291 |
//if its a container its possible the closing quote is already there |
| 292 |
//don't want to risk injecting an extra |
| 293 |
if(!(contentAssistRequest.getRegion() instanceof ITextRegionContainer)) { |
| 294 |
proposedText += "'"; |
| 295 |
} |
| 296 |
|
| 297 |
Image image = CMImageUtil.getImage(elementDecl); |
| 298 |
if (image == null) { |
| 299 |
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); |
| 300 |
} |
| 301 |
|
| 302 |
//create the proposal |
| 303 |
int cursorAdjustment = getCursorPositionForProposedText(proposedText); |
| 304 |
String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl); |
| 267 |
String tagname = getContentGenerator().getRequiredName(node, ed); |
305 |
String tagname = getContentGenerator().getRequiredName(node, ed); |
| 268 |
StringBuffer contents = new StringBuffer("\""); //$NON-NLS-1$ |
306 |
CustomCompletionProposal proposal = new CustomCompletionProposal( |
| 269 |
getContentGenerator().generateTag(node, ed, contents); |
307 |
proposedText, contentAssistRequest.getReplacementBeginPosition(), |
| 270 |
contents.append('"'); //$NON-NLS-1$ |
308 |
contentAssistRequest.getReplacementLength(), cursorAdjustment, image, tagname, null, proposedInfo, |
| 271 |
CustomCompletionProposal proposal = new CustomCompletionProposal(contents.toString(), contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), contents.length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), tagname, null, null, XMLRelevanceConstants.R_JSP_ATTRIBUTE_VALUE); |
309 |
XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); |
| 272 |
contentAssistRequest.addProposal(proposal); |
310 |
contentAssistRequest.addProposal(proposal); |
| 273 |
} |
311 |
} |
| 274 |
} |
312 |
} |
| 275 |
|
|
|
| 276 |
} |
313 |
} |
| 277 |
} |
314 |
} |
| 278 |
} |
315 |
} |
|
Lines 400-407
Link Here
|
| 400 |
Logger.logException("Error in embedded JSP Content Assist", e); //$NON-NLS-1$ |
437 |
Logger.logException("Error in embedded JSP Content Assist", e); //$NON-NLS-1$ |
| 401 |
} |
438 |
} |
| 402 |
} |
439 |
} |
| 403 |
|
|
|
| 404 |
|
| 405 |
} |
440 |
} |
| 406 |
|
441 |
|
| 407 |
/** |
442 |
/** |
|
Lines 668-702
Link Here
|
| 668 |
} |
703 |
} |
| 669 |
} |
704 |
} |
| 670 |
|
705 |
|
| 671 |
// check if it's in an attribute value, if so, don't add CDATA |
706 |
//get the embedded results |
| 672 |
// proposal |
|
|
| 673 |
ITextRegion attrContainer = (fn != null) ? fn.getRegionAtCharacterOffset(documentPosition) : null; |
| 674 |
if (attrContainer != null && attrContainer instanceof ITextRegionContainer) { |
| 675 |
if (attrContainer.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { |
| 676 |
// test location of the cursor |
| 677 |
// return null if it's in the middle of an open/close |
| 678 |
// delimeter |
| 679 |
Iterator attrRegions = ((ITextRegionContainer) attrContainer).getRegions().iterator(); |
| 680 |
ITextRegion testRegion = null; |
| 681 |
while (attrRegions.hasNext()) { |
| 682 |
testRegion = (ITextRegion) attrRegions.next(); |
| 683 |
// need to check for other valid attribute regions |
| 684 |
if (XMLContentAssistUtilities.isJSPOpenDelimiter(testRegion.getType())) { |
| 685 |
if (!(((ITextRegionContainer) attrContainer).getEndOffset(testRegion) <= documentPosition)) |
| 686 |
return EMPTY_PROPOSAL_SET; |
| 687 |
} |
| 688 |
else if (XMLContentAssistUtilities.isJSPCloseDelimiter(testRegion.getType())) { |
| 689 |
if (!(((ITextRegionContainer) attrContainer).getStartOffset(testRegion) >= documentPosition)) |
| 690 |
return EMPTY_PROPOSAL_SET; |
| 691 |
} |
| 692 |
} |
| 693 |
// TODO: handle non-Java code such as nested tags |
| 694 |
if (testRegion.getType().equals(DOMJSPRegionContexts.JSP_CONTENT)) |
| 695 |
return getJSPJavaCompletionProposals(viewer, documentPosition); |
| 696 |
return EMPTY_PROPOSAL_SET; |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(partitionType); |
707 |
IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(partitionType); |
| 701 |
if (p != null) { |
708 |
if (p != null) { |
| 702 |
embeddedResults = p.computeCompletionProposals(viewer, documentPosition); |
709 |
embeddedResults = p.computeCompletionProposals(viewer, documentPosition); |