/** * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName() */ @Override public char[] getFileName() { return this.typeHandle.getCompilationUnit().getElementName().toCharArray(); }
private CompilationUnitRewrite getCompilationUnitRewrite(final ICompilationUnit unit) { Assert.isNotNull(unit); if (unit.equals(fType.getCompilationUnit())) return fSourceRewrite; return new CompilationUnitRewrite(unit); }
private ICompilationUnit[] getAffectedCompilationUnits(final IProgressMonitor monitor) throws JavaModelException { final IType[] allSubtypes= getDestinationTypeHierarchy(monitor).getAllSubtypes(getDestinationType()); final Set<ICompilationUnit> result= new HashSet<>(allSubtypes.length); for (int i= 0; i < allSubtypes.length; i++) { ICompilationUnit cu= allSubtypes[i].getCompilationUnit(); if (cu != null) result.add(cu); } result.add(getDestinationType().getCompilationUnit()); return result.toArray(new ICompilationUnit[result.size()]); }
private void addTypes(IType[] allSubtypes, HashSet<ICompilationUnit> cus, List<IType> types) throws JavaModelException { for (int i = 0; i < allSubtypes.length; i++) { IType type = allSubtypes[i]; IField field = type.getField(NAME_FIELD); if (!field.exists()) { if (type.isClass() && cus.contains(type.getCompilationUnit())) { types.add(type); } } } }
private void addTypes(IType[] allSubtypes, HashSet<ICompilationUnit> cus, List<IType> types) throws JavaModelException { for (int i= 0; i < allSubtypes.length; i++) { IType type= allSubtypes[i]; IField field= type.getField(NAME_FIELD); if (!field.exists()) { if (type.isClass() && cus.contains(type.getCompilationUnit())){ types.add(type); } } } }
private static boolean isPrimaryType(IType type) { String cuName = type.getCompilationUnit().getElementName(); String typeName = type.getElementName(); return type.getDeclaringType() == null && JavaCore.removeJavaLikeExtension(cuName).equals(typeName); }
private IType[] getAbstractDestinations(IProgressMonitor monitor) throws JavaModelException { IType[] allDirectSubclasses= getHierarchyOfDeclaringClass(monitor).getSubclasses(getDeclaringType()); List<IType> result= new ArrayList<>(allDirectSubclasses.length); for (int index= 0; index < allDirectSubclasses.length; index++) { IType subclass= allDirectSubclasses[index]; if (subclass.exists() && !subclass.isBinary() && !subclass.isReadOnly() && subclass.getCompilationUnit() != null && subclass.isStructureKnown()) result.add(subclass); } return result.toArray(new IType[result.size()]); }
private boolean isPrimaryType() { String cuName= fType.getCompilationUnit().getElementName(); String typeName= fType.getElementName(); return Checks.isTopLevel(fType) && JavaCore.removeJavaLikeExtension(cuName).equals(typeName); }
private static ICompilationUnit getNewCompilationUnit(IType type, String newName) { ICompilationUnit cu = type.getCompilationUnit(); if (isPrimaryType(type)) { IPackageFragment parent = type.getPackageFragment(); String renamedCUName = JavaModelUtil.getRenamedCUName(cu, newName); return parent.getCompilationUnit(renamedCUName); } else { return cu; } }
@Override public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) { ISourceType sourceType = sourceTypes[0]; while (sourceType.getEnclosingType() != null) sourceType = sourceType.getEnclosingType(); SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType; IType type = elementInfo.getHandle(); ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit(); accept(sourceUnit, accessRestriction); }
private ICompilationUnit getNewCompilationUnit() { ICompilationUnit cu= fType.getCompilationUnit(); if (isPrimaryType()) { IPackageFragment parent= fType.getPackageFragment(); String renamedCUName= JavaModelUtil.getRenamedCUName(cu, getNewElementName()); return parent.getCompilationUnit(renamedCUName); } else { return cu; } }
private RefactoringStatus checkTypesImportedInCu() throws CoreException { IImportDeclaration imp = getImportedType(fType.getCompilationUnit(), getNewElementName()); if (imp == null) { return null; } String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_imported, new Object[] { getNewElementLabel(), BasicElementLabels.getPathLabel(fType.getCompilationUnit().getResource().getFullPath(), false) }); IJavaElement grandParent = imp.getParent().getParent(); if (grandParent instanceof ICompilationUnit) { return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(imp)); } return null; }
void initialize(IType type) throws JavaModelException { RefactoringASTParser parser= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL); fUnit= parser.parse(type.getCompilationUnit(), true); fTypeBinding= null; // type cannot be anonymous final AbstractTypeDeclaration declaration= ASTNodes.getParent(NodeFinder.perform(fUnit, type.getNameRange()), AbstractTypeDeclaration.class); if (declaration != null) fTypeBinding= declaration.resolveBinding(); }
private BodyDeclaration createNewTypeDeclarationNode(final IType type, final AbstractTypeDeclaration oldType, final CompilationUnit declaringCuNode, final TypeVariableMaplet[] mapping, final ASTRewrite rewrite) throws JavaModelException { final ICompilationUnit declaringCu= getDeclaringType().getCompilationUnit(); if (!JdtFlags.isPublic(type) && !JdtFlags.isProtected(type)) { if (mapping.length > 0) return createPlaceholderForTypeDeclaration(oldType, declaringCu, mapping, rewrite, true); return createPlaceholderForProtectedTypeDeclaration(oldType, declaringCuNode, declaringCu, rewrite, true); } if (mapping.length > 0) return createPlaceholderForTypeDeclaration(oldType, declaringCu, mapping, rewrite, true); return createPlaceholderForTypeDeclaration(oldType, declaringCu, rewrite, true); }
private RefactoringStatus checkNewPathValidity() { IContainer c= fType.getCompilationUnit().getResource().getParent(); String notRename= RefactoringCoreMessages.RenameTypeRefactoring_will_not_rename; IStatus status= c.getWorkspace().validateName(getNewElementName(), IResource.FILE); if (status.getSeverity() == IStatus.ERROR) return RefactoringStatus.createWarningStatus(status.getMessage() + ". " + notRename); //$NON-NLS-1$ status= c.getWorkspace().validatePath(createNewPath(getNewElementName()), IResource.FILE); if (status.getSeverity() == IStatus.ERROR) return RefactoringStatus.createWarningStatus(status.getMessage() + ". " + notRename); //$NON-NLS-1$ return new RefactoringStatus(); }
private boolean canEnable(IStructuredSelection selection) throws JavaModelException { if (getSelectedFields(selection) != null) return true; if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { IType type= (IType) selection.getFirstElement(); return type.getCompilationUnit() != null && !type.isInterface() && !type.isAnonymous(); } if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit)) return true; return false; }
private boolean canEnable(IStructuredSelection selection) throws JavaModelException { if (getSelectedFields(selection) != null) return true; if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { IType type= (IType) selection.getFirstElement(); return type.getCompilationUnit() != null && !type.isInterface() && !type.isAnonymous(); } if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit)) return true; return false; }
private void initialize() throws JavaModelException { fQualifiedTypeName= JavaModelUtil.concatenateName(fType.getPackageFragment().getElementName(), fType.getElementName()); fEnclosingInstanceFieldName= getInitialNameForEnclosingInstanceField(); fSourceRewrite= new CompilationUnitRewrite(fType.getCompilationUnit()); fIsInstanceFieldCreationPossible= !(JdtFlags.isStatic(fType) || fType.isAnnotation() || fType.isEnum()); fIsInstanceFieldCreationMandatory= fIsInstanceFieldCreationPossible && isInstanceFieldCreationMandatory(); fCreateInstanceField= fIsInstanceFieldCreationMandatory; }
@Override protected RenameModifications computeRenameModifications() { RenameModifications result = new RenameModifications(); result.rename(fType, new RenameTypeArguments(getNewElementName(), getUpdateReferences(), getUpdateSimilarDeclarations(), getSimilarElements()), createParticipantDescriptorFilter()); if (isPrimaryType()) { ICompilationUnit cu = fType.getCompilationUnit(); String newCUName = getNewCompilationUnit().getElementName(); result.rename(cu, new RenameArguments(newCUName, getUpdateReferences())); } return result; }
@Override protected RenameModifications computeRenameModifications() { RenameModifications result= new RenameModifications(); result.rename(fType, new RenameTypeArguments(getNewElementName(), getUpdateReferences(), getUpdateSimilarDeclarations(), getSimilarElements()), createParticipantDescriptorFilter()); if (isPrimaryType()) { ICompilationUnit cu= fType.getCompilationUnit(); String newCUName= getNewCompilationUnit().getElementName(); result.rename(cu, new RenameArguments(newCUName, getUpdateReferences())); } return result; }