List of usage examples for org.eclipse.jdt.core IJavaElement getElementName
String getElementName();
From source file:com.liferay.ide.service.ui.editor.ServiceMethodHyperlinkDetector.java
License:Open Source License
private IMethodWrapper getServiceWrapperMethod(final IMethod method) { IMethodWrapper retval = null;/*from w ww .j av a 2s . co m*/ try { final IJavaElement methodClass = method.getParent(); final IType methodClassType = method.getDeclaringType(); final String methodClassName = methodClass.getElementName(); if (methodClassName.endsWith("Util") && JdtFlags.isPublic(method) && JdtFlags.isStatic(method)) { final String packageName = methodClassType.getPackageFragment().getElementName(); final String baseServiceName = methodClassName.substring(0, methodClassName.length() - 4); // as per liferay standard wrapper type will be in service package with Wrapper suffix // e.g. com.example.service.FooUtil.getBar() --> com.example.service.FooWrapper.getBar() final String fullyQualifiedName = packageName + "." + baseServiceName + "Wrapper"; final IType wrapperType = findType(methodClass, fullyQualifiedName); if (wrapperType != null) { IMethod[] wrapperBaseMethods = wrapperType.findMethods(method); if (!CoreUtil.isNullOrEmpty(wrapperBaseMethods)) { // look for classes that implement this wrapper final List<IMethod> overrides = new ArrayList<IMethod>(); final SearchRequestor requestor = new WrapperMethodCollector(overrides, method); final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, wrapperType, true, false, null); final SearchPattern search = SearchPattern.createPattern(method.getElementName(), IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); new SearchEngine().search(search, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); if (overrides.size() > 1) { retval = new IMethodWrapper(wrapperBaseMethods[0], true); } else if (overrides.size() == 1) { retval = new IMethodWrapper(overrides.get(0), false); } } } } } catch (Exception e) { } return retval; }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
/** * Appends the label for a Java element with the flags as defined by this class. * * @param element the element to render/*from w w w . j a v a 2s.co m*/ * @param flags the rendering flags. */ public void appendElementLabel(IJavaElement element, long flags) { int type = element.getElementType(); IPackageFragmentRoot root = null; if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && getFlag(flags, PREPEND_ROOT_PATH)) { appendPackageFragmentRootLabel(root, ROOT_QUALIFIED); fBuffer.append(CONCAT_STRING); } switch (type) { case IJavaElement.METHOD: appendMethodLabel((IMethod) element, flags); break; case IJavaElement.FIELD: appendFieldLabel((IField) element, flags); break; case IJavaElement.LOCAL_VARIABLE: appendLocalVariableLabel((ILocalVariable) element, flags); break; case IJavaElement.TYPE_PARAMETER: appendTypeParameterLabel((ITypeParameter) element, flags); break; case IJavaElement.INITIALIZER: appendInitializerLabel((IInitializer) element, flags); break; case IJavaElement.TYPE: appendTypeLabel((IType) element, flags); break; case IJavaElement.CLASS_FILE: appendClassFileLabel((IClassFile) element, flags); break; case IJavaElement.COMPILATION_UNIT: appendCompilationUnitLabel((ICompilationUnit) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT: appendPackageFragmentLabel((IPackageFragment) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags); break; case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.PACKAGE_DECLARATION: appendDeclarationLabel(element, flags); break; case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: fBuffer.append(element.getElementName()); break; default: fBuffer.append(element.getElementName()); } if (root != null && getFlag(flags, APPEND_ROOT_PATH)) { int offset = fBuffer.length(); fBuffer.append(CONCAT_STRING); appendPackageFragmentRootLabel(root, ROOT_QUALIFIED); } }
From source file:com.motorola.studio.android.wizards.buildingblocks.NewBuildingBlocksWizardPage.java
License:Apache License
/** * Checks for cross package/class collision among source folders * //w w w . ja v a 2s .c om * @return true if there is any collision or false otherwise */ private boolean packageAndClassExist() { boolean exists = false; try { if ((getJavaProject() != null) && getJavaProject().isOpen()) { IPackageFragmentRoot[] roots = getJavaProject().getPackageFragmentRoots(); if (roots != null) { for (IPackageFragmentRoot root : roots) { if ((root.getKind() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE) { IPackageFragment pack = root.getPackageFragment(getPackageText()); if ((pack != null) && pack.exists()) { IJavaElement classes[] = pack.getChildren(); if (classes != null) { for (IJavaElement clazz : classes) { if (clazz.getElementName().equals(getTypeName() + JAVA_EXTENSION)) { exists = true; break; } } } } } if (exists) { break; } } } } } catch (JavaModelException e) { // Do nothing StudioLogger.error(NewBuildingBlocksWizardPage.class, e.getLocalizedMessage(), e); } return exists; }
From source file:com.redhat.ceylon.eclipse.core.model.JDTModule.java
License:Open Source License
private void listPackages(Set<String> packageList, IParent parent) { try {//w w w. java 2s. c om for (IJavaElement child : parent.getChildren()) { if (child instanceof PackageFragment) { packageList.add(child.getElementName()); listPackages(packageList, (IPackageFragment) child); } } } catch (JavaModelException e) { e.printStackTrace(); } }
From source file:com.siteview.mde.internal.ui.refactoring.PluginManifestChange.java
License:Open Source License
private static TextEdit createTextEdit(IDocumentAttributeNode attr, IJavaElement element, String newName) { if (attr == null) return null; String oldName = (element instanceof IType) ? ((IType) element).getFullyQualifiedName('$') : element.getElementName(); String value = attr.getAttributeValue(); if (oldName.equals(value) || isGoodMatch(value, oldName, element instanceof IPackageFragment)) { int offset = attr.getValueOffset(); if (offset >= 0) return new ReplaceEdit(offset, oldName.length(), newName); }/*from w ww. j a v a2 s .c om*/ return null; }
From source file:com.siteview.mde.internal.ui.search.ClassSearchParticipant.java
License:Open Source License
public void search(ISearchRequestor requestor, QuerySpecification querySpecification, IProgressMonitor monitor) throws CoreException { if (querySpecification.getLimitTo() != S_LIMIT_REF && querySpecification.getLimitTo() != S_LIMIT_ALL) return;/*w w w . ja v a 2 s .c om*/ String search; if (querySpecification instanceof ElementQuerySpecification) { IJavaElement element = ((ElementQuerySpecification) querySpecification).getElement(); if (element instanceof IType) search = ((IType) element).getFullyQualifiedName('.'); else search = element.getElementName(); int type = element.getElementType(); if (type == IJavaElement.TYPE) fSearchFor = S_FOR_TYPES; else if (type == IJavaElement.PACKAGE_FRAGMENT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT) fSearchFor = S_FOR_PACKAGES; } else { fSearchFor = ((PatternQuerySpecification) querySpecification).getSearchFor(); search = ((PatternQuerySpecification) querySpecification).getPattern(); } if (fSearchFor != S_FOR_TYPES && fSearchFor != S_FOR_PACKAGES) return; fSearchPattern = PatternConstructor.createPattern(search, true); fSearchRequestor = requestor; IPath[] enclosingPaths = querySpecification.getScope().enclosingProjectsAndJars(); IMonitorModelBase[] pluginModels = MonitorRegistry.getWorkspaceModels(); monitor.beginTask(MDEUIMessages.ClassSearchParticipant_taskMessage, pluginModels.length); for (int i = 0; i < pluginModels.length; i++) { IProject project = pluginModels[i].getUnderlyingResource().getProject(); if (!monitor.isCanceled() && encloses(enclosingPaths, project.getFullPath())) searchProject(project, monitor); } }
From source file:costabs.utils.SourceUtils.java
License:Open Source License
private static void fileEvaluations(IJavaElement javaFile) throws CostabsException { try {/*w w w . ja va2s . c o m*/ if (javaFile.getElementType() != IJavaElement.COMPILATION_UNIT) { throw new CostabsException("The file must be a Java file"); } ICompilationUnit javaFileComp = (ICompilationUnit) javaFile; if (!javaFile.isStructureKnown()) { throw new CostabsException("The file cannot have errors to analyze it"); } if (!javaFile.getElementName().endsWith(".java")) { throw new CostabsException("The file is not a Java File"); } if (!javaFileComp.isConsistent()) { throw new CostabsException("The file is not consistent, cannot proccess it"); } } catch (JavaModelException e) { throw new CostabsException("Cannot evaluate the file, it may be incorrect"); } }
From source file:de.jevopi.j2og.ui.CreateOmniGraffleDiagramAction.java
License:Open Source License
/** * @param i_packageFragment/*w ww .ja v a 2 s. c om*/ * @param i_allPackageFragments * @throws JavaModelException * @since Oct 31, 2011 */ private void collectSubPackages(IPackageFragment packageFragment, HashSet<IPackageFragment> o_allPackageFragments) throws JavaModelException { IJavaElement[] packages = ((IPackageFragmentRoot) (packageFragment.getParent())).getChildren(); String n = packageFragment.getElementName(); for (IJavaElement sub : packages) { if (sub != packageFragment && sub instanceof IPackageFragment && sub.getElementName().startsWith(n)) { o_allPackageFragments.add((IPackageFragment) sub); collectSubPackages((IPackageFragment) sub, o_allPackageFragments); } } }
From source file:de.lmu.ifi.dbs.knowing.debug.ui.wizard.pages.CreateProcessorPage.java
License:Apache License
private void handlePackageBrowse() { Object obj = selection.getFirstElement(); IResource res = (IResource) Platform.getAdapterManager().getAdapter(obj, IResource.class); IProject project = res.getProject(); try {//from w w w . j ava 2 s.c o m SelectionDialog dialog = JavaUI.createPackageDialog(getShell(), JavaCore.create(project), IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS); if (dialog.open() != Window.OK) return; Object[] result = dialog.getResult(); for (Object r : result) { IJavaElement e = (IJavaElement) r; classPackage = (IPackageFragment) e; tPackage.setText(e.getElementName()); } } catch (JavaModelException e) { e.printStackTrace(); } validate(); }
From source file:de.loskutov.bco.ui.EclipseUtils.java
License:Open Source License
/** * @param resource// www. ja v a 2 s .co m * @return full package name in default java notation (with dots) */ public static String getJavaPackageName(IJavaElement resource) { String name; if (resource == null) { return ""; } name = resource.getElementName(); if (name == null) { return ""; } int type = resource.getElementType(); if (type == IJavaElement.PACKAGE_FRAGMENT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT) { return name; } IJavaElement ancestor = resource.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (ancestor != null) { return ancestor.getElementName(); } return ""; //$NON-NLS-1$ }