use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class StructuredRegionProcessor method _getOuterRegion.
/**
* Assumes that when this method is called, region1's node start offset >=
* region2's node start offset. Determines if region1 contains region2 or
* vice versa. Returns region1 if:
* <ul>
* <li>region1's node region == region2's node region</li>
* <li>region1's node region contains region2's node region</li>
* </ul>
* Returns region2 if:
* <ul>
* <li>region1's node region and region2's node region starts at same
* offset but region2's node region is longer</li>
* </ul>
* Returns null otherwise.
*
* @param region1
* @param region2
* @param sModel
* @param region1NodeStart
* @param region2NodeStart
* @return outer dirty region or null if none exists.
*/
private DirtyRegion _getOuterRegion(DirtyRegion region1, DirtyRegion region2, IStructuredModel sModel, int region1NodeStart, int region2NodeStart) {
DirtyRegion outer = null;
int region1NodeEnd = -1;
int region2NodeEnd = -1;
// then check if region1's end appears after
// region2's end
IndexedRegion region1EndNode = sModel.getIndexedRegion(region1.getOffset() + region1.getLength());
if (region1EndNode == null) {
// if no end, just assume region spans all the
// way to the end so it includes other region
outer = region1;
} else {
region1NodeEnd = region1EndNode.getEndOffset();
IndexedRegion region2EndNode = sModel.getIndexedRegion(region2.getOffset() + region2.getLength());
region2NodeEnd = region2EndNode != null ? region2EndNode.getEndOffset() : getDocument().getLength();
if (region1NodeEnd >= region2NodeEnd) {
// root contains or is equal to possible
outer = region1;
} else if (region1NodeStart == region2NodeStart && region2NodeEnd >= region1NodeEnd) {
// possible contains root because they
// both start at same place but possible
// is longer
outer = region2;
}
}
if (DEBUG) {
if (outer != null)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
System.out.println("checking if [" + region1NodeStart + ":" + region1NodeEnd + "] contains [" + region2NodeStart + ":" + region2NodeEnd + "] ... " + outer.toString());
else
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
System.out.println("checking if [" + region1NodeStart + ":" + region1NodeEnd + "] contains [" + region2NodeStart + ":" + region2NodeEnd + "] ... NO CONTAIN");
}
return outer;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class JSPContentSourceValidator method validate.
/**
* This validate call is for the ISourceValidator partial document
* validation approach
*
* @param dirtyRegion
* @param helper
* @param reporter
* @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator
*/
public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) {
if (helper == null || fDocument == null || !fEnableSourceValidation)
return;
if ((reporter != null) && (reporter.isCancelled() == true)) {
throw new OperationCanceledException();
}
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument);
if (model == null)
// error
return;
try {
IDOMDocument document = null;
if (model instanceof IDOMModel) {
document = ((IDOMModel) model).getDocument();
}
if (document == null || !hasHTMLFeature(document))
// ignore
return;
ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument);
if (fb == null)
return;
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fb.getLocation());
if (file == null || !file.exists())
return;
// this will be the wrong region if it's Text (instead of Element)
// we don't know how to validate Text
// model.getIndexedRegion(dirtyRegion.getOffset());
IndexedRegion ir = getCoveringNode(dirtyRegion);
if (ir instanceof Text) {
while (ir != null && ir instanceof Text) {
// it's assumed that this gets the IndexedRegion to
// the right of the end offset
ir = model.getIndexedRegion(ir.getEndOffset());
}
}
if (ir instanceof INodeNotifier) {
INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
ValidationAdapter adapter = (ValidationAdapter) factory.adapt((INodeNotifier) ir);
if (adapter == null)
// error
return;
if (reporter != null) {
HTMLValidationReporter rep = null;
rep = getReporter(reporter, file, (IDOMModel) model);
rep.clear();
adapter.setReporter(rep);
Message mess = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
reporter.displaySubtask(this, mess);
}
adapter.validate(ir);
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class CleanupProcessorCSS method cleanupModel.
public void cleanupModel(IStructuredModel structuredModel, int start, int length) {
CSSFormatUtil formatUtil = CSSFormatUtil.getInstance();
if (structuredModel instanceof ICSSModel) {
ICSSDocument doc = ((ICSSModel) structuredModel).getDocument();
CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) doc);
StringBuffer buf = formatter.cleanup(doc);
if (buf != null) {
int startOffset = ((IndexedRegion) doc).getStartOffset();
int endOffset = ((IndexedRegion) doc).getEndOffset();
formatUtil.replaceSource(doc.getModel(), startOffset, endOffset - startOffset, buf.toString());
}
} else if (structuredModel instanceof IDOMModel) {
List cssnodes = formatUtil.collectCSSNodes(structuredModel, start, length);
if (cssnodes != null && !cssnodes.isEmpty()) {
ICSSModel model = null;
for (int i = 0; i < cssnodes.size(); i++) {
ICSSNode node = (ICSSNode) cssnodes.get(i);
CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) node);
StringBuffer buf = formatter.cleanup(node);
if (buf != null) {
int startOffset = ((IndexedRegion) node).getStartOffset();
int endOffset = ((IndexedRegion) node).getEndOffset();
if (model == null) {
model = node.getOwnerDocument().getModel();
}
formatUtil.replaceSource(model, startOffset, endOffset - startOffset, buf.toString());
}
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class CleanupProcessorJSON method cleanupModel.
public void cleanupModel(IStructuredModel structuredModel, int start, int length) {
JSONFormatUtil formatUtil = JSONFormatUtil.getInstance();
if (structuredModel instanceof IJSONModel) {
IJSONDocument doc = ((IJSONModel) structuredModel).getDocument();
IJSONSourceFormatter formatter = JSONSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) doc);
StringBuilder buf = formatter.cleanup(doc);
if (buf != null) {
int startOffset = ((IndexedRegion) doc).getStartOffset();
int endOffset = ((IndexedRegion) doc).getEndOffset();
formatUtil.replaceSource(doc.getModel(), startOffset, endOffset - startOffset, buf.toString());
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class JSPPropertyCompletionProposalComputer method addBeanNameProposals.
/**
* <p>Add bean name propoasals to the given {@link ContentAssistRequest}</p>
*
* @param contentAssistRequest
* @param node
* @param matchString
*/
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) {
// $NON-NLS-1$
String id = "";
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() && useBean.hasAttribute(JSP11Namespace.ATTR_NAME_ID)) {
id = useBean.hasAttribute(JSP11Namespace.ATTR_NAME_ID) ? StringUtils.strip(useBean.getAttribute(JSP11Namespace.ATTR_NAME_ID)) : null;
displayString = null;
classOrType = null;
imageName = JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ;
// set the Image based on whether the class, type, or beanName attribute is present
if (useBean.hasAttribute(JSP11Namespace.ATTR_NAME_CLASS))
classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_CLASS);
if ((classOrType == null || classOrType.length() < 1) && useBean.hasAttribute(JSP11Namespace.ATTR_NAME_TYPE)) {
classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_TYPE);
imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC;
}
if ((classOrType == null || classOrType.length() < 1) && useBean.hasAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME)) {
classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME);
imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC;
}
if (classOrType != null && classOrType.length() > 0) {
// $NON-NLS-1$
displayString = id + " - " + classOrType;
} 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 // $NON-NLS-1$ //$NON-NLS-2$
CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + id + "\"", contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), id.length() + 2, JSPEditorPluginImageHelper.getInstance().getImage(imageName), displayString, null, null, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
contentAssistRequest.addProposal(proposal);
}
}
}
}
}
}
Aggregations