use of org.jboss.ide.eclipse.freemarker.model.MacroDirective in project liferay-ide by liferay.
the class OutlineContentProvider method getElements.
public Object[] getElements(Object inputElement) {
ItemSet itemSet = null;
if (inputElement instanceof ItemSet)
itemSet = (ItemSet) inputElement;
else
itemSet = fEditor.getItemSet();
List rootItems = new ArrayList();
rootItems.addAll(fEditor.getItemSet().getMacroDefinitions());
Item[] items = fEditor.getItemSet().getRootItems();
for (int i = 0; i < items.length; i++) {
if (!(items[i] instanceof MacroDirective))
rootItems.add(items[i]);
}
return rootItems.toArray();
}
use of org.jboss.ide.eclipse.freemarker.model.MacroDirective in project liferay-ide by liferay.
the class OutlineContentProvider method getChildren.
public Object[] getChildren(Object anElement) {
if (anElement instanceof Item) {
if (anElement instanceof MacroDirective)
return null;
Object[] items = ((Item) anElement).getChildItems().toArray(new Item[((Item) anElement).getChildItems().size()]);
List l = new ArrayList(items.length);
for (int i = 0; i < items.length; i++) {
if (!(items[i] instanceof MacroDirective))
l.add(items[i]);
}
return l.toArray();
} else
return null;
}
use of org.jboss.ide.eclipse.freemarker.model.MacroDirective in project liferay-ide by liferay.
the class MacroHyperlinkDetector method detectHyperlinks.
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
Item item = editor.getItemSet().getItem(region.getOffset());
if (null != item && item instanceof MacroInstance) {
MacroInstance instance = (MacroInstance) item;
int index = instance.getName().indexOf('.');
if (index > 0) {
// it is from a macro library
String namespace = instance.getName().substring(0, index);
MacroLibrary macroLibrary = ConfigurationManager.getInstance(editor.getProject()).getMacroLibrary(namespace);
if (null != macroLibrary) {
for (int i = 0; i < macroLibrary.getMacros().length; i++) {
if (macroLibrary.getMacros()[i].getName().equals(instance.getName())) {
// we have a match
return new IHyperlink[] { new MacroHyperlink(instance, macroLibrary.getFile(), macroLibrary.getMacros()[i].getOffset(), macroLibrary.getMacros()[i].getLength()) };
}
}
}
if (null != macroLibrary)
return new IHyperlink[] { new MacroHyperlink(instance, macroLibrary.getFile(), -1, -1) };
} else {
List macroDefinitions = instance.getItemSet().getMacroDefinitions();
for (Iterator i = macroDefinitions.iterator(); i.hasNext(); ) {
MacroDirective macroDefinition = (MacroDirective) i.next();
if (macroDefinition.getName().equals(instance.getName())) {
return new IHyperlink[] { new MacroHyperlink(instance, editor.getFile(), macroDefinition.getOffset(), macroDefinition.getLength()) };
}
}
}
}
return null;
}
use of org.jboss.ide.eclipse.freemarker.model.MacroDirective in project liferay-ide by liferay.
the class MacroLibrary method load.
private void load() {
try {
List macros = new ArrayList();
// $NON-NLS-1$
String search = "#macro ";
int index = content.indexOf(search);
int startIndex = index;
char startChar = content.charAt(index - 1);
char endChar;
if (startChar == '[')
endChar = ']';
else
endChar = '>';
while (startIndex > 0) {
int stackCount = 0;
boolean inString = false;
// find the end
int endIndex = Integer.MIN_VALUE;
boolean escape = false;
while (content.length() > index && index >= 0) {
boolean doEscape = false;
char c = content.charAt(index++);
if (!escape) {
if (c == '\"')
inString = !inString;
else if (c == '\\' && inString)
doEscape = true;
else if (c == startChar)
stackCount++;
else if (c == endChar) {
if (stackCount > 0)
stackCount--;
else {
endIndex = index - 1;
break;
}
}
}
escape = doEscape;
}
if (endIndex > 0) {
String sub = content.substring(startIndex, endIndex);
MacroDirective macroDirective = new LibraryMacroDirective(namespace, sub, startIndex - 1, endIndex - index + 2);
macros.add(macroDirective);
index = content.indexOf(startChar + search, endIndex);
if (index >= 0)
index++;
startIndex = index;
endIndex = Integer.MIN_VALUE;
} else {
break;
}
}
this.macros = (MacroDirective[]) macros.toArray(new MacroDirective[macros.size()]);
if (null != file)
this.lastUpdatedTime = file.getModificationStamp();
} catch (Exception e) {
macros = new MacroDirective[0];
Plugin.log(e);
}
}
Aggregations