use of org.eclipse.wst.css.core.internal.util.SelectionCollector in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForAtmarkRule method getCandidateImportRule.
/**
*/
private CSSCACandidate getCandidateImportRule() {
// check content model
CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
if (!util.collectNodesByType(CSSMMNode.TYPE_IMPORT_RULE).hasNext()) {
return null;
}
// charset and import can precede import rule.
int offset = fContext.getCursorPos();
if (0 < offset) {
SelectionCollector trav = new SelectionCollector();
trav.setRegion(0, offset - 1);
trav.apply(fContext.getModel().getDocument());
Iterator i = trav.getSelectedNodes().iterator();
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof ICSSNode && !(obj instanceof ICSSDocument || obj instanceof ICSSCharsetRule || obj instanceof ICSSImportRule)) {
return null;
}
}
}
int cursorPos = 0;
String ident = (fUseUpperCase) ? IMPORT.toUpperCase() : IMPORT.toLowerCase();
StringBuffer buf = new StringBuffer();
buf.append(ident);
// $NON-NLS-1$
buf.append(" ");
cursorPos = buf.length();
StringAndOffset sao;
sao = generateURI();
buf.append(sao.fString);
cursorPos += sao.fOffset;
sao = generateSemicolon();
buf.append(sao.fString);
String text = buf.toString();
if (isMatch(text)) {
CSSCACandidate item = new CSSCACandidate();
item.setReplacementString(buf.toString());
item.setCursorPosition(cursorPos);
item.setDisplayString(ident);
item.setImageType(CSSImageType.RULE_IMPORT);
return item;
} else {
return null;
}
}
use of org.eclipse.wst.css.core.internal.util.SelectionCollector in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForAtmarkRule method getCandidateCharsetRule.
/**
*/
private CSSCACandidate getCandidateCharsetRule() {
// check content model
CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
if (!util.collectNodesByType(CSSMMNode.TYPE_CHARSET_RULE).hasNext()) {
return null;
}
// check if embedded or not
if (fContext.getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
return null;
}
// check if caret precede all other rules.
int offset = fContext.getCursorPos();
if (0 < offset) {
SelectionCollector trav = new SelectionCollector();
trav.setRegion(0, offset - 1);
trav.apply(fContext.getModel().getDocument());
Iterator i = trav.getSelectedNodes().iterator();
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof ICSSNode && !(obj instanceof ICSSDocument)) {
return null;
}
}
}
int cursorPos = 0;
String ident = (fUseUpperCase) ? CHARSET.toUpperCase() : CHARSET.toLowerCase();
StringBuffer buf = new StringBuffer();
buf.append(ident);
// $NON-NLS-1$
buf.append(" ");
cursorPos = buf.length();
StringAndOffset sao;
sao = generateQuotes();
buf.append(sao.fString);
cursorPos += sao.fOffset;
sao = generateSemicolon();
buf.append(sao.fString);
String text = buf.toString();
if (isMatch(text)) {
CSSCACandidate item = new CSSCACandidate();
item.setReplacementString(text);
item.setCursorPosition(cursorPos);
item.setDisplayString(ident);
item.setImageType(CSSImageType.RULE_CHARSET);
return item;
} else {
return null;
}
}
Aggregations