work-in-progress-patches/phonegap.txt
author Eugene Ostroukhov <eugeneo@symbian.org>
Fri, 23 Apr 2010 17:08:33 -0700
changeset 320 147e1da95419
parent 312 11f39c9c3156
permissions -rw-r--r--
NPE in JSDT walkaround
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
312
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
diff -r eef7c6acd0f3 org.symbian.tools.wrttools/plugin.xml
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
--- a/org.symbian.tools.wrttools/plugin.xml	Mon Apr 19 18:04:34 2010 -0700
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
+++ b/org.symbian.tools.wrttools/plugin.xml	Tue Apr 20 15:14:30 2010 -0700
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
@@ -875,5 +875,13 @@
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
           installer="org.symbian.tools.wrttools.core.libraries.PhoneGapInstaller"
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
           name="PhoneGap">
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
     </library>
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
+ </extension>
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
+ <extension
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
+       id="org.symbian.tools.wrttools.phonegap"
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
+       name="PhoneGap Library Support"
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
+       point="org.eclipse.wst.jsdt.core.inferrenceSupport">
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
+    <inferenceProvider
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
+          class="org.symbian.tools.wrttools.core.libraries.jsdt.PhoneGapInferrenceProvider">
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
+    </inferenceProvider>
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
  </extension>
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
 </plugin>
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
diff -r eef7c6acd0f3 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java	Mon Apr 19 18:04:34 2010 -0700
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java	Tue Apr 20 15:14:30 2010 -0700
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
@@ -41,7 +41,7 @@
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
                 if (file.exists()) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
                     IProject project = file.getProject();
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
                     if (ProjectUtils.hasWrtNature(project)) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
-                        return InferrenceProvider.ONLY_THIS;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
+                        return InferrenceProvider.MAYBE_THIS;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
                     }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
                 }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
             }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
