Search in sources :

Example 1 with MacroDirective

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();
}
Also used : Item(org.jboss.ide.eclipse.freemarker.model.Item) ItemSet(org.jboss.ide.eclipse.freemarker.model.ItemSet) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MacroDirective(org.jboss.ide.eclipse.freemarker.model.MacroDirective)

Example 2 with MacroDirective

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;
}
Also used : Item(org.jboss.ide.eclipse.freemarker.model.Item) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MacroDirective(org.jboss.ide.eclipse.freemarker.model.MacroDirective)

Example 3 with MacroDirective

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;
}
Also used : Item(org.jboss.ide.eclipse.freemarker.model.Item) MacroLibrary(org.jboss.ide.eclipse.freemarker.configuration.MacroLibrary) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Iterator(java.util.Iterator) MacroInstance(org.jboss.ide.eclipse.freemarker.model.MacroInstance) List(java.util.List) MacroDirective(org.jboss.ide.eclipse.freemarker.model.MacroDirective)

Example 4 with MacroDirective

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LibraryMacroDirective(org.jboss.ide.eclipse.freemarker.model.LibraryMacroDirective) MacroDirective(org.jboss.ide.eclipse.freemarker.model.MacroDirective) LibraryMacroDirective(org.jboss.ide.eclipse.freemarker.model.LibraryMacroDirective) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

List (java.util.List)4 MacroDirective (org.jboss.ide.eclipse.freemarker.model.MacroDirective)4 ArrayList (java.util.ArrayList)3 Item (org.jboss.ide.eclipse.freemarker.model.Item)3 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 CoreException (org.eclipse.core.runtime.CoreException)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 MacroLibrary (org.jboss.ide.eclipse.freemarker.configuration.MacroLibrary)1 ItemSet (org.jboss.ide.eclipse.freemarker.model.ItemSet)1 LibraryMacroDirective (org.jboss.ide.eclipse.freemarker.model.LibraryMacroDirective)1 MacroInstance (org.jboss.ide.eclipse.freemarker.model.MacroInstance)1