aspect ChangeAccessibility { // the Change Accessibility refactoring changes the accessibility of a given declaration (represented as a Visible) // to a new accessibility and adjusts accessibilities of other elements as necessary public void Visible.changeAccessibility(int v) { // TODO: array decls are fromSource(); maybe that should be changed in general? if(!fromSource()) throw new RefactoringException("cannot change accessibility of non-source type"); if(isAnonymousType()) throw new RefactoringException("cannot change accessibility of anonymous type"); Collection constraints = programRoot().accessibilityConstraints(); constraints.add(new AccessibilityConstraint(this, this, Operator.EQ, v)); Map acc_map = programRoot().solve(constraints); if(acc_map == null) { throw new RefactoringException("no solution found"); } else { for(Map.Entry e : acc_map.entrySet()) { Visible vis = e.getKey(); // TODO: hide this behind an interface if(vis instanceof FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration)vis; programRoot().lockNames(fd.name()); } else if(vis instanceof MethodDecl) { MethodDecl md = (MethodDecl)vis; programRoot().lockMethodNames(md.name()); } else if(vis instanceof TypeDecl) { TypeDecl td = (TypeDecl)vis; programRoot().lockNames(td.name()); } vis.setVisibility(e.getValue()); } programRoot().eliminate(LOCKED_NAMES); } } public boolean Visible.isAnonymousType(); public boolean ConstructorDecl.isAnonymousType(){return false;} public boolean FieldDeclaration.isAnonymousType(){return false;} public boolean MethodDecl.isAnonymousType(){return false;} public boolean TypeDecl.isAnonymousType(){return isAnonymous();} }