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 37374 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.jst.jsp.ui.patch
org.eclipse.jst.jsp.ui.patch (text/plain), 12.92 KB, created by
Amy Wu
on 2006-03-30 20:03:29 EST
(
hide
)
Description:
org.eclipse.jst.jsp.ui.patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2006-03-30 20:03:29 EST
Size:
12.92 KB
patch
obsolete
>Index: src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java >=================================================================== >RCS file: /cvsroot/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java,v >retrieving revision 1.48 >diff -u -r1.48 JSPContentAssistProcessor.java >--- src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java 22 Nov 2005 02:40:41 -0000 1.48 >+++ src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java 31 Mar 2006 01:03:16 -0000 >@@ -1145,7 +1145,8 @@ > } > } > >- addTemplates(request, TemplateContextTypeIdsJSP.ALL); >+ // bug115927 use original document position for all/any region templates >+ addTemplates(request, TemplateContextTypeIdsJSP.ALL, documentPosition); > return request; > } > >@@ -1163,6 +1164,17 @@ > * @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; > >@@ -1174,7 +1186,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]); >@@ -1184,8 +1196,7 @@ > } > } > } >- >- >+ > protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) { > // ignore > } >Index: src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java >=================================================================== >RCS file: /cvsroot/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java,v >retrieving revision 1.5 >diff -u -r1.5 JSPTemplateCompletionProcessor.java >--- src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java 24 Jun 2005 20:12:58 -0000 1.5 >+++ src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java 31 Mar 2006 01:03:16 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2004 IBM Corporation and others. >+ * Copyright (c) 2004, 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 >@@ -10,14 +10,24 @@ > *******************************************************************************/ > package org.eclipse.jst.jsp.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.jst.jsp.ui.internal.JSPUIPlugin; > import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; >@@ -30,12 +40,90 @@ > * JSPTemplateCompletionProcessor is asked for content assist proposals, the > * jsp content assist processor has already set the context type for > * templates. >- * >- * @plannedfor 1.0 > */ > class JSPTemplateCompletionProcessor 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/jst/jsp/ui/internal/contentassist/ReplaceNameTemplateContext.java >=================================================================== >RCS file: src/org/eclipse/jst/jsp/ui/internal/contentassist/ReplaceNameTemplateContext.java >diff -N src/org/eclipse/jst/jsp/ui/internal/contentassist/ReplaceNameTemplateContext.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jst/jsp/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.jst.jsp.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