Java Code Examples for org.eclipse.jdt.core.JavaModelException#getMessage()
The following examples show how to use
org.eclipse.jdt.core.JavaModelException#getMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResolveElementHandler.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * Resolve the Java element at the selected position. * @return the resolved Java element information. */ public static Object resolveElementAtSelection(List<Object> arguments, IProgressMonitor monitor) throws DebugException { if (arguments == null || arguments.size() < 3) { return Collections.emptyList(); } String uri = (String) arguments.get(0); int line = (int) Math.round((double) arguments.get(1)); int column = (int) Math.round((double) arguments.get(2)); final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri); try { IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, JavaLanguageServerPlugin.getPreferencesManager(), monitor); if (element instanceof IMethod) { return new JavaElement(((IMethod) element).getDeclaringType().getFullyQualifiedName(), element.getJavaProject().getProject().getName(), ((IMethod) element).isMainMethod()); } else if (element instanceof IType) { return new JavaElement(((IType) element).getFullyQualifiedName(), element.getJavaProject().getProject().getName(), ResolveMainMethodHandler.getMainMethod((IType) element) != null); } } catch (JavaModelException e) { throw new DebugException("Failed to resolve the selected element information: " + e.getMessage(), e); } return null; }
Example 2
Source File: FieldInitializerUtil.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public IJavaElement getSelectedResource(IStructuredSelection selection) { IJavaElement elem = null; if(selection != null && !selection.isEmpty()){ Object o = selection.getFirstElement(); elem = Adapters.adapt(o, IJavaElement.class); if(elem == null){ elem = getPackage(o); } } if (elem == null) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = activePage.getActivePart(); if (part instanceof ContentOutline) { part= activePage.getActiveEditor(); } if (part instanceof XtextEditor) { IXtextDocument doc = ((XtextEditor)part).getDocument(); IFile file = Adapters.adapt(doc, IFile.class); elem = getPackage(file); } } if (elem == null || elem.getElementType() == IJavaElement.JAVA_MODEL) { try { IJavaProject[] projects= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects(); if (projects.length == 1) { elem= projects[0]; } } catch (JavaModelException e) { throw new RuntimeException(e.getMessage()); } } return elem; }
Example 3
Source File: FieldInitializerUtil.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the Java element that corresponds to the given selection. * * @param selection the current selection. * @return the Java element. */ @SuppressWarnings("static-method") public IJavaElement getSelectedResource(IStructuredSelection selection) { IJavaElement elem = null; if (selection != null && !selection.isEmpty()) { final Object object = selection.getFirstElement(); if (object instanceof IAdaptable) { final IAdaptable adaptable = (IAdaptable) object; elem = adaptable.getAdapter(IJavaElement.class); if (elem == null) { elem = getPackage(adaptable); } } } if (elem == null) { final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = activePage.getActivePart(); if (part instanceof ContentOutline) { part = activePage.getActiveEditor(); } if (part instanceof XtextEditor) { final IXtextDocument doc = ((XtextEditor) part).getDocument(); final IFile file = doc.getAdapter(IFile.class); elem = getPackage(file); } } if (elem == null || elem.getElementType() == IJavaElement.JAVA_MODEL) { try { final IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects(); if (projects.length == 1) { elem = projects[0]; } } catch (JavaModelException e) { throw new RuntimeException(e.getMessage()); } } return elem; }
Example 4
Source File: ComputeScriptDependenciesJob.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected IStatus run(final IProgressMonitor monitor) { if (groovyCompilationUnit == null || !groovyCompilationUnit.exists()) { return Status.CANCEL_STATUS; } try { findDependencies(); } catch (final JavaModelException e) { return new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); } return Status.OK_STATUS; }
Example 5
Source File: BuildPathCommand.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static Result listSourcePaths() { List<SourcePath> sourcePathList = new ArrayList<>(); IProject[] projects = ProjectUtils.getAllProjects(); for (IProject project : projects) { if (!ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName()) && ProjectUtils.isJavaProject(project)) { try { IPath[] paths = ProjectUtils.listSourcePaths(JavaCore.create(project)); for (IPath path : paths) { IPath entryPath = path; String projectName = project.getName(); String projectType = "General"; if (ProjectUtils.isMavenProject(project)) { projectType = "Maven"; } if (ProjectUtils.isGradleProject(project)) { projectType = "Gradle"; } IContainer projectRoot = project; if (!ProjectUtils.isVisibleProject(project)) { projectType = "Workspace"; IFolder workspaceLinkFolder = project.getFolder(ProjectUtils.WORKSPACE_LINK); if (!workspaceLinkFolder.isLinked()) { continue; } projectRoot = workspaceLinkFolder; } IPath relativePath = entryPath.makeRelativeTo(projectRoot.getFullPath()); IPath location = projectRoot.getRawLocation().append(relativePath); IPath displayPath = getWorkspacePath(location); sourcePathList.add(new SourcePath(location != null ? location.toOSString() : "", displayPath != null ? displayPath.toOSString() : entryPath.toOSString(), entryPath.toOSString(), projectName, projectType)); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Failed to resolve the existing source paths in current workspace.", e); return new ListCommandResult(false, e.getMessage()); } } } return new ListCommandResult(true, null, sourcePathList.toArray(new SourcePath[0])); }