diff -r eef7c6acd0f3 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java	Tue Apr 20 15:14:30 2010 -0700
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
@@ -0,0 +1,70 @@
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
+/**
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
+ * All rights reserved.
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
+ * This component and the accompanying materials are made available
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
+ * under the terms of the License "Eclipse Public License v1.0"
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
+ * which accompanies this distribution, and is available
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
+ *
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
+ * Initial Contributors:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
+ * Symbian Foundation - initial contribution.
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
+ * Contributors:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
+ * Description:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
+ * Overview:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
+ * Details:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
+ * Platforms/Drives/Compatibility:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
+ * Assumptions/Requirement/Pre-requisites:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
+ * Failures and causes:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
+ */
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
+package org.symbian.tools.wrttools.core.libraries.jsdt;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
+import java.util.Map;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
+import java.util.TreeMap;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    56
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
+import org.eclipse.wst.jsdt.core.infer.InferEngine;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    58
+import org.eclipse.wst.jsdt.core.infer.InferredAttribute;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
+import org.eclipse.wst.jsdt.core.infer.InferredType;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
+import org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
+public class PhoneGapInferEngine extends InferEngine {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
+    private static final Map<String, String> TYPE_TO_PROPERTY = new TreeMap<String, String>();
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
+    private CompilationUnitDeclaration compilationUnit;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
+    static {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
+        TYPE_TO_PROPERTY.put("Notification", "notification");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
+        TYPE_TO_PROPERTY.put("Accelerometer", "accelerometer");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
+        TYPE_TO_PROPERTY.put("Camera", "camera");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    69
+        TYPE_TO_PROPERTY.put("Contacts", "contacts");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    70
+        TYPE_TO_PROPERTY.put("Geolocation", "geolocation");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    71
+        TYPE_TO_PROPERTY.put("Media", "media");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    72
+        TYPE_TO_PROPERTY.put("Notification", "notification");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    73
+        TYPE_TO_PROPERTY.put("Orientation", "orientation");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    74
+        TYPE_TO_PROPERTY.put("Sms", "sms");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
+        TYPE_TO_PROPERTY.put("Storage", "storage");
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    76
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    77
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    78
+    @SuppressWarnings("restriction")
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
+    @Override
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
+    public void setCompilationUnit(CompilationUnitDeclaration compilationUnit) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
+        this.compilationUnit = compilationUnit;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
+        super.setCompilationUnit(compilationUnit);
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
+    @SuppressWarnings("restriction")
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
+    @Override
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
+    protected InferredType addType(char[] className, boolean isDefinition) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
+        InferredType type = super.addType(className, isDefinition);
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    89
+        if (TYPE_TO_PROPERTY.containsKey(String.valueOf(type.getName()))) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    90
+            InferredType inferredType = compilationUnit.findInferredType("Navigator".toCharArray());
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    91
+            System.out.println(inferredType);
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    92
+            if (inferredGlobal != null) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    93
+                InferredAttribute[] attributes = inferredGlobal.attributes;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    94
+                for (InferredAttribute attr : attributes) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
+                    System.out.println(String.valueOf(attr.name));
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
+                }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
+            }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    98
+            final InferredType definedType = findDefinedType("Navigator".toCharArray());
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
+            System.out.println(definedType);
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   100
+        }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   101
+        return type;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   102
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   103
+}
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   104
diff -r eef7c6acd0f3 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   105
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   106
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java	Tue Apr 20 15:14:30 2010 -0700
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   107
@@ -0,0 +1,89 @@
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   108
+/**
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   109
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   110
+ * All rights reserved.
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   111
+ * This component and the accompanying materials are made available
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   112
+ * under the terms of the License "Eclipse Public License v1.0"
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   113
+ * which accompanies this distribution, and is available
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   114
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   115
+ *
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   116
+ * Initial Contributors:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   117
+ * Symbian Foundation - initial contribution.
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   118
+ * Contributors:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   119
+ * Description:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   120
+ * Overview:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   121
+ * Details:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   122
+ * Platforms/Drives/Compatibility:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   123
+ * Assumptions/Requirement/Pre-requisites:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   124
+ * Failures and causes:
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   125
+ */
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   126
+package org.symbian.tools.wrttools.core.libraries.jsdt;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   127
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   128
+import java.util.Arrays;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   129
+import java.util.Collection;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   130
+import java.util.TreeSet;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   131
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   132
+import org.eclipse.core.resources.IFile;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   133
+import org.eclipse.core.resources.ResourcesPlugin;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   134
+import org.eclipse.core.runtime.Path;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   135
+import org.eclipse.wst.jsdt.core.IJavaScriptUnit;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   136
+import org.eclipse.wst.jsdt.core.IType;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   137
+import org.eclipse.wst.jsdt.core.JavaScriptCore;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   138
+import org.eclipse.wst.jsdt.core.JavaScriptModelException;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   139
+import org.eclipse.wst.jsdt.core.infer.IInferenceFile;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   140
+import org.eclipse.wst.jsdt.core.infer.InferEngine;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   141
+import org.eclipse.wst.jsdt.core.infer.InferrenceProvider;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   142
+import org.eclipse.wst.jsdt.core.infer.RefactoringSupport;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   143
+import org.eclipse.wst.jsdt.core.infer.ResolutionConfiguration;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   144
+import org.symbian.tools.wrttools.Activator;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   145
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   146
+public class PhoneGapInferrenceProvider implements InferrenceProvider {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   147
+    public static final String ID = "org.symbian.tools.wrttools.phonegap";
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   148
+    private static final Collection<String> PHONEGAP_TYPES = new TreeSet<String>(Arrays.asList("Acceleration",
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   149
+            "AccelerationOptions", "Accelerometer", "Camera", "DeviceError", "Contacts", "Contact", "Geolocation",
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   150
+            "PositionOptions", "Coordinates", "Media", "Notification", "Orientation", "Position", "PositionError",
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   151
+            "Sms", "Storage"));
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   152
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   153
+    public int applysTo(IInferenceFile scriptFile) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   154
+        String path = String.valueOf(scriptFile.getFileName());
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   155
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   156
+        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   157
+        if (file != null && file.isAccessible()) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   158
+            IJavaScriptUnit unit = (IJavaScriptUnit) JavaScriptCore.create(file);
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   159
+            try {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   160
+                IType[] types = unit.getAllTypes();
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   161
+                int typeCount = 0;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   162
+                for (IType type : types) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   163
+                    if (PHONEGAP_TYPES.contains(type.getElementName())) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   164
+                        typeCount += 1;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   165
+                    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   166
+                }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   167
+                if (typeCount > 1) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   168
+                    return ONLY_THIS;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   169
+                }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   170
+            } catch (JavaScriptModelException e) {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   171
+                Activator.log(e);
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   172
+            }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   173
+        }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   174
+        return NOT_THIS;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   175
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   176
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   177
+    public String getID() {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   178
+        return ID;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   179
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   180
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   181
+    public InferEngine getInferEngine() {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   182
+        final InferEngine engine = new PhoneGapInferEngine();
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   183
+        engine.inferenceProvider = this;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   184
+        return engine;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   185
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   186
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   187
+    public RefactoringSupport getRefactoringSupport() {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   188
+        // TODO Auto-generated method stub
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   189
+        return null;
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   190
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   191
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   192
+    public ResolutionConfiguration getResolutionConfiguration() {
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   193
+        return new ResolutionConfiguration();
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   194
+    }
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   195
+
11f39c9c3156 Patch before moving to Helios
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   196
+}