use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project liferay-ide by liferay.
the class LiferayDependencyQuickFix method getCorrections.
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
if (ListUtil.isEmpty(locations)) {
return null;
}
List<IJavaCompletionProposal> resultingCollections = new ArrayList<>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation curr = locations[i];
List<IJavaCompletionProposal> newProposals = _process(context, curr);
for (IJavaCompletionProposal newProposal : newProposals) {
boolean existed = false;
for (IJavaCompletionProposal existedProposal : resultingCollections) {
if (existedProposal.getDisplayString().equals(newProposal.getDisplayString())) {
existed = true;
}
}
if (existed == false) {
resultingCollections.add(newProposal);
}
}
}
return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project liferay-ide by liferay.
the class QuickFixGradleDep method getCorrections.
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) {
if (ListUtil.isEmpty(locations)) {
return null;
}
IResource resource = context.getCompilationUnit().getResource();
IProject project = resource.getProject();
_gradleFile = project.getFile("build.gradle");
List<IJavaCompletionProposal> resultingCollections = new ArrayList<>();
if (FileUtil.exists(_gradleFile)) {
for (int i = 0; i < locations.length; i++) {
IProblemLocation curr = locations[i];
_process(context, curr, resultingCollections);
}
}
return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project jbosstools-hibernate by jbosstools.
the class HQLQuickAssistProcessor method getAssists.
public IJavaCompletionProposal[] getAssists(final IInvocationContext context, IProblemLocation[] locations) throws CoreException {
IJavaCompletionProposal[] result = new IJavaCompletionProposal[0];
if (!hasAssists(context))
return result;
ASTNode coveringNode = context.getCoveringNode();
if (!(coveringNode instanceof StringLiteral)) {
return result;
}
final StringLiteral stringLiteral = (StringLiteral) coveringNode;
String contents = stringLiteral.getLiteralValue();
result = new IJavaCompletionProposal[1];
result[0] = new ExternalActionQuickAssistProposal(contents, EclipseImages.getImage(ImageConstants.HQL_EDITOR), JdtUiMessages.HQLQuickAssistProcessor_copy_to_hql_editor, context) {
public void apply(IDocument document) {
IEditorPart editorPart = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
ITextEditor[] textEditors = OpenMappingUtils.getTextEditors(editorPart);
if (textEditors.length == 0)
return;
Point position = new Point(stringLiteral.getStartPosition() + 1, stringLiteral.getLength() - 2);
new SaveQueryEditorListener(textEditors[0], getName(), getContents(), position, SaveQueryEditorListener.HQLEditor);
}
};
return result;
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project jbosstools-hibernate by jbosstools.
the class JavaCompletionProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int position) {
try {
setErrorMessage(null);
if (editor.getConsoleConfiguration() == null) {
setErrorMessage(HibernateConsoleMessages.JavaCompletionProcessor_no_console_configuration_found);
return new ICompletionProposal[0];
}
// has to do this because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=141518
String prefix = HibernateConsoleMessages.JavaCompletionProcessor_session_session;
IJavaCompletionProposal[] results = new IJavaCompletionProposal[0];
IJavaProject[] projects = null;
// try {
projects = ProjectUtils.findJavaProjects(editor.getConsoleConfiguration());
/*} catch (RuntimeException e){
String mess = NLS.bind(HibernateConsoleMessages.JavaCompletionProcessor_error_find_project,
editor.getConsoleConfiguration().getName());
HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
}*/
for (int i = 0; projects != null && i < projects.length && results.length <= 0; i++) {
IJavaProject javaProject = projects[i];
collector = new CompletionProposalCollector(javaProject);
collector.acceptContext(new CompletionContext());
try {
editor.codeComplete(prefix, collector, position, javaProject);
} catch (JavaModelException x) {
Shell shell = viewer.getTextWidget().getShell();
ErrorDialog.openError(shell, HibernateConsoleMessages.JavaCompletionProcessor_error, HibernateConsoleMessages.JavaCompletionProcessor_error_while_performing_code_completion, x.getStatus());
HibernateConsolePlugin.getDefault().log(x);
}
results = collector.getJavaCompletionProposals();
}
CompletionHelper.transpose(null, -prefix.length(), results);
return results;
} finally {
if (collector != null) {
setErrorMessage(collector.getErrorMessage());
collector = null;
}
}
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project jbosstools-hibernate by jbosstools.
the class CompletionHelper method completeOnJavaTypes.
public static ICompletionProposal[] completeOnJavaTypes(IJavaProject javaProject, Settings settings, String packageName, String start, int offset) {
if (javaProject != null) {
IEvaluationContext context = javaProject.newEvaluationContext();
if (packageName != null) {
context.setPackageName(packageName);
}
HibernateResultCollector rc = new HibernateResultCollector(javaProject);
rc.acceptContext(new CompletionContext());
// rc.reset(offset, javaProject, null);
rc.setAccepts(settings);
try {
// cannot send in my own document as it won't compile as
// java - so we just send in
// the smallest snippet possible
context.codeComplete(start, start.length(), rc);
} catch (JavaModelException jme) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.CompletionHelper_could_not_complete_java_types, jme);
}
IJavaCompletionProposal[] results = rc.getJavaCompletionProposals();
transpose(start, offset, results);
return results;
}
return new ICompletionProposal[0];
}
Aggregations