Color colorComment = ClickPlugin.getDefault().getColorManager().get(ClickPlugin.PREF_COLOR_CMT);
IStructuredDocument document = getDocument();
for(Iterator ite = results.iterator(); ite.hasNext();){
StyleRange styleRange = (StyleRange)ite.next();
IStructuredDocumentRegion region = document.getRegionAtCharacterOffset(styleRange.start);
String text = region.getText();
int mStart = styleRange.start - region.getStartOffset();
int mEnd = mStart + styleRange.length;
for(IStructuredDocumentRegion chkRegion = region.getPrevious(); chkRegion != null; chkRegion = chkRegion.getPrevious()){
String type = chkRegion.getType();
if(!type.equals(DOMRegionContext.XML_CONTENT) && !type.equals(DOMRegionContext.UNDEFINED)){
break;
}
text = chkRegion.getText() + text;
mStart += chkRegion.getLength();
mEnd += chkRegion.getLength();
}
for(IStructuredDocumentRegion chkRegion = region.getNext(); chkRegion != null; chkRegion = chkRegion.getNext()){
String type = chkRegion.getType();
if(!type.equals(DOMRegionContext.XML_CONTENT) && !type.equals(DOMRegionContext.UNDEFINED)){
break;
}
text = (new StringBuilder(String.valueOf(text))).append(chkRegion.getText()).toString();
}
Pattern p = Pattern.compile("##.*|#[a-z]+|\\$((\\{.*?\\})|([a-zA-Z0-9\\-_]*))");
Matcher m = p.matcher(text);
int pos = 0;
while(m.find()) {
Color color = m.group().startsWith("##") ? colorComment :
m.group().startsWith("#") ? colorDirective : colorVariable;
if(m.start() < mStart){
if(m.end() < mStart){
continue;
}
StyleRange curr;
if(m.end() < mEnd){
curr = (StyleRange)styleRange.clone();
curr.start = styleRange.start;
curr.length = m.end() - mStart;
curr.foreground = color;
styleRanges.add(curr);
pos = m.end() - mStart;
continue;
}
curr = (StyleRange)styleRange.clone();
curr.foreground = color;
styleRanges.add(curr);
pos = m.end();
break;
}
if(m.start() >= mEnd){
break;
}
if(m.start() > mStart && pos == 0){
StyleRange prev = (StyleRange)styleRange.clone();
prev.start = styleRange.start;
prev.length = m.start() - mStart;
styleRanges.add(prev);
pos = m.end() - mStart;
}
if(m.end() < mEnd){
StyleRange curr = (StyleRange)styleRange.clone();
curr.start = (styleRange.start + m.start()) - mStart;
curr.length = m.end() - m.start();
curr.foreground = color;
styleRanges.add(curr);
pos = m.end() - mStart;
} else {
StyleRange curr = (StyleRange)styleRange.clone();
curr.start = (styleRange.start + m.start()) - mStart;
curr.length = (styleRange.length - m.start()) + mStart;
curr.foreground = color;
styleRanges.add(curr);
pos = m.end() - mStart;
}
}
if(pos < styleRange.length){
StyleRange post = (StyleRange)styleRange.clone();
post.start = styleRange.start + pos;
post.length = styleRange.length - pos;
styleRanges.add(post);
}
//styleRanges.remove(styleRange);