Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 107138 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java (-46 / +53 lines)
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);
(-)src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java (-22 / +45 lines)
Lines 340-367 Link Here
340
					}
340
					}
341
					boolean currentValid = false;
341
					boolean currentValid = false;
342
342
343
					// d210858, if the region's a container, don't suggest the
343
					//create suggestions for enumerated values
344
					// enumerated values as they probably won't help
344
					int rOffset = contentAssistRequest.getReplacementBeginPosition();
345
					boolean existingComplicatedValue = (contentAssistRequest.getRegion() != null) && (contentAssistRequest.getRegion() instanceof ITextRegionContainer);
345
					int rLength = contentAssistRequest.getReplacementLength();
346
					if (!existingComplicatedValue) {
346
					for (Iterator j = possibleValues.iterator(); j.hasNext();) {
347
						int rOffset = contentAssistRequest.getReplacementBeginPosition();
347
						String possibleValue = (String) j.next();
348
						int rLength = contentAssistRequest.getReplacementLength();
348
						if(!possibleValue.equals(defaultValue)) {
349
						for (Iterator j = possibleValues.iterator(); j.hasNext();) {
349
							currentValid = currentValid || possibleValue.equals(currentValue);
350
							String possibleValue = (String) j.next();
350
							if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
351
							if(!possibleValue.equals(defaultValue)) {
351
								String rString = "\"" + possibleValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
352
								currentValid = currentValid || possibleValue.equals(currentValue);
352
								CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, possibleValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
353
								if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
353
								contentAssistRequest.addProposal(proposal);
354
									String rString = "\"" + possibleValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
355
									CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, possibleValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
356
									contentAssistRequest.addProposal(proposal);
357
								}
358
							}
354
							}
359
						}
355
						}
360
						if(defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
356
					}
361
							String rString = "\"" + defaultValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
357
					if(defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
362
							CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, defaultValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
358
						String rString = "\"" + defaultValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
363
							contentAssistRequest.addProposal(proposal);
359
						CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, defaultValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
364
						}
360
						contentAssistRequest.addProposal(proposal);
365
					}
361
					}
366
				}
362
				}
367
				else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) || (attrDecl.getAttrType().getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) && (attrDecl.getAttrType().getImpliedValue() != null)) {
363
				else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) || (attrDecl.getAttrType().getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) && (attrDecl.getAttrType().getImpliedValue() != null)) {
Lines 1132-1138 Link Here
1132
	 * @return the position the cursor should be in after the proposal is
1128
	 * @return the position the cursor should be in after the proposal is
1133
	 *         applied
1129
	 *         applied
1134
	 */
1130
	 */
1135
	private int getCursorPositionForProposedText(String proposedText) {
1131
	protected int getCursorPositionForProposedText(String proposedText) {
1136
		int cursorAdjustment;
1132
		int cursorAdjustment;
1137
		cursorAdjustment = proposedText.indexOf("\"\"") + 1; //$NON-NLS-1$
1133
		cursorAdjustment = proposedText.indexOf("\"\"") + 1; //$NON-NLS-1$
1138
		// otherwise, after the first tag
1134
		// otherwise, after the first tag
Lines 1262-1268 Link Here
1262
				addAttributeNameProposals(contentAssistRequest);
1258
				addAttributeNameProposals(contentAssistRequest);
1263
			}
1259
			}
1264
			else {
1260
			else {
1265
				contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
1261
				int replaceLength = completionRegion.getTextLength();
1262
				
1263
				//if container region, be sure replace length is only the attribute value region not the entire container
1264
				if(completionRegion instanceof ITextRegionContainer){
1265
					ITextRegion openRegion = ((ITextRegionContainer) completionRegion).getFirstRegion();
1266
					ITextRegion closeRegion = ((ITextRegionContainer) completionRegion).getLastRegion();
1267
					
1268
					/*
1269
					 * check to see if the container is opened the same way its closed.
1270
					 * Such as:
1271
					 * <img src=' '
1272
					 * But not:
1273
					 * <img src='
1274
					 * 
1275
					 * </body>
1276
					 * </html>
1277
					 * In the latter case we only want to replace the opening text of the container
1278
					 * Admittedly crude test, but effective.
1279
					 */
1280
					if(openRegion.getType() != closeRegion.getType()) {
1281
						replaceLength = openRegion.getTextLength();
1282
					}
1283
				} 
1284
				
1285
				contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion,
1286
						completionRegion, sdRegion.getStartOffset(completionRegion),
1287
						replaceLength, matchString);
1288
				
1266
				addAttributeValueProposals(contentAssistRequest);
1289
				addAttributeValueProposals(contentAssistRequest);
1267
			}
1290
			}
1268
		}
1291
		}

Return to bug 107138