use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StyleSheetFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, IRegion region, java.lang.StringBuffer source) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
for (int i = 0; i < regions.length; i++) {
if (i != 0 || needS(outside[0]) || regions[i].getType() == CSSRegionContexts.CSS_CDO || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)
appendDelimBefore(node, regions[i], source);
source.append(decoratedRegion(regions[i], 0, stgy));
}
if (needS(outside[1])) {
if (isIncludesPreEnd(node, region)) {
if (source.length() > 0 || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
String delim = getLineDelimiter(node);
source.append(delim);
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StyleSheetFormatter method formatPre.
/**
*/
protected void formatPre(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode node, java.lang.StringBuffer source) {
int start = ((IndexedRegion) node).getStartOffset();
int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
if (end > 0) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
if (i != 0 || regions[i].getType() == CSSRegionContexts.CSS_CDO || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)
appendDelimBefore(node, regions[i], source);
source.append(decoratedRegion(regions[i], 0, stgy));
}
if (node.getLastChild() != null && (source.length() > 0 || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)) {
appendDelimBefore(node, null, source);
}
} else if (node.getOwnerDocument().getModel() != null && node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
appendDelimBefore(node, null, source);
// source.append("<!--");
// appendDelimBefore(node,null, source);
} else
// nothing
return;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StyleSheetFormatter method formatPost.
/**
*/
protected void formatPost(ICSSNode node, IRegion region, StringBuffer source) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
for (int i = 0; i < regions.length; i++) {
if (i != 0 || needS(outside[0]))
appendDelimBefore(node, regions[i], source);
source.append(decoratedRegion(regions[i], 0, stgy));
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class HTMLValidationReporter method translateMessage.
/**
* Translate ValidationMessage to IMessage and generate result log
*/
private IMessage translateMessage(ValidationMessage message) {
int severity = IMessage.LOW_SEVERITY;
HTMLValidationResult result = getResult();
switch(message.getSeverity()) {
case ValidationMessage.ERROR:
severity = IMessage.HIGH_SEVERITY;
result.addError();
break;
case ValidationMessage.WARNING:
severity = IMessage.NORMAL_SEVERITY;
result.addWarning();
break;
case ValidationMessage.INFORMATION:
result.addInformation();
break;
default:
// result.addInformation();
break;
}
IMessage mes = new LocalizedMessage(severity, message.getMessage(), this.file);
mes.setOffset(message.getOffset());
mes.setLength(message.getLength());
if (this.model != null) {
IStructuredDocument flatModel = this.model.getStructuredDocument();
if (flatModel != null) {
int line = flatModel.getLineOfOffset(message.getOffset());
mes.setLineNo(line + 1);
}
}
return mes;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class HTMLContentAssistProcessor method computeCompletionProposals.
/**
* 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 textViewer, int documentPosition) {
fTemplateContexts.clear();
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition);
IDOMNode node = (IDOMNode) treeNode;
setErrorMessage(null);
// check if it's in a comment node
IStructuredDocument structuredDocument = (IStructuredDocument) textViewer.getDocument();
IStructuredDocumentRegion fn = structuredDocument.getRegionAtCharacterOffset(documentPosition);
if (fn != null && fn.getType() == DOMRegionContext.XML_COMMENT_TEXT && documentPosition != fn.getStartOffset()) {
return new ICompletionProposal[0];
}
// if it's a </script> tag, bounce back to JS ca processor...
if (fn != null && fn.getType() == DOMRegionContext.XML_TAG_NAME && documentPosition == fn.getStartOffset()) {
ITextRegionList v = fn.getRegions();
if (v.size() > 1) {
// determine that it's a close tag
if ((v.get(0)).getType() == DOMRegionContext.XML_END_TAG_OPEN) {
Iterator it = v.iterator();
ITextRegion region = null;
// search for script tag name
while (it.hasNext()) {
region = (ITextRegion) it.next();
if (fn.getText(region).equalsIgnoreCase("script")) {
// $NON-NLS-1$
IContentAssistProcessor jsProcessor = getJSContentAssistProcessor();
if (jsProcessor != null) {
return jsProcessor.computeCompletionProposals(textViewer, documentPosition);
}
return new ICompletionProposal[0];
}
}
}
}
}
isXHTML = getXHTML(node);
// force reload of content generator
fGenerator = null;
// handle blank HTML document case
if (treeNode == null || isViewerEmpty(textViewer)) {
// cursor is at the EOF
ICompletionProposal htmlTagProposal = getHTMLTagProposal(textViewer, documentPosition);
ICompletionProposal[] superResults = super.computeCompletionProposals(textViewer, documentPosition);
if (superResults != null && superResults.length > 0 && htmlTagProposal != null) {
ICompletionProposal[] blankHTMLDocResults = new ICompletionProposal[superResults.length + 1];
blankHTMLDocResults[0] = htmlTagProposal;
System.arraycopy(superResults, 0, blankHTMLDocResults, 1, superResults.length);
return blankHTMLDocResults;
}
}
if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
// check embedded CSS proposals at the beginning of the STYLE end
// tag
Element element = (Element) node;
String tagName = element.getTagName();
if (tagName != null && tagName.equalsIgnoreCase(HTML40Namespace.ATTR_NAME_STYLE)) {
// $NON-NLS-1$
IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion != null && endStructuredDocumentRegion.getStartOffset() == documentPosition) {
IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
if (startStructuredDocumentRegion != null) {
int offset = startStructuredDocumentRegion.getEndOffset();
int pos = documentPosition - offset;
ICompletionProposal[] proposals = getCSSProposals(textViewer, pos, node, offset, (char) 0);
if (proposals != null)
return proposals;
}
}
}
// check inline CSS proposals
// need to find attr region from sd region
IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(textViewer, documentPosition);
Iterator regions = sdRegion.getRegions().iterator();
ITextRegion styleNameRegion = null;
ITextRegion styleValueRegion = null;
while (regions.hasNext()) {
styleNameRegion = (ITextRegion) regions.next();
if (styleNameRegion.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) && sdRegion.getText(styleNameRegion).equalsIgnoreCase(HTML40Namespace.ATTR_NAME_STYLE)) {
// the next region should be "="
if (regions.hasNext()) {
// skip the "="
regions.next();
// next region should be attr value region
if (regions.hasNext()) {
styleValueRegion = (ITextRegion) regions.next();
break;
}
}
}
}
if (styleValueRegion != null) {
int offset = sdRegion.getStartOffset(styleValueRegion);
int end = sdRegion.getTextEndOffset(styleValueRegion);
if (documentPosition >= offset && documentPosition <= end) {
boolean askCSS = true;
char quote = (char) 0;
String text = sdRegion.getText(styleValueRegion);
int length = (text != null ? text.length() : 0);
if (length > 0) {
char firstChar = text.charAt(0);
if (firstChar == '"' || firstChar == '\'') {
if (documentPosition == offset) {
// before quote
askCSS = false;
} else {
offset++;
quote = firstChar;
}
}
if (documentPosition == end) {
if (length > 1 && text.charAt(length - 1) == quote) {
// after quote
askCSS = false;
}
}
}
if (askCSS) {
int pos = documentPosition - offset;
ICompletionProposal[] proposals = getCSSProposals(textViewer, pos, node, offset, quote);
if (proposals != null)
return proposals;
}
}
}
}
return super.computeCompletionProposals(textViewer, documentPosition);
}
Aggregations