diff -r eef7c6acd0f3 org.symbian.tools.wrttools/plugin.xml
--- a/org.symbian.tools.wrttools/plugin.xml Mon Apr 19 18:04:34 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml Tue Apr 20 15:14:30 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>
diff -r eef7c6acd0f3 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java Mon Apr 19 18:04:34 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java Tue Apr 20 15:14:30 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;
}
}
}
diff -r eef7c6acd0f3 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java
--- /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 Tue Apr 20 15:14:30 2010 -0700
@@ -0,0 +1,70 @@
+/**
+ * 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.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);
+ }
+
+ @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;
+ }
+}
diff -r eef7c6acd0f3 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/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java Tue Apr 20 15:14:30 2010 -0700
@@ -0,0 +1,89 @@
+/**
+ * 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.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.jsdt.core.IJavaScriptUnit;
+import org.eclipse.wst.jsdt.core.IType;
+import org.eclipse.wst.jsdt.core.JavaScriptCore;
+import org.eclipse.wst.jsdt.core.JavaScriptModelException;
+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;
+import org.symbian.tools.wrttools.Activator;
+
+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() {
+ return new ResolutionConfiguration();
+ }
+
+}