/** * Returns the package fragment root of the stored type. * Package fragment root cannot be null and <strong>does</strong> exist. * * @see #getType() * @see IJavaElement#getAncestor(int) * * @throws NullPointerException if matched type is <code> null</code> * @return the existing java model package fragment root (i.e. cannot be <code>null</code> * and will return <code>true</code> to <code>exists()</code> message). */ public IPackageFragmentRoot getPackageFragmentRoot() { return (IPackageFragmentRoot) getType().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
/** * Returns the package fragment root of the stored type. * Package fragment root cannot be null and <strong>does</strong> exist. * * @see #getType() * @see IJavaElement#getAncestor(int) * * @throws NullPointerException if matched type is <code> null</code> * @return the existing java model package fragment root (i.e. cannot be <code>null</code> * and will return <code>true</code> to <code>exists()</code> message). */ public IPackageFragmentRoot getPackageFragmentRoot() { return (IPackageFragmentRoot) getType().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
/** * Returns the package fragment root of the stored type. * Package fragment root cannot be null and <strong>does</strong> exist. * * @see #getType() * @see IJavaElement#getAncestor(int) * * @throws NullPointerException if matched type is <code> null</code> * @return the existing java model package fragment root (i.e. cannot be <code>null</code> * and will return <code>true</code> to <code>exists()</code> message). */ public IPackageFragmentRoot getPackageFragmentRoot() { return (IPackageFragmentRoot) getType().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
/** * Returns the package fragment root of the stored type. * Package fragment root cannot be null and <strong>does</strong> exist. * * @see #getType() * @see IJavaElement#getAncestor(int) * * @throws NullPointerException if matched type is <code> null</code> * @return the existing java model package fragment root (i.e. cannot be <code>null</code> * and will return <code>true</code> to <code>exists()</code> message). */ public IPackageFragmentRoot getPackageFragmentRoot() { return (IPackageFragmentRoot) getType().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
/** * Returns the package fragment root of the stored type. * Package fragment root cannot be null and <strong>does</strong> exist. * * @see #getType() * @see IJavaElement#getAncestor(int) * * @throws NullPointerException if matched type is <code> null</code> * @return the existing java model package fragment root (i.e. cannot be <code>null</code> * and will return <code>true</code> to <code>exists()</code> message). */ public IPackageFragmentRoot getPackageFragmentRoot() { return (IPackageFragmentRoot) getType().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
/** * Returns the package fragment root of the stored type. * Package fragment root cannot be null and <strong>does</strong> exist. * * @see #getType() * @see IJavaElement#getAncestor(int) * * @throws NullPointerException if matched type is <code> null</code> * @return the existing java model package fragment root (i.e. cannot be <code>null</code> * and will return <code>true</code> to <code>exists()</code> message). */ public IPackageFragmentRoot getPackageFragmentRoot() { return (IPackageFragmentRoot) getType().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
/** * Return the count of implementation for the given java element type. * * @param type the java element type. * @param monitor the monitor * @return the count of implementation for the given java element type. * @throws JavaModelException throws when Java error */ private static long countImplementations(IType type, IProgressMonitor monitor) throws JavaModelException { IType[] results = type.newTypeHierarchy(monitor).getAllSubtypes(type); return Stream.of(results).filter(t -> t.getAncestor(IJavaElement.COMPILATION_UNIT) != null).count(); }
/** * Return the count of implementation for the given java element type. * * @param type the java element type. * @param monitor the monitor * @return the count of implementation for the given java element type. * @throws JavaModelException throws when Java error */ private static long countImplementations(IType type, IProgressMonitor monitor) throws JavaModelException { IType[] results= type.newTypeHierarchy(monitor).getAllSubtypes(type); return Stream.of(results).filter(t -> t.getAncestor(IJavaElement.COMPILATION_UNIT) != null).count(); }
private AccessRestriction getViolatedRestriction(String typeName, String packageName, IType type, AccessRestriction accessRestriction) { PackageFragmentRoot root = (PackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); ClasspathEntry entry = (ClasspathEntry) this.rootToResolvedEntries.get(root); if (entry != null) { // reverse map always contains resolved CP entry AccessRuleSet accessRuleSet = entry.getAccessRuleSet(); if (accessRuleSet != null) { // TODO (philippe) improve char[] <-> String conversions to avoid performing them on the fly char[][] packageChars = CharOperation.splitOn('.', packageName.toCharArray()); char[] typeChars = typeName.toCharArray(); accessRestriction = accessRuleSet.getViolatedRestriction(CharOperation.concatWith(packageChars, typeChars, '/')); } } return accessRestriction; }
private AccessRestriction getViolatedRestriction(String typeName, String packageName, IType type, AccessRestriction accessRestriction) { PackageFragmentRoot root = (PackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); ClasspathEntry entry = (ClasspathEntry) this.rootToResolvedEntries.get(root); if (entry != null) { // reverse map always contains resolved CP entry AccessRuleSet accessRuleSet = entry.getAccessRuleSet(); if (accessRuleSet != null) { // TODO (philippe) improve char[] <-> String conversions to avoid performing them on the fly char[][] packageChars = CharOperation.splitOn('.', packageName.toCharArray()); char[] typeChars = typeName.toCharArray(); accessRestriction = accessRuleSet.getViolatedRestriction(CharOperation.concatWith(packageChars, typeChars, '/')); } } return accessRestriction; }
private AccessRestriction getViolatedRestriction(String typeName, String packageName, IType type, AccessRestriction accessRestriction) { PackageFragmentRoot root = (PackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); ClasspathEntry entry = (ClasspathEntry) this.rootToResolvedEntries.get(root); if (entry != null) { // reverse map always contains resolved CP entry AccessRuleSet accessRuleSet = entry.getAccessRuleSet(); if (accessRuleSet != null) { // TODO (philippe) improve char[] <-> String conversions to avoid performing them on the fly char[][] packageChars = CharOperation.splitOn('.', packageName.toCharArray()); char[] typeChars = typeName.toCharArray(); accessRestriction = accessRuleSet.getViolatedRestriction(CharOperation.concatWith(packageChars, typeChars, '/')); } } return accessRestriction; }
@Override protected boolean initialize(Object element) { if (element instanceof IType) { IType type = (IType) element; IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); IProject project = javaProject.getProject(); if (WorkspaceModelManager.isPluginProject(project)) { fProject = javaProject.getProject(); fElements = new HashMap<>(); fElements.put(type, getArguments().getNewName()); return true; } } return false; }
@Override protected boolean initialize(Object element) { if (element instanceof IType) { IType type = (IType) element; IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); IProject project = javaProject.getProject(); if (WorkspaceModelManager.isPluginProject(project)) { fProject = javaProject.getProject(); fElements = new HashMap<>(); fElements.put(element, getNewName(getArguments().getDestination(), element)); return true; } } return false; }
public static boolean hasJUnit4TestAnnotation(IJavaProject project) { try { if (project != null) { IType type= project.findType(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME); if (type != null) { // @Test annotation is not accessible if the JUnit classpath container is set to JUnit 3 // (although it may resolve to a JUnit 4 JAR) IPackageFragmentRoot root= (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IClasspathEntry cpEntry= root.getRawClasspathEntry(); return ! JUnitCore.JUNIT3_CONTAINER_PATH.equals(cpEntry.getPath()); } } } catch (JavaModelException e) { // not available } return false; }
public static boolean hasTestAnnotation(IJavaProject project) { try { if (project != null) { IType type= project.findType(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME); if (type != null) { // @Test annotation is not accessible if the JUnit classpath container is set to JUnit 3 // (although it may resolve to a JUnit 4 JAR) IPackageFragmentRoot root= (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IClasspathEntry cpEntry= root.getRawClasspathEntry(); return ! JUnitCore.JUNIT3_CONTAINER_PATH.equals(cpEntry.getPath()); } } } catch (JavaModelException e) { // not available } return false; }
protected boolean isDifferentScope(IType type) { if (fFilter != null && !fFilter.select(null, null, type)) { return true; } IJavaElement input= fHierarchy.getInputElement(); if (input == null || input.getElementType() == IJavaElement.TYPE) { return false; } IJavaElement parent= type.getAncestor(input.getElementType()); if (input.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { if (parent == null || parent.getElementName().equals(input.getElementName())) { return false; } } else if (input.equals(parent)) { return false; } return true; }
public static boolean hasJUnit5TestAnnotation(IJavaProject project) { try { if (project != null) { IType type= project.findType(JUnitCorePlugin.JUNIT5_TESTABLE_ANNOTATION_NAME); if (type != null) { // @Testable annotation is not accessible if the JUnit classpath container is set to JUnit 3 or JUnit 4 // (although it may resolve to a JUnit 5 JAR) IPackageFragmentRoot root= (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IClasspathEntry cpEntry= root.getRawClasspathEntry(); return ! JUnitCore.JUNIT3_CONTAINER_PATH.equals(cpEntry.getPath()) && ! JUnitCore.JUNIT4_CONTAINER_PATH.equals(cpEntry.getPath()); } } } catch (JavaModelException e) { // not available } return false; }
@Override protected List<ITranslationResource> loadTranslationResources() throws CoreException { if (getNlsType().getType().isReadOnly()) { IPackageFragmentRoot r = (IPackageFragmentRoot) getNlsType().getType().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (r == null) { SdkLog.warning("Could not find text resource for type '{}'.", getNlsType().getType().getFullyQualifiedName()); return Collections.emptyList(); } return loadTranslationFilesFromPlatform(getNlsType(), r); } return loadTranslationFilesWorkspace(getNlsType()); }
private RefactoringStatus checkPackageClass() { RefactoringStatus status= new RefactoringStatus(); IType type= fDescriptor.getType(); IPackageFragmentRoot ancestor= (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPackageFragment packageFragment= ancestor.getPackageFragment(fDescriptor.getPackage()); if (packageFragment.getCompilationUnit(fDescriptor.getClassName() + JavaModelUtil.DEFAULT_CU_SUFFIX).exists()) status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_toplevel_name_clash, new Object[] { BasicElementLabels.getJavaElementName(fDescriptor.getClassName()), BasicElementLabels.getJavaElementName(fDescriptor.getPackage()) })); return status; }
private RefactoringStatus checkPackageClass() { RefactoringStatus status= new RefactoringStatus(); IType type= fDescriptor.getType(); IPackageFragmentRoot ancestor= (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPackageFragment packageFragment= ancestor.getPackageFragment(fDescriptor.getPackage()); if (packageFragment.getCompilationUnit(fDescriptor.getClassName() + JavaModelUtil.DEFAULT_CU_SUFFIX).exists()) status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_toplevel_name_clash, new Object[] { BasicElementLabels.getJavaElementName(fDescriptor.getClassName()), BasicElementLabels.getJavaElementName(fDescriptor.getPackage()) })); return status; }