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