Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 37376 Details for
Bug 115927
First attribute quote is deleted if insert JSP expression through statement completion
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
org.eclipse.wst.xml.ui.patch
org.eclipse.wst.xml.ui.patch (text/plain), 12.51 KB, created by
Amy Wu
on 2006-03-30 20:03:53 EST
(
hide
)
Description:
org.eclipse.wst.xml.ui.patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2006-03-30 20:03:53 EST
Size:
12.51 KB
patch
obsolete
>Index: src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xml/plugins/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java,v >retrieving revision 1.2 >diff -u -r1.2 XMLContentAssistProcessor.java >--- src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java 18 Apr 2005 07:59:12 -0000 1.2 >+++ src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java 31 Mar 2006 01:02:49 -0000 >@@ -65,9 +65,20 @@ > * @param context > */ > private void addTemplates(ContentAssistRequest contentAssistRequest, String context) { >+ addTemplates(contentAssistRequest, context, contentAssistRequest.getReplacementBeginPosition()); >+ } >+ >+ /** >+ * Adds templates to the list of proposals >+ * >+ * @param contentAssistRequest >+ * @param context >+ * @param startOffset >+ */ >+ private void addTemplates(ContentAssistRequest contentAssistRequest, String context, int startOffset) { > if (contentAssistRequest == null) > return; >- >+ > // if already adding template proposals for a certain context type, do > // not add again > if (!fTemplateContexts.contains(context)) { >@@ -76,7 +87,7 @@ > > if (getTemplateCompletionProcessor() != null) { > getTemplateCompletionProcessor().setContextType(context); >- ICompletionProposal[] proposals = getTemplateCompletionProcessor().computeCompletionProposals(fTextViewer, contentAssistRequest.getReplacementBeginPosition()); >+ ICompletionProposal[] proposals = getTemplateCompletionProcessor().computeCompletionProposals(fTextViewer, startOffset); > for (int i = 0; i < proposals.length; ++i) { > if (useProposalList) > contentAssistRequest.addProposal(proposals[i]); >@@ -89,7 +100,8 @@ > > protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) { > ContentAssistRequest request = super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); >- addTemplates(request, TemplateContextTypeIdsXML.ALL); >+ // bug115927 use original document position for all/any region templates >+ addTemplates(request, TemplateContextTypeIdsXML.ALL, documentPosition); > return request; > } > >Index: src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xml/plugins/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java,v >retrieving revision 1.1 >diff -u -r1.1 XMLTemplateCompletionProcessor.java >--- src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java 13 Apr 2005 13:59:25 -0000 1.1 >+++ src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java 31 Mar 2006 01:02:49 -0000 >@@ -12,14 +12,24 @@ > *******************************************************************************/ > package org.eclipse.wst.xml.ui.internal.contentassist; > >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.Comparator; >+import java.util.List; >+ >+import org.eclipse.jface.text.IDocument; > import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITextSelection; > import org.eclipse.jface.text.ITextViewer; >+import org.eclipse.jface.text.Region; > import org.eclipse.jface.text.contentassist.ICompletionProposal; > import org.eclipse.jface.text.templates.ContextTypeRegistry; > import org.eclipse.jface.text.templates.Template; > import org.eclipse.jface.text.templates.TemplateCompletionProcessor; > import org.eclipse.jface.text.templates.TemplateContext; > import org.eclipse.jface.text.templates.TemplateContextType; >+import org.eclipse.jface.text.templates.TemplateException; >+import org.eclipse.jface.text.templates.TemplateProposal; > import org.eclipse.jface.text.templates.persistence.TemplateStore; > import org.eclipse.swt.graphics.Image; > import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; >@@ -35,8 +45,88 @@ > * templates. > */ > class XMLTemplateCompletionProcessor extends TemplateCompletionProcessor { >+ private static final class ProposalComparator implements Comparator { >+ public int compare(Object o1, Object o2) { >+ return ((TemplateProposal) o2).getRelevance() - ((TemplateProposal) o1).getRelevance(); >+ } >+ } >+ >+ private static final Comparator fgProposalComparator = new ProposalComparator(); > private String fContextTypeId = null; > >+ /* >+ * Copied from super class except instead of calling createContext(viewer, >+ * region) call createContext(viewer, region, offset) instead >+ */ >+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { >+ >+ ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection(); >+ >+ // adjust offset to end of normalized selection >+ if (selection.getOffset() == offset) >+ offset = selection.getOffset() + selection.getLength(); >+ >+ String prefix = extractPrefix(viewer, offset); >+ Region region = new Region(offset - prefix.length(), prefix.length()); >+ TemplateContext context = createContext(viewer, region, offset); >+ if (context == null) >+ return new ICompletionProposal[0]; >+ >+ context.setVariable("selection", selection.getText()); // name of the >+ // selection >+ // variables >+ // {line, >+ // word}_selection >+ // //$NON-NLS-1$ >+ >+ Template[] templates = getTemplates(context.getContextType().getId()); >+ >+ List matches = new ArrayList(); >+ for (int i = 0; i < templates.length; i++) { >+ Template template = templates[i]; >+ try { >+ context.getContextType().validate(template.getPattern()); >+ } >+ catch (TemplateException e) { >+ continue; >+ } >+ if (template.matches(prefix, context.getContextType().getId())) >+ matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix))); >+ } >+ >+ Collections.sort(matches, fgProposalComparator); >+ >+ return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]); >+ } >+ >+ /** >+ * Creates a concrete template context for the given region in the >+ * document. This involves finding out which context type is valid at the >+ * given location, and then creating a context of this type. The default >+ * implementation returns a <code>SmartReplaceTemplateContext</code> for >+ * the context type at the given location. This takes the offset at which >+ * content assist was invoked into consideration. >+ * >+ * @param viewer >+ * the viewer for which the context is created >+ * @param region >+ * the region into <code>document</code> for which the >+ * context is created >+ * @param offset >+ * the original offset where content assist was invoked >+ * @return a template context that can handle template insertion at the >+ * given location, or <code>null</code> >+ */ >+ private TemplateContext createContext(ITextViewer viewer, IRegion region, int offset) { >+ // pretty much same code as super.createContext except create SmartReplaceTemplateContext >+ TemplateContextType contextType = getContextType(viewer, region); >+ if (contextType != null) { >+ IDocument document = viewer.getDocument(); >+ return new ReplaceNameTemplateContext(contextType, document, region.getOffset(), region.getLength(), offset); >+ } >+ return null; >+ } >+ > protected ICompletionProposal createProposal(Template template, TemplateContext context, IRegion region, int relevance) { > return new CustomTemplateProposal(template, context, region, getImage(template), relevance); > } >Index: src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java >diff -N src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,109 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.xml.ui.internal.contentassist; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.Position; >+import org.eclipse.jface.text.templates.DocumentTemplateContext; >+import org.eclipse.jface.text.templates.Template; >+import org.eclipse.jface.text.templates.TemplateBuffer; >+import org.eclipse.jface.text.templates.TemplateContextType; >+import org.eclipse.jface.text.templates.TemplateException; >+ >+/** >+ * Just like DocumentTemplateContext except if an insert offset is passed in, >+ * during evaluation, the "prefix" before the template will be checked to see >+ * if it matches the template name. If so, overwrite the template name. >+ * Otherwise, just insert the template at the insert offset location (by not >+ * overwriting the prefix text) >+ */ >+public class ReplaceNameTemplateContext extends DocumentTemplateContext { >+ private int fInsertOffset = -1; >+ >+ /** >+ * Creates a document template context. >+ * >+ * @param type >+ * the context type >+ * @param document >+ * the document this context applies to >+ * @param offset >+ * the offset of the document region >+ * @param length >+ * the length of the document region >+ */ >+ public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, int offset, int length) { >+ this(type, document, new Position(offset, length)); >+ } >+ >+ /** >+ * Creates a document template context. The supplied <code>Position</code> >+ * will be queried to compute the <code>getStart</code> and >+ * <code>getEnd</code> methods, which will therefore answer updated >+ * position data if it is registered with the document. >+ * >+ * @param type >+ * the context type >+ * @param document >+ * the document this context applies to >+ * @param position >+ * the position describing the area of the document which forms >+ * the template context >+ * @since 3.1 >+ */ >+ public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, Position position) { >+ super(type, document, position); >+ } >+ >+ /** >+ * Creates a document template context. >+ * >+ * @param type >+ * the context type >+ * @param document >+ * the document this context applies to >+ * @param offset >+ * the offset of the document region >+ * @param length >+ * the length of the document region >+ * @param insertOffset >+ * the offset of the document region where insert was >+ * originally requested >+ */ >+ public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, int offset, int length, int insertOffset) { >+ this(type, document, new Position(offset, length)); >+ fInsertOffset = insertOffset; >+ } >+ >+ /* >+ * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template) >+ */ >+ public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { >+ TemplateBuffer buffer = super.evaluate(template); >+ if (buffer != null) { >+ if (fInsertOffset > -1 && fInsertOffset > getStart()) { >+ try { >+ String prefix = getDocument().get(getStart(), fInsertOffset - getStart()); >+ if (!template.getName().startsWith(prefix)) { >+ // generate a new buffer that actually contains the >+ // text that was going to be overwritten >+ buffer = new TemplateBuffer(prefix + buffer.getString(), buffer.getVariables()); >+ } >+ } >+ catch (BadLocationException e) { >+ >+ } >+ } >+ } >+ return buffer; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 115927
:
37284
|
37285
|
37286
|
37374
|
37375
| 37376