You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ds...@apache.org on 2010/07/23 11:27:40 UTC
svn commit: r967011 - in /felix/trunk/sigil/eclipse/ui: ./
src/org/apache/felix/sigil/ui/eclipse/refactor/
Author: dsavage
Date: Fri Jul 23 09:27:40 2010
New Revision: 967011
URL: http://svn.apache.org/viewvc?rev=967011&view=rev
Log:
add activator refactor support (FELIX-2482)
Added:
felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/BundleActivatorChange.java
felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/MoveActivatorParticipant.java
felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorParticipant.java
Modified:
felix/trunk/sigil/eclipse/ui/plugin.properties
felix/trunk/sigil/eclipse/ui/plugin.xml
Modified: felix/trunk/sigil/eclipse/ui/plugin.properties
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/plugin.properties?rev=967011&r1=967010&r2=967011&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/ui/plugin.properties (original)
+++ felix/trunk/sigil/eclipse/ui/plugin.properties Fri Jul 23 09:27:40 2010
@@ -3,5 +3,7 @@ newtonRepoPrefs=Newton Repository
librariesPrefsPage=OSGi Libraries
commandConvertProject=Convert Project To Sigil Project
commandRefreshClasspath=Refresh bundle classpath
+RenameActivatorParticipant.name=Rename Activator Participant
RenamePackageParticipant.name=Rename Package Participant
+MoveActivatorParticipant.name=Move Activator Participant
MovePackageParticipant.name=Move Package Participant
\ No newline at end of file
Modified: felix/trunk/sigil/eclipse/ui/plugin.xml
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/plugin.xml?rev=967011&r1=967010&r2=967011&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/ui/plugin.xml (original)
+++ felix/trunk/sigil/eclipse/ui/plugin.xml Fri Jul 23 09:27:40 2010
@@ -281,6 +281,21 @@
</with>
</enablement>
</renameParticipant>
+ <renameParticipant
+ id="org.apache.felix.sigil.renameActivatorParticipant"
+ name="%RenameActivatorParticipant.name"
+ class="org.apache.felix.sigil.ui.eclipse.refactor.RenameActivatorParticipant">
+ <enablement>
+ <with variable="affectedNatures">
+ <iterate operator="or">
+ <equals value="org.apache.felix.sigil.sigilnature"/>
+ </iterate>
+ </with>
+ <with variable="element">
+ <instanceof value="org.eclipse.jdt.core.ICompilationUnit"/>
+ </with>
+ </enablement>
+ </renameParticipant>
</extension>
<extension point="org.eclipse.ltk.core.refactoring.moveParticipants">
<moveParticipant
@@ -298,5 +313,20 @@
</with>
</enablement>
</moveParticipant>
+ <moveParticipant
+ id="org.apache.felix.sigil.moveActivatorParticipant"
+ name="%MoveActivatorParticipant.name"
+ class="org.apache.felix.sigil.ui.eclipse.refactor.MoveActivatorParticipant">
+ <enablement>
+ <with variable="affectedNatures">
+ <iterate operator="or">
+ <equals value="org.apache.felix.sigil.sigilnature"/>
+ </iterate>
+ </with>
+ <with variable="element">
+ <instanceof value="org.eclipse.jdt.core.ICompilationUnit"/>
+ </with>
+ </enablement>
+ </moveParticipant>
</extension>
</plugin>
Added: felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/BundleActivatorChange.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/BundleActivatorChange.java?rev=967011&view=auto
==============================================================================
--- felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/BundleActivatorChange.java (added)
+++ felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/BundleActivatorChange.java Fri Jul 23 09:27:40 2010
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.ui.eclipse.refactor;
+
+import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
+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;
+
+/**
+ * @author dave
+ *
+ */
+public class BundleActivatorChange extends Change
+{
+
+ private final ISigilProjectModel sigil;
+ private final String oldName;
+ private final String newName;
+
+ /**
+ * @param sigil
+ * @param oldName
+ * @param newName
+ */
+ public BundleActivatorChange(ISigilProjectModel sigil, String oldName, String newName)
+ {
+ this.sigil = sigil;
+ this.oldName = oldName;
+ this.newName = newName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
+ */
+ @Override
+ public Object getModifiedElement()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName()
+ {
+ return "Bundle Activator Rename";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void initializeValidationData(IProgressMonitor monitor)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException,
+ OperationCanceledException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor monitor) throws CoreException
+ {
+ sigil.getBundle().getBundleInfo().setActivator(newName);
+ sigil.save(monitor);
+ return new BundleActivatorChange(sigil, newName, oldName);
+ }
+
+}
Added: felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/MoveActivatorParticipant.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/MoveActivatorParticipant.java?rev=967011&view=auto
==============================================================================
--- felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/MoveActivatorParticipant.java (added)
+++ felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/MoveActivatorParticipant.java Fri Jul 23 09:27:40 2010
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.ui.eclipse.refactor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.felix.sigil.eclipse.SigilCore;
+import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaModel;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.NullChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;
+
+public class MoveActivatorParticipant extends MoveParticipant
+{
+ private ICompilationUnit compilationUnit;
+ private List<Change> changes = new LinkedList<Change>();
+
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor monitor,
+ CheckConditionsContext ctx) throws OperationCanceledException
+ {
+ RefactoringStatus status = null;
+ if(getArguments().getUpdateReferences()) {
+ IPackageFragment pf = (IPackageFragment) compilationUnit.getAncestor(IJavaModel.PACKAGE_FRAGMENT);
+ String oldName = qualifiedName(pf, compilationUnit.getElementName());
+ try
+ {
+ ISigilProjectModel sigil = SigilCore.create(compilationUnit.getJavaProject().getProject());
+ if (oldName.equals(sigil.getBundle().getBundleInfo().getActivator())) {
+ IPackageFragment dest = (IPackageFragment) getArguments().getDestination();
+ String newName = qualifiedName(dest, compilationUnit.getElementName());
+
+ RefactorUtil.touch(ctx, sigil);
+ changes.add(new BundleActivatorChange(sigil, oldName, newName));
+ status = RefactoringStatus.createInfoStatus("Updating bundle activator from " + oldName + " to " + newName );
+ }
+ }
+ catch (CoreException e)
+ {
+ SigilCore.warn("Failed to update activator", e);
+ }
+ }
+
+ return status;
+ }
+
+ /**
+ * @param pf
+ * @param compilationUnit2
+ * @return
+ */
+ private static String qualifiedName(IPackageFragment pf, String name)
+ {
+ name = name.substring(0, name.lastIndexOf('.'));
+ return pf.getElementName() + '.' + name;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor monitor) throws CoreException,
+ OperationCanceledException
+ {
+ if (changes.isEmpty()) {
+ return new NullChange();
+ }
+ else
+ {
+ CompositeChange ret = new CompositeChange("Export-Package update");
+
+ ret.addAll(changes.toArray(new Change[changes.size()]));
+
+ return ret;
+ }
+ }
+
+ @Override
+ public String getName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected boolean initialize(Object element)
+ {
+ compilationUnit = (ICompilationUnit) element;
+ return true;
+ }
+
+}
Added: felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorParticipant.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorParticipant.java?rev=967011&view=auto
==============================================================================
--- felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorParticipant.java (added)
+++ felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/refactor/RenameActivatorParticipant.java Fri Jul 23 09:27:40 2010
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.ui.eclipse.refactor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.felix.sigil.eclipse.SigilCore;
+import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaModel;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.NullChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+
+public class RenameActivatorParticipant extends RenameParticipant
+{
+ private ICompilationUnit compilationUnit;
+ private List<Change> changes = new LinkedList<Change>();
+
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor monitor,
+ CheckConditionsContext ctx) throws OperationCanceledException
+ {
+ RefactoringStatus status = null;
+ if(getArguments().getUpdateReferences()) {
+ IPackageFragment pf = (IPackageFragment) compilationUnit.getAncestor(IJavaModel.PACKAGE_FRAGMENT);
+ String oldName = qualifiedName(pf, compilationUnit.getElementName());
+ try
+ {
+ ISigilProjectModel sigil = SigilCore.create(compilationUnit.getJavaProject().getProject());
+ if (oldName.equals(sigil.getBundle().getBundleInfo().getActivator())) {
+ String newName = qualifiedName(pf, getArguments().getNewName());
+
+ RefactorUtil.touch(ctx, sigil);
+ changes.add(new BundleActivatorChange(sigil, oldName, newName));
+ status = RefactoringStatus.createInfoStatus("Updating bundle activator from " + oldName + " to " + newName );
+ }
+ }
+ catch (CoreException e)
+ {
+ SigilCore.warn("Failed to update activator", e);
+ }
+ }
+
+ return status;
+ }
+
+ /**
+ * @param pf
+ * @param compilationUnit2
+ * @return
+ */
+ private static String qualifiedName(IPackageFragment pf, String name)
+ {
+ name = name.substring(0, name.lastIndexOf('.'));
+ return pf.getElementName() + '.' + name;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor monitor) throws CoreException,
+ OperationCanceledException
+ {
+ if (changes.isEmpty()) {
+ return new NullChange();
+ }
+ else
+ {
+ CompositeChange ret = new CompositeChange("Export-Package update");
+
+ ret.addAll(changes.toArray(new Change[changes.size()]));
+
+ return ret;
+ }
+ }
+
+ @Override
+ public String getName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected boolean initialize(Object element)
+ {
+ compilationUnit = (ICompilationUnit) element;
+ return true;
+ }
+
+}