diff options
Diffstat (limited to 'bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist')
24 files changed, 0 insertions, 5111 deletions
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/AutoImportProposal.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/AutoImportProposal.java deleted file mode 100644 index a4d8c143d5..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/AutoImportProposal.java +++ /dev/null @@ -1,142 +0,0 @@ -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.ITextViewer; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.swt.graphics.Image; -import org.eclipse.text.edits.InsertEdit; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class AutoImportProposal extends JSPCompletionProposal { - - // the import string, no quotes or colons - String fImportDeclaration; - - public AutoImportProposal(String importDeclaration, String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo, int relevance, boolean updateReplacementLengthOnValidate) { - super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo, relevance, updateReplacementLengthOnValidate); - setImportDeclaration(importDeclaration); - } - - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - super.apply(viewer, trigger, stateMask, offset); - addImportDeclaration(viewer); - } - /** - * adds the import declaration to the document in the viewer in the appropriate position - * @param viewer - */ - private void addImportDeclaration(ITextViewer viewer) { - - IDocument doc = viewer.getDocument(); - - // calculate once and pass along - boolean isXml = isXmlFormat(doc); - - int insertPosition = getInsertPosition(doc, isXml); - String insertText = createImportDeclaration(doc, isXml); - InsertEdit insert = new InsertEdit(insertPosition, insertText); - try { - insert.apply(doc); - } - catch (MalformedTreeException e) { - Logger.logException(e); - } - catch (BadLocationException e) { - Logger.logException(e); - } - - // make sure the cursor position after is correct - setCursorPosition(getCursorPosition() + insertText.length()); - } - /** - * - * @param doc - * @param isXml - * @return position after <jsp:root> if xml, otherwise right before the document element - */ - private int getInsertPosition(IDocument doc, boolean isXml) { - int pos = 0; - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - try { - if(sModel != null) { - if(sModel instanceof IDOMModel) { - IDOMDocument documentNode = ((IDOMModel)sModel).getDocument(); - Node docElement = documentNode.getDocumentElement(); - if(docElement != null && docElement instanceof IDOMElement) { - IStructuredDocumentRegion sdRegion = ((IDOMElement)docElement).getFirstStructuredDocumentRegion(); - if(isXml) { - // insert right after document element - pos = sdRegion.getEndOffset(); - } - else { - // insert before document element - pos = sdRegion.getStartOffset(); - } - } - } - } - } - finally { - if(sModel != null) - sModel.releaseFromRead(); - } - return pos; - } - /** - * - * @param doc - * @return true if this document is xml-jsp syntax, otherwise false - */ - private boolean isXmlFormat(IDocument doc) { - boolean isXml = false; - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - try { - if(sModel != null) { - if(!isXml) { - if(sModel instanceof IDOMModel) { - IDOMDocument documentNode = ((IDOMModel)sModel).getDocument(); - Element docElement = documentNode.getDocumentElement(); - isXml = docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() == null && ((IDOMNode) docElement).getEndStructuredDocumentRegion() == null))); //$NON-NLS-1$ - } - } - } - } - finally { - if(sModel != null) - sModel.releaseFromRead(); - } - return isXml; - } - /** - * - * @param doc - * @param isXml - * @return appropriate import declaration string depending if document is xml or not - */ - private String createImportDeclaration(IDocument doc, boolean isXml) { - String delim = (doc instanceof IStructuredDocument) ? ((IStructuredDocument)doc).getLineDelimiter() : TextUtilities.getDefaultLineDelimiter(doc); - if(isXml) - return delim + "<jsp:directive.page import=\""+getImportDeclaration()+"\"/>"; //$NON-NLS-1$ //$NON-NLS-2$ - return "<%@page import=\"" + getImportDeclaration() + "\"%>" + delim; //$NON-NLS-1$ //$NON-NLS-2$ - } - - public String getImportDeclaration() { - return fImportDeclaration; - } - public void setImportDeclaration(String importDeclaration) { - fImportDeclaration = importDeclaration; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/BeanInfoProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/BeanInfoProvider.java deleted file mode 100644 index 63ded692f6..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/BeanInfoProvider.java +++ /dev/null @@ -1,442 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 java.beans.Introspector; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import com.ibm.icu.util.StringTokenizer; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.ITypeHierarchy; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsp.ui.internal.Logger; - -/** - * Navigates the IJavaProject classpath (incl. source) on a given resource and infers bean properties - * given a fully qualified beanname. Bean properties can be retrieved using: - * <code>getRuntimeProperties(IResource baseResource, String typeName)</code> - * - * @plannedfor 1.0 - */ -public class BeanInfoProvider implements IBeanInfoProvider { - - public class JavaPropertyDescriptor implements IJavaPropertyDescriptor { - String fType = null; - String fName = null; - boolean fReadable = true; - boolean fWritable = true; - - public JavaPropertyDescriptor(String name, String type, boolean readable, boolean writable) { - fName = name; - fType = type; - fReadable = readable; - fWritable = writable; - } - - public String getDeclaredType() { - return fType; - } - - public String getDisplayName() { - return fName; - } - - public String getName() { - return fName; - } - - public boolean getReadable() { - return fReadable; - } - - public boolean getWriteable() { - return fWritable; - } - } - - // looks up encoded type (see Class.getName), and gives you a displayable string - private HashMap fEncodedTypeMap = null; - // to avoid repeat properties from showing up - private HashSet fRepeatMethods = null; - - public BeanInfoProvider() { - fRepeatMethods = new HashSet(); - } - - /** - * Returns the inferred properties of a bean based on the project from the baseResource, - * and the fully qualified name of the bean. - * - * @param baseResource the base resource where the bean is being used - * @param typeName the <i>fully qualified</i> type name (eg. javax.swing.JButton) of the bean - */ - public IJavaPropertyDescriptor[] getRuntimeProperties(IResource baseResource, String typeName) { - IJavaProject javaProject = JavaCore.create(baseResource.getProject()); - QualifiedName typeQualifiedName = getTypeQualifiedName(typeName); - List getMethodResults = new ArrayList(); - List isMethodResults = new ArrayList(); - List setMethodResults = new ArrayList(); - List descriptorResults = new ArrayList(); - try { - IType type = javaProject.findType(typeQualifiedName.getQualifier() + "." + typeQualifiedName.getLocalName()); //$NON-NLS-1$ - // type must exist - if(type != null) { - ITypeHierarchy hierarchy = type.newTypeHierarchy(null); - IType[] supers = hierarchy.getAllSuperclasses(type); - - IMethod[] methods = type.getMethods(); - // iterate the bean's methods - for (int i = 0; i < methods.length; i++) - acceptMethod(getMethodResults, isMethodResults, setMethodResults, methods[i]); - // the bean hierarchy's methods - for (int i = 0; i < supers.length; i++) { - methods = supers[i].getMethods(); - for (int j = 0; j < methods.length; j++) - acceptMethod(getMethodResults, isMethodResults, setMethodResults, methods[j]); - } - adaptMethodsToPropertyDescriptors(getMethodResults, isMethodResults, setMethodResults, descriptorResults); - } - } - catch (JavaModelException jmex) { - Logger.logException("Problem navigating JavaProject in BeanInfoProvider", jmex); //$NON-NLS-1$ - } - - IJavaPropertyDescriptor[] finalResults = new IJavaPropertyDescriptor[descriptorResults.size()]; - System.arraycopy(descriptorResults.toArray(), 0, finalResults, 0, descriptorResults.size()); - return finalResults; - } - - /** - * Retrieves the necessary information from method declaration lists, creates and fills a list of JavaPropertyDescriptors. - * @param getMethods - * @param isMethods - * @param setMethods - * @param descriptorResults - */ - private void adaptMethodsToPropertyDescriptors(List getMethods, List isMethods, List setMethods, List descriptors) throws JavaModelException { - List readable = new ArrayList(); - HashMap types = new HashMap(); - - // iterate through get* and is* methods, updating 'readable' list and 'types' map - filterGetMethods(getMethods, readable, types); - filterIsMethods(isMethods, readable, types); - - // iterate set* methods, checking overlap w/ readable - Iterator it = setMethods.iterator(); - IMethod temp = null; - String name = ""; //$NON-NLS-1$ - String type = ""; //$NON-NLS-1$ - String[] encodedParams = null; - String returnType = ""; //$NON-NLS-1$ - String param0 = ""; //$NON-NLS-1$ - - while (it.hasNext()) { - temp = (IMethod) it.next(); - name = createPropertyNameFromMethod(temp); - // invalid naming convention - if (name == null) - continue; - - returnType = getDecodedTypeName(temp.getReturnType()); - // setter should have no return type - if (!returnType.equals("void")) //$NON-NLS-1$ - continue; - - // need to get type from parameter - encodedParams = temp.getParameterTypes(); - if (encodedParams != null && encodedParams.length > 0) { - if (encodedParams.length > 1) { - // multiple params - param0 = getDecodedTypeName(encodedParams[0]); - if (!param0.equals("int")) //$NON-NLS-1$ - // not a valid indexed property - continue; - - type = getDecodedTypeName(encodedParams[1]); - } - else { - // one param, regular setter - if (isArray(encodedParams[0])) - type = getDecodedTypeName(encodedParams[0]); - } - } - - if (readable.contains(name)) { - // writable and readable - if (!fRepeatMethods.contains(name)) { - descriptors.add(new JavaPropertyDescriptor(name, (String) types.get(name), true, true)); - readable.remove(name); - fRepeatMethods.add(name); - } - } - else { - // wasn't readable, just writable - String[] params = temp.getParameterTypes(); - // can't be setProperty if no parameters - if (!(params.length > 0)) - continue; - if (!fRepeatMethods.contains(name)) { - type = getDecodedTypeName(params[0]); - descriptors.add(new JavaPropertyDescriptor(name, type, false, true)); - fRepeatMethods.add(name); - } - } - } - // add leftover from readable, get* and is* methods (readable = true, writable = false) - it = readable.iterator(); - while (it.hasNext()) { - name = (String) it.next(); - if (!fRepeatMethods.contains(name)) { - descriptors.add(new JavaPropertyDescriptor(name, (String) types.get(name), true, false)); - fRepeatMethods.add(name); - } - } - } - - private void filterGetMethods(List getMethods, List readable, HashMap types) throws JavaModelException { - IMethod temp; - String name; - String encodedReturnType; - String returnType; - Iterator it = getMethods.iterator(); - String[] encodedParams; - String paramType; - // iterate get* methods - while (it.hasNext()) { - temp = (IMethod) it.next(); - name = createPropertyNameFromMethod(temp); - // invalid bean naming convention - if (name == null) - continue; - - encodedReturnType = temp.getReturnType(); - returnType = getDecodedTypeName(encodedReturnType); - - // can't get be a getProperty if returns void - if (returnType.equals("void")) //$NON-NLS-1$ - continue; - - // check params in case it's indexed propety - encodedParams = temp.getParameterTypes(); - if (encodedParams != null && encodedParams.length == 1) { - paramType = getDecodedTypeName(encodedParams[0]); - // syntax is > Type getter(int); - if (!paramType.equals("int")) { //$NON-NLS-1$ - //it's not an indexed property - continue; - } - // it is indexed, prop type is an ARRAY - returnType += "[]"; //$NON-NLS-1$ - } - - readable.add(name); - types.put(name, returnType); - } - - } - - private void filterIsMethods(List isMethodResults, List readable, HashMap types) throws JavaModelException { - IMethod temp; - String name; - String encodedReturnType; - String returnType; - String[] encodedParams; - String paramType; - // iterate is* methods - Iterator it = isMethodResults.iterator(); - while (it.hasNext()) { - temp = (IMethod) it.next(); - name = createPropertyNameFromMethod(temp); - // invalid bean naming convention - if (name == null) - continue; - encodedReturnType = temp.getReturnType(); - returnType = getDecodedTypeName(encodedReturnType); - - // isProperty only valid for boolean - if (!returnType.equals("boolean")) //$NON-NLS-1$ - continue; - - // check params in case it's indexed propety - encodedParams = temp.getParameterTypes(); - if (encodedParams != null && encodedParams.length == 1) { - paramType = getDecodedTypeName(encodedParams[0]); - // syntax is > Type getter(int); - if (!paramType.equals("int")) { //$NON-NLS-1$ - //it's not a valid indexed property - continue; - } - } - - readable.add(name); - types.put(name, returnType); - } - } - - /** - * Pass in a get*|set*|is* method and it will return an inferred property name using <code>Introspector.decapitalize(String)</code> - * @param temp - * @return an inferred property name based on the IMethod name, null if the name is not valid according to bean spec - */ - private String createPropertyNameFromMethod(IMethod temp) { - String name = temp.getElementName(); - if (name.startsWith("is")) //$NON-NLS-1$ - name = Introspector.decapitalize(name.substring(2)); - else - // must be get or set - name = Introspector.decapitalize(name.substring(3)); - return name; - } - - /** - * Initial filtering of methods. Checks prefix if it's valid length. If the prefix is "get" the method name - * is placed in the getMethodResults List. If the prefix is "is", the name is added to the isMethodResults list. If the - * prefix is "set", it's added to the setMethodResultsList. - * - * @param getMethodResults - * @param isMethodResults - * @param setMethodResults - * @param method - */ - private void acceptMethod(List getMethodResults, List isMethodResults, List setMethodResults, IMethod method) throws JavaModelException { - if (!fRepeatMethods.contains(method.getElementName())) { - fRepeatMethods.add(method.getElementName()); - int flags = method.getFlags(); - String methodName = method.getElementName(); - if (Flags.isPublic(flags)) { - if (methodName.length() > 3 && methodName.startsWith("get")) //$NON-NLS-1$ - getMethodResults.add(method); - else if (methodName.length() > 2 && methodName.startsWith("is")) //$NON-NLS-1$ - isMethodResults.add(method); - else if (methodName.length() > 3 && methodName.startsWith("set")) //$NON-NLS-1$ - setMethodResults.add(method); - } - } - } - - /** - * @param typeName - * @return a Qualified name with the package as the qualifier, and class name as LocalName - */ - private QualifiedName getTypeQualifiedName(String typeName) { - StringTokenizer st = new StringTokenizer(typeName, ".", false); //$NON-NLS-1$ - int length = st.countTokens(); - int count = 0; - StringBuffer root = new StringBuffer(); - while (count++ < length - 1) { - root.append(st.nextToken()); - if (count < length - 1) - root.append('.'); - } - return new QualifiedName(root.toString(), st.nextToken()); - } - - /** - * Checks if encodedTypeName is an array - * @param encodedTypeName - * @return true if encodedTypeName is an array, false otherwise. - */ - private boolean isArray(String encodedTypeName) { - if (encodedTypeName != null && encodedTypeName.length() > 0) { - if (encodedTypeName.charAt(0) == '[') - return true; - } - return false; - } - - /** - * Returns the decoded (displayable) name fo the type. - * Either a primitive type (int, long, float...) Object (String) - * @param type - * @return decoded name for the encoded string - */ - private String getDecodedTypeName(String encoded) { - HashMap map = getEncodedTypeMap(); - - StringBuffer decoded = new StringBuffer(); - char BRACKET = '['; - String BRACKETS = "[]"; //$NON-NLS-1$ - char identifier = ' '; - int last = 0; - // count brackets - while (encoded.indexOf(BRACKET, last) != -1) { - last++; - } - identifier = encoded.charAt(last); - Object primitiveType = map.get(String.valueOf(identifier)); - // L > binary type name, Q > source type name - if (identifier == 'L' || identifier == 'Q') { - // handle object - String classname = encoded.substring(last + 1, encoded.length() - 1); - decoded.append(classname); - } - else if (primitiveType != null) { - // handle primitive type (from IField.getSignature()) - decoded.append((String) primitiveType); - } - else { - // handle primitive type (from Class.getName()) - decoded.append(encoded); - } - // handle arrays - if (last > 0) { - for (int i = 0; i < last; i++) { - decoded.append(BRACKETS); - } - } - return decoded.toString(); - } - - /** - * from Class.getName() javadoc - * also see Signature in jdt.core api - *<pre> - * B byte - * C char - * D double - * F float - * I int - * J long - * Lclassname; class or interface - * Qsourcename; source - * S short - * Z boolean - * V void - *</pre> - * - * @return the "encoding letter" to "type" map. - */ - private HashMap getEncodedTypeMap() { - if (fEncodedTypeMap == null) { - fEncodedTypeMap = new HashMap(); - fEncodedTypeMap.put("B", "byte"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("C", "char"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("D", "double"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("F", "float"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("I", "int"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("J", "long"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("S", "short"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("Z", "boolean"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("V", "void"); //$NON-NLS-1$ //$NON-NLS-2$ - } - return fEncodedTypeMap; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/CustomTemplateProposal.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/CustomTemplateProposal.java deleted file mode 100644 index c580bd4180..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/CustomTemplateProposal.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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.IRegion; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.text.templates.TemplateContext; -import org.eclipse.jface.text.templates.TemplateProposal; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal; - -/** - * Purpose of this class is to make the additional proposal info into content - * fit for an HTML viewer (by escaping characters) - * - * @plannedfor 1.0 - */ -class CustomTemplateProposal extends TemplateProposal implements IRelevanceCompletionProposal { - // copies of this class exist in: - // org.eclipse.jst.jsp.ui.internal.contentassist - // org.eclipse.wst.html.ui.internal.contentassist - // org.eclipse.wst.xml.ui.internal.contentassist - - public CustomTemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance) { - super(template, context, region, image, relevance); - } - - public String getAdditionalProposalInfo() { - String additionalInfo = super.getAdditionalProposalInfo(); - return StringUtils.convertToHTMLContent(additionalInfo); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/IBeanInfoProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/IBeanInfoProvider.java deleted file mode 100644 index 7487e3cccb..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/IBeanInfoProvider.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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.core.resources.IResource; - -/** - * @plannedfor 1.0 - */ -public interface IBeanInfoProvider { - IJavaPropertyDescriptor[] getRuntimeProperties(IResource baseResource, String typeName); -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/IJavaPropertyDescriptor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/IJavaPropertyDescriptor.java deleted file mode 100644 index 1606a2e4f4..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/IJavaPropertyDescriptor.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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; - -/** - * @plannedfor 1.0 - */ -public interface IJavaPropertyDescriptor { - - String getDeclaredType(); - - String getDisplayName(); - - String getName(); - - boolean getReadable(); - - boolean getWriteable(); -} 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 deleted file mode 100644 index 73d1e50725..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 java.util.HashMap; -import java.util.Iterator; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.ui.internal.JSPUIMessages; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.osgi.framework.Bundle; - - -/** - * @plannedfor 1.0 - */ -public class JSPCompletionProcessor implements IContentAssistProcessor, IReleasable { - // for debugging - private static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/jsptranslation"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - private static final String JDT_CORE_PLUGIN_ID = "org.eclipse.jdt.core"; //$NON-NLS-1$ - - protected int fJspSourcePosition, fJavaPosition; - protected String fErrorMessage = null; - protected StructuredTextViewer fViewer = null; - private JSPTranslationAdapter fTranslationAdapter = null; - - /** - * Returns a list of completion proposals based on the specified location - * within the document that corresponds to the current cursor position - * within the text viewer. - * - * @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 - * @return an array of completion proposals or <code>null</code> if no - * proposals are possible - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos) { - initialize(pos); - - JSPProposalCollector collector = null; - - IDOMModel xmlModel = null; - try { - if (viewer instanceof StructuredTextViewer) - fViewer = (StructuredTextViewer) viewer; - - xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.getDocument()); - - IDOMDocument xmlDoc = xmlModel.getDocument(); - if (fTranslationAdapter == null) - fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (fTranslationAdapter != null) { - - JSPTranslation translation = fTranslationAdapter.getJSPTranslation(); - fJavaPosition = translation.getJavaOffset(getDocumentPosition()); - - if (DEBUG) - System.out.println(debug(translation)); - - try { - - ICompilationUnit cu = translation.getCompilationUnit(); - - // can't get java proposals w/out a compilation unit - // or without a valid position - if (cu == null || -1 == fJavaPosition) - return new ICompletionProposal[0]; - - collector = getProposalCollector(cu, translation); - synchronized (cu) { - cu.codeComplete(fJavaPosition, collector, null); - } - } - catch (CoreException coreEx) { - // a possible Java Model Exception due to not being a Web - // (Java) Project - coreEx.printStackTrace(); - } - } - } - catch (Exception exc) { - exc.printStackTrace(); - // throw out exceptions on code assist. - } - finally { - if (xmlModel != null) { - xmlModel.releaseFromRead(); - } - } - ICompletionProposal[] results = new ICompletionProposal[0]; - if(collector != null) { - results = collector.getJSPCompletionProposals(); - if (results == null || results.length < 1) - fErrorMessage = JSPUIMessages.Java_Content_Assist_is_not_UI_; - } - return results; - } - - protected JSPProposalCollector getProposalCollector(ICompilationUnit cu, JSPTranslation translation) { - return new JSPProposalCollector(cu, translation); - } - - /** - * For debugging translation mapping only. - * - * @param translation - */ - private String debug(JSPTranslation translation) { - StringBuffer debugString = new StringBuffer(); - HashMap jsp2java = translation.getJsp2JavaMap(); - String javaText = translation.getJavaText(); - String jspText = fViewer.getDocument().get(); - debugString.append("[jsp2JavaMap in JSPCompletionProcessor]\r\n"); //$NON-NLS-1$ - debugString.append("jsp cursor position >> " + fViewer.getTextWidget().getCaretOffset() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ - Iterator it = jsp2java.keySet().iterator(); - while (it.hasNext()) { - try { - Position jspPos = (Position) it.next(); - Position javaPos = (Position) jsp2java.get(jspPos); - debugString.append("jsp > " + jspPos.offset + ":" + jspPos.length + ":" + jspText.substring(jspPos.offset, jspPos.offset + jspPos.length) + ":\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - debugString.append("java > " + javaPos.offset + ":" + javaPos.length + ":" + javaText.substring(javaPos.offset, javaPos.offset + javaPos.length) + ":\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - debugString.append("-------------------------------------------------\n"); //$NON-NLS-1$ - } - catch (Exception e) { - // eat exceptions, it's only for debug - } - } - return debugString.toString(); - } - - /** - * Returns information about possible contexts based on the specified - * location within the document that corresponds to the current cursor - * position within the text viewer. - * - * @param viewer - * the viewer whose document is used to compute the possible - * contexts - * @param documentPosition - * an offset within the document for which context information - * should be computed - * @return an array of context information objects or <code>null</code> - * if no context could be found - */ - public org.eclipse.jface.text.contentassist.IContextInformation[] computeContextInformation(org.eclipse.jface.text.ITextViewer viewer, int documentOffset) { - return null; - } - - /** - * Returns a string of characters which when pressed should automatically - * display content-assist proposals. - * - * @return string of characters - */ - public java.lang.String getAutoProposalInvocationCharacters() { - return null; - } - - /** - * Returns a string of characters which when pressed should automatically - * display a content-assist tip. - * - * @return string of characters - */ - public java.lang.String getAutoTipInvocationCharacters() { - return null; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of possible completions. - * - * @return the auto activation characters for completion proposal or - * <code>null</code> if no auto activation is desired - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return null; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of context information. - * - * @return the auto activation characters for presenting context - * information or <code>null</code> if no auto activation is - * desired - */ - public char[] getContextInformationAutoActivationCharacters() { - return null; - } - - /** - * Returns a validator used to determine when displayed context - * information should be dismissed. May only return <code>null</code> if - * the processor is incapable of computing context information. - * - * @return a context information validator, or <code>null</code> if the - * processor is incapable of computing context information - */ - public org.eclipse.jface.text.contentassist.IContextInformationValidator getContextInformationValidator() { - return null; - } - - protected int getDocumentPosition() { - return fJspSourcePosition; - } - - public String getErrorMessage() { - // TODO: get appropriate error message - // if (fCollector.getErrorMessage() != null && - // fCollector.getErrorMessage().length() > 0) - // return fCollector.getErrorMessage(); - return fErrorMessage; - } - - /** - * Initialize the code assist processor. - */ - protected void initialize(int pos) { - initializeJavaPlugins(); - - fJspSourcePosition = pos; - fErrorMessage = null; - } - - /** - * Initialize the Java Plugins that the JSP processor requires. - * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=143765 - * We should not call "start", because that will cause that - * state to be remembered, and re-started automatically during - * the next boot up sequence. - * - * ISSUE: we may be able to get rid of this all together, in future, - * since 99% we probably have already used some JDT class by the time - * we need JDT to be active ... but ... this is the safest fix for - * this point in 1.5 stream. Next release, let's just remove this, - * re-discover what ever bug this was fixing (if any) and if there is - * one, then we'll either put back in, as is, or come up with a - * more appropriate fix. - * - */ - protected void initializeJavaPlugins() { - try { - Bundle bundle = Platform.getBundle(JDT_CORE_PLUGIN_ID); - bundle.loadClass("dummyClassNameThatShouldNeverExist"); - } - catch (ClassNotFoundException e) { - // this is the expected result, we just want to - // nudge the bundle to be sure its activated. - } - } - - public void release() { - fTranslationAdapter = null; - } -}
\ No newline at end of file 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 deleted file mode 100644 index 0229d51877..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProposal.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; - -/** - * Implements IJavaCompletionProposal for use with JSPProposalCollector. - * - * @plannedfor 1.0 - */ -public class JSPCompletionProposal extends CustomCompletionProposal implements IJavaCompletionProposal { - - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483 - * - * This is a wrapped proposal so we don't need to - * make "slow" calls to the java proposal up front, only when needed - * for example, getAdditionalInfo() reads external javadoc, and it makes - * no sense - */ - ICompletionProposal fJavaCompletionProposal = null; - - public JSPCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo, int relevance, boolean updateReplacementLengthOnValidate) { - super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo, relevance, updateReplacementLengthOnValidate); - } - - /** - * Sets cursor position after applying. - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - super.apply(viewer, trigger, stateMask, offset); - } - - final public ICompletionProposal getJavaCompletionProposal() { - return fJavaCompletionProposal; - } - - final public void setJavaCompletionProposal(ICompletionProposal javaCompletionProposal) { - fJavaCompletionProposal = javaCompletionProposal; - } - - public String getAdditionalProposalInfo() { - - String additionalInfo = super.getAdditionalProposalInfo(); - ICompletionProposal javaProposal = getJavaCompletionProposal(); - if(javaProposal != null) - additionalInfo = javaProposal.getAdditionalProposalInfo(); - - return additionalInfo; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java deleted file mode 100644 index 67a4f529d0..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java +++ /dev/null @@ -1,1274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager; -import org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter; -import org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapterFactory; -import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; -import org.eclipse.jst.jsp.core.internal.provisional.JSP12Namespace; -import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP; -import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts; -import org.eclipse.jst.jsp.core.text.IJSPPartitions; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; -import org.eclipse.jst.jsp.ui.internal.preferences.JSPUIPreferenceNames; -import org.eclipse.jst.jsp.ui.internal.templates.TemplateContextTypeIdsJSP; -import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor; -import org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocumentFactory; -import org.eclipse.wst.html.core.internal.contentmodel.HTMLElementDeclaration; -import org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument; -import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties; -import org.eclipse.wst.html.core.text.IHTMLPartitions; -import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor; -import org.eclipse.wst.javascript.ui.internal.common.contentassist.JavaScriptContentAssistProcessor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker; -import org.eclipse.wst.sse.core.internal.provisional.IModelManager; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.text.IStructuredPartitions; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceConstants; -import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryProvider; -import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; -import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMDocType; -import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMDocumentTracker; -import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter; -import org.eclipse.wst.xml.core.text.IXMLPartitions; -import org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor; -import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest; -import org.eclipse.wst.xml.ui.internal.contentassist.NonValidatingModelQueryAction; -import org.eclipse.wst.xml.ui.internal.contentassist.ProposalComparator; -import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor; -import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistUtilities; -import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * Adds proposals not normally covered by the generic behavior with the - * content model - * - * @plannedfor 1.0 - */ -public class JSPContentAssistProcessor extends AbstractContentAssistProcessor { - - protected int depthCount = 0; - protected ITextViewer fViewer = null; - protected boolean useEmbeddedResults = true; - protected boolean isInternalAdapter = false; - protected HashMap fNameToProcessorMap = null; - protected HashMap fPartitionToProcessorMap = null; - private final ICompletionProposal[] EMPTY_PROPOSAL_SET = new ICompletionProposal[0]; - private JSPTemplateCompletionProcessor fTemplateProcessor = null; - private List fTemplateContexts = new ArrayList(); - - public JSPContentAssistProcessor() { - super(); - initNameToProcessorMap(); - initPartitionToProcessorMap(); - } - - /** - * init map for extra content assist processors (useBean, - * get/setProperty). points [tagname > processor] - */ - protected void initNameToProcessorMap() { - fNameToProcessorMap = new HashMap(); - JSPPropertyContentAssistProcessor jspPropertyCAP = new JSPPropertyContentAssistProcessor(); - fNameToProcessorMap.put(JSP11Namespace.ElementName.SETPROPERTY, jspPropertyCAP); - fNameToProcessorMap.put(JSP11Namespace.ElementName.GETPROPERTY, jspPropertyCAP); - fNameToProcessorMap.put(JSP11Namespace.ElementName.USEBEAN, new JSPUseBeanContentAssistProcessor()); - fNameToProcessorMap.put(JSP11Namespace.ElementName.DIRECTIVE_TAGLIB, new JSPTaglibDirectiveContentAssistProcessor()); - } - - /** - * int map that points [partition > processor]. This takes place of - * embedded adapters for now. - */ - protected void initPartitionToProcessorMap() { - fPartitionToProcessorMap = new HashMap(); - HTMLContentAssistProcessor htmlProcessor = new HTMLContentAssistProcessor(); - JSPJavaContentAssistProcessor jspJavaProcessor = new JSPJavaContentAssistProcessor(); - XMLContentAssistProcessor xmlProcessor = new XMLContentAssistProcessor(); - JavaScriptContentAssistProcessor javascriptProcessor = new JavaScriptContentAssistProcessor(); - - fPartitionToProcessorMap.put(IHTMLPartitions.HTML_DEFAULT, htmlProcessor); - fPartitionToProcessorMap.put(IXMLPartitions.XML_DEFAULT, xmlProcessor); - fPartitionToProcessorMap.put(IStructuredPartitions.DEFAULT_PARTITION, htmlProcessor); - fPartitionToProcessorMap.put(IJSPPartitions.JSP_DEFAULT, jspJavaProcessor); - fPartitionToProcessorMap.put(IJSPPartitions.JSP_DIRECTIVE, xmlProcessor); - fPartitionToProcessorMap.put(IHTMLPartitions.HTML_COMMENT, htmlProcessor); - fPartitionToProcessorMap.put(IJSPPartitions.JSP_CONTENT_JAVASCRIPT, javascriptProcessor); - fPartitionToProcessorMap.put(IJSPPartitions.JSP_DEFAULT_EL, jspJavaProcessor); - fPartitionToProcessorMap.put(IHTMLPartitions.SCRIPT, javascriptProcessor); // default - // to - // javascript - // for - // all - // script - } - - protected void addCommentProposal(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsJSP.NEW); - - super.addEmptyDocumentProposals(contentAssistRequest); - addTagInsertionProposals(contentAssistRequest, 0); - } - - protected void addEndTagNameProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addXMLProposal(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addEndTagProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsJSP.ATTRIBUTE); - } - - /** - * add proposals for tags in attribute values - */ - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsJSP.ATTRIBUTE_VALUE); - - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - - // add JSP extra proposals from JSPBeanInfoContentAssistProcessor - // JSPPropertyContentAssistProcessor - - // 2.1 - // get results from JSPUseBean and JSPProperty here - // (look up processor in a map based on node name) - JSPDummyContentAssistProcessor extraProcessor = (JSPDummyContentAssistProcessor) fNameToProcessorMap.get(node.getNodeName()); - if (extraProcessor != null && contentAssistRequest != null) { - extraProcessor.addAttributeValueProposals(contentAssistRequest); - } - - ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - if (mq != null) { - CMDocument doc = mq.getCorrespondingCMDocument(node); - // this shouldn't have to have the prefix coded in - if (doc instanceof JSPCMDocument || doc instanceof CMNodeWrapper || node.getNodeName().startsWith("jsp:")) //$NON-NLS-1$ - return; - } - - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) - return; - ITextRegion nameRegion = null; - while (i >= 0) { - nameRegion = openRegions.get(i--); - if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - - String attributeName = null; - if (nameRegion != null) - attributeName = open.getText(nameRegion); - String currentValue = null; - if (attributeName != null) - currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue(); - - // on an empty value, add all the JSP and taglib tags - if ((contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS && contentAssistRequest.getReplacementLength() == 0) || (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE && (currentValue == null || currentValue.length() == 0))) { - List rejectElements = new ArrayList(); - rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET); - rejectElements.add(JSP12Namespace.ElementName.EXPRESSION); - rejectElements.add(JSP12Namespace.ElementName.DECLARATION); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB); - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.USEBEAN); - rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY); - rejectElements.add(JSP12Namespace.ElementName.FORWARD); - rejectElements.add(JSP12Namespace.ElementName.PLUGIN); - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.PARAMS); - - List additionalElements = getAdditionalChildren(new ArrayList(), node, -1); - for (i = 0; i < additionalElements.size(); i++) { - CMElementDeclaration ed = (CMElementDeclaration) additionalElements.get(i); - if (rejectElements.contains(ed.getNodeName())) - continue; - String tagname = getContentGenerator().getRequiredName(node, ed); - StringBuffer contents = new StringBuffer("\""); //$NON-NLS-1$ - getContentGenerator().generateTag(node, ed, contents); - contents.append('"'); - 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); - contentAssistRequest.addProposal(proposal); - } - } - - else if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - try { - // Create a new model for Content Assist to operate on. This - // will simulate - // a full Document and then adjust the offset numbers in the - // list of results. - IStructuredModel internalModel = null; - IModelManager mmanager = StructuredModelManager.getModelManager(); - internalModel = mmanager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP); - IDOMNode xmlNode = null; - IDOMModel xmlOuterModel = null; - if (contentAssistRequest.getNode() instanceof IDOMNode) { - xmlNode = (IDOMNode) contentAssistRequest.getNode(); - xmlOuterModel = xmlNode.getModel(); - internalModel.setResolver(xmlOuterModel.getResolver()); - internalModel.setBaseLocation(xmlOuterModel.getBaseLocation()); - } - String contents = StringUtils.strip(contentAssistRequest.getText()); - if (xmlNode != null && contents != null) { - int additionalShifts = 0; - // Be sure that custom tags from taglibs also show up - // by - // adding taglib declarations to the internal model. - TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(xmlOuterModel.getStructuredDocument()); - if (mgr != null) { - List trackers = mgr.getCMDocumentTrackers(contentAssistRequest.getReplacementBeginPosition()); - if (trackers != null) { - for (i = 0; i < trackers.size(); i++) { - CMDocumentTracker tracker = (CMDocumentTracker) trackers.get(i); - String declaration = tracker.getStructuredDocumentRegion().getText(); - if (declaration != null) { - contents = declaration + contents; - additionalShifts += declaration.length(); - } - } - } - } - // Also copy any jsp:useBean tags so that - // jsp:[gs]etProperty will function - Document doc = null; - if (contentAssistRequest.getNode().getNodeType() == Node.DOCUMENT_NODE) - doc = (Document) node; - else - doc = node.getOwnerDocument(); - NodeList useBeans = doc.getElementsByTagName(JSP12Namespace.ElementName.USEBEAN); - for (int k = 0; k < useBeans.getLength(); k++) { - IDOMNode useBean = (IDOMNode) useBeans.item(k); - if (useBean.getStartOffset() < contentAssistRequest.getReplacementBeginPosition()) { - StringBuffer useBeanText = new StringBuffer("<jsp:useBean"); //$NON-NLS-1$ - for (int j = 0; j < useBean.getAttributes().getLength(); j++) { - Attr attr = (Attr) useBean.getAttributes().item(j); - useBeanText.append(' '); - useBeanText.append(attr.getName()); - useBeanText.append("=\""); //$NON-NLS-1$ - useBeanText.append(attr.getValue()); - useBeanText.append('"'); - } - useBeanText.append("/>"); //$NON-NLS-1$ - additionalShifts += useBeanText.length(); - contents = useBeanText.toString() + contents; - } - } - internalModel.getStructuredDocument().set(contents); - int internalOffset = 0; - boolean quoted = false; - // if quoted, use position inside and shift by one - if (contentAssistRequest.getMatchString().length() > 0 && (contentAssistRequest.getMatchString().charAt(0) == '\'' || contentAssistRequest.getMatchString().charAt(0) == '"')) { - internalOffset = contentAssistRequest.getMatchString().length() - 1 + additionalShifts; - quoted = true; - } - // if unquoted, use position inside - else if (contentAssistRequest.getMatchString().length() > 0 && contentAssistRequest.getMatchString().charAt(0) == '<') - internalOffset = contentAssistRequest.getMatchString().length() + additionalShifts; - else - internalOffset = contentAssistRequest.getReplacementBeginPosition() - contentAssistRequest.getStartOffset() + additionalShifts; - depthCount++; - IndexedRegion internalNode = null; - int tmpOffset = internalOffset; - while (internalNode == null && tmpOffset >= 0) - internalNode = internalModel.getIndexedRegion(tmpOffset--); - - if (internalModel.getFactoryRegistry() != null) { - // set up the internal model - if (internalModel.getFactoryRegistry().getFactoryFor(PageDirectiveAdapter.class) == null) { - internalModel.getFactoryRegistry().addFactory(new PageDirectiveAdapterFactory()); - } - PageDirectiveAdapter outerEmbeddedTypeAdapter = (PageDirectiveAdapter) xmlOuterModel.getDocument().getAdapterFor(PageDirectiveAdapter.class); - PageDirectiveAdapter internalEmbeddedTypeAdapter = (PageDirectiveAdapter) ((INodeNotifier) ((Node) internalNode).getOwnerDocument()).getAdapterFor(PageDirectiveAdapter.class); - internalEmbeddedTypeAdapter.setEmbeddedType(outerEmbeddedTypeAdapter.getEmbeddedType()); - } - - AdapterFactoryRegistry adapterRegistry = JSPUIPlugin.getDefault().getAdapterFactoryRegistry(); - Iterator adapterList = adapterRegistry.getAdapterFactories(); - // And all those appropriate for this particular type - // of content - while (adapterList.hasNext()) { - try { - AdapterFactoryProvider provider = (AdapterFactoryProvider) adapterList.next(); - if (provider.isFor(internalModel.getModelHandler())) { - provider.addAdapterFactories(internalModel); - } - } - catch (Exception e) { - Logger.logException(e); - } - } - - /** - * the internal adapter does all the real work of using - * the JSP content model to form proposals - */ - ICompletionProposal[] results = null; - depthCount--; - if (results != null) { - for (i = 0; i < results.length; i++) { - contentAssistRequest.addProposal(new CustomCompletionProposal(((CustomCompletionProposal) results[i]).getReplacementString(), ((CustomCompletionProposal) results[i]).getReplacementOffset() - additionalShifts + contentAssistRequest.getStartOffset() + (quoted ? 1 : 0), ((CustomCompletionProposal) results[i]).getReplacementLength(), ((CustomCompletionProposal) results[i]).getCursorPosition(), results[i].getImage(), results[i].getDisplayString(), ((CustomCompletionProposal) results[i]).getContextInformation(), ((CustomCompletionProposal) results[i]).getAdditionalProposalInfo(), (results[i] instanceof IRelevanceCompletionProposal) ? ((IRelevanceCompletionProposal) results[i]).getRelevance() : IRelevanceConstants.R_NONE)); - } - } - } - } - catch (Exception e) { - Logger.logException("Error in embedded JSP Content Assist", e); //$NON-NLS-1$ - } - } - - - } - - private List getAdditionalChildren(List elementDecls, Node node, int childIndex) { - if (node instanceof IDOMNode) { - /* - * find the location of the intended insertion as it will give us - * the correct offset for checking position dependent CMDocuments - */ - int textInsertionOffset = 0; - NodeList children = node.getChildNodes(); - if (children.getLength() >= childIndex && childIndex >= 0) { - Node nodeAlreadyAtIndex = children.item(childIndex); - if (nodeAlreadyAtIndex instanceof IDOMNode) - textInsertionOffset = ((IDOMNode) nodeAlreadyAtIndex).getEndOffset(); - } - else { - textInsertionOffset = ((IDOMNode) node).getStartOffset(); - } - TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(((IDOMNode) node).getStructuredDocument()); - if (mgr != null) { - List moreCMDocuments = mgr.getCMDocumentTrackers(textInsertionOffset); - if (moreCMDocuments != null) { - for (int i = 0; i < moreCMDocuments.size(); i++) { - CMDocument doc = (CMDocument) moreCMDocuments.get(i); - CMNamedNodeMap elements = doc.getElements(); - if (elements != null) { - for (int j = 0; j < elements.getLength(); j++) { - CMElementDeclaration ed = (CMElementDeclaration) elements.item(j); - elementDecls.add(ed); - } - } - } - } - } - - // get position dependent CMDocuments and insert their tags as - // proposals - - ModelQueryAdapter mqAdapter = null; - if (node.getNodeType() == Node.DOCUMENT_NODE) - mqAdapter = (ModelQueryAdapter) ((IDOMNode) node).getAdapterFor(ModelQueryAdapter.class); - else - mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class); - - if (mqAdapter != null) { - CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node); - if (doc != null) { - - CMDocument JCMDoc = HTMLCMDocumentFactory.getCMDocument(CMDocType.JSP11_DOC_TYPE); - CMNamedNodeMap jspelements = JCMDoc.getElements(); - - if (jspelements != null) { - List rejectElements = new ArrayList(); - - // determine if the document is in XML form - Document domDoc = null; - if (node.getNodeType() == Node.DOCUMENT_NODE) - domDoc = (Document) node; - else - domDoc = node.getOwnerDocument(); - - // Show XML tag forms of JSP markers if jsp:root is - // the document element OR it's HTML but - // isn't really in the text. - // If the document isn't strictly XML, pull out the - // XML tag forms it is xml format - rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET); - rejectElements.add(JSP12Namespace.ElementName.EXPRESSION); - rejectElements.add(JSP12Namespace.ElementName.DECLARATION); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE); - rejectElements.add(JSP12Namespace.ElementName.TEXT); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB); - - if (isXMLFormat(domDoc)) { - - // jsp actions - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.USEBEAN); - rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY); - rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY); - rejectElements.add(JSP12Namespace.ElementName.INCLUDE); - rejectElements.add(JSP12Namespace.ElementName.FORWARD); - rejectElements.add(JSP12Namespace.ElementName.PLUGIN); - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.PARAM); - rejectElements.add(JSP12Namespace.ElementName.PARAMS); - } - - - // don't show jsp:root if a document element already - // exists - Element docElement = domDoc.getDocumentElement(); - if (docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null)))) //$NON-NLS-1$ - rejectElements.add(JSP12Namespace.ElementName.ROOT); - - for (int j = 0; j < jspelements.getLength(); j++) { - CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j); - if (rejectElements.contains(ed.getNodeName())) - continue; - elementDecls.add(ed); - } - - } - } - } - } - return elementDecls; - } - - protected List getAvailableChildrenAtIndex(Element parent, int index, int validityChecking) { - List list = new ArrayList(); - List additionalElements = getAdditionalChildren(new ArrayList(), parent, index); - for (int i = 0; i < additionalElements.size(); i++) { - ModelQueryAction insertAction = new NonValidatingModelQueryAction((CMElementDeclaration) additionalElements.get(i), ModelQueryAction.INSERT, 0, parent.getChildNodes().getLength(), null); - list.add(insertAction); - } - - // add allowed children of implicit tags that don't already exist - NodeList children = parent.getChildNodes(); - List childNames = new ArrayList(); - if (children != null) { - for (int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if (child.getNodeType() == Node.ELEMENT_NODE) - childNames.add(child.getNodeName().toLowerCase()); - } - } - List allActions = new ArrayList(); - Iterator iterator = list.iterator(); - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument()); - while (iterator.hasNext()) { - ModelQueryAction action = (ModelQueryAction) iterator.next(); - allActions.add(action); - if (action.getCMNode() instanceof HTMLElementDeclaration) { - HTMLElementDeclaration ed = (HTMLElementDeclaration) action.getCMNode(); - String ommission = (String) ed.getProperty(HTMLCMProperties.OMIT_TYPE); - if (!childNames.contains(ed.getNodeName().toLowerCase()) && ((ommission != null) && (ommission.equals(HTMLCMProperties.Values.OMIT_BOTH)))) { - List implicitValidActions = new ArrayList(); - modelQuery.getInsertActions(parent, ed, 0, ModelQuery.INCLUDE_CHILD_NODES, ModelQuery.VALIDITY_NONE, implicitValidActions); - if (implicitValidActions != null) { - Iterator implicitValidActionsIterator = implicitValidActions.iterator(); - while (implicitValidActionsIterator.hasNext()) { - ModelQueryAction insertAction = new NonValidatingModelQueryAction(((ModelQueryAction) implicitValidActionsIterator.next()).getCMNode(), ModelQueryAction.INSERT, 0, parent.getChildNodes().getLength(), null); - allActions.add(insertAction); - } - } - } - } - } - return allActions; - } - - protected List getAvailableRootChildren(Document document, int childIndex) { - List list = new ArrayList(); - if (!isXMLFormat(document)) - getAdditionalChildren(list, document, childIndex); - return list; - } - - protected void init() { - super.init(); - } - - public void setErrorMessage(String errorMessage) { - if (depthCount == 0) - fErrorMessage = errorMessage; - } - - /** - * This method is acting as a "catch all" for pulling together content - * assist proposals from different Processors when document partitioning - * alone couldn't determine definitively what content assist should show - * up at that particular position in the document - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(ITextViewer, - * int) - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentPosition) { - fTemplateContexts.clear(); - - IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(viewer, documentPosition); - fViewer = viewer; - ICompletionProposal[] jspResults = EMPTY_PROPOSAL_SET; - ICompletionProposal[] embeddedResults = EMPTY_PROPOSAL_SET; - - // check the actual partition type - String partitionType = getPartitionType((StructuredTextViewer) viewer, documentPosition); - IStructuredDocument structuredDocument = (IStructuredDocument) viewer.getDocument(); - - IStructuredDocumentRegion fn = structuredDocument.getRegionAtCharacterOffset(documentPosition); - - // //////////////////////////////////////////////////////////////////////////// - // ANOTHER WORKAROUND UNTIL PARTITIONING TAKES CARE OF THIS - // check for xml-jsp tags... - if (partitionType == IJSPPartitions.JSP_DIRECTIVE && fn != null) { - IStructuredDocumentRegion possibleXMLJSP = ((fn.getType() == DOMRegionContext.XML_CONTENT) && fn.getPrevious() != null) ? fn.getPrevious() : fn; - ITextRegionList regions = possibleXMLJSP.getRegions(); - if (regions.size() > 1) { - // check bounds cases - ITextRegion xmlOpenOrClose = regions.get(0); - if (xmlOpenOrClose.getType() == DOMRegionContext.XML_TAG_OPEN && documentPosition == possibleXMLJSP.getStartOffset()) { - // do regular jsp content assist - } - else if (xmlOpenOrClose.getType() == DOMRegionContext.XML_END_TAG_OPEN && documentPosition > possibleXMLJSP.getStartOffset()) { - // do regular jsp content assist - } - else { - // possible xml-jsp - ITextRegion nameRegion = regions.get(1); - String name = possibleXMLJSP.getText(nameRegion); - if (name.equals("jsp:scriptlet") || name.equals("jsp:expression") || name.equals("jsp:declaration")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - - // //////////////////////////////////////////////////////////////////////////// - // ** THIS IS A TEMP FIX UNTIL PARTITIONING TAKES CARE OF THIS... - // check for XML-JSP in a <script> region - if (partitionType == IJSPPartitions.JSP_CONTENT_JAVASCRIPT || partitionType == IHTMLPartitions.SCRIPT) { - // fn should be block text - IStructuredDocumentRegion decodedSDRegion = decodeScriptBlock(fn.getFullText()); - // System.out.println("decoded > " + - // blockOfText.substring(decodedSDRegion.getStartOffset(), - // decodedSDRegion.getEndOffset())); - if (decodedSDRegion != null) { - IStructuredDocumentRegion sdr = decodedSDRegion; - while (sdr != null) { - // System.out.println("sdr " + sdr.getType()); - // System.out.println("sdr > " + - // blockOfText.substring(sdr.getStartOffset(), - // sdr.getEndOffset())); - if (sdr.getType() == DOMJSPRegionContexts.JSP_CONTENT) { - if (documentPosition >= fn.getStartOffset() + sdr.getStartOffset() && documentPosition <= fn.getStartOffset() + sdr.getEndOffset()) { - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - else if (sdr.getType() == DOMRegionContext.XML_TAG_NAME) { - if (documentPosition > fn.getStartOffset() + sdr.getStartOffset() && documentPosition < fn.getStartOffset() + sdr.getEndOffset()) { - return EMPTY_PROPOSAL_SET; - } - else if (documentPosition == fn.getStartOffset() + sdr.getEndOffset() && sdr.getNext() != null && sdr.getNext().getType() == DOMJSPRegionContexts.JSP_CONTENT) { - // the end of an open tag <script> - // <jsp:scriptlet>| blah </jsp:scriptlet> - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - else if (documentPosition == fn.getStartOffset() + sdr.getStartOffset() && sdr.getPrevious() != null && sdr.getPrevious().getType() == DOMRegionContext.XML_TAG_NAME) { - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - sdr = sdr.getNext(); - } - } - } - // ///////////////////////////////////////////////////////////////////////// - // check special JSP delimiter cases - if (fn != null && partitionType == IJSPPartitions.JSP_CONTENT_DELIMITER) { - IStructuredDocumentRegion fnDelim = fn; - - // if it's a nested JSP region, need to get the correct - // StructuredDocumentRegion - // not sure why this check was there... - // if (fnDelim.getType() == XMLRegionContext.BLOCK_TEXT) { - Iterator blockRegions = fnDelim.getRegions().iterator(); - ITextRegion temp = null; - ITextRegionContainer trc; - while (blockRegions.hasNext()) { - temp = (ITextRegion) blockRegions.next(); - // we hit a nested - if (temp instanceof ITextRegionContainer) { - trc = (ITextRegionContainer) temp; - // it's in this region - if (documentPosition >= trc.getStartOffset() && documentPosition < trc.getEndOffset()) { - Iterator nestedJSPRegions = trc.getRegions().iterator(); - while (nestedJSPRegions.hasNext()) { - temp = (ITextRegion) nestedJSPRegions.next(); - if (XMLContentAssistUtilities.isJSPOpenDelimiter(temp.getType()) && documentPosition == trc.getStartOffset(temp)) { - // HTML content assist - // we actually want content assist for the - // previous type of region, - // well get those proposals from the embedded - // adapter - if (documentPosition > 0) { - partitionType = getPartitionType((StructuredTextViewer) viewer, documentPosition - 1); - break; - } - } - else if (XMLContentAssistUtilities.isJSPCloseDelimiter(temp.getType()) && documentPosition == trc.getStartOffset(temp)) { - // JSP content assist - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - // } - } - - // take care of XML-JSP delimter cases - if (XMLContentAssistUtilities.isXMLJSPDelimiter(fnDelim)) { - // since it's a delimiter, we know it's a ITextRegionContainer - ITextRegion firstRegion = fnDelim.getRegions().get(0); - if (fnDelim.getStartOffset() == documentPosition && (firstRegion.getType() == DOMRegionContext.XML_TAG_OPEN)) { - // |<jsp:scriptlet> </jsp:scriptlet> - // (pa) commented out so that we get regular behavior JSP - // macros etc... - // return getHTMLCompletionProposals(viewer, - // documentPosition); - } - else if (fnDelim.getStartOffset() == documentPosition && (firstRegion.getType() == DOMRegionContext.XML_END_TAG_OPEN)) { - // <jsp:scriptlet> |</jsp:scriptlet> - // check previous partition type to see if it's JAVASCRIPT - // if it is, we're just gonna let the embedded JAVASCRIPT - // adapter get the proposals - if (documentPosition > 0) { - String checkType = getPartitionType((StructuredTextViewer) viewer, documentPosition - 1); - if (checkType != IJSPPartitions.JSP_CONTENT_JAVASCRIPT) { // this - // check - // is - // failing - // for - // XML-JSP - // (region - // is - // not - // javascript...) - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - partitionType = IJSPPartitions.JSP_CONTENT_JAVASCRIPT; - } - } - else if ((firstRegion.getType() == DOMRegionContext.XML_TAG_OPEN) && documentPosition >= fnDelim.getEndOffset()) { - // anything else inbetween - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - else if (XMLContentAssistUtilities.isJSPDelimiter(fnDelim)) { - // the delimiter <%, <%=, <%!, ... - if (XMLContentAssistUtilities.isJSPCloseDelimiter(fnDelim)) { - if (documentPosition == fnDelim.getStartOffset()) { - // check previous partition type to see if it's - // JAVASCRIPT - // if it is, we're just gonna let the embedded - // JAVASCRIPT adapter get the proposals - if (documentPosition > 0) { - String checkType = getPartitionType((StructuredTextViewer) viewer, documentPosition - 1); - if (checkType != IJSPPartitions.JSP_CONTENT_JAVASCRIPT) { - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - partitionType = IJSPPartitions.JSP_CONTENT_JAVASCRIPT; - } - } - } - else if (XMLContentAssistUtilities.isJSPOpenDelimiter(fnDelim)) { - // if it's the first position of open delimiter - // use embedded HTML results - if (documentPosition == fnDelim.getStartOffset()) { - embeddedResults = getHTMLCompletionProposals(viewer, documentPosition); - } - else if (documentPosition == fnDelim.getEndOffset()) { - // it's at the EOF <%| - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - - // need to check if it's JSP region inside of CDATA w/ no region - // <![CDATA[ <%|%> ]]> - // or a comment region - // <!-- <% |%> --> - if (fn != null && (fn.getType() == DOMRegionContext.XML_CDATA_TEXT || fn.getType() == DOMRegionContext.XML_COMMENT_TEXT)) { - if (fn instanceof ITextRegionContainer) { - Object[] cdataRegions = fn.getRegions().toArray(); - ITextRegion r = null; - ITextRegion jspRegion = null; - for (int i = 0; i < cdataRegions.length; i++) { - r = (ITextRegion) cdataRegions[i]; - if (r instanceof ITextRegionContainer) { - // CDATA embedded container, or comment container - Object[] jspRegions = ((ITextRegionContainer) r).getRegions().toArray(); - for (int j = 0; j < jspRegions.length; j++) { - jspRegion = (ITextRegion) jspRegions[j]; - if (jspRegion.getType() == DOMJSPRegionContexts.JSP_CLOSE) { - if (sdRegion.getStartOffset(jspRegion) == documentPosition) - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - - } - } - - // check if it's in an attribute value, if so, don't add CDATA - // proposal - ITextRegion attrContainer = (fn != null) ? fn.getRegionAtCharacterOffset(documentPosition) : null; - if (attrContainer != null && attrContainer instanceof ITextRegionContainer) { - if (attrContainer.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - // test location of the cursor - // return null if it's in the middle of an open/close - // delimeter - Iterator attrRegions = ((ITextRegionContainer) attrContainer).getRegions().iterator(); - ITextRegion testRegion = null; - while (attrRegions.hasNext()) { - testRegion = (ITextRegion) attrRegions.next(); - // need to check for other valid attribute regions - if (XMLContentAssistUtilities.isJSPOpenDelimiter(testRegion.getType())) { - if (!(((ITextRegionContainer) attrContainer).getEndOffset(testRegion) <= documentPosition)) - return EMPTY_PROPOSAL_SET; - } - else if (XMLContentAssistUtilities.isJSPCloseDelimiter(testRegion.getType())) { - if (!(((ITextRegionContainer) attrContainer).getStartOffset(testRegion) >= documentPosition)) - return EMPTY_PROPOSAL_SET; - } - } - // TODO: handle non-Java code such as nested tags - if (testRegion.getType().equals(DOMJSPRegionContexts.JSP_CONTENT)) - return getJSPJavaCompletionProposals(viewer, documentPosition); - return EMPTY_PROPOSAL_SET; - } - } - - IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(partitionType); - if (p != null) { - embeddedResults = p.computeCompletionProposals(viewer, documentPosition); - // get bean methods, objects, and constants if there are any... - if (partitionType == IJSPPartitions.JSP_CONTENT_JAVASCRIPT || partitionType == IHTMLPartitions.SCRIPT) { - ICompletionProposal[] beanResults = getJSPJavaBeanProposals(viewer, documentPosition); - if (beanResults != null && beanResults.length > 0) { - ICompletionProposal[] added = new ICompletionProposal[beanResults.length + embeddedResults.length]; - System.arraycopy(beanResults, 0, added, 0, beanResults.length); - System.arraycopy(embeddedResults, 0, added, beanResults.length, embeddedResults.length); - embeddedResults = added; - } - } - } - else { - // the partition type is probably not mapped - } - - // fix for: - // HTML content assist give JSP tags in between empty script tags - if (!(p instanceof JavaScriptContentAssistProcessor || p instanceof CSSContentAssistProcessor)) { - fTemplateContexts.clear(); - jspResults = super.computeCompletionProposals(viewer, documentPosition); - } - if (useEmbeddedResults) { - if (embeddedResults != null && embeddedResults.length > 0) { - List results = new ArrayList(); - for (int i = 0; i < embeddedResults.length; i++) - results.add(embeddedResults[i]); - if (jspResults != null) { - for (int i = 0; i < jspResults.length; i++) - results.add(jspResults[i]); - } - jspResults = new ICompletionProposal[results.size()]; - Collections.sort(results, new ProposalComparator()); - for (int i = 0; i < results.size(); i++) - jspResults[i] = (ICompletionProposal) results.get(i); - - } - } - if (jspResults == null) - jspResults = EMPTY_PROPOSAL_SET; - setErrorMessage(jspResults.length == 0 ? UNKNOWN_CONTEXT : null); - - // fix for: - // check for |<%-- --%> first position of jsp comment - if (partitionType == IJSPPartitions.JSP_COMMENT) { - if (sdRegion.getStartOffset() == documentPosition) { - ICompletionProposal[] htmlResults = getHTMLCompletionProposals(viewer, documentPosition); - jspResults = merge(jspResults, htmlResults); - } - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86656 - if (partitionType == IJSPPartitions.JSP_DIRECTIVE) { - ICompletionProposal[] importProposals = getImportProposals(viewer, documentPosition); - if (importProposals.length > 0) - jspResults = merge(jspResults, importProposals); - } - return jspResults; - } - - private ICompletionProposal[] getImportProposals(ITextViewer viewer, int documentPosition) { - List importProposals = new ArrayList(); - ICompletionProposal[] proposals = getJSPJavaCompletionProposals(viewer, documentPosition); - for (int i = 0; i < proposals.length; i++) { - if (proposals[i] instanceof JSPCompletionProposal) { - - ICompletionProposal importProposal = adjustImportProposal((JSPCompletionProposal) proposals[i]); - importProposals.add(importProposal); - } - } - return (ICompletionProposal[]) importProposals.toArray(new ICompletionProposal[importProposals.size()]); - } - - - private ICompletionProposal adjustImportProposal(JSPCompletionProposal importProposal) { - - // just need to remove the ";" - // and adjust offsets for the change - String newReplace = importProposal.getReplacementString().replaceAll(";", ""); //$NON-NLS-1$ //$NON-NLS-2$ - importProposal.setReplacementString(newReplace); - - String newDisplay = importProposal.getDisplayString().replaceAll(";", ""); //$NON-NLS-1$ //$NON-NLS-2$ - importProposal.setDisplayString(newDisplay); - - int newReplacementLength = importProposal.getReplacementLength() - 1; - importProposal.setReplacementLength(newReplacementLength); - - int newCursorPosition = importProposal.getCursorPosition() - 1; - importProposal.setCursorPosition(newCursorPosition); - - return importProposal; - } - - /** - * Adds 2 arrays of ICompletionProposals and sorts them with a - * ProposalComparator. - * - * @param jspResults - * @param htmlResults - * @return - */ - private ICompletionProposal[] merge(ICompletionProposal[] jspResults, ICompletionProposal[] htmlResults) { - List results = new ArrayList(); - List jsps = Arrays.asList(jspResults); - List htmls = Arrays.asList(htmlResults); - - results.addAll(jsps); - results.addAll(htmls); - - Collections.sort(results, new ProposalComparator()); - return (ICompletionProposal[]) results.toArray(new ICompletionProposal[results.size()]); - } - - /* - * This method will return JSPJava Proposals that are relevant to any java - * beans that in scope at the documentPosition - * - * TODO (pa) are taglib vars getting filtered? - * - * @param viewer @param documentPosition @return ICompletionProposal[] - */ - private ICompletionProposal[] getJSPJavaBeanProposals(ITextViewer viewer, int documentPosition) { - ICompletionProposal[] regularJSPResults = getJSPJavaCompletionProposals(viewer, documentPosition); - Vector filteredProposals = new Vector(); - ICompletionProposal[] finalResults = EMPTY_PROPOSAL_SET; - for (int i = 0; i < regularJSPResults.length; i++) { - ICompletionProposal test = regularJSPResults[i]; - - System.out.println("proposal > " + test.getDisplayString()); //$NON-NLS-1$ - System.out.println("relevance > " + ((CustomCompletionProposal) test).getRelevance()); //$NON-NLS-1$ - - if (isRelevanceAllowed(((CustomCompletionProposal) test).getRelevance())) { - filteredProposals.add(test); - } - } - if (filteredProposals.size() > 0) { - finalResults = new ICompletionProposal[filteredProposals.size()]; - Iterator it = filteredProposals.iterator(); - int j = 0; - while (it.hasNext()) { - finalResults[j++] = (ICompletionProposal) it.next(); - } - } - return finalResults; - } - - // These are the only things I'm allowing for use bean if the language is - // JAVASCRIPT - // I'm filtering based on JavaContentAssistProposal relevance - // - // 485 > method that belongs to the bean - // 486 > bean object - // 386 > bean CONSTANT - private boolean isRelevanceAllowed(int relevance) { - return (relevance == 485 || relevance == 486 || relevance == 326); - } - - - /** - * - * @param viewer - * @param documentPosition - * @return ICompletionProposal[] - */ - private ICompletionProposal[] getHTMLCompletionProposals(ITextViewer viewer, int documentPosition) { - - IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(IHTMLPartitions.HTML_DEFAULT); - return p.computeCompletionProposals(viewer, documentPosition); - } - - /** - * - * @param viewer - * @param documentPosition - * @return ICompletionProposal[] - */ - protected ICompletionProposal[] getJSPJavaCompletionProposals(ITextViewer viewer, int documentPosition) { - JSPJavaContentAssistProcessor p = (JSPJavaContentAssistProcessor) fPartitionToProcessorMap.get(IJSPPartitions.JSP_DEFAULT); - return p.computeCompletionProposals(viewer, documentPosition); - } - - /** - * @param viewer - * @param documentPosition - * @return String - */ - protected String getPartitionType(StructuredTextViewer viewer, int documentPosition) { - String partitionType = null; - try { - partitionType = TextUtilities.getContentType(viewer.getDocument(), IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, viewer.modelOffset2WidgetOffset(documentPosition), false); - } - catch (BadLocationException e) { - partitionType = IDocument.DEFAULT_CONTENT_TYPE; - } - return partitionType; - } - - /* - * ** TEMP WORKAROUND FOR CMVC 241882 Takes a String and blocks out - * jsp:scriptlet, jsp:expression, and jsp:declaration @param blockText - * @return - */ - private IStructuredDocumentRegion decodeScriptBlock(String blockText) { - XMLSourceParser parser = new XMLSourceParser(); - // use JSP_CONTENT for region type - parser.addBlockMarker(new BlockMarker("jsp:scriptlet", null, DOMJSPRegionContexts.JSP_CONTENT, false, false)); //$NON-NLS-1$ - parser.addBlockMarker(new BlockMarker("jsp:expression", null, DOMJSPRegionContexts.JSP_CONTENT, false, false)); //$NON-NLS-1$ - parser.addBlockMarker(new BlockMarker("jsp:declaration", null, DOMJSPRegionContexts.JSP_CONTENT, false, false)); //$NON-NLS-1$ - parser.reset(blockText); - return parser.getDocumentRegions(); - } - - /* - * @see ContentAssistAdapter#computeContextInformation(ITextViewer, int, - * IndexedRegion) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset, IndexedRegion indexedNode) { - return super.computeContextInformation(viewer, documentOffset); - } - - /* - * @see ContentAssistAdapter#getContextInformationAutoActivationCharacters() - */ - public char[] getContextInformationAutoActivationCharacters() { - return super.getContextInformationAutoActivationCharacters(); - } - - - public char[] getCompletionProposalAutoActivationCharacters() { - IPreferenceStore store = JSPUIPlugin.getDefault().getPreferenceStore(); - String key = JSPUIPreferenceNames.AUTO_PROPOSE_CODE; - - String chars = store.getString(key); - return (chars != null) ? chars.toCharArray() : new char[0]; - } - - /* - * @see ContentAssistAdapter#getContextInformationValidator() - */ - public IContextInformationValidator getContextInformationValidator() { - return super.getContextInformationValidator(); - } - - protected boolean isXMLFormat(Document doc) { - if (doc == null) - return false; - Element docElement = doc.getDocumentElement(); - return docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() == null && ((IDOMNode) docElement).getEndStructuredDocumentRegion() == null))); //$NON-NLS-1$ - } - - /* - * @see ContentAssistAdapter#release() - */ - public void release() { - super.release(); - // release *ContentAssistProcessors in maps - // CMVC 254023 - releasePartitionToProcessorMap(); - releaseNameToProcessorMap(); - } - - protected void releasePartitionToProcessorMap() { - releaseMap(fPartitionToProcessorMap); - } - - protected void releaseNameToProcessorMap() { - releaseMap(fNameToProcessorMap); - } - - protected void releaseMap(HashMap map) { - if (map != null) { - if (!map.isEmpty()) { - Iterator it = map.keySet().iterator(); - Object key = null; - while (it.hasNext()) { - key = it.next(); - if (map.get(key) instanceof IReleasable) { - ((IReleasable) map.get(key)).release(); - } - } - } - map.clear(); - map = null; - } - } - - /** - * @see AbstractContentAssistProcessor#computeCompletionProposals(int, - * String, ITextRegion, IDOMNode, IDOMNode) - */ - protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) { - - ContentAssistRequest request = super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(fTextViewer, documentPosition); - - Document doc = null; - if (xmlnode != null) { - if (xmlnode.getNodeType() == Node.DOCUMENT_NODE) - doc = (Document) xmlnode; - else - doc = xmlnode.getOwnerDocument(); - } - String[] directiveNames = {"page", "include", "taglib"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // suggest JSP Expression inside of XML comments - if (completionRegion.getType() == DOMRegionContext.XML_COMMENT_TEXT && !isXMLFormat(doc)) { - if (request == null) - request = newContentAssistRequest(treeNode, xmlnode, sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$ - request.addProposal(new CustomCompletionProposal("<%= %>", documentPosition, 0, 4, JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), "jsp:expression", null, "<%= %>", XMLRelevanceConstants.R_JSP)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - // handle proposals in and around JSP_DIRECTIVE_OPEN and - // JSP_DIRECTIVE_NAME - else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN && documentPosition >= sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition <= sdRegion.getTextEndOffset(completionRegion))) { - if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) { - if (request == null) - request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, documentPosition, 0, matchString); - Iterator regions = sdRegion.getRegions().iterator(); - String nameString = null; - int begin = request.getReplacementBeginPosition(); - int length = request.getReplacementLength(); - while (regions.hasNext()) { - ITextRegion region = (ITextRegion) regions.next(); - if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { - nameString = sdRegion.getText(region); - begin = sdRegion.getStartOffset(region); - length = region.getTextLength(); - break; - } - } - if (nameString == null) - nameString = ""; //$NON-NLS-1$ - for (int i = 0; i < directiveNames.length; i++) { - if (directiveNames[i].startsWith(nameString) || documentPosition <= begin) - request.addProposal(new CustomCompletionProposal(directiveNames[i], begin, length, directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP)); - } - } - else { // by default, JSP_DIRECTIVE_NAME - if (request == null) - request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - for (int i = 0; i < directiveNames.length; i++) { - if (directiveNames[i].startsWith(matchString)) - request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP)); - } - } - } - else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition > sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion))) { - if (request == null) - request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - super.addTagCloseProposals(request); - // CMVC 274033, this is being added for all <jsp:* tags - // in addAttributeNameProposals(contentAssistRequest) - // super.addAttributeNameProposals(request); - } - // no name?: <%@ %> - else if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion)) { - if (request != null) - request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - Iterator regions = sdRegion.getRegions().iterator(); - String nameString = null; - while (regions.hasNext()) { - ITextRegion region = (ITextRegion) regions.next(); - if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { - nameString = sdRegion.getText(region); - break; - } - } - if (nameString == null) { - for (int i = 0; i < directiveNames.length; i++) { - request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP)); - } - } - } - - // bug115927 use original document position for all/any region templates - addTemplates(request, TemplateContextTypeIdsJSP.ALL, documentPosition); - return request; - } - - private JSPTemplateCompletionProcessor getTemplateCompletionProcessor() { - if (fTemplateProcessor == null) { - fTemplateProcessor = new JSPTemplateCompletionProcessor(); - } - return fTemplateProcessor; - } - - /** - * Adds templates to the list of proposals - * - * @param contentAssistRequest - * @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 - */ - 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)) { - fTemplateContexts.add(context); - boolean useProposalList = !contentAssistRequest.shouldSeparate(); - - if (getTemplateCompletionProcessor() != null) { - getTemplateCompletionProcessor().setContextType(context); - ICompletionProposal[] proposals = getTemplateCompletionProcessor().computeCompletionProposals(fTextViewer, startOffset); - for (int i = 0; i < proposals.length; ++i) { - if (useProposalList) - contentAssistRequest.addProposal(proposals[i]); - else - contentAssistRequest.addMacro(proposals[i]); - } - } - } - } - - protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) { - // ignore - } - - protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsJSP.TAG); - - super.addTagInsertionProposals(contentAssistRequest, childPosition); - if (isInternalAdapter) - useEmbeddedResults = false; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPDummyContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPDummyContentAssistProcessor.java deleted file mode 100644 index 19f2aa5619..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPDummyContentAssistProcessor.java +++ /dev/null @@ -1,304 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 java.util.List; -import java.util.Properties; -import java.util.Vector; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor; -import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest; -import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * This class is a "null" version of AbstractContentAssistProcessor - * - * @plannedfor 1.0 - */ -public class JSPDummyContentAssistProcessor extends AbstractContentAssistProcessor { - protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) { - super.addAttributeNameProposals(contentAssistRequest); - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - super.addAttributeValueProposals(contentAssistRequest); - } - - - protected void addCommentProposal(ContentAssistRequest contentAssistRequest) { - super.addCommentProposal(contentAssistRequest); - } - - - protected void addContent(List contentList, CMContent content) { - super.addContent(contentList, content); - } - - - protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) { - super.addDocTypeProposal(contentAssistRequest); - } - - - protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) { - super.addEmptyDocumentProposals(contentAssistRequest); - } - - - protected void addEndTagNameProposals(ContentAssistRequest contentAssistRequest) { - super.addEndTagNameProposals(contentAssistRequest); - } - - - protected void addEndTagProposals(ContentAssistRequest contentAssistRequest) { - super.addEndTagProposals(contentAssistRequest); - } - - - protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) { - super.addEntityProposals(contentAssistRequest, documentPosition, completionRegion, treeNode); - } - - - protected void addEntityProposals(Vector proposals, Properties map, String key, int nodeOffset, IStructuredDocumentRegion parent, ITextRegion completionRegion) { - super.addEntityProposals(proposals, map, key, nodeOffset, parent, completionRegion); - } - - - protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) { - super.addPCDATAProposal(nodeName, contentAssistRequest); - } - - - protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) { - super.addStartDocumentProposals(contentAssistRequest); - } - - - protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) { - super.addTagCloseProposals(contentAssistRequest); - } - - - protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - super.addTagInsertionProposals(contentAssistRequest, childPosition); - } - - - protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - super.addTagNameProposals(contentAssistRequest, childPosition); - } - - protected boolean attributeInList(IDOMNode node, Node parent, CMNode cmnode) { - return super.attributeInList(node, parent, cmnode); - } - - - protected boolean beginsWith(String aString, String prefix) { - return super.beginsWith(aString, prefix); - } - - - protected ContentAssistRequest computeAttributeProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeAttributeProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - - protected ContentAssistRequest computeAttributeValueProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeAttributeValueProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - - protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) { - return super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - - - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { - return super.computeCompletionProposals(viewer, documentOffset); - } - - - protected ContentAssistRequest computeContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeContentProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, - * int) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { - return super.computeContextInformation(viewer, documentOffset); - } - - protected ContentAssistRequest computeEndTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeEndTagOpenProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - - protected ICompletionProposal[] computeEntityReferenceProposals(int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) { - return super.computeEntityReferenceProposals(documentPosition, completionRegion, treeNode); - } - - protected ContentAssistRequest computeEqualsProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeEqualsProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - protected ContentAssistRequest computeStartDocumentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeStartDocumentProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - protected ContentAssistRequest computeTagCloseProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeTagCloseProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - protected ContentAssistRequest computeTagNameProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeTagNameProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - protected ContentAssistRequest computeTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - return super.computeTagOpenProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - protected String getAdditionalInfo(CMNode parentOrOwner, CMNode cmnode) { - return super.getAdditionalInfo(parentOrOwner, cmnode); - } - - protected List getAvailableChildrenAtIndex(Element parent, int index, int validityChecking) { - return super.getAvailableChildrenAtIndex(parent, index, validityChecking); - } - - protected List getAvailableRootChildren(Document document, int childIndex) { - return super.getAvailableRootChildren(document, childIndex); - } - - protected CMElementDeclaration getCMElementDeclaration(Node node) { - return super.getCMElementDeclaration(node); - } - - public char[] getCompletionProposalAutoActivationCharacters() { - return super.getCompletionProposalAutoActivationCharacters(); - } - - protected ITextRegion getCompletionRegion(int offset, IStructuredDocumentRegion flatNode) { - return super.getCompletionRegion(offset, flatNode); - } - - protected ITextRegion getCompletionRegion(int documentPosition, Node domnode) { - return super.getCompletionRegion(documentPosition, domnode); - } - - public XMLContentModelGenerator getContentGenerator() { - return super.getContentGenerator(); - } - - public char[] getContextInformationAutoActivationCharacters() { - return super.getContextInformationAutoActivationCharacters(); - } - - public IContextInformationValidator getContextInformationValidator() { - return super.getContextInformationValidator(); - } - - protected int getElementPosition(Node child) { - return super.getElementPosition(child); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() - */ - public String getErrorMessage() { - return super.getErrorMessage(); - } - - protected String getMatchString(IStructuredDocumentRegion parent, ITextRegion aRegion, int offset) { - return super.getMatchString(parent, aRegion, offset); - } - - protected ITextRegion getNameRegion(IStructuredDocumentRegion flatNode) { - return super.getNameRegion(flatNode); - } - - - protected List getPossibleDataTypeValues(Node node, CMAttributeDeclaration ad) { - return super.getPossibleDataTypeValues(node, ad); - } - - - protected String getRequiredName(Node parentOrOwner, CMNode cmnode) { - return super.getRequiredName(parentOrOwner, cmnode); - } - - protected String getRequiredText(Node parentOrOwner, CMAttributeDeclaration attrDecl) { - return super.getRequiredText(parentOrOwner, attrDecl); - } - - protected String getRequiredText(Node parentOrOwner, CMElementDeclaration elementDecl) { - return super.getRequiredText(parentOrOwner, elementDecl); - } - - protected List getValidChildElementDeclarations(Element parent, int childPosition, int kindOfAction) { - return super.getValidChildElementDeclarations(parent, childPosition, kindOfAction); - } - - protected void init() { - super.init(); - } - - protected boolean isCloseRegion(ITextRegion region) { - return super.isCloseRegion(region); - } - - protected boolean isNameRegion(ITextRegion region) { - return super.isNameRegion(region); - } - - protected boolean isQuote(String string) { - return super.isQuote(string); - } - - protected Properties mapToProperties(CMNamedNodeMap map) { - return super.mapToProperties(map); - } - - public void setErrorMessage(String errorMessage) { - super.setErrorMessage(errorMessage); - } - - protected void setErrorMessage(String errorMessage, String append) { - super.setErrorMessage(errorMessage, append); - } - - protected void setErrorMessage(String errorMessage, String prepend, String append) { - super.setErrorMessage(errorMessage, prepend, append); - } - - protected boolean stringsEqual(String a, String b) { - return super.stringsEqual(a, b); - } - -}
\ No newline at end of file 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 deleted file mode 100644 index 0ef4b79b2b..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELCompletionProcessor.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import org.eclipse.jdt.core.ICompilationUnit; -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); - } -} 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 deleted file mode 100644 index 324b806ebb..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELContentAssistProcessor.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction; -import org.eclipse.jst.jsp.core.internal.java.jspel.ASTExpression; -import org.eclipse.jst.jsp.core.internal.java.jspel.ASTFunctionInvocation; -import org.eclipse.jst.jsp.core.internal.java.jspel.FindFunctionInvocationVisitor; -import org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParser; -import org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParserConstants; -import org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParserTokenManager; -import org.eclipse.jst.jsp.core.internal.java.jspel.ParseException; -import org.eclipse.jst.jsp.core.internal.java.jspel.SimpleCharStream; -import org.eclipse.jst.jsp.core.internal.java.jspel.Token; -import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; - -public class JSPELContentAssistProcessor extends JSPJavaContentAssistProcessor { - protected char elCompletionProposalAutoActivationCharacters[] = new char[]{'.', ':'}; - - protected JSPCompletionProcessor getJspCompletionProcessor() { - if (fJspCompletionProcessor == null) { - fJspCompletionProcessor = new JSPELCompletionProcessor(); - } - return fJspCompletionProcessor; - } - - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentPosition) { - - - // get results from JSP completion processor - fJspCompletionProcessor = getJspCompletionProcessor(); - ICompletionProposal[] results = fJspCompletionProcessor.computeCompletionProposals(viewer, documentPosition); - fErrorMessage = fJspCompletionProcessor.getErrorMessage(); - if (results.length == 0 && (fErrorMessage == null || fErrorMessage.length() == 0)) { - fErrorMessage = UNKNOWN_CONTEXT; - } - - IStructuredDocumentRegion flat = ContentAssistUtils.getStructuredDocumentRegion(viewer, documentPosition); - - if (flat != null) { - ITextRegion cursorRegion = flat.getRegionAtCharacterOffset(documentPosition); - if (DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE == cursorRegion.getType()) { - ITextRegionContainer container = (ITextRegionContainer) cursorRegion; - cursorRegion = container.getRegionAtCharacterOffset(documentPosition); - if (cursorRegion.getType() == DOMJSPRegionContexts.JSP_EL_CONTENT) { - String elText = container.getText(cursorRegion).trim(); - String prefix = getPrefix(documentPosition - container.getStartOffset(cursorRegion) - 1, elText); - if (null != prefix) { - List proposals = getFunctionProposals(prefix, (StructuredTextViewer) viewer, documentPosition); - results = new ICompletionProposal[proposals.size()]; - proposals.toArray(results); - } - } - } - } - - - return results; - } - - protected String getPrefix(int relativePosition, String elText) { - java.io.StringReader reader = new java.io.StringReader(elText); - JSPELParserTokenManager scanner = new JSPELParserTokenManager(new SimpleCharStream(reader, 1, 1)); - Token curToken = null, lastIdentifier = null; - while (JSPELParserConstants.EOF != (curToken = scanner.getNextToken()).kind) { - if (JSPELParserConstants.COLON == curToken.kind && curToken.endColumn == relativePosition && null != lastIdentifier) { - return (lastIdentifier.image); - } - - if (JSPELParserConstants.IDENTIFIER == curToken.kind) { - lastIdentifier = curToken; - } - else { - lastIdentifier = null; - } - } - return null; - } - - protected ASTFunctionInvocation getInvocation(int relativePosition, String elText) { - FindFunctionInvocationVisitor visitor = new FindFunctionInvocationVisitor(relativePosition); - JSPELParser parser = JSPELParser.createParser(elText); - try { - ASTExpression expression = parser.Expression(); - return (ASTFunctionInvocation) expression.jjtAccept(visitor, null); - } - catch (ParseException e) { /* parse exception = no completion */ - } - return (null); - } - - - public char[] getCompletionProposalAutoActivationCharacters() { - return elCompletionProposalAutoActivationCharacters; - } - - protected List getFunctionProposals(String prefix, StructuredTextViewer viewer, int offset) { - TLDCMDocumentManager docMgr = TaglibController.getTLDCMDocumentManager(viewer.getDocument()); - ArrayList completionList = new ArrayList(); - if (docMgr == null) - return null; - - Iterator taglibs = docMgr.getCMDocumentTrackers(offset).iterator(); - while (taglibs.hasNext()) { - TaglibTracker tracker = (TaglibTracker) taglibs.next(); - if (tracker.getPrefix().equals(prefix)) { - CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument(); - - List functions = doc.getFunctions(); - for (Iterator it = functions.iterator(); it.hasNext();) { - TLDFunction function = (TLDFunction) it.next(); - CustomCompletionProposal proposal = new CustomCompletionProposal(function.getName() + "()", //$NON-NLS-1$ - offset, 0, function.getName().length() + 1, null, function.getName() + " - " + function.getSignature(), null, null, 1); //$NON-NLS-1$ - - completionList.add(proposal); - } - } - } - return completionList; - } - - - -} 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 deleted file mode 100644 index 2efe5eca6a..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPELProposalCollector.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import org.eclipse.jdt.core.CompletionProposal; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.swt.graphics.Image; - -public class JSPELProposalCollector extends JSPProposalCollector { - - public JSPELProposalCollector(ICompilationUnit cu, JSPTranslation translation) { - super(cu, translation); - } - - protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) { - JSPCompletionProposal jspProposal = null; - - if(null == proposal || null == proposal.getName()) - return(null); - - String rawName = new String(proposal.getName()); - String completion = null; - - if(proposal.getKind() == CompletionProposal.METHOD_REF && proposal.findParameterNames(null).length == 0) { - if(rawName.length() > 3 && rawName.startsWith("get")) { //$NON-NLS-1$ - completion = rawName.substring(3,4).toLowerCase() + rawName.substring(4, rawName.length()); - } else { - return null; - } - - // java offset - int offset = proposal.getReplaceStart() + 1; - - // replacement length - int length = proposal.getReplaceEnd() - offset + 1; - - // translate offset from Java > JSP - offset = getTranslation().getJspOffset(offset); - - // cursor position after must be calculated - int positionAfter = offset + completion.length(); - - // from java proposal - IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal); - Image image = null; - String longDisplayString = javaProposal.getDisplayString(); - int fistSpaceIndex = longDisplayString.indexOf(' '); - String shortDisplayString = longDisplayString; - - if(fistSpaceIndex != -1) { - shortDisplayString = longDisplayString.substring(fistSpaceIndex); - } - - String displayString = completion + " " + shortDisplayString; //$NON-NLS-1$ - IContextInformation contextInformation = javaProposal.getContextInformation(); - String additionalInfo = javaProposal.getAdditionalProposalInfo(); - int relevance = javaProposal.getRelevance(); - - boolean updateLengthOnValidate = true; - - jspProposal = new JSPCompletionProposal(completion, offset, length, positionAfter, image, displayString, contextInformation, additionalInfo, relevance, updateLengthOnValidate); - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483 - // set wrapped java proposal so additional info can be calculated on demand - jspProposal.setJavaCompletionProposal(javaProposal); - - return jspProposal; - } else { - return null; - } - } - -// protected void acceptMethod(char[] declaringTypePackageName, char[] declaringTypeName, char[] name, char[][] parameterPackageNames, char[][] parameterTypeNames, char[][] parameterNames, char[] returnTypePackageName, char[] returnTypeName, char[] completionName, int modifiers, int start, int end, int relevance) { -// String rawName = String.valueOf(name); -// if(parameterNames.length == 0 && rawName.length() > 3 && rawName.startsWith("get")) -// { -// String mangledName = rawName.substring(3,4).toLowerCase() + rawName.substring(4, rawName.length()); -// super.acceptField(declaringTypePackageName, declaringTypeName, mangledName.toCharArray(), returnTypePackageName, returnTypeName, mangledName.toCharArray(), modifiers, start, end, relevance); -// } -// } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPJavaContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPJavaContentAssistProcessor.java deleted file mode 100644 index f76c207119..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPJavaContentAssistProcessor.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts; -import org.eclipse.jst.jsp.core.text.IJSPPartitions; -import org.eclipse.jst.jsp.ui.internal.JSPUIMessages; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants; -import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper; - -/** - * @plannedfor 1.0 - */ -public class JSPJavaContentAssistProcessor implements IContentAssistProcessor, IReleasable { - protected char completionProposalAutoActivationCharacters[] = new char[]{'.'}; - protected char contextInformationAutoActivationCharacters[] = null; - protected static final String UNKNOWN_CONTEXT = JSPUIMessages.Content_Assist_not_availab_UI_; - protected String fErrorMessage = null; - protected JSPCompletionProcessor fJspCompletionProcessor = null; - - public JSPJavaContentAssistProcessor() { - super(); - } - - /** - * Return a list of proposed code completions based on the - * specified location within the document that corresponds - * to the current cursor position within the text-editor control. - * - * @param documentPosition a location within the document - * @return an array of code-assist items - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentPosition) { - - IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, documentPosition); - - // get results from JSP completion processor - fJspCompletionProcessor = getJspCompletionProcessor(); - ICompletionProposal[] results = fJspCompletionProcessor.computeCompletionProposals(viewer, documentPosition); - fErrorMessage = fJspCompletionProcessor.getErrorMessage(); - if (results.length == 0 && (fErrorMessage == null || fErrorMessage.length() == 0)) { - fErrorMessage = UNKNOWN_CONTEXT; - } - - IDOMNode xNode = null; - IStructuredDocumentRegion flat = null; - if (treeNode instanceof IDOMNode) { - xNode = (IDOMNode) treeNode; - flat = xNode.getFirstStructuredDocumentRegion(); - if (flat != null && flat.getType() == DOMJSPRegionContexts.JSP_CONTENT) { - flat = flat.getPrevious(); - } - } - - // this is in case it's a <%@, it will be a region container... - ITextRegion openRegion = null; - if (flat != null && flat instanceof ITextRegionContainer) { - ITextRegionList v = ((ITextRegionContainer) flat).getRegions(); - if (v.size() > 0) - openRegion = v.get(0); - } - - // ADD CDATA PROPOSAL IF IT'S AN XML-JSP TAG - if (flat != null && flat.getType() != DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_DECLARATION_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_EXPRESSION_OPEN && flat.getType() != DOMRegionContext.BLOCK_TEXT && (openRegion != null && openRegion.getType() != DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) && !inAttributeRegion(flat, documentPosition)) { - - // determine if cursor is before or after selected range - int adjustedDocPosition = documentPosition; - int realCaretPosition = viewer.getTextWidget().getCaretOffset(); - int selectionLength = viewer.getSelectedRange().y; - if (documentPosition > realCaretPosition) { - adjustedDocPosition -= selectionLength; - } - - CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength); - ICompletionProposal[] newResults = new ICompletionProposal[results.length + 1]; - System.arraycopy(results, 0, newResults, 0, results.length); - newResults[results.length] = cdataProposal; - results = newResults; - } - - // (pa) ** this is code in progress... - // add ending %> proposal for non closed JSP tags - // String tagText = flat.getText(); - // // TODO need a much better compare (using constants?) - // if(tagText.equals("<%") || tagText.equals("<%=") || tagText.equals("<%!")); - // { - // ICompletionProposal testah = ContentAssistUtils.computeJSPEndTagProposal(viewer,documentPosition, treeNode, "<%" , SharedXMLEditorPluginImageHelper.IMG_OBJ_TAG_GENERIC); - // if(testah != null) - // { - // ICompletionProposal[] newResults = new ICompletionProposal[results.length + 1]; - // System.arraycopy( results, 0, newResults, 0, results.length); - // newResults[results.length] = testah; - // results = newResults; - // } - // } - - return results; - } - - private CustomCompletionProposal createCDATAProposal(int adjustedDocPosition, int selectionLength) { - return new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$ - adjustedDocPosition, selectionLength, // should be the selection length - 9, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_CDATASECTION), - "CDATA Section", //$NON-NLS-1$ - null, null, XMLRelevanceConstants.R_CDATA); - } - - private boolean inAttributeRegion(IStructuredDocumentRegion flat, int documentPosition) { - ITextRegion attrContainer = flat.getRegionAtCharacterOffset(documentPosition); - if (attrContainer != null && attrContainer instanceof ITextRegionContainer) { - if (attrContainer.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - return true; - } - } - return false; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of possible completions. - * - * @return the auto activation characters for completion proposal or <code>null</code> - * if no auto activation is desired - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return completionProposalAutoActivationCharacters; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of context information. - * - * @return the auto activation characters for presenting context information - * or <code>null</code> if no auto activation is desired - */ - public char[] getContextInformationAutoActivationCharacters() { - return contextInformationAutoActivationCharacters; - } - - /** - * Return the reason why computeProposals was not able to find any completions. - * - * @return an error message - * or null if no error occurred - */ - public String getErrorMessage() { - return fErrorMessage; - } - - /** - * @see ContentAssistAdapter#release() - */ - public void release() { - if (fJspCompletionProcessor != null) { - fJspCompletionProcessor.release(); - fJspCompletionProcessor = null; - } - } - - /** - * - */ - protected JSPCompletionProcessor getJspCompletionProcessor() { - if (fJspCompletionProcessor == null) { - fJspCompletionProcessor = new JSPCompletionProcessor(); - } - return fJspCompletionProcessor; - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { - List results = new ArrayList(); - // need to compute context info here, if it's JSP, call java computer - IDocument doc = viewer.getDocument(); - IDocumentPartitioner dp = null; - if(doc instanceof IDocumentExtension3) { - dp = ((IDocumentExtension3)doc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING); - } - if(dp != null) { - //IDocumentPartitioner dp = viewer.getDocument().getDocumentPartitioner(); - String type = dp.getPartition(documentOffset).getType(); - if (type == IJSPPartitions.JSP_DEFAULT || type == IJSPPartitions.JSP_CONTENT_JAVA) { - // get context info from completion results... - ICompletionProposal[] proposals = computeCompletionProposals(viewer, documentOffset); - for (int i = 0; i < proposals.length; i++) { - IContextInformation ci = proposals[i].getContextInformation(); - if (ci != null) - results.add(ci); - } - } - } - return (IContextInformation[]) results.toArray(new IContextInformation[results.size()]); - } - - /** - * Returns a validator used to determine when displayed context information - * should be dismissed. May only return <code>null</code> if the processor is - * incapable of computing context information. - * - * @return a context information validator, or <code>null</code> if the processor - * is incapable of computing context information - */ - public IContextInformationValidator getContextInformationValidator() { - return new JavaParameterListValidator(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPPropertyContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPPropertyContentAssistProcessor.java deleted file mode 100644 index 4e8719cb17..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPPropertyContentAssistProcessor.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -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.util.SharedXMLEditorPluginImageHelper; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * This class computes attribute value completion proposals for <jsp:[gs]etProperty> tags. - * @plannedfor 1.0 - */ -public class JSPPropertyContentAssistProcessor extends JSPDummyContentAssistProcessor { - public JSPPropertyContentAssistProcessor() { - super(); - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) - return; - - // get the attribute in question (first attr name to the left of the cursor) - ITextRegion attrNameRegion = null; - String attributeName = null; - while (i >= 0) { - attrNameRegion = openRegions.get(i--); - if (attrNameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - if (attrNameRegion != null) - attributeName = open.getText(attrNameRegion); - - // determine get or set - ITextRegion tagNameRegion = null; - boolean isGetProperty = true; - for (int j = 0; j < openRegions.size(); j++) { - tagNameRegion = openRegions.get(j); - if (tagNameRegion.getType() == DOMRegionContext.XML_TAG_NAME && open.getText(tagNameRegion).trim().equals("jsp:setProperty")) { //$NON-NLS-1$ - isGetProperty = false; - break; - } - } - - String currentValue = null; - if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) - currentValue = contentAssistRequest.getText(); - else - currentValue = ""; //$NON-NLS-1$ - String matchString = null; - // fixups since the matchString computations don't care if there are quotes around the value - if (currentValue.length() > StringUtils.strip(currentValue).length() && (currentValue.startsWith("\"") || currentValue.startsWith("'")) && contentAssistRequest.getMatchString().length() > 0) //$NON-NLS-1$ //$NON-NLS-2$ - matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length()); - else - matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length()); - - // for now we ignore complicated values such as jsp embedded in an attribute - boolean existingComplicatedValue = contentAssistRequest.getRegion() != null && contentAssistRequest.getRegion() instanceof ITextRegionContainer; - if (existingComplicatedValue) { - contentAssistRequest.getProposals().clear(); - contentAssistRequest.getMacros().clear(); - } - else { - if (attributeName.equals(JSP11Namespace.ATTR_NAME_NAME)) { - addBeanNameProposals(contentAssistRequest, node, matchString); - } - else if (attributeName.equals(JSP11Namespace.ATTR_NAME_PROPERTY)) { - addBeanPropertyProposals(contentAssistRequest, node, isGetProperty, matchString); - } - } - } - - private void addBeanPropertyProposals(ContentAssistRequest contentAssistRequest, IDOMNode node, boolean isGetProperty, String matchString) { - // assumes that the node is the [gs]etProperty tag - String useBeanName = ((Element) node).getAttribute(JSP11Namespace.ATTR_NAME_NAME); - // properties can only be provided if a class/type/beanName has been declared - if (useBeanName != null && useBeanName.length() > 0) { - NodeList useBeans = node.getOwnerDocument().getElementsByTagName(JSP11Namespace.ElementName.USEBEAN); - if (useBeans != null) { - String typeName = null; - for (int j = 0; j < useBeans.getLength(); j++) { - if (useBeans.item(j).getNodeType() != Node.ELEMENT_NODE) - continue; - Element useBean = (Element) useBeans.item(j); - if (useBean instanceof IndexedRegion && ((IndexedRegion) useBean).getStartOffset() < node.getStartOffset()) { - if (useBean.getAttribute(JSP11Namespace.ATTR_NAME_ID).equals(useBeanName)) { - typeName = useBean.getAttribute(JSP11Namespace.ATTR_NAME_CLASS); - if (typeName == null || typeName.length() < 1) { - typeName = useBean.getAttribute(JSP11Namespace.ATTR_NAME_TYPE); - } - if (typeName == null || typeName.length() < 1) { - typeName = useBean.getAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME); - } - } - } - } - if (typeName != null && typeName.length() > 0) { - // find the class/type/beanName definition and obtain the list of properties - IBeanInfoProvider provider = new BeanInfoProvider(); - IResource resource = getResource(contentAssistRequest); - IJavaPropertyDescriptor[] descriptors = provider.getRuntimeProperties(resource, typeName); - CustomCompletionProposal proposal = null; - String displayString = ""; //$NON-NLS-1$ - for (int j = 0; j < descriptors.length; j++) { - IJavaPropertyDescriptor pd = descriptors[j]; - // check whether it's get or set kinda property - if (pd.getReadable() && isGetProperty || pd.getWriteable() && !isGetProperty) { - // filter attr value name - if (matchString.length() == 0 || pd.getName().toLowerCase().startsWith(matchString.toLowerCase())) { - displayString = pd.getDisplayName(); - if (pd.getDeclaredType() != null && pd.getDeclaredType().length() > 0) - displayString += " - " + pd.getDeclaredType(); //$NON-NLS-1$ - proposal = new CustomCompletionProposal("\"" + pd.getName() + "\"", //$NON-NLS-1$ //$NON-NLS-2$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), pd.getName().length() + 2, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE), - displayString, null, pd.getDeclaredType(), XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } - } - } - } - } - - private void addBeanNameProposals(ContentAssistRequest contentAssistRequest, IDOMNode node, String matchString) { - // will not catch useBeans specified using other than actual DOM Nodes - NodeList useBeans = node.getOwnerDocument().getElementsByTagName(JSP11Namespace.ElementName.USEBEAN); - if (useBeans != null) { - String id = ""; //$NON-NLS-1$ - String displayString = null; - String classOrType = null; - String imageName = JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ; - for (int j = 0; j < useBeans.getLength(); j++) { - if (useBeans.item(j).getNodeType() != Node.ELEMENT_NODE) - continue; - Element useBean = (Element) useBeans.item(j); - if (useBean instanceof IndexedRegion && ((IndexedRegion) useBean).getStartOffset() < node.getStartOffset()) { - id = StringUtils.strip(useBean.getAttribute(JSP11Namespace.ATTR_NAME_ID)); - displayString = null; - classOrType = null; - imageName = JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ; - // set the Image based on whether the class, type, or beanName attribute is present - classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_CLASS); - if (classOrType == null || classOrType.length() < 1) { - classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_TYPE); - imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC; - } - if (classOrType == null || classOrType.length() < 1) { - classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME); - imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC; - } - if (classOrType != null && classOrType.length() > 0) - displayString = id + " - " + classOrType; //$NON-NLS-1$ - else - displayString = id; - - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=2341 - if(id != null) { - // filter - if (matchString.length() == 0 || id.startsWith(matchString)) { - CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + id + "\"", //$NON-NLS-1$ //$NON-NLS-2$ - contentAssistRequest.getReplacementBeginPosition(), - contentAssistRequest.getReplacementLength(), - id.length() + 2, - JSPEditorPluginImageHelper.getInstance().getImage(imageName), - displayString, - null, - null, - XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } - } - } - } - - /** - * Returns project request is in - * - * @param request - * @return - */ - private IResource getResource(ContentAssistRequest request) { - IResource resource = null; - String baselocation = null; - - if (request != null) { - IStructuredDocumentRegion region = request.getDocumentRegion(); - if (region != null) { - IDocument document = region.getParentDocument(); - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (model != null) { - baselocation = model.getBaseLocation(); - } - } finally { - if (model != null) - model.releaseFromRead(); - } - } - } - - if (baselocation != null) { - // copied from JSPTranslationAdapter#getJavaProject - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IPath filePath = new Path(baselocation); - IFile file = null; - - if (filePath.segmentCount() > 1) { - file = root.getFile(filePath); - } - if (file != null) { - resource = file.getProject(); - } - } - return resource; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPProposalCollector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPProposalCollector.java deleted file mode 100644 index fe6a3dfe21..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPProposalCollector.java +++ /dev/null @@ -1,209 +0,0 @@ -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.jdt.core.CompletionProposal; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jdt.ui.text.java.CompletionProposalCollector; -import org.eclipse.jdt.ui.text.java.CompletionProposalComparator; -import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.swt.graphics.Image; - -/** - * Passed into ICodeComplete#codeComplete(int offset, CompletionRequestor requestor). - * Adapts IJavaCompletionProposals to JSPCompletion proposals. - * This includes: - * - translating offsets - * - "fixing" up display strings - * - filtering some unwanted proposals - * - * @plannedfor 1.0 - */ -public class JSPProposalCollector extends CompletionProposalCollector { - - private JSPTranslation fTranslation; - private Comparator fComparator; - - public JSPProposalCollector(ICompilationUnit cu, JSPTranslation translation) { - super(cu); - - if(translation == null) - throw new IllegalArgumentException("JSPTranslation cannot be null"); //$NON-NLS-1$ - - fTranslation = translation; - } - - /** - * Ensures that we only return JSPCompletionProposals. - * @return an array of JSPCompletionProposals - */ - public JSPCompletionProposal[] getJSPCompletionProposals() { - List results = new ArrayList(); - IJavaCompletionProposal[] javaProposals = getJavaCompletionProposals(); - // need to filter out non JSPCompletionProposals - // because their offsets haven't been translated - for (int i = 0; i < javaProposals.length; i++) { - if(javaProposals[i] instanceof JSPCompletionProposal) - results.add(javaProposals[i]); - } - Collections.sort(results, getComparator()); - return (JSPCompletionProposal[])results.toArray(new JSPCompletionProposal[results.size()]); - } - - private Comparator getComparator() { - if(fComparator == null) - fComparator = new CompletionProposalComparator(); - return fComparator; - } - - /** - * Overridden to: - * - translate Java -> JSP offsets - * - fix cursor-position-after - * - fix mangled servlet name in display string - * - remove unwanted proposals (servlet constructor) - */ - protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) { - - JSPCompletionProposal jspProposal = null; - - // ignore constructor proposals (they're not relevant for our JSP proposal list) - if(!proposal.isConstructor()) { - - if(proposal.getKind() == CompletionProposal.TYPE_REF) { - String signature = String.valueOf(proposal.getDeclarationSignature()); - String completion = String.valueOf(proposal.getCompletion()); - if(completion.indexOf(signature) != -1) { - jspProposal = createAutoImportProposal(proposal); - } - } - - // default behavior - if(jspProposal == null) - jspProposal = createJspProposal(proposal); - } - return jspProposal; - } - - - - private JSPCompletionProposal createAutoImportProposal(CompletionProposal proposal) { - - JSPCompletionProposal jspProposal = null; - - String signature = new String(proposal.getDeclarationSignature()); - String completion = new String(proposal.getCompletion()); - - // it's fully qualified so we should - // add an import statement - // create an autoimport proposal - String newCompletion = completion.replaceAll(signature + ".", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - // java offset - int offset = proposal.getReplaceStart(); - // replacement length - int length = proposal.getReplaceEnd() - offset; - // translate offset from Java > JSP - offset = fTranslation.getJspOffset(offset); - // cursor position after must be calculated - int positionAfter = calculatePositionAfter(proposal, newCompletion, offset); - - // from java proposal - IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal); - proposal.getDeclarationSignature(); - Image image = javaProposal.getImage(); - String displayString = javaProposal.getDisplayString(); - displayString = getTranslation().fixupMangledName(displayString); - IContextInformation contextInformation = javaProposal.getContextInformation(); - // don't do this, it's slow - // String additionalInfo = javaProposal.getAdditionalProposalInfo(); - int relevance = javaProposal.getRelevance(); - - boolean updateLengthOnValidate = true; - - jspProposal = new AutoImportProposal(completion, newCompletion, offset, length, positionAfter, image, displayString, contextInformation, null, relevance, updateLengthOnValidate); - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483 - // set wrapped java proposal so additional info can be calculated on demand - jspProposal.setJavaCompletionProposal(javaProposal); - - return jspProposal; - } - - private JSPCompletionProposal createJspProposal(CompletionProposal proposal) { - - JSPCompletionProposal jspProposal; - String completion = String.valueOf(proposal.getCompletion()); - // java offset - int offset = proposal.getReplaceStart(); - // replacement length - int length = proposal.getReplaceEnd() - offset; - // translate offset from Java > JSP - offset = fTranslation.getJspOffset(offset); - // cursor position after must be calculated - int positionAfter = calculatePositionAfter(proposal, completion, offset); - - // from java proposal - IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal); - proposal.getDeclarationSignature(); - Image image = javaProposal.getImage(); - String displayString = javaProposal.getDisplayString(); - displayString = getTranslation().fixupMangledName(displayString); - IContextInformation contextInformation = javaProposal.getContextInformation(); - // String additionalInfo = javaProposal.getAdditionalProposalInfo(); - int relevance = javaProposal.getRelevance(); - - boolean updateLengthOnValidate = true; - - jspProposal = new JSPCompletionProposal(completion, offset, length, positionAfter, image, displayString, contextInformation, null, relevance, updateLengthOnValidate); - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483 - // set wrapped java proposal so additional info can be calculated on demand - jspProposal.setJavaCompletionProposal(javaProposal); - - return jspProposal; - } - - /** - * Cacluates the where the cursor should be after applying this proposal. - * eg. method(|) if the method proposal chosen had params. - * - * @param proposal - * @param completion - * @param currentCursorOffset - * @return - */ - private int calculatePositionAfter(CompletionProposal proposal, String completion, int currentCursorOffset) { - // calculate cursor position after - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=118398 - //int positionAfter = currentCursorOffset+completion.length(); - int positionAfter = completion.length(); - - int kind = proposal.getKind(); - - // may need better logic here... - // put cursor inside parenthesis if there's params - // only checking for any kind of declaration - if(kind == CompletionProposal.ANONYMOUS_CLASS_DECLARATION || kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.POTENTIAL_METHOD_DECLARATION || kind == CompletionProposal.METHOD_REF) { - String[] params = Signature.getParameterTypes(String.valueOf(proposal.getSignature())); - if(completion.length() > 0 && params.length > 0) - positionAfter--; - } - return positionAfter; - } - - static char[] getTypeTriggers() { - return TYPE_TRIGGERS; - } - - public JSPTranslation getTranslation() { - return fTranslation; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTaglibDirectiveContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTaglibDirectiveContentAssistProcessor.java deleted file mode 100644 index 7a3775f8b1..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTaglibDirectiveContentAssistProcessor.java +++ /dev/null @@ -1,275 +0,0 @@ -/******************************************************************************* - * 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 java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; -import org.eclipse.jst.jsp.core.taglib.IJarRecord; -import org.eclipse.jst.jsp.core.taglib.ITLDRecord; -import org.eclipse.jst.jsp.core.taglib.ITaglibDescriptor; -import org.eclipse.jst.jsp.core.taglib.ITaglibRecord; -import org.eclipse.jst.jsp.core.taglib.IURLRecord; -import org.eclipse.jst.jsp.core.taglib.TaglibIndex; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceConstants; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest; -import org.w3c.dom.Node; - -/** - * @plannedfor 1.0 - */ -public class JSPTaglibDirectiveContentAssistProcessor extends JSPDummyContentAssistProcessor { - - public JSPTaglibDirectiveContentAssistProcessor() { - super(); - } - - String getSmallImageURL(ITaglibRecord taglibRecord) { - String url = null; - switch (taglibRecord.getRecordType()) { - case (ITaglibRecord.TLD) : { - ITLDRecord record = (ITLDRecord) taglibRecord; - IResource file = ResourcesPlugin.getWorkspace().getRoot().getFile(record.getPath()); - if (file.getLocation() != null && record.getDescriptor().getSmallIcon().length() > 0) { - url = "file:" + URIHelper.normalize(record.getDescriptor().getSmallIcon(), file.getFullPath().toString(), TaglibIndex.getContextRoot(file.getFullPath()).toString()); //$NON-NLS-1$ - } - } - break; - case (ITaglibRecord.JAR) : { - IJarRecord record = (IJarRecord) taglibRecord; - if (record.getDescriptor().getSmallIcon().length() > 0) { - // url = "file:" + - // URIHelper.normalize(record.getDescriptor().getSmallIcon(), - // record.getLocation().toString(), "/"); //$NON-NLS-1$ - } - } - break; - case (ITaglibRecord.TAGDIR) : { - } - break; - case (ITaglibRecord.URL) : { - IURLRecord record = (IURLRecord) taglibRecord; - if (record.getDescriptor().getSmallIcon().length() > 0) { - url = URIHelper.normalize(record.getDescriptor().getSmallIcon(), record.getURL().toString(), "/"); //$NON-NLS-1$ - } - } - break; - } - return url; - } - - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - IPath basePath = getBasePath(contentAssistRequest); - if (basePath == null) - return; - - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) - return; - ITextRegion nameRegion = null; - while (i >= 0) { - nameRegion = openRegions.get(i--); - if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - - String attributeName = null; - if (nameRegion != null) - attributeName = open.getText(nameRegion); - - String currentValue = null; - if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) - currentValue = contentAssistRequest.getText(); - else - currentValue = ""; //$NON-NLS-1$ - String matchString = null; - // fixups - int start = contentAssistRequest.getReplacementBeginPosition(); - int length = contentAssistRequest.getReplacementLength(); - if (currentValue.length() > StringUtils.strip(currentValue).length() && (currentValue.startsWith("\"") || currentValue.startsWith("'")) //$NON-NLS-1$ //$NON-NLS-2$ - && contentAssistRequest.getMatchString().length() > 0) { - matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length()); - } - else - matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length()); - boolean existingComplicatedValue = contentAssistRequest.getRegion() != null && contentAssistRequest.getRegion() instanceof ITextRegionContainer; - if (existingComplicatedValue) { - contentAssistRequest.getProposals().clear(); - contentAssistRequest.getMacros().clear(); - } - else { - String lowerCaseMatch = matchString.toLowerCase(Locale.US); - if (attributeName.equals(JSP11Namespace.ATTR_NAME_URI)) { - ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath); - /* - * a simple enough way to remove duplicates (resolution at - * runtime would be nondeterministic anyway) - */ - Map uriToRecords = new HashMap(); - for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) { - ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber]; - ITaglibDescriptor descriptor = taglibRecord.getDescriptor(); - String uri = null; - switch (taglibRecord.getRecordType()) { - case ITaglibRecord.URL : - uri = descriptor.getURI(); - uriToRecords.put(uri, taglibRecord); - break; - case ITaglibRecord.JAR : { - IPath location = ((IJarRecord) taglibRecord).getLocation(); - IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location); - IPath localContextRoot = TaglibIndex.getContextRoot(basePath); - for (int fileNumber = 0; fileNumber < files.length; fileNumber++) { - if (localContextRoot.isPrefixOf(files[fileNumber].getFullPath())) { - uri = IPath.SEPARATOR + files[fileNumber].getFullPath().removeFirstSegments(localContextRoot.segmentCount()).toString(); - uriToRecords.put(uri, taglibRecord); - } - } - break; - } - case ITaglibRecord.TLD : { - IPath path = ((ITLDRecord) taglibRecord).getPath(); - IPath localContextRoot = TaglibIndex.getContextRoot(basePath); - if (localContextRoot.isPrefixOf(path)) { - uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString(); - uriToRecords.put(uri, taglibRecord); - } - break; - } - case ITaglibRecord.TAGDIR : - break; - } - } - /* - * use the records and their descriptors to construct - * proposals - */ - Object[] uris = uriToRecords.keySet().toArray(); - for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) { - String uri = uris[uriNumber].toString(); - ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri); - ITaglibDescriptor descriptor = (taglibRecord).getDescriptor(); - if (uri != null && uri.length() > 0 && (matchString.length() == 0 || uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) { - String url = getSmallImageURL(taglibRecord); - ImageDescriptor imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url); - if (imageDescriptor == null && url != null) { - URL imageURL; - try { - imageURL = new URL(url); - imageDescriptor = ImageDescriptor.createFromURL(imageURL); - JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor); - } - catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - String additionalInfo = descriptor.getDescription() + "<br/>" + descriptor.getTlibVersion(); - CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + uri + "\"", start, length, uri.length() + 2, JSPUIPlugin.getInstance().getImageRegistry().get(url), uri, null, additionalInfo, IRelevanceConstants.R_NONE); - contentAssistRequest.addProposal(proposal); - } - } - } - else if (attributeName.equals(JSP11Namespace.ATTR_NAME_PREFIX)) { - Node uriAttr = node.getAttributes().getNamedItem(JSP11Namespace.ATTR_NAME_URI); - String uri = uriAttr.getNodeValue(); - ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath); - Map prefixMap = new HashMap(); - for (int taglibrecordNumber = 0; taglibrecordNumber < availableTaglibRecords.length; taglibrecordNumber++) { - ITaglibDescriptor descriptor = availableTaglibRecords[taglibrecordNumber].getDescriptor(); - if (descriptor != null && descriptor.getURI().toLowerCase(Locale.US).equals(uri.toLowerCase(Locale.US))) { - String shortName = descriptor.getShortName().trim(); - if (shortName.length() > 0) { - boolean valid = true; - for (int character = 0; character < shortName.length(); character++) { - valid = valid && !Character.isWhitespace(shortName.charAt(character)); - } - if (valid) { - prefixMap.put(shortName, descriptor); - } - } - } - } - Object prefixes[] = prefixMap.keySet().toArray(); - for (int j = 0; j < prefixes.length; j++) { - String prefix = (String) prefixes[j]; - ITaglibDescriptor descriptor = (ITaglibDescriptor) prefixMap.get(prefix); - CustomCompletionProposal proposal = new CustomCompletionProposal(prefix, start, length, prefix.length(), null, prefix, null, descriptor.getDescription(), IRelevanceConstants.R_NONE); - contentAssistRequest.addProposal(proposal); - } - } - } - } - - /** - * Returns project request is in - * - * @param request - * @return - */ - private IPath getBasePath(ContentAssistRequest request) { - IPath baselocation = null; - - if (request != null) { - IStructuredDocumentRegion region = request.getDocumentRegion(); - if (region != null) { - IDocument document = region.getParentDocument(); - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (model != null) { - String location = model.getBaseLocation(); - if (location != null) { - baselocation = new Path(location); - } - } - } - finally { - if (model != null) - model.releaseFromRead(); - } - } - } - return baselocation; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java deleted file mode 100644 index 753a206574..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -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; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; -import org.eclipse.swt.graphics.Image; - -/** - * Completion processor for JSP Templates. Most of the work is already done by - * the JSP Content Assist processor, so by the time the - * JSPTemplateCompletionProcessor is asked for content assist proposals, the - * jsp content assist processor has already set the context type for - * templates. - */ -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]; - - // name of the selection variables {line, word}_selection - context.setVariable("selection", selection.getText()); // //$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); - } - - protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { - TemplateContextType type = null; - - ContextTypeRegistry registry = getTemplateContextRegistry(); - if (registry != null) - type = registry.getContextType(fContextTypeId); - - return type; - } - - protected Image getImage(Template template) { - // just return the same image for now - return JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP); - } - - private ContextTypeRegistry getTemplateContextRegistry() { - return JSPUIPlugin.getDefault().getTemplateContextRegistry(); - } - - protected Template[] getTemplates(String contextTypeId) { - Template templates[] = null; - - TemplateStore store = getTemplateStore(); - if (store != null) - templates = store.getTemplates(contextTypeId); - - return templates; - } - - private TemplateStore getTemplateStore() { - return JSPUIPlugin.getDefault().getTemplateStore(); - } - - void setContextType(String contextTypeId) { - fContextTypeId = contextTypeId; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPUseBeanContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPUseBeanContentAssistProcessor.java deleted file mode 100644 index 15db25dba1..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPUseBeanContentAssistProcessor.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest; - -/** - * @plannedfor 1.0 - */ -public class JSPUseBeanContentAssistProcessor extends JSPDummyContentAssistProcessor { - - public JSPUseBeanContentAssistProcessor() { - super(); - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) - return; - ITextRegion nameRegion = null; - while (i >= 0) { - nameRegion = openRegions.get(i--); - if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - - String attributeName = null; - if (nameRegion != null) - attributeName = open.getText(nameRegion); - - String currentValue = null; - if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) - currentValue = contentAssistRequest.getText(); - else - currentValue = ""; //$NON-NLS-1$ - String matchString = null; - // fixups - int start = contentAssistRequest.getReplacementBeginPosition(); - int length = contentAssistRequest.getReplacementLength(); - if (currentValue.length() > StringUtils.strip(currentValue).length() && (currentValue.startsWith("\"") || currentValue.startsWith("'")) //$NON-NLS-1$ //$NON-NLS-2$ - && contentAssistRequest.getMatchString().length() > 0) { - matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length()); - start++; - length = matchString.length(); - } else - matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length()); - boolean existingComplicatedValue = contentAssistRequest.getRegion() != null && contentAssistRequest.getRegion() instanceof ITextRegionContainer; - if (existingComplicatedValue) { - contentAssistRequest.getProposals().clear(); - contentAssistRequest.getMacros().clear(); - } else { - if (attributeName.equals(JSP11Namespace.ATTR_NAME_CLASS)) { - // class is the concrete implementation class - IResource resource = getResource(contentAssistRequest); - ICompletionProposal[] classProposals = JavaTypeFinder.getClassProposals(resource, start, length); - if (classProposals != null) { - for (int j = 0; j < classProposals.length; j++) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) classProposals[j]; - if (matchString.length() == 0 || proposal.getQualifiedName().toLowerCase().startsWith(matchString.toLowerCase()) || proposal.getShortName().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } - } - } else if (attributeName.equals(JSP11Namespace.ATTR_NAME_TYPE)) { - // type is the more general type for the bean - // which means it may be an interface - IResource resource = getResource(contentAssistRequest); - ICompletionProposal[] typeProposals = JavaTypeFinder.getTypeProposals(resource, start, length); - if (typeProposals != null) { - for (int j = 0; j < typeProposals.length; j++) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) typeProposals[j]; - if (matchString.length() == 0 || proposal.getQualifiedName().toLowerCase().startsWith(matchString.toLowerCase()) || proposal.getShortName().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } - } - } else if (attributeName.equals(JSP11Namespace.ATTR_NAME_BEAN_NAME)) { - IResource resource = getResource(contentAssistRequest); - ICompletionProposal[] beanNameProposals = JavaTypeFinder.getBeanProposals(resource, start, length); - if (beanNameProposals != null) { - for (int j = 0; j < beanNameProposals.length; j++) { - if (beanNameProposals[j] instanceof CustomCompletionProposal) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) beanNameProposals[j]; - if (matchString.length() == 0 || proposal.getDisplayString().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } else if (beanNameProposals[j] instanceof JavaTypeCompletionProposal) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) beanNameProposals[j]; - if (matchString.length() == 0 || proposal.getQualifiedName().toLowerCase().startsWith(matchString.toLowerCase()) || proposal.getShortName().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } - } - } - } - } - } - - /** - * Returns project request is in - * - * @param request - * @return - */ - private IResource getResource(ContentAssistRequest request) { - IResource resource = null; - String baselocation = null; - - if (request != null) { - IStructuredDocumentRegion region = request.getDocumentRegion(); - if (region != null) { - IDocument document = region.getParentDocument(); - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (model != null) { - baselocation = model.getBaseLocation(); - } - } finally { - if (model != null) - model.releaseFromRead(); - } - } - } - - if (baselocation != null) { - // copied from JSPTranslationAdapter#getJavaProject - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IPath filePath = new Path(baselocation); - IFile file = null; - - if (filePath.segmentCount() > 1) { - file = root.getFile(filePath); - } - if (file != null) { - resource = file.getProject(); - } - } - return resource; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaParameterListValidator.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaParameterListValidator.java deleted file mode 100644 index 3eb1f5681e..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaParameterListValidator.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationPresenter; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; - - -/** - * @plannedfor 1.0 - */ -public class JavaParameterListValidator implements IContextInformationValidator, IContextInformationPresenter { - - private int fPosition; - private ITextViewer fViewer; - private IContextInformation fInformation; - - private int fCurrentParameter; - - /** - * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int) - * @see IContextInformationPresenter#install(IContextInformation, ITextViewer, int) - */ - public void install(IContextInformation info, ITextViewer viewer, int documentPosition) { - fPosition= documentPosition; - fViewer= viewer; - fInformation= info; - - fCurrentParameter= -1; - } - - private int getCommentEnd(IDocument d, int pos, int end) throws BadLocationException { - while (pos < end) { - char curr= d.getChar(pos); - pos++; - if (curr == '*') { - if (pos < end && d.getChar(pos) == '/') { - return pos + 1; - } - } - } - return end; - } - - private int getStringEnd(IDocument d, int pos, int end, char ch) throws BadLocationException { - while (pos < end) { - char curr= d.getChar(pos); - pos++; - if (curr == '\\') { - // ignore escaped characters - pos++; - } else if (curr == ch) { - return pos; - } - } - return end; - } - - private int getCharCount(IDocument document, int start, int end, char increment, char decrement, boolean considerNesting) throws BadLocationException { - - Assert.isTrue((increment != 0 || decrement != 0) && increment != decrement); - - int nestingLevel= 0; - int charCount= 0; - while (start < end) { - char curr= document.getChar(start++); - switch (curr) { - case '/': - if (start < end) { - char next= document.getChar(start); - if (next == '*') { - // a comment starts, advance to the comment end - start= getCommentEnd(document, start + 1, end); - } else if (next == '/') { - // '//'-comment: nothing to do anymore on this line - start= end; - } - } - break; - case '*': - if (start < end) { - char next= document.getChar(start); - if (next == '/') { - // we have been in a comment: forget what we read before - charCount= 0; - ++ start; - } - } - break; - case '"': - case '\'': - start= getStringEnd(document, start, end, curr); - break; - default: - - if (considerNesting) { - - if ('(' == curr) - ++ nestingLevel; - else if (')' == curr) - -- nestingLevel; - - if (nestingLevel != 0) - break; - } - - if (increment != 0) { - if (curr == increment) - ++ charCount; - } - - if (decrement != 0) { - if (curr == decrement) - -- charCount; - } - } - } - - return charCount; - } - - /** - * @see IContextInformationValidator#isContextInformationValid(int) - */ - public boolean isContextInformationValid(int position) { - - try { - if (position < fPosition) - return false; - - IDocument document= fViewer.getDocument(); - IRegion line= document.getLineInformationOfOffset(fPosition); - - if (position < line.getOffset() || position >= document.getLength()) - return false; - - return (getCharCount(document, fPosition, position, '(', ')', false) >= 0); - - } catch (BadLocationException x) { - return false; - } - } - - /** - * @see IContextInformationPresenter#updatePresentation(int, TextPresentation) - */ - public boolean updatePresentation(int position, TextPresentation presentation) { - - int currentParameter= -1; - - try { - currentParameter= getCharCount(fViewer.getDocument(), fPosition, position, ',', (char) 0, true); - } catch (BadLocationException x) { - return false; - } - - if (fCurrentParameter != -1) { - if (currentParameter == fCurrentParameter) - return false; - } - - presentation.clear(); - fCurrentParameter= currentParameter; - - String s= fInformation.getInformationDisplayString(); - int start= 0; - int occurrences= 0; - while (occurrences < fCurrentParameter) { - int found= s.indexOf(',', start); - if (found == -1) - break; - start= found + 1; - ++ occurrences; - } - - if (occurrences < fCurrentParameter) { - presentation.addStyleRange(new StyleRange(0, s.length(), null, null, SWT.NORMAL)); - return true; - } - - if (start == -1) - start= 0; - - int end= s.indexOf(',', start); - if (end == -1) - end= s.length(); - - if (start > 0) - presentation.addStyleRange(new StyleRange(0, start, null, null, SWT.NORMAL)); - - if (end > start) - presentation.addStyleRange(new StyleRange(start, end - start, null, null, SWT.BOLD)); - - if (end < s.length()) - presentation.addStyleRange(new StyleRange(end, s.length() - end, null, null, SWT.NORMAL)); - - return true; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeCompletionProposal.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeCompletionProposal.java deleted file mode 100644 index d8b4de75a6..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeCompletionProposal.java +++ /dev/null @@ -1,300 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; -import org.eclipse.jst.jsp.core.internal.provisional.JSP12Namespace; -import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; - -/** - * An implementation of ICompletionProposal whose values can be - * read after creation. - * - * @plannedfor 1.0 - */ -public class JavaTypeCompletionProposal extends CustomCompletionProposal implements IRelevanceCompletionProposal { - - private int fCursorPosition = 0; - private String fLocalDisplayString; - private String fShortName; - private String fQualifiedName; - private String fContainerName; - - public JavaTypeCompletionProposal(String replacementString, int replacementOffset, int replacementLength, String qualifiedName, Image image, String typeName, String containerName, int relevence, boolean updateReplacementLengthOnValidate) { - super(replacementString, replacementOffset, replacementLength, qualifiedName.length() + 2, image, - (containerName != null && containerName.length() > 0) ? typeName + " - " + containerName : typeName, null, null, relevence, true); //$NON-NLS-1$ - // CMVC 243817, superclass was comparing incorrect display string in validate method... - //super(replacementString, replacementOffset, replacementLength, image, (containerName != null && containerName.length() > 0)? typeName + " - " + containerName:typeName/*qualifiedName*/, relevence); - fShortName = typeName; - fQualifiedName = qualifiedName; - fContainerName = containerName; - fCursorPosition = fQualifiedName.length() + 2; - //fProposalInfo = proposalInfo; - if (containerName != null && containerName.length() > 0) - fLocalDisplayString = typeName + " - " + containerName; //$NON-NLS-1$ - else - fLocalDisplayString = typeName; - } - - public String getDisplayString() { - return fLocalDisplayString; - } - - public int getCursorPosition() { - return fCursorPosition; - } - - public void setCursorPosition(int cursorPosition) { - super.setCursorPosition(cursorPosition); - fCursorPosition = cursorPosition; - } - - public String getQualifiedName() { - return fQualifiedName; - } - - public String getAdditionalProposalInfo() { - // String info = super.getAdditionalProposalInfo(); - // if (info == null || info.length() == 0 && fProposalInfo != null) - // return fProposalInfo.getInfo(); - // return info; - return null; // unexplained NPE - } - - public String getShortName() { - return fShortName; - } - - protected String getImport(IStructuredDocumentRegion flatNode) { - ITextRegionList regions = flatNode.getRegions(); - String importSpec = null; - boolean isImport = false; - for (int i = 0; i < regions.size(); i++) { - ITextRegion region = regions.get(i); - if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - if (flatNode.getText(region).equals(JSP11Namespace.ATTR_NAME_IMPORT)) { - isImport = true; - } - else { - isImport = false; - } - } - else if (isImport && region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - importSpec = flatNode.getText(region); - } - } - return importSpec; - } - - /** - * Add an import page directive for the current type name - */ - protected int applyImport(IStructuredDocument model) { - // if the type is in the default package or java.lang, skip it - if (fContainerName == null || fContainerName.length() == 0 || fContainerName.equals("java.lang")) //$NON-NLS-1$ - return 0; - // collect page directives and store their import values - List imports = new ArrayList(); - IStructuredDocumentRegion node = model.getFirstStructuredDocumentRegion(); - - // use the last position of a page directive as a hint as to where to add - // a new one - int hint = 0; - // watch for jsp:root so that we use the right XML/JSP format for the directive - boolean useXML = false; - - while (node != null) { - // Can't just look for all StructuredDocumentRegions starting with JSP_DIRECTIVE_OPEN - // since the XML form is required, too - ITextRegionList regions = node.getRegions(); - if (regions.size() > 1) { - ITextRegion name = regions.get(1); - // verify that this is a JSP directive - if (name.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { - // verify that this is a *page* directive - if (node.getText(name).equals(JSP11Namespace.ATTR_NAME_PAGE) || node.getText(name).equals(JSP12Namespace.ElementName.DIRECTIVE_PAGE)) { - if (node.getEndOffset() < getReplacementOffset()) - hint = node.getEndOffset(); - String importSpec = getImport(node); - if (importSpec != null) { - imports.add(importSpec); - } - } - } - else { - // if this is a jsp:root tag, use the XML form - useXML = useXML || name.getType() == DOMJSPRegionContexts.JSP_ROOT_TAG_NAME; - } - } - node = node.getNext(); - } - - // evaluate requirements for a "new" import directive - boolean needsImport = !importHandles(fQualifiedName, imports); - int adjustmentLength = 0; - // insert "new" import directive - if (needsImport) { - String directive = null; - - // vary the XML behavior - if (useXML) { - directive = "<jsp:directive.page import=\"" + fQualifiedName + "\"/>"; //$NON-NLS-1$ //$NON-NLS-2$ - } - else { - directive = "<%@ page import=\"" + fQualifiedName + "\" %>"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - try { - IRegion line = model.getLineInformationOfOffset(hint); - boolean prependNewLine = line.getOffset() + line.getLength() == hint; - boolean appendNewLine = hint == 0; - if (prependNewLine) - directive = model.getLineDelimiter() + directive; - if (appendNewLine) - directive = directive + model.getLineDelimiter(); - adjustmentLength = directive.length(); - } - catch (BadLocationException e) { - // ignore - } - - try { - model.replace(hint, 0, directive); - - } - catch (BadLocationException e) { - // Not that we should ever get a BLE, but if so, our - // replacement offset from the Content Assist call should - // work - try { - model.replace(getReplacementOffset(), 0, directive); - adjustmentLength = directive.length(); - } - catch (BadLocationException e2) { - // now what? - } - } - } - return adjustmentLength; - } - - /** - * See if the import specification is a wildcard import, and if so, that - * it applies to the given type. - */ - protected boolean isWildcardMatch(String importSpec, String type) { - int specLength = importSpec.length(); - if (importSpec.endsWith("*") && specLength > 2 && type.length() >= specLength) { //$NON-NLS-1$ - // pull out the package name including the final '.' - String container = importSpec.substring(0, specLength - 1); - // verify that the type is in the container's hierarchy and that - // there are no other package separators afterwards - if (type.startsWith(container) && type.indexOf('.', specLength - 1) < 0) { - // container matches - return true; - } - } - return false; - } - - protected boolean importHandles(String type, List listOfImports) { - Iterator imports = listOfImports.iterator(); - while (imports.hasNext()) { - String importSpec = StringUtils.strip(imports.next().toString()); - if (importSpec.equals(type) || isWildcardMatch(importSpec, type)) - return true; - } - return false; - } - - public void apply(IDocument document, char trigger, int offset) { - // If we have a parsed IStructuredDocument, insert the short name instead of the - // fully qualified name and a import page directive if - // needed. Do the import first so the cursor goes to the right location - // and we don't surprise the user. - - boolean addShortForm = false; //document instanceof IStructuredDocument && fContainerName != null && fContainerName.length() > 0; - if (addShortForm) { - setReplacementString('"' + fShortName + '"'); - int importLength = applyImport((IStructuredDocument) document); - setReplacementOffset(getReplacementOffset() + importLength); - } - - setCursorPosition(getReplacementString().length()); - super.apply(document, trigger, offset); - - } - - /* - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension1#apply(org.eclipse.jface.text.ITextViewer, char, int, int) - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - // CMVC 243815 - // (pa) this is overridden to get around replacement length modification - // which is done in the super (since eclipse 2.1) - apply(viewer.getDocument(), trigger, offset); - } - - // code is borrowed from JavaCompletionProposal - protected boolean startsWith(IDocument document, int offset, String word) { - int wordLength = word == null ? 0 : word.length(); - if (offset > getReplacementOffset() + wordLength) - return false; - - try { - int length = offset - getReplacementOffset(); - // CMVC 243817 - // slightly modified to be a little more flexible for attribute value string matching.. - String start = StringUtils.stripQuotes(document.get(getReplacementOffset(), length)); - return word.toLowerCase().startsWith(start.toLowerCase()) || fQualifiedName.toLowerCase().startsWith(start.toLowerCase()); - //return word.substring(0, length).equalsIgnoreCase(start); - } - catch (BadLocationException x) { - // ignore - } - - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent) - // */ - // public boolean validate(IDocument document, int offset, org.eclipse.jface.text.DocumentEvent event) { - // return super.validate(document, offset, event); - // } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal#selected(org.eclipse.jface.text.ITextViewer, boolean) - */ - public void selected(ITextViewer viewer, boolean smartToggle) { - // (pa) we currently don't use smart toggle... - super.selected(viewer, false); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeFinder.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeFinder.java deleted file mode 100644 index b3120d6422..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeFinder.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.search.IJavaSearchConstants; -import org.eclipse.jdt.core.search.IJavaSearchScope; -import org.eclipse.jdt.core.search.SearchEngine; -import org.eclipse.jdt.core.search.SearchPattern; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceConstants; - -/** - * @plannedfor 1.0 - */ -public class JavaTypeFinder { - - public static ICompletionProposal[] getBeanProposals(IResource resource, int replacementStart, int replacementLength) { - ICompletionProposal[] typeProposals = getTypeProposals(resource, replacementStart, replacementLength); - ICompletionProposal[] serialProposals = getSerializedProposals(resource, replacementStart, replacementLength); - ICompletionProposal[] beanProposals = new ICompletionProposal[typeProposals.length + serialProposals.length]; - - int i; - for (i = 0; i < serialProposals.length; i++) { - beanProposals[i] = serialProposals[i]; - } - for (i = serialProposals.length; i < serialProposals.length + typeProposals.length; i++) { - beanProposals[i] = typeProposals[i - serialProposals.length]; - } - return beanProposals; - } - - private static void getMembers(IContainer container, List membersList) { - try { - IResource[] members = container.members(true); - if (members != null) { - for (int i = 0; i < members.length; i++) { - if (members[i].getType() == IResource.FILE) - membersList.add(members[i]); - else if (members[i].getType() == IResource.FOLDER) - getMembers((IContainer) members[i], membersList); - } - } - } - catch (CoreException e) { - // do nothing - } - } - - private static ICompletionProposal[] getSerializedProposals(IResource resource, int replacementStart, int replacementLength) { - List names = new ArrayList(); - List resources = new ArrayList(); - getMembers(resource.getProject(), resources); - IResource memberResource = null; - for (int i = 0; i < resources.size(); i++) { - memberResource = (IResource) resources.get(i); - if (memberResource.getType() == IResource.FILE && memberResource.getName().endsWith(".ser")) { //$NON-NLS-1$ - String path = URIHelper.normalize(memberResource.getFullPath().toString(), resource.getFullPath().toString(), resource.getProject().getFullPath().toString()); - if (path != null) { - names.add(new CustomCompletionProposal("\"" + path + "\"", //$NON-NLS-1$ //$NON-NLS-2$ - replacementStart, replacementLength, path.length() + 2, null, path, null, null, IRelevanceConstants.R_NONE)); - } - } - } - return (ICompletionProposal[]) names.toArray(new ICompletionProposal[names.size()]); - } - - /** - * - * @param resource - * @param replacementStart - * @param replacementLength - * @param searchFor IJavaSearchConstants.TYPE, IJavaSearchConstants.CLASS - * @return - */ - private static ICompletionProposal[] findProposals(IResource resource, int replacementStart, int replacementLength, int searchFor, boolean ignoreAbstractClasses) { - - JavaTypeNameRequestor requestor = new JavaTypeNameRequestor(); - requestor.setJSPOffset(replacementStart); - requestor.setReplacementLength(replacementLength); - requestor.setIgnoreAbstractClasses(ignoreAbstractClasses); - - try { - IJavaElement[] elements = new IJavaElement[]{getJavaProject(resource)}; - IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements); - new SearchEngine().searchAllTypeNames(null, null, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_PREFIX_MATCH, searchFor, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); - - } - catch (CoreException exc) { - Logger.logException(exc); - } - catch (Exception exc) { - // JavaModel - Logger.logException(exc); - } - return requestor.getProposals(); - } - - public static ICompletionProposal[] getTypeProposals(IResource resource, int replacementStart, int replacementLength) { - return findProposals(resource, replacementStart, replacementLength, IJavaSearchConstants.TYPE, false); - } - - public static ICompletionProposal[] getClassProposals(IResource resource, int replacementStart, int replacementLength) { - return findProposals(resource, replacementStart, replacementLength, IJavaSearchConstants.CLASS, true); - } - - private static IJavaProject getJavaProject(IResource resource) { - IProject proj = resource.getProject(); - IJavaProject javaProject = JavaCore.create(proj); - return javaProject; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeNameRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeNameRequestor.java deleted file mode 100644 index c254d14761..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeNameRequestor.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jdt.core.CompletionProposal; -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jdt.core.search.TypeNameRequestor; -import org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.javascript.ui.internal.common.contentassist.IRelevanceConstants; - -/** - * Use w/ JDT search engine to find all type names. - * Creates proposals from matches reported. - * - * @plannedfor 1.0 - */ -public class JavaTypeNameRequestor extends TypeNameRequestor { - - private int fJSPOffset = -1; - private int fReplacementLength = -1; - private List fProposals = new ArrayList(); - private boolean fIgnoreAbstractClasses = false; - - private CompletionProposalLabelProvider fLabelProvider = new CompletionProposalLabelProvider(); - - public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { - - int offset = getJSPOffset(); - int length = getReplacementLength(); - - // somehow offset or length was set incorrectly - if(offset == -1 || length == -1) - return; - // ignore abstract classes? - if(ignoreAbstractClasses() && Flags.isAbstract(modifiers)) - return; - - Image image = calculateImage(modifiers); - - String containerNameString = new String(packageName); - String typeNameString = String.valueOf(simpleTypeName); - - // containername can be null - String fullName = concatenateName(containerNameString, typeNameString); - - String simpleName = Signature.getSimpleName(fullName); - StringBuffer buf = new StringBuffer(simpleName); - String typeQualifier = Signature.getQualifier(fullName); - if (typeQualifier.length() > 0) { - buf.append(" - "); //$NON-NLS-1$ - buf.append(typeQualifier); - } - - JavaTypeCompletionProposal proposal = new JavaTypeCompletionProposal(fullName, offset, length, fullName, image, typeNameString, typeQualifier, IRelevanceConstants.R_NONE, true); - proposal.setTriggerCharacters(JSPProposalCollector.getTypeTriggers()); - fProposals.add(proposal); - } - - - private Image calculateImage(int modifiers) { - CompletionProposal p = CompletionProposal.create(CompletionProposal.TYPE_REF, getJSPOffset()); - p.setFlags(modifiers); - - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=102206 - char[] sig = new char[]{Signature.C_UNRESOLVED}; - p.setSignature(sig); - - ImageDescriptor descriptor = fLabelProvider.createImageDescriptor(p); - Image image = JSPEditorPluginImageHelper.getInstance().getImage(descriptor); - return image; - } - - /** - * Concatenates two names. Uses a dot for separation. Both strings can be - * empty or <code>null</code>. - */ - public String concatenateName(String name1, String name2) { - StringBuffer buf = new StringBuffer(); - if (name1 != null && name1.length() > 0) { - buf.append(name1); - } - if (name2 != null && name2.length() > 0) { - if (buf.length() > 0) { - buf.append('.'); - } - buf.append(name2); - } - return buf.toString(); - } - - int getJSPOffset() { - return fJSPOffset; - } - - void setJSPOffset(int offset) { - fJSPOffset = offset; - } - - int getReplacementLength() { - return fReplacementLength; - } - - void setReplacementLength(int replacementLength) { - fReplacementLength = replacementLength; - } - void setIgnoreAbstractClasses(boolean ignore) { - fIgnoreAbstractClasses = ignore; - } - boolean ignoreAbstractClasses() { - return fIgnoreAbstractClasses; - } - - JavaTypeCompletionProposal[] getProposals() { - return (JavaTypeCompletionProposal[])fProposals.toArray(new JavaTypeCompletionProposal[fProposals.size()]); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/NoRegionContentAssistProcessorForJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/NoRegionContentAssistProcessorForJSP.java deleted file mode 100644 index d3229386f8..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/NoRegionContentAssistProcessorForJSP.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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.ITextViewer; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; -import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts; -import org.eclipse.jst.jsp.core.text.IJSPPartitions; -import org.eclipse.wst.html.core.text.IHTMLPartitions; -import org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.IStructuredPartitions; -import org.eclipse.wst.xml.core.text.IXMLPartitions; - -/** - * @plannedfor 1.0 - */ -public class NoRegionContentAssistProcessorForJSP extends NoRegionContentAssistProcessorForHTML { - - private String[] fJSPContexts = null; - - public NoRegionContentAssistProcessorForJSP() { - super(); - initJSPContexts(); - } - - /* - * @see org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML#initPartitionToProcessorMap() - */ - protected void initPartitionToProcessorMap() { - super.initPartitionToProcessorMap(); - IContentAssistProcessor jspContentAssistProcessor = new JSPContentAssistProcessor(); - - // JSP - addPartitionProcessor(IStructuredPartitions.DEFAULT_PARTITION, jspContentAssistProcessor); - addPartitionProcessor(IXMLPartitions.XML_DEFAULT, jspContentAssistProcessor); - addPartitionProcessor(IHTMLPartitions.HTML_DEFAULT, jspContentAssistProcessor); - addPartitionProcessor(IHTMLPartitions.HTML_COMMENT, jspContentAssistProcessor); - addPartitionProcessor(IJSPPartitions.JSP_DEFAULT, jspContentAssistProcessor); - addPartitionProcessor(IJSPPartitions.JSP_DIRECTIVE, jspContentAssistProcessor); - addPartitionProcessor(IJSPPartitions.JSP_CONTENT_DELIMITER, jspContentAssistProcessor); - addPartitionProcessor(IJSPPartitions.JSP_CONTENT_JAVASCRIPT, jspContentAssistProcessor); - - IContentAssistProcessor jspJavaContentAssistProcessor = new JSPJavaContentAssistProcessor(); - addPartitionProcessor(IJSPPartitions.JSP_CONTENT_JAVA, jspJavaContentAssistProcessor); - - } - - protected void initNameToProcessorMap() { - super.initNameToProcessorMap(); - JSPPropertyContentAssistProcessor jspPropertyCAP = new JSPPropertyContentAssistProcessor(); - addNameProcessor(JSP11Namespace.ElementName.SETPROPERTY, jspPropertyCAP); - addNameProcessor(JSP11Namespace.ElementName.GETPROPERTY, jspPropertyCAP); - addNameProcessor(JSP11Namespace.ElementName.USEBEAN, new JSPUseBeanContentAssistProcessor()); - } - - private void initJSPContexts() { - fJSPContexts = new String[]{DOMJSPRegionContexts.JSP_CLOSE, DOMJSPRegionContexts.JSP_CONTENT, DOMJSPRegionContexts.JSP_DECLARATION_OPEN, DOMJSPRegionContexts.JSP_EXPRESSION_OPEN, DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN}; - } - - /** - * Quick check to see if context (String) should map to - * JSPContentAssistProcessor. - * - * @param context - * @return if it's a JSP Region (for which we need JSP Content assist) - */ - private boolean isJSPRegion(IStructuredDocumentRegion sdRegion) { - String context = sdRegion.getType(); - for (int i = 0; i < fJSPContexts.length; i++) { - if (context == fJSPContexts[i]) - return true; - } - return false; - } - - protected IContentAssistProcessor guessContentAssistProcessor(ITextViewer viewer, int documentOffset) { - IContentAssistProcessor p = super.guessContentAssistProcessor(viewer, documentOffset); - if (p == null) { - IStructuredDocumentRegion sdRegion = ((IStructuredDocument) viewer.getDocument()).getRegionAtCharacterOffset(documentOffset); - if (isJSPRegion(sdRegion)) - p = getPartitionProcessor(IJSPPartitions.JSP_CONTENT_JAVA); - } - return p; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/ReplaceNameTemplateContext.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/ReplaceNameTemplateContext.java deleted file mode 100644 index 1f4e9d13bf..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/ReplaceNameTemplateContext.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * 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()) { - 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()); - } - } - } - return buffer; - } -} |