use of org.jboss.ide.eclipse.freemarker.configuration.MacroLibrary in project liferay-ide by liferay.
the class MacroInstance method getCompletionProposals.
public ICompletionProposal[] getCompletionProposals(int offset, Map context) {
ContentWithOffset contentWithOffset = splitContents(offset);
int index = contentWithOffset.getIndex();
int subOffset = contentWithOffset.getOffsetInIndex();
int directiveOffset = contentWithOffset.getOffset();
String[] contents = contentWithOffset.getContents();
if (index == 0 && !contentWithOffset.wasLastCharSpace()) {
// name
String prefix = contents[index].substring(0, subOffset);
List l = new ArrayList();
for (Iterator i = getItemSet().getMacroDefinitions().iterator(); i.hasNext(); ) {
MacroDirective macro = (MacroDirective) i.next();
if (macro.getName().startsWith(prefix)) {
l.add(getCompletionProposal(offset, subOffset, macro.getName(), contents[0]));
}
}
MacroLibrary[] libraries = ConfigurationManager.getInstance(getResource().getProject()).getMacroLibraries();
for (int i = 0; i < libraries.length; i++) {
for (int j = 0; j < libraries[i].getMacros().length; j++) {
MacroDirective macro = libraries[i].getMacros()[j];
if (macro.getName().startsWith(prefix)) {
l.add(getCompletionProposal(offset, subOffset, macro.getName(), contents[0]));
}
}
}
return completionProposals(l);
} else if ((contentWithOffset.wasLastCharSpace()) || !contents[index - 1].equals("=")) {
// $NON-NLS-1$
String name = contents[0];
// see if we can find a macro match
MacroDirective match = null;
for (Iterator i = getItemSet().getMacroDefinitions().iterator(); i.hasNext(); ) {
MacroDirective macro = (MacroDirective) i.next();
if (macro.getName().equals(name)) {
match = macro;
break;
}
}
if (null == match) {
MacroLibrary[] libraries = ConfigurationManager.getInstance(getResource().getProject()).getMacroLibraries();
for (int i = 0; i < libraries.length; i++) {
for (int j = 0; j < libraries[i].getMacros().length; j++) {
MacroDirective macro = libraries[i].getMacros()[j];
if (macro.getName().equals(name)) {
match = macro;
break;
}
}
if (null != match)
break;
}
}
if (null != match) {
String prefix = null;
if (contentWithOffset.wasLastCharSpace() || contents.length < index + 1)
// $NON-NLS-1$
prefix = "";
else
prefix = contents[index].substring(0, subOffset);
List l = new ArrayList();
for (int i = 0; i < match.getAttributes().length; i++) {
if (match.getAttributes()[i].startsWith(prefix)) {
l.add(getCompletionProposal(offset, subOffset, match.getAttributes()[i], // $NON-NLS-1$
(contentWithOffset.isNextCharSpace() || contents.length < index + 1) ? "" : contents[index]));
}
}
return completionProposals(l);
}
}
return null;
}
use of org.jboss.ide.eclipse.freemarker.configuration.MacroLibrary 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;
}
Aggregations