use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class CSSModelUpdater method valueChanged.
/**
*/
void valueChanged(CSSNodeImpl node, String oldValue) {
if (!(node instanceof CSSRegionContainer)) {
CSSUtil.debugOut(// $NON-NLS-1$
"Too Bad.." + // $NON-NLS-1$
((node == null) ? "null" : node.getClass().toString()));
return;
}
int start = node.getStartOffset();
if (node.getNodeType() == ICSSNode.ATTR_NODE) {
ICSSAttr attr = (ICSSAttr) node;
CSSSourceGenerator formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) attr.getOwnerCSSNode());
if (formatter != null)
start = formatter.getAttrInsertPos(attr.getOwnerCSSNode(), attr.getName());
}
int oldLength = (oldValue == null) ? 0 : oldValue.length();
// flash old IStructuredDocumentRegion/ITextRegion
if (node instanceof CSSStructuredDocumentRegionContainer) {
((CSSStructuredDocumentRegionContainer) node).setFirstStructuredDocumentRegion(null);
((CSSStructuredDocumentRegionContainer) node).setLastStructuredDocumentRegion(null);
} else if (node instanceof CSSRegionContainer) {
((CSSRegionContainer) node).setRangeRegion(null, null, null);
}
// generate new source
String newValue = node.generateSource();
ICSSNode parent;
if (node.getNodeType() == ICSSNode.ATTR_NODE) {
parent = ((ICSSAttr) node).getOwnerCSSNode();
} else {
parent = node.getParentNode();
}
fParser.setupUpdateContext(CSSModelUpdateContext.UPDATE_CHANGE_RCONTAINER, parent, node);
insertText(start, oldLength, newValue);
fParser.cleanupUpdateContext();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class ImportRuleFormatter method getAttrInsertPos.
/**
*/
public int getAttrInsertPos(ICSSNode node, String attrName) {
if (node == null || attrName == null || attrName.length() == 0)
return -1;
if (!ICSSImportRule.HREF.equalsIgnoreCase(attrName))
return -1;
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICSSImportRule.HREF);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IndexedRegion iNode = (IndexedRegion) node;
if (iNode.getEndOffset() <= 0)
return -1;
FormatRegion formatRegion = null;
ICSSNode child = node.getFirstChild();
if (child != null && ((IndexedRegion) child).getEndOffset() > 0)
formatRegion = new FormatRegion(iNode.getStartOffset(), ((IndexedRegion) child).getStartOffset() - iNode.getStartOffset());
else
formatRegion = new FormatRegion(iNode.getStartOffset(), iNode.getEndOffset() - iNode.getStartOffset());
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(node.getOwnerDocument().getModel().getStructuredDocument(), formatRegion, getCleanupStrategy(node));
boolean atrule = false;
for (int i = 0; i < regions.length; i++) {
if (regions[i].getType() == CSSRegionContexts.CSS_IMPORT) {
atrule = true;
continue;
} else if (!atrule)
continue;
if (regions[i].getType() != CSSRegionContexts.CSS_COMMENT)
return regions[i].getStartOffset();
}
return (child != null && ((IndexedRegion) child).getEndOffset() > 0) ? ((IndexedRegion) child).getStartOffset() : iNode.getEndOffset();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class CSSModelUtil method diagnoseNode.
static boolean diagnoseNode(ICSSNode parent, IStructuredDocument structuredDocument) {
// check this
Vector errors = new Vector();
if (parent instanceof CSSStructuredDocumentRegionContainer) {
CSSStructuredDocumentRegionContainer node = (CSSStructuredDocumentRegionContainer) parent;
// $NON-NLS-1$
String nodeText = CSSUtil.getClassString(node) + ": ";
IStructuredDocumentRegion flatNode = node.getFirstStructuredDocumentRegion();
if (flatNode == null && (!(node instanceof CSSStyleDeclarationImpl || node instanceof CSSStyleSheetImpl) || node.getFirstChild() != null)) {
// $NON-NLS-1$
errors.add(nodeText + "first flat node is null.");
} else if (flatNode != null) {
IStructuredDocumentRegion modelNode = structuredDocument.getRegionAtCharacterOffset(flatNode.getStart());
if (flatNode != modelNode) {
// $NON-NLS-1$
errors.add(nodeText + "first flat node is not in model.");
}
}
flatNode = node.getLastStructuredDocumentRegion();
if (flatNode == null && (!(node instanceof CSSStyleDeclarationImpl || node instanceof CSSStyleSheetImpl) || node.getFirstChild() != null)) {
// $NON-NLS-1$
errors.add(nodeText + "last flat node is null.");
} else if (flatNode != null) {
IStructuredDocumentRegion modelNode = structuredDocument.getRegionAtCharacterOffset(flatNode.getStart());
if (flatNode != modelNode) {
// $NON-NLS-1$
errors.add(nodeText + "last flat node is not in model.");
}
}
} else if (parent instanceof CSSRegionContainer) {
CSSRegionContainer node = (CSSRegionContainer) parent;
// $NON-NLS-1$
String nodeText = CSSUtil.getClassString(node) + ": ";
ITextRegion region = node.getFirstRegion();
IStructuredDocumentRegion parentRegion = node.getDocumentRegion();
if (region == null && (!(node instanceof MediaListImpl) || node.getFirstChild() != null)) {
// $NON-NLS-1$
errors.add(nodeText + "first region is null.");
} else if (region != null) {
int offset = parentRegion.getStartOffset(region);
IStructuredDocumentRegion modelNode = structuredDocument.getRegionAtCharacterOffset(offset);
ITextRegion modelRegion = modelNode.getRegionAtCharacterOffset(offset);
if (region != modelRegion) {
// $NON-NLS-1$
errors.add(nodeText + "first region is not in model.");
}
}
region = node.getLastRegion();
if (region == null && (!(node instanceof MediaListImpl) || node.getFirstChild() != null)) {
// $NON-NLS-1$
errors.add(nodeText + "last region is null.");
} else if (region != null) {
int offset = parentRegion.getStartOffset(region);
IStructuredDocumentRegion modelNode = structuredDocument.getRegionAtCharacterOffset(offset);
ITextRegion modelRegion = modelNode.getRegionAtCharacterOffset(offset);
if (region != modelRegion) {
// $NON-NLS-1$
errors.add(nodeText + "last region is not in model.");
}
}
}
ICSSNodeList attrs = parent.getAttributes();
int nAttrs = attrs.getLength();
for (int i = 0; i < nAttrs; i++) {
ICSSAttr attr = (ICSSAttr) attrs.item(i);
CSSRegionContainer node = (CSSRegionContainer) attr;
// $NON-NLS-2$//$NON-NLS-1$
String nodeText = CSSUtil.getClassString(node) + "(" + attr.getName() + "): ";
ITextRegion region = node.getFirstRegion();
IStructuredDocumentRegion parentRegion = node.getDocumentRegion();
if (region == null && 0 < attr.getValue().length()) {
// $NON-NLS-1$
errors.add(nodeText + "first region is null.");
} else if (region != null) {
int offset = parentRegion.getStartOffset(region);
IStructuredDocumentRegion modelNode = structuredDocument.getRegionAtCharacterOffset(offset);
ITextRegion modelRegion = modelNode.getRegionAtCharacterOffset(offset);
if (region != modelRegion) {
// $NON-NLS-1$
errors.add(nodeText + "first region is not in model.");
}
}
region = node.getLastRegion();
if (region == null && 0 < attr.getValue().length()) {
// $NON-NLS-1$
errors.add(nodeText + "last region is null.");
} else if (region != null) {
int offset = parentRegion.getStartOffset(region);
IStructuredDocumentRegion modelNode = structuredDocument.getRegionAtCharacterOffset(offset);
ITextRegion modelRegion = modelNode.getRegionAtCharacterOffset(offset);
if (region != modelRegion) {
// $NON-NLS-1$
errors.add(nodeText + "last region is not in model.");
}
}
}
if (!errors.isEmpty()) {
Iterator i = errors.iterator();
while (i.hasNext()) {
CSSUtil.debugOut((String) i.next());
}
return false;
} else {
return true;
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class MediaListFormatter method getAttrInsertPos.
/**
*/
public int getAttrInsertPos(ICSSNode node, String attrName) {
if (node == null || attrName == null || attrName.length() == 0)
return -1;
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(attrName);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IndexedRegion iNode = (IndexedRegion) node;
if (iNode.getEndOffset() <= 0)
return -1;
/*
* ITextRegion regions[] =
* getRegionsWithoutWhiteSpaces(node.getOwnerDocument().getModel().getStructuredDocument(),
* new FormatRegion(iNode.getStartOffset(), iNode.getEndOffset() -
* iNode.getStartOffset() + 1)); for(int i=regions.length - 1; i >= 0;
* i--) { if (regions[i].getType() == CSSRegionContexts.IMPORTANT_SYM)
* return regions[i].getStartOffset(); }
*/
return iNode.getEndOffset();
}
Aggregations