Search in sources :

Example 1 with JavaModelStatus

use of org.eclipse.jdt.internal.core.JavaModelStatus in project che by eclipse.

the class CodeAssist method prepareCompilationUnit.

private ICompilationUnit prepareCompilationUnit(IJavaProject project, String fqn) throws JavaModelException {
    ICompilationUnit compilationUnit;
    IType type = project.findType(fqn);
    if (type == null) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Can't find a file: " + fqn));
    }
    if (type.isBinary()) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Can't organize imports on binary file"));
    } else {
        compilationUnit = type.getCompilationUnit();
    }
    return compilationUnit;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus) IType(org.eclipse.jdt.core.IType)

Example 2 with JavaModelStatus

use of org.eclipse.jdt.internal.core.JavaModelStatus in project che by eclipse.

the class CodeAssist method computeAssistProposals.

@SuppressWarnings("unchecked")
public Proposals computeAssistProposals(IJavaProject project, String fqn, int offset, List<Problem> problems) throws CoreException {
    ICompilationUnit compilationUnit;
    IType type = project.findType(fqn);
    if (type == null) {
        return null;
    }
    if (type.isBinary()) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Can't calculate Quick Assist on binary file"));
    } else {
        compilationUnit = type.getCompilationUnit();
    }
    IBuffer buffer = compilationUnit.getBuffer();
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    bufferManager.connect(compilationUnit.getPath(), LocationKind.IFILE, new NullProgressMonitor());
    ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(compilationUnit.getPath(), LocationKind.IFILE);
    IDocument document = textFileBuffer.getDocument();
    TextViewer viewer = new TextViewer(document, new Point(offset, 0));
    AssistContext context = new AssistContext(compilationUnit, offset, 0);
    ArrayList proposals = new ArrayList<>();
    JavaCorrectionProcessor.collectProposals(context, problems, true, true, proposals);
    return convertProposals(offset, compilationUnit, viewer, proposals);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus) Point(org.eclipse.swt.graphics.Point) IBuffer(org.eclipse.jdt.core.IBuffer) IType(org.eclipse.jdt.core.IType) TextViewer(org.eclipse.che.jdt.javaeditor.TextViewer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with JavaModelStatus

use of org.eclipse.jdt.internal.core.JavaModelStatus in project che by eclipse.

the class MavenWorkspace method addSourcesFromBuildHelperPlugin.

private void addSourcesFromBuildHelperPlugin(MavenProject project) {
    IJavaProject javaProject = JavaCore.create(project.getProject());
    try {
        ClasspathHelper helper = new ClasspathHelper(javaProject);
        Element pluginConfigurationSource = project.getPluginConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "add-source");
        Element pluginConfigurationTestSource = project.getPluginConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "add-test-source");
        IPath projectPath = project.getProject().getFullPath();
        RegisteredProject registeredProject = projectRegistryProvider.get().getProject(projectPath.toOSString());
        if (registeredProject == null) {
            throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Project " + projectPath.toOSString() + " doesn't exist"));
        }
        List<String> sourceFolders = registeredProject.getAttributes().get(Constants.SOURCE_FOLDER);
        List<String> testSourceFolders = registeredProject.getAttributes().get(MavenAttributes.TEST_SOURCE_FOLDER);
        addSourcePathFromConfiguration(helper, project, pluginConfigurationSource, sourceFolders);
        addSourcePathFromConfiguration(helper, project, pluginConfigurationTestSource, testSourceFolders);
        javaProject.setRawClasspath(helper.getEntries(), null);
    } catch (JavaModelException e) {
        LOG.error("Can't update Java project classpath with Maven build helper plugin configuration", e);
    }
}
Also used : ClasspathHelper(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) Element(org.jdom.Element) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus)

Aggregations

JavaModelException (org.eclipse.jdt.core.JavaModelException)3 JavaModelStatus (org.eclipse.jdt.internal.core.JavaModelStatus)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IType (org.eclipse.jdt.core.IType)2 ArrayList (java.util.ArrayList)1 RegisteredProject (org.eclipse.che.api.project.server.RegisteredProject)1 TextViewer (org.eclipse.che.jdt.javaeditor.TextViewer)1 ClasspathHelper (org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IBuffer (org.eclipse.jdt.core.IBuffer)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)1 IDocument (org.eclipse.jface.text.IDocument)1 Point (org.eclipse.swt.graphics.Point)1 Element (org.jdom.Element)1