felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsav...@apache.org
Subject svn commit: r966636 - in /felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util: JavaHelper.java ModelHelper.java
Date Thu, 22 Jul 2010 13:07:21 GMT
Author: dsavage
Date: Thu Jul 22 13:07:21 2010
New Revision: 966636

URL: http://svn.apache.org/viewvc?rev=966636&view=rev
Log:
add helper methods to aid refactoring support (FELIX-1346)

Modified:
    felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java
    felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/ModelHelper.java

Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java?rev=966636&r1=966635&r2=966636&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java
(original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java
Thu Jul 22 13:07:21 2010
@@ -65,6 +65,7 @@ import org.eclipse.core.runtime.IProgres
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SubMonitor;
 import org.eclipse.core.runtime.content.IContentDescription;
 import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.core.runtime.content.IContentTypeManager;
@@ -78,9 +79,11 @@ import org.eclipse.jdt.core.ICompilation
 import org.eclipse.jdt.core.IField;
 import org.eclipse.jdt.core.IImportDeclaration;
 import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaModel;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.ILocalVariable;
 import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageDeclaration;
 import org.eclipse.jdt.core.IPackageFragment;
 import org.eclipse.jdt.core.IPackageFragmentRoot;
 import org.eclipse.jdt.core.IParent;
@@ -1150,14 +1153,8 @@ public class JavaHelper
 
         String packageName = pe.getPackageName();
 
-        IPreferenceStore store = SigilCore.getDefault().getPreferenceStore();
-        VersionRangeBoundingRule lowerBoundRule = VersionRangeBoundingRule.valueOf( store
-            .getString( SigilCore.DEFAULT_VERSION_LOWER_BOUND ) );
-        VersionRangeBoundingRule upperBoundRule = VersionRangeBoundingRule.valueOf( store
-            .getString( SigilCore.DEFAULT_VERSION_UPPER_BOUND ) );
-
         Version version = pe.getVersion();
-        VersionRange versions = VersionRange.newInstance( version, lowerBoundRule, upperBoundRule
);
+        VersionRange versions = ModelHelper.getDefaultRange(version);
 
         IPackageImport pi = ModelElementFactory.getInstance().newModelElement( IPackageImport.class
);
         pi.setPackageName( packageName );
@@ -1258,4 +1255,55 @@ public class JavaHelper
 
         throw new JavaModelException( new IllegalStateException( "Missing type for " + root
), IStatus.ERROR );
     }
+
+
+    public static Set<String> findLocalPackageDependencies(
+        ISigilProjectModel project, String packageName, IProgressMonitor monitor) throws
JavaModelException
+    {
+        Set<String> imports = findJavaImports( project, monitor );
+        imports.remove(packageName);
+        return imports;
+    }
+
+
+    public static Set<String> findLocalPackageUsers(
+        ISigilProjectModel project, String packageName, IProgressMonitor monitor) throws
JavaModelException
+    {
+        Set<String> imports = new HashSet<String>();
+        Set<String> check = new HashSet<String>();
+        for ( IPackageFragment root : project.getJavaModel().getPackageFragments() )
+        {
+            IPackageFragmentRoot rt = ( IPackageFragmentRoot ) root
+                .getAncestor( IJavaElement.PACKAGE_FRAGMENT_ROOT );
+
+            if ( isInClassPath( project, rt ) )
+            {
+                for ( ICompilationUnit cu : root.getCompilationUnits() )
+                {
+                    IPackageFragment pack = (IPackageFragment) cu.getAncestor(IJavaModel.PACKAGE_FRAGMENT);
+                    if ( !pack.getElementName().equals(packageName)) {
+                        scanImports( cu, check );
+                        if (check.contains(packageName)) {
+                            imports.add(pack.getElementName());
+                        }
+                    }
+                    check.clear();
+                }
+
+                for ( IClassFile cf : root.getClassFiles() )
+                {
+                    IPackageFragment pack = (IPackageFragment) cf.getAncestor(IJavaModel.PACKAGE_FRAGMENT);
+                    if ( !pack.getElementName().equals(packageName)) {
+                        scanImports( cf, check );
+                        if (check.contains(packageName)) {
+                            imports.add(pack.getElementName());
+                        }
+                    }
+                    check.clear();
+                }
+            }
+        }
+        
+        return imports;
+    }
 }
\ No newline at end of file

Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/ModelHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/ModelHelper.java?rev=966636&r1=966635&r2=966636&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/ModelHelper.java
(original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/ModelHelper.java
Thu Jul 22 13:07:21 2010
@@ -20,15 +20,24 @@
 package org.apache.felix.sigil.eclipse.model.util;
 
 
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.felix.sigil.common.osgi.VersionRange;
+import org.apache.felix.sigil.common.osgi.VersionRangeBoundingRule;
 import org.apache.felix.sigil.eclipse.SigilCore;
+import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
 import org.apache.felix.sigil.model.ICapabilityModelElement;
 import org.apache.felix.sigil.model.ICompoundModelElement;
 import org.apache.felix.sigil.model.IModelElement;
 import org.apache.felix.sigil.model.IModelWalker;
 import org.apache.felix.sigil.model.IRequirementModelElement;
+import org.apache.felix.sigil.model.ModelElementFactory;
+import org.apache.felix.sigil.model.osgi.IPackageExport;
+import org.apache.felix.sigil.model.osgi.IPackageImport;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.osgi.framework.Version;
 
 
 public class ModelHelper
@@ -77,5 +86,35 @@ public class ModelHelper
             }
         }
     }
+    
+    public static VersionRange getDefaultRange(Version version) {
+        IPreferenceStore store = SigilCore.getDefault().getPreferenceStore();
+        
+        VersionRangeBoundingRule lowerBoundRule = VersionRangeBoundingRule.valueOf( store
+            .getString( SigilCore.DEFAULT_VERSION_LOWER_BOUND ) );
+        VersionRangeBoundingRule upperBoundRule = VersionRangeBoundingRule.valueOf( store
+            .getString( SigilCore.DEFAULT_VERSION_UPPER_BOUND ) );
+
+        VersionRange selectedVersions = VersionRange.newInstance( version, lowerBoundRule,
upperBoundRule );
+        return selectedVersions;
+    }
+    
+    public static IPackageExport findExport(ISigilProjectModel sigil, final String packageName)
{
+        final ArrayList<IPackageExport> found = new ArrayList<IPackageExport>(1);
+        sigil.visit(new IModelWalker()
+        {            
+            public boolean visit(IModelElement element)
+            {
+                if (element instanceof IPackageExport) {
+                    IPackageExport pe = (IPackageExport) element;
+                    if (pe.getPackageName().equals(packageName)) {
+                        found.add(pe);
+                    }
+                }
+                return found.isEmpty();
+            }
+        });
+        return found.isEmpty() ? null : found.get(0);
+    }
 
 }



Mime
View raw message