Author: vrubezhny
Date: 2010-04-22 10:46:15 -0400 (Thu, 22 Apr 2010)
New Revision: 21612
Added:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/ELTextProposal.java
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java
Modified:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegment.java
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegmentImpl.java
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java
Log:
JBIDE-6167: Move Proposal Info gathering for EL Proposals from resolve cycles to the
proposal itself
The long-running Javadoc Info calculation operation is moved out of proposals gathering
cycle
Patch is applied in branch 3.1.x
Modified:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java
===================================================================
---
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java 2010-04-22
14:33:41 UTC (rev 21611)
+++
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -19,11 +19,9 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
-import org.eclipse.jdt.internal.ui.text.java.ProposalInfo;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.graphics.Image;
@@ -61,7 +59,6 @@
import org.jboss.tools.common.text.TextProposal;
public abstract class AbstractELCompletionEngine<V extends IVariable> implements
ELResolver, ELCompletionEngine {
-
public AbstractELCompletionEngine() {}
public abstract Image getELProposalImage();
@@ -251,6 +248,9 @@
: operand;
ELResolutionImpl resolution = resolveELOperand(file, newOperand,
returnEqualedVariablesOnly, prefixWasChanged);
+ if(resolution==null) {
+ return null;
+ }
if(prefixWasChanged) {
resolution.setSourceOperand(operand);
@@ -296,12 +296,18 @@
var.resolveValue("#{" + var.getElToken().getText() + suffix +
"}"); //$NON-NLS-1$ //$NON-NLS-2$
ELResolutionImpl oldElResolution = resolveELOperand(file, operand,
returnEqualedVariablesOnly, false);
- resolution.getProposals().addAll(oldElResolution.getProposals());
+ if(oldElResolution!=null) {
+ resolution.getProposals().addAll(oldElResolution.getProposals());
+ }
} else {
resolution = resolveELOperand(file, operand, returnEqualedVariablesOnly, false);
}
}
+ if(resolution==null) {
+ return null;
+ }
+
// JBIDE-512, JBIDE-2541 related changes ===>>>
if(!returnEqualedVariablesOnly && vars!=null) {
@@ -310,10 +316,12 @@
if(v.getName().startsWith(prefix)) {
ELResolution r = resolveEL(file, v.getElToken(), true, vars, varSearcher);
ELSegment lastSegment = r.getLastSegment();
- MemberInfo memberInfo = null;
+ JavaMemberELSegment jmSegment = null;
+
if(lastSegment instanceof JavaMemberELSegment) {
- memberInfo = ((JavaMemberELSegment)lastSegment).getMemberInfo();
+ jmSegment = ((JavaMemberELSegment)lastSegment);
}
+ MemberInfo memberInfo = jmSegment == null ? null : jmSegment.getMemberInfo();
String sourceTypeName = memberInfo == null ? null :
memberInfo.getDeclaringTypeQualifiedName();
if (sourceTypeName != null && sourceTypeName.indexOf('.') != -1) {
@@ -324,18 +332,21 @@
typeName = Signature.getSimpleName(typeName);
}
- IJavaElement element = memberInfo == null ? null : memberInfo.getJavaElement();
- String attachedJavaDoc = (element instanceof IMember)?(new
ProposalInfo((IMember)element)).getInfo(null):null;
-
String varNameProposal = v.getName().substring(prefix.length());
- TextProposal proposal = new TextProposal();
+ ELTextProposal proposal = new ELTextProposal();
proposal.setLabel(v.getName());
proposal.setReplacementString(varNameProposal);
proposal.setLabel(v.getName());
proposal.setImage(getELProposalImage());
proposal.setType(typeName);
proposal.setSourceType(sourceTypeName);
- proposal.setContextInfo(attachedJavaDoc);
+ if (jmSegment != null) {
+ IJavaElement[] javaElements = jmSegment.getAllJavaElements();
+ for (int jeIndex = 0; javaElements != null && jeIndex <
javaElements.length; jeIndex++) {
+ proposal.addJavaElement(javaElements[jeIndex]);
+ }
+ }
+
resolution.getProposals().add(proposal);
}
}
@@ -442,16 +453,17 @@
typeName = Signature.getSimpleName(typeName);
IJavaElement element = member == null ? null : member.getJavaElement();
- String attachedJavaDoc = (element instanceof IMember)?(new
ProposalInfo((IMember)element)).getInfo(null):null;
- TextProposal proposal = new TextProposal();
+ ELTextProposal proposal = new ELTextProposal();
proposal.setLabel(varName);
proposal.setReplacementString(varName.substring(operand.getLength()));
setImage(proposal, var);
proposal.setType(typeName);
proposal.setSourceType(sourceTypeName);
- proposal.setContextInfo(attachedJavaDoc);
-
+ if (element != null) {
+ proposal.addJavaElement(element);
+ }
+
proposals.add(proposal);
// <<<=== JBIDE-512, JBIDE-2541 related changes
}
@@ -482,6 +494,7 @@
if(isSingularAttribute(var)) {
bijectedAttribute = getMemberInfoByVariable(var, true);
}
+
MemberInfo member = getMemberInfoByVariable(var, true);
String sourceTypeName = member == null ? null :
member.getDeclaringTypeQualifiedName();
if (sourceTypeName != null && sourceTypeName.indexOf('.') != -1)
@@ -489,27 +502,33 @@
String typeName = member == null ? null : member.getType().getName();
if (typeName != null && typeName.indexOf('.') != -1)
typeName = Signature.getSimpleName(typeName);
+
IJavaElement element = member == null ? null : member.getJavaElement();
- String attachedJavaDoc = (element instanceof IMember)?(new
ProposalInfo((IMember)element)).getInfo(null):null;
-
+
String varName = var.getName();
if(operand.getLength()<=varName.length()) {
- TextProposal proposal = new TextProposal();
+ ELTextProposal proposal = new ELTextProposal();
proposal.setReplacementString(varName.substring(operand.getLength()));
proposal.setLabel(varName);
setImage(proposal, var);
proposal.setType(typeName);
proposal.setSourceType(sourceTypeName);
- proposal.setContextInfo(attachedJavaDoc);
+ if (element != null) {
+ proposal.addJavaElement(element);
+ }
+
proposals.add(proposal);
} else if(returnEqualedVariablesOnly) {
- TextProposal proposal = new TextProposal();
+ ELTextProposal proposal = new ELTextProposal();
proposal.setReplacementString(varName);
proposal.setLabel(varName);
setImage(proposal, var);
proposal.setType(typeName);
proposal.setSourceType(sourceTypeName);
- proposal.setContextInfo(attachedJavaDoc);
+ if (element != null) {
+ proposal.addJavaElement(element);
+ }
+
proposals.add(proposal);
}
segment.setMemberInfo(bijectedAttribute!=null?bijectedAttribute:member);
@@ -707,16 +726,19 @@
String typeName = member == null ? null : member.getType().getName();
if (typeName != null && typeName.indexOf('.') != -1)
typeName = Signature.getSimpleName(typeName);
- IJavaElement element = member == null ? null : member.getJavaElement();
- String attachedJavaDoc = (element instanceof IMember)?(new
ProposalInfo((IMember)element)).getInfo(null):null;
- TextProposal proposal = new TextProposal();
+ ELTextProposal proposal = new ELTextProposal();
proposal.setReplacementString(presentationString);
proposal.setLabel(presentationString);
proposal.setImage(getELProposalImage());
proposal.setType(typeName);
proposal.setSourceType(sourceTypeName);
- proposal.setContextInfo(attachedJavaDoc);
+ for (MemberInfo mi : presentation.getAllMembers()) {
+ IJavaElement element = mi.getJavaElement();
+ if (element != null) {
+ proposal.addJavaElement(element);
+ }
+ }
kbProposals.add(proposal);
}
@@ -749,17 +771,20 @@
String typeName = member == null ? null : member.getType().getName();
if (typeName != null && typeName.indexOf('.') != -1)
typeName = Signature.getSimpleName(typeName);
- IJavaElement element = member == null ? null : member.getJavaElement();
- String attachedJavaDoc = (element instanceof IMember)?(new
ProposalInfo((IMember)element)).getInfo(null):null;
- TextProposal proposal = new TextProposal();
+ ELTextProposal proposal = new ELTextProposal();
proposal.setReplacementString(presentationString);
proposal.setLabel(presentationString);
proposal.setImage(getELProposalImage());
proposal.setType(typeName);
proposal.setSourceType(sourceTypeName);
- proposal.setContextInfo(attachedJavaDoc);
-
+ for (MemberInfo mi : presentation.getAllMembers()) {
+ IJavaElement element = mi.getJavaElement();
+ if (element != null) {
+ proposal.addJavaElement(element);
+ }
+ }
+
kbProposals.add(proposal);
}
}
@@ -788,13 +813,16 @@
proposalsToFilter.addAll(infos.getPropertyPresentations(segment.getUnpairedGettersOrSetters()));
// segment.setMemberInfo(mbr);
}
+
for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
// We do expect nothing but name for method tokens (No round brackets)
String filter = expr.getMemberName();
if(filter == null) filter = ""; //$NON-NLS-1$
+ String presentationString = proposal.getPresentation();
+
if(returnEqualedVariablesOnly) {
// This is used for validation.
- if (proposal.getPresentation().equals(filter)) {
+ if (presentationString.equals(filter)) {
TextProposal kbProposal = new TextProposal();
kbProposal.setReplacementString(proposal.getPresentation());
@@ -803,6 +831,14 @@
kbProposals.add(kbProposal);
segment.setMemberInfo(proposal.getMember());
+ if (proposal.getAllMembers() != null &&
!proposal.getAllMembers().isEmpty()) {
+ for (MemberInfo mi : proposal.getAllMembers()) {
+ IJavaElement je = mi.getJavaElement();
+ if (je != null) {
+ segment.addJavaElement(je);
+ }
+ }
+ }
if(segment.getUnpairedGettersOrSetters()!=null) {
TypeInfoCollector.MethodInfo unpirMethod =
segment.getUnpairedGettersOrSetters().get(filter);
segment.clearUnpairedGettersOrSetters();
@@ -812,7 +848,7 @@
}
break;
}
- } else if (proposal.getPresentation().startsWith(filter)) {
+ } else if (presentationString.startsWith(filter)) {
// JBIDE-512, JBIDE-2541 related changes ===>>>
// This is used for CA.
@@ -823,16 +859,19 @@
String typeName = member == null ? null : member.getType().getName();
if (typeName != null && typeName.indexOf('.') != -1)
typeName = Signature.getSimpleName(typeName);
- IJavaElement element = member == null ? null : member.getJavaElement();
- String attachedJavaDoc = (element instanceof IMember)?(new
ProposalInfo((IMember)element)).getInfo(null):null;
- TextProposal kbProposal = new TextProposal();
+ ELTextProposal kbProposal = new ELTextProposal();
kbProposal.setReplacementString(proposal.getPresentation().substring(filter.length()));
kbProposal.setLabel(proposal.getPresentation());
kbProposal.setImage(getELProposalImage());
kbProposal.setType(typeName);
kbProposal.setSourceType(sourceTypeName);
- kbProposal.setContextInfo(attachedJavaDoc);
+ for (MemberInfo mi : proposal.getAllMembers()) {
+ IJavaElement element = mi.getJavaElement();
+ if (element != null) {
+ kbProposal.addJavaElement(element);
+ }
+ }
kbProposals.add(kbProposal);
// <<<=== JBIDE-512, JBIDE-2541 related changes
@@ -890,6 +929,16 @@
kbProposals.add(kbProposal);
segment.setMemberInfo(proposal.getMember());
+
+ if (proposal.getAllMembers() != null &&
!proposal.getAllMembers().isEmpty()) {
+ for (MemberInfo mi : proposal.getAllMembers()) {
+ IJavaElement je = mi.getJavaElement();
+ if (je != null) {
+ segment.addJavaElement(je);
+ }
+ }
+ }
+
if(segment.getUnpairedGettersOrSetters()!=null) {
TypeInfoCollector.MethodInfo unpirMethod =
segment.getUnpairedGettersOrSetters().get(filter);
segment.clearUnpairedGettersOrSetters();
@@ -910,10 +959,8 @@
String typeName = member == null ? null : member.getType().getName();
if (typeName != null && typeName.indexOf('.') != -1)
typeName = Signature.getSimpleName(typeName);
- IJavaElement element = member == null ? null : member.getJavaElement();
- String attachedJavaDoc = (element instanceof IMember)?(new
ProposalInfo((IMember)element)).getInfo(null):null;
- TextProposal kbProposal = new TextProposal();
+ ELTextProposal kbProposal = new ELTextProposal();
String replacementString = proposal.getPresentation().substring(filter.length());
if (bSurroundWithQuotes) {
@@ -924,7 +971,12 @@
kbProposal.setImage(getELProposalImage());
kbProposal.setType(typeName);
kbProposal.setSourceType(sourceTypeName);
- kbProposal.setContextInfo(attachedJavaDoc);
+ for (MemberInfo mi : proposal.getAllMembers()) {
+ IJavaElement element = mi.getJavaElement();
+ if (element != null) {
+ kbProposal.addJavaElement(element);
+ }
+ }
kbProposals.add(kbProposal);
// <<<=== JBIDE-512, JBIDE-2541 related changes
Added:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/ELTextProposal.java
===================================================================
---
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/ELTextProposal.java
(rev 0)
+++
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/ELTextProposal.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.core.ca;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.jboss.tools.common.text.TextProposal;
+
+/**
+ * Class to store proposals generated by ELResolver implementers
+ *
+ * @author Victor Rubezhny
+ */
+public class ELTextProposal extends TextProposal {
+ private Set<IJavaElement> allElements;
+
+ /**
+ * Adds a Java Element for the proposal
+ *
+ * @param element
+ */
+ public void addJavaElement(IJavaElement element) {
+ if (this.allElements == null) {
+ this.allElements = new HashSet<IJavaElement>();
+ }
+ this.allElements.add(element);
+ }
+
+ /**
+ * returns all the Java elements for the proposal
+ * @return
+ */
+ public IJavaElement[] getAllJavaElements() {
+ if (this.allElements == null || this.allElements.size() == 0) {
+ return new IJavaElement[0];
+ }
+ return (IJavaElement[])this.allElements.toArray(new
IJavaElement[this.allElements.size()]);
+ }
+}
Property changes on:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/ELTextProposal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegment.java
===================================================================
---
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegment.java 2010-04-22
14:33:41 UTC (rev 21611)
+++
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegment.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -29,6 +29,13 @@
IJavaElement getJavaElement();
/**
+ * Returns the array of Java Elements collected for the segment
+ *
+ * @return The Array of collected Java Elements
+ */
+ IJavaElement[] getAllJavaElements();
+
+ /**
* @return true if an underlying object is field and this field has getter.
*/
boolean hasGetter();
Modified:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegmentImpl.java
===================================================================
---
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegmentImpl.java 2010-04-22
14:33:41 UTC (rev 21611)
+++
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/JavaMemberELSegmentImpl.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -11,7 +11,9 @@
package org.jboss.tools.common.el.core.resolver;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.eclipse.jdt.core.IJavaElement;
import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.MemberInfo;
@@ -22,6 +24,7 @@
public class JavaMemberELSegmentImpl extends ELSegmentImpl implements JavaMemberELSegment
{
protected IJavaElement element;
+ protected Set<IJavaElement> allElements;
protected MemberInfo memberInfo;
protected boolean hasSetter;
protected boolean hasGetter;
@@ -66,6 +69,29 @@
}
/**
+ * Adds a Java Element for the Segment
+ *
+ * @param element
+ */
+ public void addJavaElement(IJavaElement element) {
+ if (this.allElements == null) {
+ this.allElements = new HashSet<IJavaElement>();
+ }
+ this.allElements.add(element);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.common.el.core.resolver.JavaMemberELSegment#getAllJavaElements()
+ */
+ public IJavaElement[] getAllJavaElements() {
+ if (this.allElements == null || this.allElements.size() == 0) {
+ return new IJavaElement[0];
+ }
+ return (IJavaElement[])this.allElements.toArray(new
IJavaElement[this.allElements.size()]);
+ }
+
+ /**
* @return the hasSetter
*/
public boolean isHasSetter() {
Modified:
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java
===================================================================
---
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java 2010-04-22
14:33:41 UTC (rev 21611)
+++
branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -38,7 +38,7 @@
/**
* This class helps to collect information of java elements used in Seam EL.
- * @author Viktor Rubezhny, Alexey Kazakov
+ * @author Victor Rubezhny, Alexey Kazakov
*/
public class TypeInfoCollector {
IType fType;
@@ -971,11 +971,13 @@
public static class MemberPresentation {
private String presentation;
private MemberInfo member;
+ private Set<MemberInfo> allMembers = new HashSet<MemberInfo>();
public MemberPresentation(String presentation, MemberInfo member) {
super();
this.presentation = presentation;
this.member = member;
+ addMember(member);
}
public String getPresentation() {
@@ -1003,6 +1005,28 @@
public String toString() {
return presentation;
}
+
+ /**
+ * Adds a pair member to the member info
+ * In case of a property there may be up to 2 members added: getter and setter
+ * In case of a method there will be a single member added (the method itself)
+ *
+ * @param pair
+ */
+ public void addMember(MemberInfo pair) {
+ this.allMembers.add(pair);
+ }
+
+ /**
+ * Returns all the members collected
+ * In case of a property there may be up to 2 members returned: getter and setter
+ * In case of a method there will be a single member returned (the method itself)
+ *
+ * @return
+ */
+ public Set<MemberInfo> getAllMembers() {
+ return allMembers;
+ }
}
private static class MemberPresentationComparator implements
Comparator<MemberPresentation> {
@@ -1138,6 +1162,7 @@
*/
public Set<MemberPresentation> getPropertyPresentations(Map<String,
MethodInfo> unpairedGettersOrSetters) {
Set<MemberPresentation> properties = new
TreeSet<MemberPresentation>(MEMBER_PRESENTATION_COMPARATOR);
+ HashMap<String, MemberPresentation> presentations = new HashMap<String,
MemberPresentation>();
List<MemberInfo> props = getProperties();
HashMap<String, MethodInfo> getters = new HashMap<String, MethodInfo>();
HashMap<String, MethodInfo> setters = new HashMap<String, MethodInfo>();
@@ -1159,6 +1184,10 @@
MemberPresentation pr = new MemberPresentation(propertyName, m);
if(!properties.contains(pr)) {
properties.add(pr);
+ presentations.put(pr.getPresentation(), pr);
+ } else {
+ MemberPresentation existingPresentation = presentations.get(pr.getPresentation());
+ existingPresentation.addMember(m);
}
if(unpairedGettersOrSetters!=null) {
MethodInfo previousGetter = getters.get(propertyName);
@@ -1176,7 +1205,9 @@
}
}
} else {
- properties.add(new MemberPresentation(info.getName(), info));
+ MemberPresentation pr = new MemberPresentation(info.getName(), info);
+ properties.add(pr);
+ presentations.put(pr.getPresentation(), pr);
}
}
return properties;
Added:
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java
===================================================================
---
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java
(rev 0)
+++
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.contentassist;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
+import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks;
+import org.eclipse.jdt.ui.JavaElementLabels;
+import org.eclipse.jface.internal.text.html.HTMLPrinter;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Class to provide EL proposals to Content Assistant.
+ * The main purpose is to provide correct additional proposal information based on
+ * IJavaElement objects collected for the proposal.
+ *
+ * @author Victor Rubezhny
+ */
+@SuppressWarnings("restriction")
+public class AutoELContentAssistantProposal extends AutoContentAssistantProposal {
+ private IJavaElement[] fJavaElements;
+ private String fAdditionalProposalInfo;
+
+ /**
+ * Constructs the proposal object
+ *
+ * @param replacementString
+ * @param replacementOffset
+ * @param replacementLength
+ * @param cursorPosition
+ * @param image
+ * @param displayString
+ * @param contextInformation
+ * @param elements
+ * @param relevance
+ */
+ public AutoELContentAssistantProposal(String replacementString, int replacementOffset,
int replacementLength, int cursorPosition, Image image, String displayString,
IContextInformation contextInformation, IJavaElement[] elements, int relevance) {
+ super(replacementString, replacementOffset, replacementLength, cursorPosition,
image, displayString, contextInformation, null, relevance);
+ this.fJavaElements = elements;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal#getAdditionalProposalInfo()
+ */
+ public String getAdditionalProposalInfo() {
+ if (fAdditionalProposalInfo == null) {
+ if (this.fJavaElements != null && this.fJavaElements.length > 0) {
+ this.fAdditionalProposalInfo = extractProposalContextInfo(fJavaElements);
+ }
+ }
+ return fAdditionalProposalInfo;
+ }
+
+ /*
+ * Extracts the additional proposal information based on Javadoc for the stored
IJavaElement objects
+ */
+ private String extractProposalContextInfo(IJavaElement[] elements) {
+ int nResults= elements.length;
+ StringBuffer buffer= new StringBuffer();
+ boolean hasContents= false;
+ IJavaElement element= null;
+
+ if (nResults > 1) {
+ for (int i= 0; i < elements.length; i++) {
+ if (elements[i] == null) continue;
+ if (elements[i] instanceof IMember ||
+ elements[i].getElementType() == IJavaElement.LOCAL_VARIABLE ||
+ elements[i].getElementType() == IJavaElement.TYPE_PARAMETER) {
+ buffer.append('�').append(' ').append(getInfoText(elements[i]));
+ hasContents= true;
+ }
+ buffer.append("<br/>"); //$NON-NLS-1$
+ }
+
+ for (int i=0; i < elements.length; i++) {
+ if (elements[i] == null) continue;
+ if (elements[i] instanceof IMember ||
+ elements[i].getElementType() == IJavaElement.LOCAL_VARIABLE ||
+ elements[i].getElementType() == IJavaElement.TYPE_PARAMETER) {
+ buffer.append("<br/>"); //$NON-NLS-1$
+ addFullInfo(buffer, elements[i]);
+ hasContents = true;
+ }
+ }
+ } else {
+ element= elements[0];
+ if (element instanceof IMember ||
+ element.getElementType() == IJavaElement.LOCAL_VARIABLE ||
+ element.getElementType() == IJavaElement.TYPE_PARAMETER) {
+ addFullInfo(buffer, element);
+ hasContents= true;
+ }
+ }
+
+ if (!hasContents)
+ return null;
+
+ if (buffer.length() > 0) {
+ HTMLPrinter.insertPageProlog(buffer, 0, (String)null);
+ HTMLPrinter.addPageEpilog(buffer);
+ return buffer.toString();
+ }
+
+ return null;
+ }
+
+ private static final long LABEL_FLAGS= JavaElementLabels.ALL_FULLY_QUALIFIED
+ | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.M_PARAMETER_TYPES |
JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_EXCEPTIONS
+ | JavaElementLabels.F_PRE_TYPE_SIGNATURE | JavaElementLabels.M_PRE_TYPE_PARAMETERS |
JavaElementLabels.T_TYPE_PARAMETERS
+ | JavaElementLabels.USE_RESOLVED;
+ private static final long LOCAL_VARIABLE_FLAGS= LABEL_FLAGS &
~JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.F_POST_QUALIFIED;
+ private static final long TYPE_PARAMETER_FLAGS= LABEL_FLAGS |
JavaElementLabels.TP_POST_QUALIFIED;
+
+ /*
+ * Returns the label for the IJavaElement objects
+ */
+ private String getInfoText(IJavaElement element) {
+ long flags;
+ switch (element.getElementType()) {
+ case IJavaElement.LOCAL_VARIABLE:
+ flags= LOCAL_VARIABLE_FLAGS;
+ break;
+ case IJavaElement.TYPE_PARAMETER:
+ flags= TYPE_PARAMETER_FLAGS;
+ break;
+ default:
+ flags= LABEL_FLAGS;
+ break;
+ }
+ StringBuffer label= new StringBuffer(JavaElementLinks.getElementLabel(element,
flags));
+
+ StringBuffer buf= new StringBuffer();
+ buf.append("<span style='word-wrap:break-word;'>");
//$NON-NLS-1$
+ buf.append(label);
+ buf.append("</span>"); //$NON-NLS-1$
+
+ return buf.toString();
+ }
+
+ /*
+ * Adds full information to the additional proposal information
+ *
+ * @param buffer
+ * @param element
+ * @return
+ */
+ private void addFullInfo(StringBuffer buffer, IJavaElement element) {
+ if (element instanceof IMember) {
+ IMember member= (IMember) element;
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(member));
+ Reader reader = null;
+ try {
+ String content= JavadocContentAccess2.getHTMLContent(member, true);
+ reader= content == null ? null : new StringReader(content);
+ } catch (JavaModelException ex) {
+ JavaPlugin.log(ex);
+ }
+
+ if (reader != null) {
+ HTMLPrinter.addParagraph(buffer, reader);
+ }
+
+ } else if (element.getElementType() == IJavaElement.LOCAL_VARIABLE ||
element.getElementType() == IJavaElement.TYPE_PARAMETER) {
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(element));
+ }
+ }
+}
Property changes on:
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
===================================================================
---
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2010-04-22
14:33:41 UTC (rev 21611)
+++
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -10,9 +10,10 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.contentassist;
-import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
+import org.jboss.tools.common.el.core.ca.ELTextProposal;
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.text.TextProposal;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
@@ -105,10 +106,10 @@
KbQuery kbQuery = createKbQuery(Type.TEXT, query, stringQuery);
TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
-
- for (int i = 0; proposals != null && i < proposals.length; i++) {
- TextProposal textProposal = proposals[i];
-
+ if (proposals == null || proposals.length == 0)
+ return;
+
+ for (TextProposal textProposal : proposals) {
int replacementOffset = beginChangeOffset;
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString();
@@ -127,17 +128,26 @@
displayString = textProposal.getReplacementString() == null ? replacementString :
textProposal.getReplacementString();
// <<<=== JBIDE-512, JBIDE-2541 related changes
- IContextInformation contextInformation = null;
- String additionalProposalInfo = textProposal.getContextInfo();
int relevance = textProposal.getRelevance();
if (relevance == TextProposal.R_NONE) {
relevance = TextProposal.R_JSP_JSF_EL_VARIABLE_ATTRIBUTE_VALUE;
}
- AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
- contextInformation, additionalProposalInfo, relevance);
+ AutoContentAssistantProposal proposal = null;
+ if (textProposal instanceof ELTextProposal) {
+ IJavaElement[] javaElements = ((ELTextProposal)textProposal).getAllJavaElements();
+
+ proposal = new AutoELContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, javaElements, relevance);
+ } else {
+ String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
+ proposal = new AutoContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, additionalProposalInfo, relevance);
+ }
+
contentAssistRequest.addProposal(proposal);
}
@@ -157,9 +167,11 @@
protected void addAttributeNameProposals(
ContentAssistRequest contentAssistRequest) {
super.addAttributeNameProposals(contentAssistRequest);
- this.replaceJsfcTags = true;
- super.addAttributeNameProposals(contentAssistRequest);
- this.replaceJsfcTags = false;
+ if (isExistingAttribute(JSFC_ATTRIBUTE_NAME)) {
+ this.replaceJsfcTags = true;
+ super.addAttributeNameProposals(contentAssistRequest);
+ this.replaceJsfcTags = false;
+ }
}
/*
@@ -169,9 +181,11 @@
@Override
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) {
super.addAttributeValueProposals(contentAssistRequest);
- this.replaceJsfcTags = true;
- super.addAttributeValueProposals(contentAssistRequest);
- this.replaceJsfcTags = false;
+ if (isExistingAttribute(JSFC_ATTRIBUTE_NAME)) {
+ this.replaceJsfcTags = true;
+ super.addAttributeValueProposals(contentAssistRequest);
+ this.replaceJsfcTags = false;
+ }
}
/*
Modified:
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java
===================================================================
---
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java 2010-04-22
14:33:41 UTC (rev 21611)
+++
branches/jbosstools-3.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java 2010-04-22
14:46:15 UTC (rev 21612)
@@ -13,14 +13,14 @@
import java.util.List;
import java.util.Map;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
+import org.jboss.tools.common.el.core.ca.ELTextProposal;
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.text.TextProposal;
@@ -286,7 +286,7 @@
contentAssistRequest.addProposal(proposal);
}
-
+
addELPredicateProposals(contentAssistRequest, TextProposal.R_JSP_ATTRIBUTE_VALUE,
false);
}
@@ -317,13 +317,14 @@
}
int beginChangeOffset = prefix.getStartOffset() + prefix.getOffset();
-
+
KbQuery kbQuery = createKbQuery(Type.ATTRIBUTE_VALUE, query, stringQuery);
TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
- for (int i = 0; proposals != null && i < proposals.length; i++) {
- TextProposal textProposal = proposals[i];
-
+ if (proposals == null || proposals.length == 0)
+ return;
+
+ for (TextProposal textProposal : proposals) {
int replacementOffset = beginChangeOffset;
int replacementLength = prefix.getLength();
String replacementString = "#{" + prefix.getText().substring(0,
replacementLength) + textProposal.getReplacementString(); //$NON-NLS-1$
@@ -348,23 +349,30 @@
displayString = textProposal.getReplacementString() == null ? replacementString :
textProposal.getReplacementString();
// <<<=== JBIDE-512, JBIDE-2541 related changes
- IContextInformation contextInformation = null;
- String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
int relevance = textProposal.getRelevance();
if (relevance == TextProposal.R_NONE) {
relevance = baseRelevance;
}
relevance += relevanceShift;
- AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
- contextInformation, additionalProposalInfo, relevance);
+ AutoContentAssistantProposal proposal = null;
+ if (textProposal instanceof ELTextProposal) {
+ IJavaElement[] javaElements = ((ELTextProposal)textProposal).getAllJavaElements();
+
+ proposal = new AutoELContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, javaElements, relevance);
+ } else {
+ String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
+ proposal = new AutoContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, additionalProposalInfo, relevance);
+ }
contentAssistRequest.addProposal(proposal);
}
}
-
@Override
protected void addAttributeValueELProposals(ContentAssistRequest contentAssistRequest)
{
if (!isELCAToBeShown())
@@ -394,10 +402,11 @@
KbQuery kbQuery = createKbQuery(Type.ATTRIBUTE_VALUE, query, stringQuery);
TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
-
- for (int i = 0; proposals != null && i < proposals.length; i++) {
- TextProposal textProposal = proposals[i];
-
+
+ if (proposals == null || proposals.length == 0)
+ return;
+
+ for (TextProposal textProposal : proposals) {
int replacementOffset = beginChangeOffset;
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString();
@@ -425,17 +434,25 @@
displayString = textProposal.getReplacementString() == null ? replacementString :
textProposal.getReplacementString();
// <<<=== JBIDE-512, JBIDE-2541 related changes
- IContextInformation contextInformation = null;
- String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
int relevance = textProposal.getRelevance();
if (relevance == TextProposal.R_NONE) {
relevance = TextProposal.R_JSP_JSF_EL_VARIABLE_ATTRIBUTE_VALUE;
}
- AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
- contextInformation, additionalProposalInfo, relevance);
+ AutoContentAssistantProposal proposal = null;
+ if (textProposal instanceof ELTextProposal) {
+ IJavaElement[] javaElements = ((ELTextProposal)textProposal).getAllJavaElements();
+
+ proposal = new AutoELContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, javaElements, relevance);
+ } else {
+ String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
+ proposal = new AutoContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, additionalProposalInfo, relevance);
+ }
contentAssistRequest.addProposal(proposal);
}
@@ -475,9 +492,10 @@
KbQuery kbQuery = createKbQuery(Type.TEXT, query, stringQuery);
TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
- for (int i = 0; proposals != null && i < proposals.length; i++) {
- TextProposal textProposal = proposals[i];
-
+ if (proposals == null || proposals.length == 0)
+ return;
+
+ for (TextProposal textProposal : proposals) {
int replacementOffset = beginChangeOffset;
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString();
@@ -496,17 +514,25 @@
displayString = textProposal.getReplacementString() == null ? replacementString :
textProposal.getReplacementString();
// <<<=== JBIDE-512, JBIDE-2541 related changes
- IContextInformation contextInformation = null;
- String additionalProposalInfo = textProposal.getContextInfo();
int relevance = textProposal.getRelevance();
if (relevance == TextProposal.R_NONE) {
relevance = TextProposal.R_JSP_JSF_EL_VARIABLE_ATTRIBUTE_VALUE;
}
- AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
- contextInformation, additionalProposalInfo, relevance);
+ AutoContentAssistantProposal proposal = null;
+ if (textProposal instanceof ELTextProposal) {
+ IJavaElement[] javaElements = ((ELTextProposal)textProposal).getAllJavaElements();
+
+ proposal = new AutoELContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, javaElements, relevance);
+ } else {
+ String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
+ proposal = new AutoContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
+ null, additionalProposalInfo, relevance);
+ }
contentAssistRequest.addProposal(proposal);
}