# HG changeset patch # User Eugene Ostroukhov # Date 1273183770 25200 # Node ID 30d676a95944a291894dd013eabdb303befa2fa9 # Parent a2085280e663a3631ffd200bda02ee4b57e6fb61 PhoneGap content assist proposals diff -r a2085280e663 -r 30d676a95944 org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch --- a/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch Tue Apr 27 16:29:25 2010 +0100 +++ b/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch Thu May 06 15:09:30 2010 -0700 @@ -21,11 +21,10 @@ - - - + + - + diff -r a2085280e663 -r 30d676a95944 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java Tue Apr 27 16:29:25 2010 +0100 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferEngine.java Thu May 06 15:09:30 2010 -0700 @@ -21,15 +21,19 @@ import java.util.Map; import java.util.TreeMap; -import org.eclipse.wst.jsdt.core.ast.IIfStatement; +import org.eclipse.wst.jsdt.core.ast.IASTNode; +import org.eclipse.wst.jsdt.core.ast.IExpression; +import org.eclipse.wst.jsdt.core.ast.ISingleNameReference; 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 TYPE_TO_PROPERTY = new TreeMap(); - private CompilationUnitDeclaration compilationUnit; + private static final char[] NAVIGATOR_TYPE = "Navigator".toCharArray(); + + private CompilationUnitDeclaration compUnit; + static { TYPE_TO_PROPERTY.put("Notification", "notification"); TYPE_TO_PROPERTY.put("Accelerometer", "accelerometer"); @@ -42,37 +46,83 @@ 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; + public void setCompilationUnit( + CompilationUnitDeclaration scriptFileDeclaration) { + this.compUnit = scriptFileDeclaration; + super.setCompilationUnit(scriptFileDeclaration); } + + @Override + protected InferredType getInferredType2(IExpression fieldReceiver) { + if (fieldReceiver.getASTType() == IASTNode.SINGLE_NAME_REFERENCE) { + ISingleNameReference nameReference = (ISingleNameReference) fieldReceiver; + if ("navigator".equals(String.valueOf(nameReference.getToken()))) { + return addType(NAVIGATOR_TYPE, true); + } + } + return super.getInferredType2(fieldReceiver); + } + + // @Override + // public boolean visit(IAssignment assignment) { + // if (assignment.getLeftHandSide().getASTType() == IASTNode.FIELD_REFERENCE) { + // FieldReference reference = (FieldReference) assignment.getLeftHandSide(); + // if (reference.receiver.getASTType() == IASTNode.SINGLE_NAME_REFERENCE) { + // ISingleNameReference nameReference = (ISingleNameReference) reference.receiver; + // if ("navigator".equals(String.valueOf(nameReference.getToken()))) { + // return addNavigatorField(reference, assignment); + // } + // } + // } + // // TODO Auto-generated method stub + // return super.visit(assignment); + // } + // + // private boolean addNavigatorField(FieldReference fieldReference, IAssignment assignment) { + // pushContext(); + // char[] possibleTypeName = NAVIGATOR_TYPE; + // InferredType newType = compUnit.findInferredType(possibleTypeName); + // + // //create the new type if not found + // if (newType == null) { + // newType = addType(possibleTypeName); + // } + // newType.isDefinition = true; + // + // newType.updatePositions(assignment.sourceStart(), assignment.sourceEnd()); + // + // //prevent Object literal based anonymous types from being created more than once + // if (passNumber == 1 && assignment.getExpression() instanceof IObjectLiteral) { + // return false; + // } + // + // char[] memberName = fieldReference.token; + // int nameStart = (int) (fieldReference.nameSourcePosition >>> 32); + // + // InferredType typeOf = getTypeOf(assignment.getExpression()); + // IFunctionDeclaration methodDecl = null; + // + // if (typeOf == null || typeOf == FunctionType) { + // methodDecl = getDefinedFunction(assignment.getExpression()); + // } + // + // if (methodDecl != null) { + // InferredMember method = newType.addMethod(memberName, methodDecl, nameStart); + // } + // // http://bugs.eclipse.org/269053 - constructor property not supported in JSDT + // else /*if (!CharOperation.equals(CONSTRUCTOR_ID, memberName))*/ + // { + // InferredAttribute attribute = newType.addAttribute(memberName, assignment, nameStart); + // handleAttributeDeclaration(attribute, assignment.getExpression()); + // attribute.initializationStart = assignment.getExpression().sourceStart(); + // if (attribute.type == null) { + // attribute.type = typeOf; + // } + // } + // return true; + // + // } } diff -r a2085280e663 -r 30d676a95944 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java Tue Apr 27 16:29:25 2010 +0100 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/jsdt/PhoneGapInferrenceProvider.java Thu May 06 15:09:30 2010 -0700 @@ -22,61 +22,73 @@ 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 PHONEGAP_TYPES = new TreeSet(Arrays.asList("Acceleration", - "AccelerationOptions", "Accelerometer", "Camera", "DeviceError", "Contacts", "Contact", "Geolocation", - "PositionOptions", "Coordinates", "Media", "Notification", "Orientation", "Position", "PositionError", - "Sms", "Storage")); + public static final String ID = "org.symbian.tools.wrttools.phonegap"; + private static final Collection PHONEGAP_TYPES = new TreeSet( + 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()); - 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; - } + 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 MAYBE_THIS; + } + } catch (JavaScriptModelException e) { + Activator.log(e); + } + } + return NOT_THIS; + } - public String getID() { - return ID; - } + public String getID() { + return ID; + } - public InferEngine getInferEngine() { - final InferEngine engine = new PhoneGapInferEngine(); - engine.inferenceProvider = this; - return engine; - } + public InferEngine getInferEngine() { + final InferEngine engine = new PhoneGapInferEngine(); + engine.inferenceProvider = this; + return engine; + } - public RefactoringSupport getRefactoringSupport() { - // TODO Auto-generated method stub - return null; - } + public RefactoringSupport getRefactoringSupport() { + // TODO Auto-generated method stub + return null; + } - public ResolutionConfiguration getResolutionConfiguration() { - final ResolutionConfiguration configuration = new ResolutionConfiguration(); - return configuration; - } + public ResolutionConfiguration getResolutionConfiguration() { + final ResolutionConfiguration configuration = new ResolutionConfiguration(); + return configuration; + } }