1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*******************************************************************************
* 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.JSP11Namespace;
import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP;
import org.eclipse.wst.html.core.internal.text.rules.StructuredTextPartitionerForHTML;
import org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML;
import org.eclipse.wst.sse.core.text.IStructuredDocument;
import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.text.rules.StructuredTextPartitioner;
import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts;
import org.eclipse.wst.xml.core.text.rules.StructuredTextPartitionerForXML;
/**
*
* @author pavery
*/
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
fPartitionToProcessorMap.put(StructuredTextPartitioner.ST_DEFAULT_PARTITION, jspContentAssistProcessor);
fPartitionToProcessorMap.put(StructuredTextPartitionerForXML.ST_DEFAULT_XML, jspContentAssistProcessor);
fPartitionToProcessorMap.put(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML, jspContentAssistProcessor);
fPartitionToProcessorMap.put(StructuredTextPartitionerForHTML.ST_HTML_COMMENT, jspContentAssistProcessor);
fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_DEFAULT_JSP, jspContentAssistProcessor);
// JSP directives
fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE, jspContentAssistProcessor);
// JSP delimiters
fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_DELIMITER, jspContentAssistProcessor);
// JSP JavaScript
fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT, jspContentAssistProcessor);
IContentAssistProcessor jspJavaContentAssistProcessor = new JSPJavaContentAssistProcessor();
// JSP Java
fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA, jspJavaContentAssistProcessor);
}
/*
* @see com.ibm.sse.editor.xml.contentassist.NoRegionContentAssistProcessor#initNameToProcessorMap()
*/
protected void initNameToProcessorMap() {
super.initNameToProcessorMap();
JSPPropertyContentAssistProcessor jspPropertyCAP = new JSPPropertyContentAssistProcessor();
fNameToProcessorMap.put(JSP11Namespace.ElementName.SETPROPERTY, jspPropertyCAP);
fNameToProcessorMap.put(JSP11Namespace.ElementName.GETPROPERTY, jspPropertyCAP);
fNameToProcessorMap.put(JSP11Namespace.ElementName.USEBEAN, new JSPUseBeanContentAssistProcessor());
}
private void initJSPContexts() {
fJSPContexts = new String[]{XMLJSPRegionContexts.JSP_CLOSE, XMLJSPRegionContexts.JSP_CONTENT, XMLJSPRegionContexts.JSP_DECLARATION_OPEN, XMLJSPRegionContexts.JSP_EXPRESSION_OPEN, XMLJSPRegionContexts.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;
}
/*
* @see com.ibm.sse.editor.xml.contentassist.NoRegionContentAssistProcessor#guessContentAssistProcessor(org.eclipse.jface.text.ITextViewer, int)
*/
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 = (IContentAssistProcessor) fPartitionToProcessorMap.get(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA);
}
return p;
}
}
|