PhoneGap support work in progress
authorEugene Ostroukhov <eugeneo@symbian.org>
Fri, 23 Apr 2010 15:44:39 -0700
changeset 319 40387cc658b4
parent 318 3b65ff845125
child 320 147e1da95419
PhoneGap support work in progress
chrome-dev-tools-patches/doc
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/MozillaPreviewPage.java
org.symbian.tools.wrttools/plugin.xml
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/IWrtIdeContainer.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/WrtLibInitializer.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chrome-dev-tools-patches/doc	Fri Apr 23 15:44:39 2010 -0700
@@ -0,0 +1,66 @@
+hg import [OPTION]... PATCH...
+
+aliases: patch
+
+import an ordered set of patches
+
+    Import a list of patches and commit them individually (unless --no-commit
+    is specified).
+
+    If there are outstanding changes in the working directory, import will
+    abort unless given the -f/--force flag.
+
+    You can import a patch straight from a mail message. Even patches as
+    attachments work (to use the body part, it must have type text/plain or
+    text/x-patch). From and Subject headers of email message are used as
+    default committer and commit message. All text/plain body parts before
+    first diff are added to commit message.
+
+    If the imported patch was generated by hg export, user and description
+    from patch override values from message headers and body. Values given on
+    command line with -m/--message and -u/--user override these.
+
+    If --exact is specified, import will set the working directory to the
+    parent of each patch before applying it, and will abort if the resulting
+    changeset has a different ID than the one recorded in the patch. This may
+    happen due to character set problems or other deficiencies in the text
+    patch format.
+
+    With -s/--similarity, hg will attempt to discover renames and copies in
+    the patch in the same way as 'addremove'.
+
+    To read a patch from standard input, use "-" as the patch name. If a URL
+    is specified, the patch will be downloaded from it. See 'hg help dates'
+    for a list of formats valid for -d/--date.
+
+options:
+
+ -p --strip           directory strip option for patch. This has the same
+                      meaning as the corresponding patch option (default: 1)
+ -b --base            base path
+ -f --force           skip check for outstanding uncommitted changes
+    --no-commit       don't commit, just update the working directory
+    --exact           apply patch to the nodes from which it was generated
+    --import-branch   use any branch information in patch (implied by --exact)
+ -m --message         use <text> as commit message
+ -l --logfile         read commit message from <file>
+ -d --date            record datecode as commit date
+ -u --user            record the specified user as committer
+ -s --similarity      guess renamed files by similarity (0<=s<=100)
+
+global options:
+ -R --repository      repository root directory or name of overlay bundle file
+    --cwd             change working directory
+ -y --noninteractive  do not prompt, assume 'yes' for any required answers
+ -q --quiet           suppress output
+ -v --verbose         enable additional output
+    --config          set/override config option
+    --debug           enable debugging output
+    --debugger        start debugger
+    --encoding        set the charset encoding (default: cp1251)
+    --encodingmode    set the charset encoding mode (default: strict)
+    --traceback       always print a traceback on exception
+    --time            time how long the command takes
+    --profile         print command execution profile
+    --version         output version information and exit
+ -h --help            display help and exit
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java	Fri Apr 23 11:56:36 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java	Fri Apr 23 15:44:39 2010 -0700
@@ -98,7 +98,7 @@
     private boolean refreshScheduled = false;
 
     public synchronized void process(Collection<IFile> files) {
-        if (!refreshScheduled && needsRefresh(files)) {
+        if (!isDisposed() && !refreshScheduled && needsRefresh(files)) {
             asyncExec(new Runnable() {
                 public void run() {
                     refreshBrowser();
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/MozillaPreviewPage.java	Fri Apr 23 11:56:36 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/MozillaPreviewPage.java	Fri Apr 23 15:44:39 2010 -0700
@@ -168,7 +168,6 @@
                 // Mozilla. We don't want to pollute the error log with this
                 return;
             }
-
             mozillaPrefs = (nsIPrefBranch) servMgr.getServiceByContractID("@mozilla.org/preferences-service;1",
                     nsIPrefBranch.NS_IPREFBRANCH_IID);
 
@@ -208,6 +207,8 @@
             String location = "http://" + WebappManager.getHost() + ":" + WebappManager.getPort();
             mozillaPrefs.setCharPref("capability.principal.codebase.p0.id", location);
             mozillaPrefs.setBoolPref("security.fileuri.strict_origin_policy", 0);
+
+            mozillaPrefs.setBoolPref("geo.enabled", 1);
             // start JavaXPCOM section
             nsIIOService ioService = (nsIIOService) servMgr.getServiceByContractID("@mozilla.org/network/io-service;1",
                     nsIIOService.NS_IIOSERVICE_IID);
--- a/org.symbian.tools.wrttools/plugin.xml	Fri Apr 23 11:56:36 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml	Fri Apr 23 15:44:39 2010 -0700
@@ -875,5 +875,13 @@
           installer="org.symbian.tools.wrttools.core.libraries.PhoneGapInstaller"
           name="PhoneGap">
     </library>
+ </extension>
+ <extension
+       id="org.symbian.tools.wrttools.phonegap"
+       name="PhoneGap Library Support"
+       point="org.eclipse.wst.jsdt.core.inferrenceSupport">
+    <inferenceProvider
+          class="org.symbian.tools.wrttools.core.libraries.jsdt.PhoneGapInferrenceProvider">
+    </inferenceProvider>
  </extension>
 </plugin>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/IWrtIdeContainer.java	Fri Apr 23 11:56:36 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-package org.symbian.tools.wrttools.core.libraries;
-
-import java.io.IOException;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-public interface IWrtIdeContainer {
-	void populateProject(IProject project, IProgressMonitor monitor) throws IOException, CoreException;
-}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java	Fri Apr 23 11:56:36 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java	Fri Apr 23 15:44:39 2010 -0700
@@ -41,7 +41,7 @@
                 if (file.exists()) {
                     IProject project = file.getProject();
                     if (ProjectUtils.hasWrtNature(project)) {
-                        return InferrenceProvider.ONLY_THIS;
+                        return InferrenceProvider.MAYBE_THIS;
                     }
                 }
             }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/WrtLibInitializer.java	Fri Apr 23 11:56:36 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/WrtLibInitializer.java	Fri Apr 23 15:44:39 2010 -0700
@@ -51,8 +51,8 @@
 			return set.toArray(new String[set.size()]);
 		}
 
-		@SuppressWarnings("unchecked")
-		private Set<String> getEntries(Bundle bundle, String p) {
+        @SuppressWarnings("rawtypes")
+        private Set<String> getEntries(Bundle bundle, String p) {
 			final Set<String> set = new TreeSet<String>();
 			Enumeration entries = bundle.getEntryPaths(p);
 			while (entries.hasMoreElements()) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java	Fri Apr 23 15:44:39 2010 -0700
@@ -0,0 +1,78 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.core.libraries.jsdt;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.eclipse.wst.jsdt.core.ast.IIfStatement;
+import org.eclipse.wst.jsdt.core.infer.InferEngine;
+import org.eclipse.wst.jsdt.core.infer.InferredAttribute;
+import org.eclipse.wst.jsdt.core.infer.InferredType;
+import org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration;
+
+public class PhoneGapInferEngine extends InferEngine {
+    private static final Map<String, String> TYPE_TO_PROPERTY = new TreeMap<String, String>();
+    private CompilationUnitDeclaration compilationUnit;
+    static {
+        TYPE_TO_PROPERTY.put("Notification", "notification");
+        TYPE_TO_PROPERTY.put("Accelerometer", "accelerometer");
+        TYPE_TO_PROPERTY.put("Camera", "camera");
+        TYPE_TO_PROPERTY.put("Contacts", "contacts");
+        TYPE_TO_PROPERTY.put("Geolocation", "geolocation");
+        TYPE_TO_PROPERTY.put("Media", "media");
+        TYPE_TO_PROPERTY.put("Notification", "notification");
+        TYPE_TO_PROPERTY.put("Orientation", "orientation");
+        TYPE_TO_PROPERTY.put("Sms", "sms");
+        TYPE_TO_PROPERTY.put("Storage", "storage");
+    }
+
+    @SuppressWarnings("restriction")
+    @Override
+    public void setCompilationUnit(CompilationUnitDeclaration compilationUnit) {
+        this.compilationUnit = compilationUnit;
+        super.setCompilationUnit(compilationUnit);
+    }
+
+    @Override
+    public boolean visit(IIfStatement ifStatement) {
+        // TODO Auto-generated method stub
+        return super.visit(ifStatement);
+    }
+
+    @SuppressWarnings("restriction")
+    @Override
+    protected InferredType addType(char[] className, boolean isDefinition) {
+        InferredType type = super.addType(className, isDefinition);
+        if (TYPE_TO_PROPERTY.containsKey(String.valueOf(type.getName()))) {
+            InferredType inferredType = compilationUnit.findInferredType("Navigator".toCharArray());
+            System.out.println(inferredType);
+            if (inferredGlobal != null) {
+                InferredAttribute[] attributes = inferredGlobal.attributes;
+                for (InferredAttribute attr : attributes) {
+                    System.out.println(String.valueOf(attr.name));
+                }
+            }
+            final InferredType definedType = findDefinedType("Navigator".toCharArray());
+            System.out.println(definedType);
+        }
+        return type;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java	Fri Apr 23 15:44:39 2010 -0700
@@ -0,0 +1,82 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.core.libraries.jsdt;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.TreeSet;
+
+import org.eclipse.wst.jsdt.core.infer.IInferenceFile;
+import org.eclipse.wst.jsdt.core.infer.InferEngine;
+import org.eclipse.wst.jsdt.core.infer.InferrenceProvider;
+import org.eclipse.wst.jsdt.core.infer.RefactoringSupport;
+import org.eclipse.wst.jsdt.core.infer.ResolutionConfiguration;
+
+public class PhoneGapInferrenceProvider implements InferrenceProvider {
+    public static final String ID = "org.symbian.tools.wrttools.phonegap";
+    private static final Collection<String> PHONEGAP_TYPES = new TreeSet<String>(Arrays.asList("Acceleration",
+            "AccelerationOptions", "Accelerometer", "Camera", "DeviceError", "Contacts", "Contact", "Geolocation",
+            "PositionOptions", "Coordinates", "Media", "Notification", "Orientation", "Position", "PositionError",
+            "Sms", "Storage"));
+
+    public int applysTo(IInferenceFile scriptFile) {
+        //        String path = String.valueOf(scriptFile.getFileName());
+        //
+        //        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
+        //        if (file != null && file.isAccessible()) {
+        //            IJavaScriptUnit unit = (IJavaScriptUnit) JavaScriptCore.create(file);
+        //            try {
+        //                IType[] types = unit.getAllTypes();
+        //                int typeCount = 0;
+        //                for (IType type : types) {
+        //                    if (PHONEGAP_TYPES.contains(type.getElementName())) {
+        //                        typeCount += 1;
+        //                    }
+        //                }
+        //                if (typeCount > 1) {
+        //                    return ONLY_THIS;
+        //                }
+        //            } catch (JavaScriptModelException e) {
+        //                Activator.log(e);
+        //            }
+        //        }
+        return NOT_THIS;
+    }
+
+    public String getID() {
+        return ID;
+    }
+
+    public InferEngine getInferEngine() {
+        final InferEngine engine = new PhoneGapInferEngine();
+        engine.inferenceProvider = this;
+        return engine;
+    }
+
+    public RefactoringSupport getRefactoringSupport() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public ResolutionConfiguration getResolutionConfiguration() {
+        final ResolutionConfiguration configuration = new ResolutionConfiguration();
+        return configuration;
+    }
+
+}