### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.api.tools.ui Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools.ui/META-INF/MANIFEST.MF,v retrieving revision 1.16 diff -u -r1.16 MANIFEST.MF --- META-INF/MANIFEST.MF 23 Feb 2009 18:02:00 -0000 1.16 +++ META-INF/MANIFEST.MF 13 Apr 2009 16:36:38 -0000 @@ -32,5 +32,6 @@ org.eclipse.pde.api.tools.ui.internal.markers;x-friends:="org.eclipse.pde.api.tools.tests", org.eclipse.pde.api.tools.ui.internal.preferences;x-friends:="org.eclipse.pde.api.tools.tests", org.eclipse.pde.api.tools.ui.internal.properties;x-friends:="org.eclipse.pde.api.tools.tests", + org.eclipse.pde.api.tools.ui.internal.refactoring;x-internal:=true, org.eclipse.pde.api.tools.ui.internal.wizards;x-friends:="org.eclipse.pde.api.tools.tests" Import-Package: com.ibm.icu.text;version="3.6.1" Index: plugin.properties =================================================================== RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools.ui/plugin.properties,v retrieving revision 1.16 diff -u -r1.16 plugin.properties --- plugin.properties 14 Oct 2008 15:34:02 -0000 1.16 +++ plugin.properties 13 Apr 2009 16:36:38 -0000 @@ -42,4 +42,7 @@ MarkerCategory.name = API Problems ApiToolsJavadocProposals.name = API Tools Javadoc Proposals MarkerGroupingEntryLabel=API Usage and Compatibility -ApiToolsProposalCategory.name = PDE API Tools Proposals \ No newline at end of file +ApiToolsProposalCategory.name = PDE API Tools Proposals +FilterDeleteParticipant.name = API Problem Filter Delete Participant +FilterRenameParticipant.name = API Problem Filter Rename Participant +FilterMoveParticipant.name = API Problem Filter Move Participant \ No newline at end of file Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools.ui/plugin.xml,v retrieving revision 1.20 diff -u -r1.20 plugin.xml --- plugin.xml 4 Dec 2008 17:18:18 -0000 1.20 +++ plugin.xml 13 Apr 2009 16:36:38 -0000 @@ -270,4 +270,145 @@ markerType="org.eclipse.pde.api.tools.unused_filters"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/TypeFilterChange.java =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/TypeFilterChange.java diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/TypeFilterChange.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/TypeFilterChange.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.api.tools.ui.internal.refactoring; + +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.pde.api.tools.internal.provisional.IApiFilterStore; +import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter; + +/** + * A change object for {@link org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter}s + * This change can handle adds / renames and removes. + * + * @since 1.0.1 + */ +public class TypeFilterChange extends FilterChange { + + String newname = null; + String newpath = null; + + /** + * Constructor + * @param store the store the filter is to be updated in + * @param filter the filter being changed + * @param primaryname the name of the primary type (the name of the resource) + * @param newname the new value to set in the filter + * @param newpath + * @param kind the kind of the change + */ + public TypeFilterChange(IApiFilterStore store, IApiProblemFilter filter, String newname, String newpath, int kind) { + super(store, filter, kind); + this.newname = newname; + this.newpath = newpath; + } + + /* (non-Javadoc) + * @see org.eclipse.pde.api.tools.ui.internal.refactoring.FilterChange#performAdd() + */ + protected Change performAdd() { + this.store.addFilters(new IApiProblemFilter[] {this.filter}); + return new TypeFilterChange(this.store, this.filter, null, null, DELETE); + } + + /* (non-Javadoc) + * @see org.eclipse.pde.api.tools.ui.internal.refactoring.FilterChange#performDelete() + */ + protected Change performDelete() { + if(this.store.removeFilters(new IApiProblemFilter[] {this.filter})) { + return new TypeFilterChange(this.store, this.filter, null, null, ADD); + } + return null; + } +} Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringUtils.java =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringUtils.java diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringUtils.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringUtils.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,250 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.api.tools.ui.internal.refactoring; + +import java.util.HashSet; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.CompositeChange; +import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; +import org.eclipse.pde.api.tools.internal.provisional.IApiFilterStore; +import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; +import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter; + +/** + * Helper class to create API tools refactoring changes + * + * @since 1.0.1 + */ +public class RefactoringUtils { + + /** + * Creates the {@link Change} for updating the filter store + * when a type is deleted + * + * @param type the type being deleted + * @return the change to the filter store + */ + static Change createDeleteFilterChanges(IType type) { + try { + IResource resource = type.getUnderlyingResource(); + if(resource != null) { + IApiFilterStore store = resolveFilterStore(resource.getProject()); + IApiProblemFilter[] filters = store.getFilters(resource); + if(filters.length != 0) { + CompositeChange cchange = new CompositeChange(RefactoringMessages.RefactoringUtils_remove_usused_filters); + for (int i = 0; i < filters.length; i++) { + cchange.add(new TypeFilterChange(store, filters[i], null, null, FilterChange.DELETE)); + } + return cchange; + } + } + } + catch(CoreException ce) {} + return null; + } + + /** + * Creates the {@link Change} for updating a filter store when a package fragment is deleted + * @param fragment the fragment that has been deleted + * @return the {@link Change} for the package fragment deletion + */ + static Change createDeleteFilterChanges(IPackageFragment fragment) { + try { + IResource resource = fragment.getUnderlyingResource(); + if(resource != null) { + IApiFilterStore store = resolveFilterStore(resource.getProject()); + IApiProblemFilter[] filters = collectAllAffectedFilters(store, collectAffectedTypes(fragment)); + if(filters.length != 0) { + CompositeChange cchange = new CompositeChange(RefactoringMessages.RefactoringUtils_remove_usused_filters); + for (int i = 0; i < filters.length; i++) { + cchange.add(new TypeFilterChange(store, filters[i], null, null, FilterChange.DELETE)); + } + return cchange; + } + } + } + catch(CoreException ce) {} + return null; + } + + /** + * Collects the complete set of {@link IApiProblemFilter}s for the given collection of {@link IType}s + * @param types + * @return the complete collection of {@link IApiProblemFilter}s or an empty list, never null + */ + static IApiProblemFilter[] collectAllAffectedFilters(IApiFilterStore store, IType[] types) { + HashSet filters = new HashSet(); + IApiProblemFilter[] fs = null; + IResource resource = null; + for (int i = 0; i < types.length; i++) { + try { + resource = types[i].getUnderlyingResource(); + if(resource == null) { + continue; + } + fs = store.getFilters(resource); + for (int j = 0; j < fs.length; j++) { + filters.add(fs[j]); + } + } + catch(JavaModelException jme) { + //do nothing + } + } + return (IApiProblemFilter[]) filters.toArray(new IApiProblemFilter[filters.size()]); + } + + /** + * Collects the complete list of {@link IType}s affected from within the {@link IPackageFragment} + * @param fragment + * @return the complete collection of affected {@link IType}s or an empty list, never null + */ + static IType[] collectAffectedTypes(IPackageFragment fragment) { + HashSet types = new HashSet(); + try { + if(fragment.containsJavaResources()) { + ICompilationUnit[] cunits = fragment.getCompilationUnits(); + IType type = null; + for (int i = 0; i < cunits.length; i++) { + type = cunits[i].findPrimaryType(); + if(type == null) { + continue; + } + types.add(type); + } + } + } + catch(JavaModelException jme) { + //do nothing + } + return (IType[]) types.toArray(new IType[types.size()]); + } + + /** + * Creates the {@link Change} for updating {@link IApiProblemFilter}s + * that are affected by the rename of a type + * + * @param type the type being renamed + * @param newname the new name to be set on the resource + * @return the rename type change for updating filters + */ + static Change createRenameFilterChanges(IType type, String newname) { + return createDeleteFilterChanges(type); + } + + /** + * Creates the {@link Change} for {@link IApiProblemFilter}s affected by + * a package fragment rename + * @param fragment + * @param newname + * @return the change for the package fragment rename + */ + static Change createRenameFilterChanges(IPackageFragment fragment, String newname) { + return createDeleteFilterChanges(fragment); + } + + /** + * Creates the {@link Change} for updating {@link IApiProblemFilter}s + * that are affected by moving a type + * @param type the type being moved + * @param destination where the resource is being moved to + * @return the move type change for updating filters + */ + static Change createMoveFilterChanges(IType type, String destination) { + return createDeleteFilterChanges(type); + } + + /** + * Creates the {@link Change} for {@link IApiProblemFilter}s affected by + * moving a package fragment + * @param fragment + * @param destination + * @return the change for moving a package fragment + */ + static Change createMoveFilterChanges(IPackageFragment fragment, String destination) { + return createDeleteFilterChanges(fragment); + } + + /** + * Gets the {@link IApiFilterStore} for the given {@link IProject} + * @param project + * @return the filter store for the given project or null + * @throws CoreException + */ + static IApiFilterStore resolveFilterStore(IProject project) throws CoreException { + IApiComponent component = ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline().getApiComponent(project.getName()); + if(component != null) { + return component.getFilterStore(); + } + return null; + } + + /** + * Returns the new fully qualified name for the filter + * @param type + * @param newname + * @return + */ + static String getNewQualifiedName(IType type, String newname) { + IType dtype = type.getDeclaringType(); + String newqname = newname; + if (dtype == null) { + IPackageFragment packageFragment = type.getPackageFragment(); + if (!packageFragment.isDefaultPackage()) { + newqname = packageFragment.getElementName() + '.' + newname; + } + } + else { + newqname = dtype.getFullyQualifiedName() + '$' + newname; + } + return newqname; + } + + /** + * Returns the new type name with the new package qualification + * @param newname + * @param oldtypename + * @return the new fully qualified type name + */ + static String getNewQualifiedName(String newname, String oldtypename) { + //TODO switch out the package resolution + return oldtypename; + } + + /** + * Returns a new path string given the type name. + * This method basically removes the last segment of the path, appends the new name + * and resets the extension + * @param oldpath + * @param typename + * @return the new resource path to use + */ + static String getNewResourcePath(IPath oldpath, String typename) { + if(typename.indexOf('$') < 0) { + String ext = oldpath.getFileExtension(); + IPath newpath = oldpath.removeLastSegments(1).append(typename); + if(ext != null) { + return newpath.addFileExtension(ext).toString(); + } + return newpath.toString(); + } + return oldpath.toString(); + } +} Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringMessages.java =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringMessages.java diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringMessages.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/RefactoringMessages.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.api.tools.ui.internal.refactoring; + +import org.eclipse.osgi.util.NLS; + +/** + * + */ +public class RefactoringMessages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.pde.api.tools.ui.internal.refactoring.refactoringmessages"; //$NON-NLS-1$ + public static String FilterChange_add_filter; + public static String FilterChange_remove_used_filter; + public static String FilterDeleteParticipant_remove_unused_filters_for_0; + public static String RefactoringUtils_remove_usused_filters; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, RefactoringMessages.class); + } + + private RefactoringMessages() { + } +} Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterChange.java =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterChange.java diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterChange.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterChange.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.api.tools.ui.internal.refactoring; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.api.tools.internal.provisional.IApiFilterStore; +import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; +import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter; + +/** + * Generic {@link Change} for {@link IApiProblemFilter}s + * + * @since 1.0.1 + */ +public abstract class FilterChange extends Change { + + static final int DELETE = 1; + static final int ADD = 2; + + IApiFilterStore store = null; + IApiProblemFilter filter = null; + int kind = 0; + + /** + * Constructor + */ + public FilterChange(IApiFilterStore store, IApiProblemFilter filter, int kind) { + this.store = store; + this.filter = filter; + this.kind = kind; + } + + /** + * Performs the delete operation and returns an undo change or null + * @return an undo change or null + */ + protected abstract Change performDelete(); + + /** + * Performs the add operation and returns an undo change or null + * @return an undo change or null + */ + protected abstract Change performAdd(); + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor) + */ + public Change perform(IProgressMonitor pm) throws CoreException { + switch(this.kind) { + case DELETE: { + return performDelete(); + } + case ADD: { + return performAdd(); + } + } + return null; + } + + /** + * Returns the name to use for an {@link #ADD} change operation + * @return the name for an {@link #ADD} change + */ + protected String getAddName() { + return NLS.bind(RefactoringMessages.FilterChange_add_filter, this.filter.toString()); + } + + /** + * Returns the name to use for a {@link #DELETE} change operation + * @return the name for a {@link #DELETE} change + */ + protected String getDeleteName() { + IApiProblem problem = this.filter.getUnderlyingProblem(); + return NLS.bind(RefactoringMessages.FilterChange_remove_used_filter, problem.getMessage()); + } + + /** + * Returns the name to use for a {@link #RENAME} change operation + * @return the name for a {@link #RENAME} change + */ + protected String getRenameName() { + IApiProblem problem = this.filter.getUnderlyingProblem(); + return NLS.bind(RefactoringMessages.FilterChange_remove_used_filter, new Object[] {problem.getMessage()}); + } + + /** + * Returns the name to use for a {@link #MOVE} change operation + * @return the name for a {@link #MOVE} change + */ + protected String getMoveName() { + IApiProblem problem = this.filter.getUnderlyingProblem(); + return NLS.bind(RefactoringMessages.FilterChange_remove_used_filter, new Object[] {problem.getMessage()}); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.Change#getName() + */ + public String getName() { + switch(this.kind) { + case ADD: { + return getAddName(); + } + case DELETE: { + return getDeleteName(); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor) + */ + public void initializeValidationData(IProgressMonitor pm) {} + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor) + */ + public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { + return new RefactoringStatus(); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement() + */ + public Object getModifiedElement() { + return this.filter; + } +} Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterMoveParticipant.java =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterMoveParticipant.java diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterMoveParticipant.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterMoveParticipant.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,98 @@ +package org.eclipse.pde.api.tools.ui.internal.refactoring; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; +import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; +import org.eclipse.pde.api.tools.internal.provisional.Factory; +import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations; +import org.eclipse.pde.api.tools.internal.provisional.IApiDescription; +import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; +import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; +import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; + +/** + * Handles a type being moved from one location to another and updates the associated + * {@link org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter}s as + * needed + * + * @since 1.0.1 + */ +public class FilterMoveParticipant extends MoveParticipant { + + private IJavaElement element = null; + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) + */ + public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { + return new RefactoringStatus(); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor) + */ + public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { + IResource resource = (IResource) getArguments().getDestination(); + switch(this.element.getElementType()) { + case IJavaElement.TYPE: { + return RefactoringUtils.createMoveFilterChanges((IType)this.element, resource.getProjectRelativePath().toString()); + } + case IJavaElement.PACKAGE_FRAGMENT: { + return RefactoringUtils.createMoveFilterChanges((IPackageFragment)this.element, resource.getProjectRelativePath().toString()); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() + */ + public String getName() { + return NLS.bind(RefactoringMessages.FilterDeleteParticipant_remove_unused_filters_for_0, this.element.getElementName()); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) + */ + protected boolean initialize(Object element) { + if(element instanceof IJavaElement) { + this.element = (IJavaElement) element; + String projectname = this.element.getJavaProject().getElementName(); + IElementDescriptor desc = null; + switch (this.element.getElementType()) { + case IJavaElement.TYPE: { + desc = Factory.typeDescriptor(((IType)this.element).getFullyQualifiedName()); + } + case IJavaElement.PACKAGE_FRAGMENT: { + desc = Factory.packageDescriptor(((IPackageFragment)this.element).getElementName()); + } + } + if(desc != null) { + IApiComponent component = ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline().getApiComponent(projectname); + if(component != null) { + try { + IApiDescription adesc = component.getApiDescription(); + if(adesc != null) { + IApiAnnotations annot = adesc.resolveAnnotations(desc); + if(annot != null) { + return VisibilityModifiers.isAPI(annot.getVisibility()); + } + } + } + catch(CoreException ce) {} + } + } + } + return false; + } +} Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/refactoringmessages.properties =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/refactoringmessages.properties diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/refactoringmessages.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/refactoringmessages.properties 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ +FilterChange_add_filter=Add filter: {0} +FilterChange_remove_used_filter=Remove unused filter: {0} +FilterDeleteParticipant_remove_unused_filters_for_0=Remove unused API problem filters for: {0} +RefactoringUtils_remove_usused_filters=Remove unused filters + Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterRenameParticipant.java =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterRenameParticipant.java diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterRenameParticipant.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterRenameParticipant.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,95 @@ +package org.eclipse.pde.api.tools.ui.internal.refactoring; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; +import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; +import org.eclipse.pde.api.tools.internal.provisional.Factory; +import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations; +import org.eclipse.pde.api.tools.internal.provisional.IApiDescription; +import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; +import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; +import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; + +/** + * Handles updating {@link org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter}s + * when a type they reference is renamed + * + * @since 1.0.1 + */ +public class FilterRenameParticipant extends RenameParticipant { + + private IJavaElement element = null; + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) + */ + public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { + return new RefactoringStatus(); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor) + */ + public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { + switch(this.element.getElementType()) { + case IJavaElement.TYPE: { + return RefactoringUtils.createRenameFilterChanges((IType)this.element, getArguments().getNewName()); + } + case IJavaElement.PACKAGE_FRAGMENT: { + return RefactoringUtils.createRenameFilterChanges((IPackageFragment)this.element, getArguments().getNewName()); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() + */ + public String getName() { + return NLS.bind(RefactoringMessages.FilterDeleteParticipant_remove_unused_filters_for_0, this.element.getElementName()); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) + */ + protected boolean initialize(Object element) { + if(element instanceof IJavaElement) { + this.element = (IJavaElement) element; + String projectname = this.element.getJavaProject().getElementName(); + IElementDescriptor desc = null; + switch (this.element.getElementType()) { + case IJavaElement.TYPE: { + desc = Factory.typeDescriptor(((IType)this.element).getFullyQualifiedName()); + } + case IJavaElement.PACKAGE_FRAGMENT: { + desc = Factory.packageDescriptor(((IPackageFragment)this.element).getElementName()); + } + } + if(desc != null) { + IApiComponent component = ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline().getApiComponent(projectname); + if(component != null) { + try { + IApiDescription adesc = component.getApiDescription(); + if(adesc != null) { + IApiAnnotations annot = adesc.resolveAnnotations(desc); + if(annot != null) { + return VisibilityModifiers.isAPI(annot.getVisibility()); + } + } + } + catch(CoreException ce) {} + } + } + } + return false; + } +} Index: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterDeleteParticipant.java =================================================================== RCS file: src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterDeleteParticipant.java diff -N src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterDeleteParticipant.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/api/tools/ui/internal/refactoring/FilterDeleteParticipant.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,95 @@ +package org.eclipse.pde.api.tools.ui.internal.refactoring; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; +import org.eclipse.ltk.core.refactoring.participants.DeleteParticipant; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; +import org.eclipse.pde.api.tools.internal.provisional.Factory; +import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations; +import org.eclipse.pde.api.tools.internal.provisional.IApiDescription; +import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; +import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; +import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; + +/** + * Handles removing unused {@link org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter}s + * when a type they belonged to is removed + * + * @since 1.0.1 + */ +public class FilterDeleteParticipant extends DeleteParticipant { + + private IJavaElement element = null; + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) + */ + public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { + return new RefactoringStatus(); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor) + */ + public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { + switch(this.element.getElementType()) { + case IJavaElement.TYPE: { + return RefactoringUtils.createDeleteFilterChanges((IType)this.element); + } + case IJavaElement.PACKAGE_FRAGMENT: { + return RefactoringUtils.createDeleteFilterChanges((IPackageFragment)this.element); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() + */ + public String getName() { + return NLS.bind(RefactoringMessages.FilterDeleteParticipant_remove_unused_filters_for_0, this.element.getElementName()); + } + + /* (non-Javadoc) + * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) + */ + protected boolean initialize(Object element) { + if(element instanceof IJavaElement) { + this.element = (IJavaElement) element; + String projectname = this.element.getJavaProject().getElementName(); + IElementDescriptor desc = null; + switch (this.element.getElementType()) { + case IJavaElement.TYPE: { + desc = Factory.typeDescriptor(((IType)this.element).getFullyQualifiedName()); + } + case IJavaElement.PACKAGE_FRAGMENT: { + desc = Factory.packageDescriptor(((IPackageFragment)this.element).getElementName()); + } + } + if(desc != null) { + IApiComponent component = ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline().getApiComponent(projectname); + if(component != null) { + try { + IApiDescription adesc = component.getApiDescription(); + if(adesc != null) { + IApiAnnotations annot = adesc.resolveAnnotations(desc); + if(annot != null) { + return VisibilityModifiers.isAPI(annot.getVisibility()); + } + } + } + catch(CoreException ce) {} + } + } + } + return false; + } +} #P org.eclipse.pde.api.tools Index: src/org/eclipse/pde/api/tools/internal/ApiFilterStore.java =================================================================== RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiFilterStore.java,v retrieving revision 1.35 diff -u -r1.35 ApiFilterStore.java --- src/org/eclipse/pde/api/tools/internal/ApiFilterStore.java 9 Apr 2009 15:56:42 -0000 1.35 +++ src/org/eclipse/pde/api/tools/internal/ApiFilterStore.java 13 Apr 2009 16:36:39 -0000 @@ -352,10 +352,12 @@ } IResource resource = fProject.getProject().findMember(new Path(resourcePath)); if(resource == null) { - continue; + resource = fProject.getProject().getFile(resourcePath); } Map pTypeNames = (Map) fFilterMap.get(resource); - if (pTypeNames == null) continue; + if (pTypeNames == null) { + continue; + } String typeName = underlyingProblem.getTypeName(); if (typeName == null) { typeName = GLOBAL;