List of usage examples for org.eclipse.jdt.core IJavaElement exists
boolean exists();
From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java
License:Open Source License
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldDeclaration) *//*from w ww . j a v a 2 s . c o m*/ @Override public boolean visit(VariableDeclarationFragment node) { final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.FIELD); if (ancestor != null && ancestor.exists() && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) { // keep searching return true; } // wrong path, stop searching from this branch of the AST return false; }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java
License:Open Source License
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation) *///from w w w. j av a 2s . c o m @Override public boolean visit(MethodDeclaration node) { final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.METHOD); if (ancestor != null && ancestor.exists() && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) { // keep searching return true; } // wrong path, stop searching from this branch of the AST return false; }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java
License:Open Source License
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.NormalAnnotation) *//* www . j av a 2 s .c o m*/ @Override public boolean visit(NormalAnnotation node) { final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.ANNOTATION); if (ancestor != null && ancestor.exists() && ancestor.getElementName().equals(node.getTypeName().getFullyQualifiedName())) { // keep searching return true; } // wrong path, stop searching from this branch of the AST return false; }
From source file:org.jboss.tools.ws.jaxws.ui.utils.JBossWSUIUtils.java
License:Open Source License
public static IStatus validatePackageName(String name, IJavaElement context) { IStatus status = null;// w w w .j av a 2s . c om if (context == null || !context.exists()) { status = JavaConventions.validatePackageName(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); if (status != null && !status.isOK()) { return status; } } String[] sourceComplianceLevels = getSourceComplianceLevels(context); status = JavaConventions.validatePackageName(name, sourceComplianceLevels[0], sourceComplianceLevels[1]); if (status != null && status.getSeverity() == IStatus.ERROR) { return status; } IPackageFragmentRoot[] roots = null; try { IResource[] srcFolders = JBossWSCreationUtils.getJavaSourceRoots(context.getJavaProject()); roots = new IPackageFragmentRoot[srcFolders.length]; int i = 0; for (IResource src : srcFolders) { roots[i] = context.getJavaProject().getPackageFragmentRoot(src); i++; } } catch (JavaModelException e) { JBossWSUIPlugin.log(e); } for (IPackageFragmentRoot root : roots) { if (root != null) { IPackageFragment pack = root.getPackageFragment(name); try { IPath rootPath = root.getPath(); IPath outputPath = root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow // to name a package // like the bin folder IPath packagePath = pack.getPath(); if (outputPath.isPrefixOf(packagePath)) { status = StatusUtils.warningStatus( JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_IsOutputFolder); return status; } } if (pack.exists()) { if (pack.containsJavaResources() || !pack.hasSubpackages()) { status = StatusUtils .warningStatus(JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_PackageExists); } else { status = StatusUtils.warningStatus( JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_PackageNotShown); } return status; } else { if (pack.getResource() == null) { continue; } URI location = pack.getResource().getLocationURI(); if (location != null) { IFileStore store = EFS.getStore(location); if (store.fetchInfo().exists()) { status = StatusUtils.warningStatus( JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_PackageExistsDifferentCase); return status; } } } } catch (CoreException e) { JBossWSUIPlugin.log(e); } } } return status; }
From source file:org.jboss.tools.ws.ui.utils.JBossWSUIUtils.java
License:Open Source License
public static IStatus validatePackageName(String name, IJavaElement context) { IStatus status = null;//from w w w . j a va 2 s . c om if (context == null || !context.exists()) { status = JavaConventions.validatePackageName(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); if (status != null && !status.isOK()) { return status; } } String[] sourceComplianceLevels = getSourceComplianceLevels(context); status = JavaConventions.validatePackageName(name, sourceComplianceLevels[0], sourceComplianceLevels[1]); if (status != null && status.getSeverity() == IStatus.ERROR) { return status; } IPackageFragmentRoot[] roots = null; try { IResource[] srcFolders = JBossWSCreationUtils.getJavaSourceRoots(context.getJavaProject()); roots = new IPackageFragmentRoot[srcFolders.length]; int i = 0; for (IResource src : srcFolders) { roots[i] = context.getJavaProject().getPackageFragmentRoot(src); i++; } } catch (JavaModelException e) { JBossWSUIPlugin.log(e); } for (IPackageFragmentRoot root : roots) { if (root != null) { IPackageFragment pack = root.getPackageFragment(name); try { IPath rootPath = root.getPath(); IPath outputPath = root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow // to name a package // like the bin folder IPath packagePath = pack.getPath(); if (outputPath.isPrefixOf(packagePath)) { status = StatusUtils .warningStatus(JBossWSUIMessages.Error_JBossWS_GenerateWizard_IsOutputFolder); return status; } } if (pack.exists()) { if (pack.containsJavaResources() || !pack.hasSubpackages()) { status = StatusUtils .warningStatus(JBossWSUIMessages.Error_JBossWS_GenerateWizard_PackageExists); } else { status = StatusUtils .warningStatus(JBossWSUIMessages.Error_JBossWS_GenerateWizard_PackageNotShown); } return status; } else { if (pack.getResource() == null) { continue; } URI location = pack.getResource().getLocationURI(); if (location != null) { IFileStore store = EFS.getStore(location); if (store.fetchInfo().exists()) { status = StatusUtils.warningStatus( JBossWSUIMessages.Error_JBossWS_GenerateWizard_PackageExistsDifferentCase); return status; } } } } catch (CoreException e) { JBossWSUIPlugin.log(e); } } } return status; }
From source file:org.mule.munit.plugin.MunitLaunchConfigurationDelegate.java
License:Open Source License
private final IJavaElement getTestTarget(ILaunchConfiguration configuration, IJavaProject javaProject) throws CoreException { String containerHandle = configuration.getAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, ""); //$NON-NLS-1$ if (containerHandle.length() != 0) { IJavaElement element = JavaCore.create(containerHandle); if (element == null || !element.exists()) { abort(JUnitMessages.JUnitLaunchConfigurationDelegate_error_input_element_deosn_not_exist, null, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_MAIN_TYPE); }/*from w ww .j a va 2 s . c o m*/ return element; } String testTypeName = getMainTypeName(configuration); if (testTypeName != null && testTypeName.length() != 0) { IType type = javaProject.findType(testTypeName); if (type != null && type.exists()) { return type; } } abort(JUnitMessages.JUnitLaunchConfigurationDelegate_input_type_does_not_exist, null, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_MAIN_TYPE); return null; // not reachable }
From source file:org.nuxeo.ide.sdk.features.FeatureCreationWizard.java
License:Open Source License
/** * Utility method to inspect a selection to find a Java element. * /*ww w. j av a 2 s . co m*/ * @param selection the selection to be inspected * @return a Java element to be used as the initial selection, or * <code>null</code>, if no Java element exists in the given * selection */ protected IJavaElement getInitialJavaElement(IStructuredSelection sslct) { IJavaElement jelem = null; if (sslct != null && !sslct.isEmpty()) { Object selem = sslct.getFirstElement(); if (selem instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) selem; jelem = (IJavaElement) adaptable.getAdapter(IJavaElement.class); if (jelem == null || !jelem.exists()) { jelem = null; IResource resource = (IResource) adaptable.getAdapter(IResource.class); if (resource != null && resource.getType() != IResource.ROOT) { while (jelem == null && resource.getType() != IResource.PROJECT) { resource = resource.getParent(); jelem = (IJavaElement) resource.getAdapter(IJavaElement.class); } if (jelem == null) { jelem = asJavaProject(resource); // java project } } } } } if (jelem == null) { jelem = findOpenedElement(); } if (jelem == null || jelem.getElementType() == IJavaElement.JAVA_MODEL) { jelem = findDefaultElement(); } return jelem; }
From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java
License:Open Source License
protected Object internalGetParent(Object element) { // try to map resources to the containing package fragment if (element instanceof IResource) { IResource parent = ((IResource) element).getParent(); IJavaElement jParent = JavaCore.create(parent); // http://bugs.eclipse.org/bugs/show_bug.cgi?id=31374 if (jParent != null && jParent.exists()) { return jParent; }/*from ww w.j a v a 2 s .com*/ return parent; } else if (element instanceof IJavaElement) { IJavaElement parent = ((IJavaElement) element).getParent(); // For package fragments that are contained in a project package // fragment we have to skip the package fragment root as the parent. if (element instanceof IPackageFragment) { return skipProjectPackageFragmentRoot((IPackageFragmentRoot) parent); } return parent; } return null; }
From source file:org.springframework.ide.eclipse.beans.ui.refactoring.actions.AbstractBeansRefactorAction.java
License:Open Source License
protected void processAction(ExecutionEvent event, IDocument document, ITextSelection textSelection) { if (textSelection instanceof IStructuredSelection) { Object obj = ((IStructuredSelection) textSelection).getFirstElement(); Element node = null;//from w w w.j a v a 2 s . com String attributeName = null; if (obj instanceof Attr) { Attr attribute = (Attr) obj; node = attribute.getOwnerElement(); attributeName = attribute.getName(); } else if (obj instanceof Element) { node = (Element) obj; attributeName = getSelectedAttributeName(textSelection); } if (node != null && attributeName != null) { // check if bean class is selected String className = BeansEditorUtils.getAttribute(node, "class"); String propertyName = BeansEditorUtils.getAttribute(node, "name"); IJavaElement je = null; if ("bean".equals(node.getLocalName()) && StringUtils.hasText(className) && "class".equals(attributeName)) { je = JdtUtils.getJavaType(BeansEditorUtils.getProject(document), className); } else if ("property".equals(node.getLocalName()) && StringUtils.hasText(propertyName) && "name".equals(attributeName)) { Node beanNode = node.getParentNode(); List<IType> types = BeansEditorUtils.getClassNamesOfBean(getConfigFile(event), beanNode); if (types != null && types.size() > 0) { je = types.get(0).getField(propertyName); if (je == null || !je.exists()) { List<String> path = new ArrayList<String>(); path.add(propertyName); je = BeansEditorUtils.extractMethodFromPropertyPathElements(path, types, getConfigFile(event), 0); } } } try { if (je != null) { run(je); } } catch (CoreException e) { } } } }
From source file:org.summer.dsl.model.types.xtext.ui.JdtHoverDocumentationProvider.java
License:Open Source License
public String getDocumentation(EObject object) { if (object instanceof JvmIdentifiableElement) { IJavaElement element = javaElementFinder.findElementFor((JvmIdentifiableElement) object); if (element instanceof IMember && element.exists()) try { return JavadocContentAccess2.getHTMLContent((IMember) element, true); } catch (JavaModelException e) { log.error(e);// w w w . j a v a 2s .com } } return ""; }