Search in sources :

Example 21 with IJavaCompletionProposal

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()]);
}
Also used : ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)

Example 22 with IJavaCompletionProposal

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()]);
}
Also used : ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 23 with IJavaCompletionProposal

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;
}
Also used : StringLiteral(org.eclipse.jdt.core.dom.StringLiteral) ASTNode(org.eclipse.jdt.core.dom.ASTNode) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal) IDocument(org.eclipse.jface.text.IDocument)

Example 24 with IJavaCompletionProposal

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;
        }
    }
}
Also used : CompletionContext(org.eclipse.jdt.core.CompletionContext) JavaModelException(org.eclipse.jdt.core.JavaModelException) Shell(org.eclipse.swt.widgets.Shell) IJavaProject(org.eclipse.jdt.core.IJavaProject) CompletionProposalCollector(org.eclipse.jdt.ui.text.java.CompletionProposalCollector) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)

Example 25 with IJavaCompletionProposal

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];
}
Also used : CompletionContext(org.eclipse.jdt.core.CompletionContext) JavaModelException(org.eclipse.jdt.core.JavaModelException) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IEvaluationContext(org.eclipse.jdt.core.eval.IEvaluationContext) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)

Aggregations

IJavaCompletionProposal (org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)30 ArrayList (java.util.ArrayList)13 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)5 CoreException (org.eclipse.core.runtime.CoreException)4 CompletionContext (org.eclipse.jdt.core.CompletionContext)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 IType (org.eclipse.jdt.core.IType)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)4 IDocument (org.eclipse.jface.text.IDocument)4 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)4 Image (org.eclipse.swt.graphics.Image)4 ICompletionProposal (org.eclipse.che.jface.text.contentassist.ICompletionProposal)3 IJavaElement (org.eclipse.jdt.core.IJavaElement)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 ServiceContainer (com.liferay.ide.project.core.modules.ServiceContainer)2 List (java.util.List)2 Map (java.util.Map)2 IFile (org.eclipse.core.resources.IFile)2