[280115] EL: Content assist broken
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
index dbd4121..f0c4e2b 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
@@ -409,7 +409,8 @@
if(node.jjtGetChild(0) instanceof ASTValuePrefix && node.jjtGetChild(1) instanceof ASTValueSuffix) {
ASTValuePrefix prefix = (ASTValuePrefix) node.jjtGetChild(0);
ASTValueSuffix suffix = (ASTValueSuffix) node.jjtGetChild(1);
- if(prefix.firstToken.image.equals("pageContext") && suffix.getPropertyNameToken().image.equals("request")) {
+ //content assist can cause a null pointer here without the extra null check
+ if(prefix.firstToken.image.equals("pageContext") && suffix.getPropertyNameToken() != null && suffix.getPropertyNameToken().image.equals("request")) {
append("((HTTPServletRequest)");
}
}
@@ -471,7 +472,10 @@
append(")");
}
-
+ } else if(node.getLastToken().image.equals(".") && node.getLastToken().next.image.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
+ //this allows for content assist in the case of something along the lines of "pageContext." and then ctl-space
+ append(node.firstToken);
+ append("get()", node.getLastToken().beginColumn, node.getLastToken().beginColumn); //$NON-NLS-1$
} else {
append(node.firstToken);
}
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java
index ac11da6..58011e5 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2009 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
@@ -65,6 +65,24 @@
* proposals are possible
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos) {
+ return computeCompletionProposals(viewer, pos, 0);
+ }
+
+ /**
+ * The same as the normal <code>computeCompeltaionProposals</code> except the calculated
+ * java position is offset by the given extra offset.
+ *
+ * @param viewer
+ * the viewer whose document is used to compute the proposals
+ * @param documentPosition
+ * an offset within the document for which completions should
+ * be computed
+ * @param javaPositionExtraOffset
+ * the extra offset for the java position
+ * @return an array of completion proposals or <code>null</code> if no
+ * proposals are possible
+ */
+ protected ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos, int javaPositionExtraOffset) {
initialize(pos);
JSPProposalCollector collector = null;
@@ -82,7 +100,7 @@
if (fTranslationAdapter != null) {
JSPTranslation translation = fTranslationAdapter.getJSPTranslation();
- fJavaPosition = translation.getJavaOffset(getDocumentPosition());
+ fJavaPosition = translation.getJavaOffset(getDocumentPosition())+javaPositionExtraOffset;
if (DEBUG)
System.out.println(debug(translation));
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProposal.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProposal.java
index ac5c6d5..c4a6036 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProposal.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProposal.java
@@ -53,7 +53,9 @@
setCursorPosition(getCursorPosition() + 1);
}
super.apply(viewer, trigger, stateMask, offset);
-
+ //move the caret to the end of the change
+ int endOffsetOfChanges = getReplacementString().length() + getReplacementOffset();
+ viewer.getTextWidget().setCaretOffset(endOffsetOfChanges);
}
final public ICompletionProposal getJavaCompletionProposal() {
@@ -73,6 +75,17 @@
return additionalInfo;
}
+ /**
+ * use the java proposals image if there is one for this proposals image
+ */
+ public Image getImage() {
+ if(this.fJavaCompletionProposal != null) {
+ return this.fJavaCompletionProposal.getImage();
+ } else {
+ return super.getImage();
+ }
+ }
+
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension5#getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor)
*/
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELCompletionProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELCompletionProcessor.java
index 0ef4b79..f2b2d28 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELCompletionProcessor.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELCompletionProcessor.java
@@ -1,10 +1,21 @@
package org.eclipse.jst.jsp.ui.internal.contentassist;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jst.jsp.core.internal.java.JSPTranslation;
public class JSPELCompletionProcessor extends JSPCompletionProcessor {
protected JSPProposalCollector getProposalCollector(ICompilationUnit cu, JSPTranslation translation) {
return new JSPELProposalCollector(cu, translation);
}
+
+ /**
+ * The java position offset needs to be shifted 3 for the "get" in the java
+ * proposal mapped to a given JSP EL proposal
+ */
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos) {
+ //3 for the "get" at the beginning of the java proposal
+ return computeCompletionProposals(viewer, pos, 3);
+ }
}
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELContentAssistProcessor.java
index ad5ce00..75d48ad 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELContentAssistProcessor.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELContentAssistProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 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
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELProposalCollector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELProposalCollector.java
index 5aa3eb8..5c7a039 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELProposalCollector.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELProposalCollector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 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
@@ -40,10 +40,11 @@
}
// java offset
- int offset = proposal.getReplaceStart() + 1;
+ int offset = proposal.getReplaceStart();
// replacement length
- int length = proposal.getReplaceEnd() - offset + 1;
+ //-3 for "get" pre text on the java proposal
+ int length = proposal.getReplaceEnd() - offset - 3;
// translate offset from Java > JSP
offset = getTranslation().getJspOffset(offset);