use of org.eclipse.jface.text.contentassist.CompletionProposal in project liferay-ide by liferay.
the class CompletionProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
try {
ItemSet directiveSet = editor.getItemSet();
Map context = new HashMap();
ContextValue[] values = ConfigurationManager.getInstance(editor.getProject()).getContextValues(editor.getFile(), true);
for (int i = 0; i < values.length; i++) {
context.put(values[i].name, values[i].objClass);
}
Item directive = directiveSet.getSelectedItem(offset);
if (null != directive) {
return directive.getCompletionProposals(offset, context);
} else {
// we might be starting something
Item item = editor.getItemSet().getPreviousItem(offset);
int topOffset = 0;
if (null != item)
topOffset = item.getRegion().getOffset() + item.getRegion().getLength();
// check for directives and macro calls
try {
for (int i = offset - 1; i >= topOffset; i--) {
char c = editor.getDocument().getChar(i);
if (c == '>' || c == ']')
break;
if (c == '<' || c == '[') {
if (editor.getDocument().getLength() > i) {
char c2 = editor.getDocument().getChar(i + 1);
if (c2 == '#') {
CompletionDirective completionDirective = new CompletionDirective(i, offset - i, editor.getItemSet(), (ISourceViewer) viewer, (IResource) editor.getFile());
completionDirective.setItemSet(editor.getItemSet());
return completionDirective.getCompletionProposals(offset, context);
} else if (c2 == '@') {
CompletionMacroInstance completionMacroInstance = new CompletionMacroInstance(editor.getDocument().get(i, offset - i), i, editor.getItemSet(), editor.getFile());
completionMacroInstance.setItemSet(editor.getItemSet());
return completionMacroInstance.getCompletionProposals(offset, context);
} else if (c2 == '/') {
if (editor.getDocument().getLength() < i + 3 || editor.getDocument().getChar(i + 2) == ' ' || editor.getDocument().getChar(i + 2) == '\r' || editor.getDocument().getChar(i + 2) == '\n') {
Item stackItem = editor.getItemSet().getPreviousStartItem(offset);
StringBuffer value = new StringBuffer();
if (null != stackItem && stackItem instanceof MacroInstance)
// $NON-NLS-1$
value.append("@");
else
// $NON-NLS-1$
value.append("#");
String name = null;
if (null != stackItem)
name = stackItem.getFirstToken();
if (null != name)
value.append(name);
if (c == '<')
value.append('>');
else
value.append(']');
ICompletionProposal completionProposal = new CompletionProposal(value.toString(), offset, 0, offset + value.toString().length());
return new ICompletionProposal[] { completionProposal };
}
} else {
return NO_COMPLETIONS;
}
}
}
}
} catch (BadLocationException e) {
return NO_COMPLETIONS;
}
// check for interpolations
try {
for (int i = offset - 1; i >= topOffset; i--) {
char c = editor.getDocument().getChar(i);
if (c == '\n')
break;
else if (c == '$') {
if (editor.getDocument().getLength() > i) {
char c2 = editor.getDocument().getChar(i + 1);
if (c2 == '{') {
int j = offset;
while (editor.getDocument().getLength() > j) {
char c3 = editor.getDocument().getChar(j);
if (Character.isWhitespace(c3) || c3 == '(' || c3 == '.' || c3 == ')' || c3 == '}' || c3 == '?') {
// j = j-1;
break;
}
j++;
}
CompletionInterpolation interpolation = new CompletionInterpolation(editor.getDocument().get(i, j - i), i, editor.getItemSet(), editor.getFile());
interpolation.setParentItem(editor.getItemSet().getPreviousStartItem(offset));
return interpolation.getCompletionProposals(offset, context);
}
}
}
}
} catch (BadLocationException e) {
return NO_COMPLETIONS;
}
}
} catch (Exception e) {
Plugin.log(e);
}
return NO_COMPLETIONS;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project jbosstools-hibernate by jbosstools.
the class ColumnNameHandler method attributeCompletionProposals.
public ICompletionProposal[] attributeCompletionProposals(IJavaProject javaProject, Node node, String attributeName, String start, int offset) {
List columns = new ArrayList();
HibernateNature nature = HibernateNature.getHibernateNature(javaProject);
if (nature != null) {
String nearestTableName = extractor.getNearestTableName(node);
if (nearestTableName != null) {
ITable table = nature.getTable(nearestTableName);
if (table != null) {
Iterator tableMappings = table.getColumnIterator();
while (tableMappings.hasNext()) {
IColumn column = (IColumn) tableMappings.next();
if (column.getName().toUpperCase().startsWith(start.toUpperCase())) {
columns.add(column);
}
}
}
}
}
List proposals = new ArrayList();
for (Iterator iter = columns.iterator(); iter.hasNext(); ) {
IColumn element = (IColumn) iter.next();
proposals.add(new CompletionProposal(element.getName(), offset, start.length(), element.getName().length(), null, null, null, null));
}
return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project jbosstools-hibernate by jbosstools.
the class GeneratorTypeHandler method attributeCompletionProposals.
public ICompletionProposal[] attributeCompletionProposals(IJavaProject project, Node node, String attributeName, String start, int offset) {
List types = this.extractor.findMatchingGenerators(start);
List proposals = new ArrayList(types.size());
for (Iterator iter = types.iterator(); iter.hasNext(); ) {
HibernateTypeDescriptor element = (HibernateTypeDescriptor) iter.next();
String extendedinfo = MapperMessages.GeneratorTypeHandler_generator_type + element.getName();
if (element.getReturnClass() != null) {
extendedinfo += MapperMessages.GeneratorTypeHandler_return_class + element.getReturnClass();
}
proposals.add(new CompletionProposal(element.getName(), offset, start.length(), element.getName().length(), null, null, null, extendedinfo));
}
try {
// $NON-NLS-1$
IType typeInterface = project.findType("org.hibernate.id.IdentifierGenerator");
Set alreadyFound = new HashSet();
if (typeInterface != null) {
ITypeHierarchy hier = typeInterface.newTypeHierarchy(project, new NullProgressMonitor());
// TODO: cache these results ?
IType[] classes = hier.getAllSubtypes(typeInterface);
// $NON-NLS-1$
this.extractor.generateTypeProposals(start, offset, proposals, alreadyFound, classes, "org.hibernate.id");
}
} catch (CoreException e) {
// TODO: log as error!
throw new RuntimeException(e);
}
ICompletionProposal[] result = (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
return result;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project jbosstools-hibernate by jbosstools.
the class HibernateTypeHandler method attributeCompletionProposals.
public ICompletionProposal[] attributeCompletionProposals(IJavaProject project, Node node, String attributeName, String start, int offset) {
List types = this.extractor.findMatchingHibernateTypes(start);
List proposals = new ArrayList(types.size());
for (Iterator iter = types.iterator(); iter.hasNext(); ) {
HibernateTypeDescriptor element = (HibernateTypeDescriptor) iter.next();
String extendedinfo = MapperMessages.HibernateTypeHandler_hibernate_type + element.getName();
if (element.getReturnClass() != null) {
extendedinfo += MapperMessages.HibernateTypeHandler_return_class + element.getReturnClass();
}
if (element.getPrimitiveClass() != null) {
extendedinfo += MapperMessages.HibernateTypeHandler_return_primitive + element.getPrimitiveClass();
}
proposals.add(new CompletionProposal(element.getName(), offset, start.length(), element.getName().length(), null, null, null, extendedinfo));
}
try {
// $NON-NLS-1$
IType typeInterface = project.findType("org.hibernate.usertype.CompositeUserType");
Set alreadyFound = new HashSet();
if (typeInterface != null) {
ITypeHierarchy hier = typeInterface.newTypeHierarchy(project, new NullProgressMonitor());
// TODO: cache these results ?
IType[] classes = hier.getAllSubtypes(typeInterface);
this.extractor.generateTypeProposals(start, offset, proposals, alreadyFound, classes, null);
}
// $NON-NLS-1$
typeInterface = project.findType("org.hibernate.usertype.UserType");
if (typeInterface != null) {
ITypeHierarchy hier = typeInterface.newTypeHierarchy(project, new NullProgressMonitor());
// TODO: cache these results ?
IType[] classes = hier.getAllSubtypes(typeInterface);
this.extractor.generateTypeProposals(start, offset, proposals, alreadyFound, classes, null);
}
} catch (CoreException e) {
// TODO: log as error!
throw new RuntimeException(e);
}
ICompletionProposal[] result = (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
return result;
}
use of org.eclipse.jface.text.contentassist.CompletionProposal in project jbosstools-hibernate by jbosstools.
the class HBMXMLContentAssistProcessor method getAttributeValueProposals.
public List getAttributeValueProposals(String attributeName, String start, int offset, ContentAssistRequest contentAssistRequest) {
Node node = contentAssistRequest.getNode();
List proposals = new ArrayList();
// $NON-NLS-1$
String path = node.getNodeName() + ">" + attributeName;
HBMInfoHandler handler = sourceLocator.getAttributeHandler(path);
if (handler != null) {
proposals.addAll(Arrays.asList(handler.attributeCompletionProposals(getJavaProject(contentAssistRequest), node, attributeName, start, offset)));
}
if (DEBUG) {
String string = contentAssistRequest.getDocumentRegion().getText();
string = string.replace('<', '[');
string = string.replace('>', ']');
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
CompletionProposal completionProposal = new CompletionProposal("[" + start + "],[" + path + "],[" + offset + "]", offset, 1, 4, null, null, null, string);
proposals.add(completionProposal);
}
return proposals;
}
Aggregations