use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.
the class JSPSourceParser method parseNodes.
protected IStructuredDocumentRegion parseNodes() {
// regions are initially reported as complete offsets within the
// scanned input
// they are adjusted here to be indexes from the currentNode's start
// offset
IStructuredDocumentRegion headNode = null;
IStructuredDocumentRegion lastNode = null;
ITextRegion region = null;
// DMW: 2/12/03. Made current node local variable, since
// we changed class to not require state
IStructuredDocumentRegion currentNode = null;
String type = null;
while ((region = getNextRegion()) != null) {
type = region.getType();
// of them
if (type == DOMRegionContext.BLOCK_TEXT) {
if (currentNode != null && currentNode.getLastRegion().getType() == DOMRegionContext.BLOCK_TEXT) {
// multiple block texts indicated embedded containers; no
// new IStructuredDocumentRegion
currentNode.addRegion(region);
currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
region.adjustStart(-currentNode.getStart());
// region.setParent(currentNode);
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(currentNode);
}
} else {
// not continuing a IStructuredDocumentRegion
if (currentNode != null) {
// terminated
if (!currentNode.isEnded()) {
currentNode.setLength(region.getStart() - currentNode.getStart());
// fCurrentNode.setTextLength(region.getStart() -
// fCurrentNode.getStart());
}
lastNode = currentNode;
}
fireNodeParsed(currentNode);
currentNode = createStructuredDocumentRegion(type);
if (lastNode != null) {
lastNode.setNext(currentNode);
}
currentNode.setPrevious(lastNode);
currentNode.setStart(region.getStart());
currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
currentNode.setEnded(true);
region.adjustStart(-currentNode.getStart());
currentNode.addRegion(region);
// region.setParent(currentNode);
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(currentNode);
}
}
} else // the following contexts OPEN new StructuredDocumentRegions
if ((currentNode != null && currentNode.isEnded()) || (type == DOMRegionContext.XML_CONTENT) || (type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE) || (type == DOMRegionContext.XML_PI_OPEN) || (type == DOMRegionContext.XML_TAG_OPEN) || (type == DOMRegionContext.XML_END_TAG_OPEN) || (type == DOMRegionContext.XML_COMMENT_OPEN) || (type == DOMRegionContext.XML_CDATA_OPEN) || (type == DOMRegionContext.XML_DECLARATION_OPEN) || (type == DOMJSPRegionContexts.JSP_COMMENT_OPEN) || (type == DOMJSPRegionContexts.JSP_DECLARATION_OPEN) || (type == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) || (type == DOMJSPRegionContexts.JSP_EXPRESSION_OPEN) || (type == DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN) || (type == DOMJSPRegionContexts.JSP_CLOSE) || type == DOMJSPRegionContexts.JSP_EL_OPEN) {
if (currentNode != null) {
// ensure that any existing node is at least terminated
if (!currentNode.isEnded()) {
currentNode.setLength(region.getStart() - currentNode.getStart());
// fCurrentNode.setTextLength(region.getStart() -
// fCurrentNode.getStart());
}
lastNode = currentNode;
}
fireNodeParsed(currentNode);
currentNode = createStructuredDocumentRegion(type);
if (lastNode != null) {
lastNode.setNext(currentNode);
}
currentNode.setPrevious(lastNode);
currentNode.setStart(region.getStart());
currentNode.addRegion(region);
currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
region.adjustStart(-currentNode.getStart());
// region.setParent(currentNode);
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(currentNode);
}
} else // StructuredDocumentRegions; just add to them
if ((type == DOMRegionContext.XML_TAG_NAME) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) || (type == DOMRegionContext.XML_COMMENT_TEXT) || (type == DOMRegionContext.XML_PI_CONTENT) || (type == DOMRegionContext.XML_DOCTYPE_INTERNAL_SUBSET) || (type == DOMJSPRegionContexts.JSP_COMMENT_TEXT) || (type == DOMJSPRegionContexts.JSP_ROOT_TAG_NAME) || (type == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) || type == DOMJSPRegionContexts.JSP_EL_CONTENT) {
currentNode.addRegion(region);
currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
region.adjustStart(-currentNode.getStart());
// region.setParent(currentNode);
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(currentNode);
}
} else // cleanly
if ((type == DOMRegionContext.XML_PI_CLOSE) || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (type == DOMRegionContext.XML_COMMENT_CLOSE) || (type == DOMRegionContext.XML_CDATA_CLOSE) || (type == DOMJSPRegionContexts.JSP_CLOSE) || (type == DOMJSPRegionContexts.JSP_COMMENT_CLOSE) || (type == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE) || (type == DOMRegionContext.XML_DECLARATION_CLOSE) || type == DOMJSPRegionContexts.JSP_EL_CLOSE) {
currentNode.setEnded(true);
currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
currentNode.addRegion(region);
region.adjustStart(-currentNode.getStart());
// region.setParent(currentNode);
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(currentNode);
}
} else // this is extremely rare, but valid
if (type == DOMRegionContext.WHITE_SPACE) {
ITextRegion lastRegion = currentNode.getLastRegion();
// pack the embedded container with this region
if (lastRegion instanceof ITextRegionContainer) {
ITextRegionContainer container = (ITextRegionContainer) lastRegion;
container.getRegions().add(region);
// DW, 4/16/2003 container regions have parent. Probably a
// better place to set,
// but for now, will (re)set each time through
container.setParent(currentNode);
// DW, 4/16/2003 token regions no longer have parents
// region.setParent(container);
region.adjustStart(container.getLength() - region.getStart());
}
currentNode.getLastRegion().adjustLength(region.getLength());
currentNode.adjustLength(region.getLength());
} else if (type == DOMRegionContext.UNDEFINED && currentNode != null) {
// combine with previous if also undefined
if (currentNode.getLastRegion() != null && currentNode.getLastRegion().getType() == DOMRegionContext.UNDEFINED) {
currentNode.getLastRegion().adjustLength(region.getLength());
currentNode.adjustLength(region.getLength());
// region to the container and update its start location
if (currentNode.getLastRegion() instanceof ITextRegionContainer) {
region.adjustStart(-currentNode.getLastRegion().getStart() - currentNode.getStart());
((ITextRegionContainer) currentNode.getLastRegion()).getRegions().add(region);
}
} else // previous wasn't undefined
{
currentNode.addRegion(region);
currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
region.adjustStart(-currentNode.getStart());
}
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(currentNode);
}
} else {
// ensure that a node exists
if (currentNode == null) {
currentNode = createStructuredDocumentRegion(type);
currentNode.setStart(region.getStart());
}
currentNode.addRegion(region);
currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
region.adjustStart(-currentNode.getStart());
// region.setParent(currentNode);
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(currentNode);
}
if (Debug.debugTokenizer)
// $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
System.out.println(getClass().getName() + " found region of not specifically handled type " + region.getType() + " @ " + region.getStart() + "[" + region.getLength() + "]");
}
// ensures that they open StructuredDocumentRegions the same way
if ((type == DOMRegionContext.XML_CONTENT) || (type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE) || (type == DOMJSPRegionContexts.JSP_DECLARATION_OPEN) || (type == DOMJSPRegionContexts.JSP_EXPRESSION_OPEN) || (type == DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN) || (type == DOMJSPRegionContexts.JSP_CONTENT) || (type == DOMJSPRegionContexts.JSP_CLOSE)) {
currentNode.setEnded(true);
}
if (headNode == null && currentNode != null) {
headNode = currentNode;
}
}
if (currentNode != null) {
fireNodeParsed(currentNode);
currentNode.setPrevious(lastNode);
}
primReset();
return headNode;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.
the class TEIValidation method testCustomTagInAttribute.
public void testCustomTagInAttribute() throws Exception {
// $NON-NLS-1$
final String path = "/" + PROJECT_NAME + "/WebContent/test.jsp";
final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(file);
try {
assertTrue("Not an IDOMModel", model instanceof IDOMModel);
NodeList divs = ((IDOMModel) model).getDocument().getElementsByTagName("div");
assertTrue("Missing a div", divs.getLength() > 0);
IDOMNode node = (IDOMNode) divs.item(0);
IStructuredDocumentRegion region = node.getStartStructuredDocumentRegion();
ITextRegionList regions = region.getRegions();
assertTrue(regions.size() > 2);
/* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
/* JSPJavaTranslatorCoreTest.waitForBuildAndValidation(getProject()); */
final TaglibHelper helper = new TaglibHelper(getProject());
final List problems = new ArrayList();
final IStructuredDocument document = model.getStructuredDocument();
ITextRegion embedded = regions.get(2);
assertTrue("Not a container region", embedded instanceof ITextRegionContainer);
helper.getCustomTag("test:foo", document, (ITextRegionContainer) embedded, problems);
/* assertEquals("No problems should be generated", 0, problems.size()); */
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.
the class JSPPropertyCompletionProposalComputer method addAttributeValueProposals.
/**
* @see org.eclipse.wst.xml.ui.internal.contentassist.DefaultXMLCompletionProposalComputer#addAttributeValueProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
*/
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
// only add attribute value proposals for specific elements
if (node.getNodeName().equals(JSP11Namespace.ElementName.SETPROPERTY) || node.getNodeName().equals(JSP11Namespace.ElementName.GETPROPERTY)) {
// 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
// $NON-NLS-1$
currentValue = "";
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() && // $NON-NLS-1$ //$NON-NLS-2$
(currentValue.startsWith("\"") || currentValue.startsWith("'")) && contentAssistRequest.getMatchString().length() > 0) {
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);
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.
the class JSPTaglibCompletionProposalComputer method addAttributeValueProposals.
/**
* @see org.eclipse.wst.xml.ui.internal.contentassist.DefaultXMLCompletionProposalComputer#addAttributeValueProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
*/
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
IPath basePath = getBasePath(contentAssistRequest);
if (basePath != null) {
IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
// only add attribute value proposals for specific elements
if (node.getNodeName().equals(JSP11Namespace.ElementName.DIRECTIVE_TAGLIB)) {
// 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
// $NON-NLS-1$
currentValue = "";
String matchString = null;
// fixups
int start = contentAssistRequest.getReplacementBeginPosition();
int length = contentAssistRequest.getReplacementLength();
if (currentValue.length() > StringUtils.strip(currentValue).length() && // $NON-NLS-1$ //$NON-NLS-2$
(currentValue.startsWith("\"") || currentValue.startsWith("'")) && 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 = FacetModuleCoreSupport.computeWebContentRootPath(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);
} else {
uri = FacetModuleCoreSupport.getRuntimePath(files[fileNumber].getFullPath()).toString();
uriToRecords.put(uri, taglibRecord);
}
}
break;
}
case ITaglibRecord.TLD:
{
uri = descriptor.getURI();
if (uri == null || uri.trim().length() == 0) {
IPath path = ((ITLDRecord) taglibRecord).getPath();
IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
if (localContextRoot.isPrefixOf(path)) {
uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
} else {
uri = FacetModuleCoreSupport.getRuntimePath(path).toString();
}
}
uriToRecords.put(uri, taglibRecord);
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) {
Logger.logException(e);
}
}
String additionalInfo = // $NON-NLS-1$
descriptor.getDisplayName() + "<br/>" + descriptor.getDescription() + "<br/>" + // $NON-NLS-1$
descriptor.getTlibVersion();
Image image = null;
try {
image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
} catch (Exception e) {
Logger.logException(e);
}
if (image == null) {
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
}
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + uri + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
uri.length() + 2, image, uri, null, additionalInfo, IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
}
}
} else if (attributeName.equals(JSP20Namespace.ATTR_NAME_TAGDIR)) {
ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
/*
* a simple enough way to remove duplicates (resolution at
* runtime would be nondeterministic anyway)
*/
Map uriToRecords = new HashMap();
IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
String uri = null;
if (taglibRecord.getRecordType() == ITaglibRecord.TAGDIR) {
IPath path = ((ITagDirRecord) taglibRecord).getPath();
if (localContextRoot.isPrefixOf(path)) {
uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
uriToRecords.put(uri, taglibRecord);
}
}
}
/*
* 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 = null;
if (url != null) {
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) {
Logger.logException(e);
}
}
// $NON-NLS-1$
String additionalInfo = descriptor.getDescription() + "<br/>" + descriptor.getTlibVersion();
Image image = null;
try {
image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
} catch (Exception e) {
Logger.logException(e);
}
if (image == null) {
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
}
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + uri + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
uri.length() + 2, // $NON-NLS-1$ //$NON-NLS-2$
image, // $NON-NLS-1$ //$NON-NLS-2$
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 = null;
if (uriAttr != null) {
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 (isTaglibForURI(uri, basePath, availableTaglibRecords[taglibrecordNumber])) {
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);
Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + prefix + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
prefix.length() + 2, // $NON-NLS-1$ //$NON-NLS-2$
image, prefix, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
}
} else {
Node dirAttr = node.getAttributes().getNamedItem(JSP20Namespace.ATTR_NAME_TAGDIR);
if (dirAttr != null) {
String dir = dirAttr.getNodeValue();
if (dir != null) {
ITaglibRecord record = TaglibIndex.resolve(basePath.toString(), dir, false);
if (record != null) {
ITaglibDescriptor descriptor = record.getDescriptor();
if (descriptor != null) {
String shortName = descriptor.getShortName();
Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + shortName + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
shortName.length() + 2, image, shortName, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
} else {
if (dir.startsWith("/WEB-INF/")) {
// $NON-NLS-1$
dir = dir.substring(9);
}
// $NON-NLS-1$ //$NON-NLS-2$
String prefix = StringUtils.replace(dir, "/", "-");
Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + prefix + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
prefix.length() + 2, image, prefix, null, null, IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
}
}
}
}
}
}
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.
the class JSPUseBeanCompletionProposalComputer method addAttributeValueProposals.
/**
* @see org.eclipse.wst.xml.ui.internal.contentassist.DefaultXMLCompletionProposalComputer#addAttributeValueProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
*/
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
// only add attribute value proposals for specific elements
if (node.getNodeName().equals(JSP11Namespace.ElementName.USEBEAN)) {
// 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
// $NON-NLS-1$
currentValue = "";
String matchString = null;
// fixups
int start = contentAssistRequest.getReplacementBeginPosition();
int length = contentAssistRequest.getReplacementLength();
if (// $NON-NLS-1$ //$NON-NLS-2$
currentValue.length() > StringUtils.strip(currentValue).length() && (currentValue.startsWith("\"") || currentValue.startsWith("'")) && 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 = JSPContentAssistHelper.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 = JSPContentAssistHelper.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 = JSPContentAssistHelper.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);
}
}
}
}
}
}
}
Aggregations