Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 17 commits
  • 36 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jan 17, 2013
@jcompagner jcompagner when variable has declared type then just add the assignment value,
don't assign it because that will overrride an existing declared type
that can also have javascript stuff already defined.

added test
633073d
@jcompagner jcompagner this type declaration f250508
@jcompagner jcompagner IRLocalType support, IValueReference wrapped ina RLocalType. 8219305
Commits on Jan 18, 2013
@panchenko ti: use AnonymousValue in ImmutableValueCollection and drop inner class 83e8989
@panchenko ti: log exception occurred when visited a node only once 767772f
@panchenko ImmutableValue: limit nested recursion depth c95f25e
@jcompagner jcompagner record type could be inside a union type, extract it from there first. 40a67ee
@panchenko JSDocTypeParser: small refactoring
JSDocTypeParserBase -> parser.util.CharStreamUtil
parse(input, autoUnion) -> public
654a9ad
@panchenko parser: ASTVisitor class generator e1ee8f9
Commits on Jan 21, 2013
@panchenko cleanup: deprecate reportUnknownType() with 4 parameters 590487c
Commits on Jan 23, 2013
@panchenko RLocalType changes to avoid recursion 2f21877
Commits on Jan 24, 2013
@panchenko formatter: correctly check if function is a declaration 52bfdc1
@panchenko validation: drop NotExistingIdentiferValidator as now they can be val…
…idated directly
63a611c
Commits on Jan 25, 2013
@panchenko validation/tests: variable used in for-in loop must be declared b8a2e45
Commits on Jan 28, 2013
@panchenko validation/API: TypeInfoValidator.runDelayedValidationsFor(references…
…...)
249e442
@jcompagner jcompagner forEach has an optional thisArg parameter 9772c29
Commits on Jan 29, 2013
@jcompagner jcompagner a little bit better doc for the forEach function e49d3fc
Showing with 809 additions and 466 deletions.
  1. +2 −1  plugins/org.eclipse.dltk.javascript.core/resources/native-references.xml
  2. +12 −7 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/AbstractReference.java
  3. +11 −3 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/AnonymousValue.java
  4. +31 −2 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ElementValue.java
  5. +14 −1 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/IValue.java
  6. +16 −4 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ImmutableValue.java
  7. +8 −50 .../org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ImmutableValueCollection.java
  8. +10 −29 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/LazyTypeReference.java
  9. +3 −1 ...ins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/NestedValueCollection.java
  10. +1 −1  plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/PhantomValue.java
  11. +2 −2 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TopValueThis.java
  12. +34 −0 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencer2.java
  13. +30 −17 ...ins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java
  14. +11 −2 ...org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitorBase.java
  15. +6 −2 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ValueCollection.java
  16. +4 −0 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/WithValueCollection.java
  17. +104 −52 ...org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/TypeInfoValidator.java
  18. +2 −0  plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinference/IValueParent.java
  19. +4 −0 ...s/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinference/PhantomValueReference.java
  20. +2 −1  .../org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinference/ValueCollectionFactory.java
  21. +33 −0 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/IRLocalType.java
  22. +8 −0 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/ITypeInfoContext.java
  23. +5 −2 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/JSDocTypeParser.java
  24. +92 −0 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RLocalType.java
  25. +10 −0 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RSimpleType.java
  26. +14 −1 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RTypes.java
  27. +9 −0 ...ns/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/model/impl/SimpleTypeImpl.java
  28. +1 −1  ...ipse.dltk.javascript.formatter/src/org/eclipse/dltk/javascript/formatter/internal/FormatterNodeBuilder.java
  29. +2 −1  plugins/org.eclipse.dltk.javascript.parser/META-INF/MANIFEST.MF
  30. +158 −259 plugins/org.eclipse.dltk.javascript.parser/src/org/eclipse/dltk/javascript/ast/ASTVisitor.java
  31. +8 −6 ... → org.eclipse.dltk.javascript.parser/src/org/eclipse/dltk/javascript/parser/util/CharStreamUtil.java}
  32. +49 −0 plugins/org.eclipse.dltk.javascript.parser/tools/generator.js
  33. +1 −0  plugins/org.eclipse.dltk.javascript.ui/templates/jsdoc-templates.properties
  34. +8 −0 plugins/org.eclipse.dltk.javascript.ui/templates/jsdoc-templates.xml
  35. +16 −4 ...pse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/contentassist/CodeCompletion.java
  36. +88 −17 ...tk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/validation/TypeInfoValidationTests.java
View
3  plugins/org.eclipse.dltk.javascript.core/resources/native-references.xml
@@ -204,8 +204,9 @@
<itemType xsi:type="ref:TypeVariableReference" variable="@ROOT/Array/E"/>
</type>
</members>
- <members xsi:type="ref:Method" name="forEach" description="Calls a function for each element in the array.">
+ <members xsi:type="ref:Method" name="forEach" description="Calls a function for each element in the array. The callback will be called with 3 arguments (elementValue,elementIndex,traversedArray). Optionally with a thisObject argument to use as this when executing callback.">
<parameters name="callback" directType="Function"/>
+ <parameters name="thisArg" kind="OPTIONAL"/>
</members>
<members xsi:type="ref:Method" name="indexOf" directType="Number" description="Returns the first index at which a given element can be found in the array, or -1 if it is not present.">
<parameters name="searchElement"/>
View
19 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/AbstractReference.java
@@ -15,9 +15,11 @@
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.dltk.internal.javascript.validation.JavaScriptValidations;
import org.eclipse.dltk.javascript.typeinference.IValueReference;
import org.eclipse.dltk.javascript.typeinference.ReferenceKind;
import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
+import org.eclipse.dltk.javascript.typeinfo.IRLocalType;
import org.eclipse.dltk.javascript.typeinfo.IRType;
import org.eclipse.dltk.javascript.typeinfo.JSTypeSet;
@@ -184,9 +186,13 @@ public boolean hasChild(String name) {
return value != null && value.getChild(name, true) != null;
}
- public Set<String> getDirectChildren() {
+ public final Set<String> getDirectChildren() {
+ return getDirectChildren(IValue.DEFAULT);
+ }
+
+ public Set<String> getDirectChildren(int flags) {
final IValue value = getValue();
- return value != null ? value.getDirectChildren() : Collections
+ return value != null ? value.getDirectChildren(flags) : Collections
.<String> emptySet();
}
@@ -244,11 +250,10 @@ public void resolve() {
if (!finalResolve && !typeResolved) {
typeResolved = true;
IValueReference parent = reference.getParent();
- while (parent instanceof IValueProvider) {
- value = ((IValueProvider) parent).getValue();
- if (value != null) {
- resolvedToType = !value.getTypes().isEmpty()
- || !value.getDeclaredTypes().isEmpty();
+ while (parent != null) {
+ IRType type = JavaScriptValidations.typeOf(parent);
+ if (type != null) {
+ resolvedToType = !(type instanceof IRLocalType);
break;
}
parent = parent.getParent();
View
14 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/AnonymousValue.java
@@ -15,19 +15,27 @@
public class AnonymousValue extends AbstractReference {
- private final Value value = new Value();
+ private final IValue value;
+
+ protected AnonymousValue(IValue value) {
+ this.value = value;
+ }
+
+ public AnonymousValue() {
+ this(new Value());
+ }
public boolean isReference() {
return false;
}
@Override
- public Value getValue() {
+ public IValue getValue() {
return value;
}
@Override
- public Value createValue() {
+ public IValue createValue() {
return getValue();
}
View
33 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ElementValue.java
@@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -33,6 +34,7 @@
import org.eclipse.dltk.javascript.typeinfo.IRClassType;
import org.eclipse.dltk.javascript.typeinfo.IRElement;
import org.eclipse.dltk.javascript.typeinfo.IRFunctionType;
+import org.eclipse.dltk.javascript.typeinfo.IRLocalType;
import org.eclipse.dltk.javascript.typeinfo.IRMapType;
import org.eclipse.dltk.javascript.typeinfo.IRMember;
import org.eclipse.dltk.javascript.typeinfo.IRMethod;
@@ -85,8 +87,7 @@ public boolean isExtensible() {
}
}
- static IValue findMemberA(ITypeSystem context, IRType type,
- String name,
+ static IValue findMemberA(ITypeSystem context, IRType type, String name,
boolean resolve) {
final MemberPredicate predicate;
if (type instanceof IRClassType) {
@@ -205,6 +206,15 @@ public static IValue findMember(ITypeSystem context, IRType type,
selection.toArray(new IRMember[selection.size()]));
}
}
+ } else if (type instanceof IRLocalType) {
+ final IValueReference child = ((IRLocalType) type)
+ .getDirectChild(name);
+ if (child != null) {
+ final IValue value = ((IValueProvider) child).getValue();
+ if (value != null)
+ return value;
+ }
+ return findMember(context, RTypes.OBJECT, name);
} else {
final IRTypeDeclaration t = TypeUtil.extractType(context, type);
if (t != null) {
@@ -344,6 +354,21 @@ public TypeValue(ITypeSystem context, JSTypeSet types) {
}
@Override
+ public final Set<String> getDirectChildren(int flags) {
+ if ((flags & NO_LOCAL_TYPES) == 0) {
+ final Set<String> set = new HashSet<String>();
+ for (IRType irType : getTypes()) {
+ if (irType instanceof IRLocalType) {
+ set.addAll(((IRLocalType) irType).getDirectChildren());
+ }
+ }
+ return set;
+ } else {
+ return Collections.emptySet();
+ }
+ }
+
+ @Override
protected Type[] getElements() {
return types.toArray();
}
@@ -943,6 +968,10 @@ public final void setAttribute(String key, Object value) {
}
public final Set<String> getDirectChildren() {
+ return getDirectChildren(IValue.DEFAULT);
+ }
+
+ public Set<String> getDirectChildren(int flags) {
return Collections.emptySet();
}
View
15 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/IValue.java
@@ -15,19 +15,32 @@
import org.eclipse.dltk.javascript.typeinference.ReferenceKind;
import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
+import org.eclipse.dltk.javascript.typeinfo.IRLocalType;
import org.eclipse.dltk.javascript.typeinfo.IRType;
import org.eclipse.dltk.javascript.typeinfo.JSTypeSet;
public interface IValue {
+ int DEFAULT = 0;
int CREATE = 1;
+ int NO_LOCAL_TYPES = 2;
boolean hasChild(String name);
- Set<String> getDirectChildren();
+ /**
+ * @param flags
+ * {@link #DEFAULT} or {@link #NO_LOCAL_TYPES} to skip delegation
+ * to children of {@link IRLocalType}.
+ */
+ Set<String> getDirectChildren(int flags);
IValue getChild(String name, boolean resolve);
+ /**
+ * @param flags
+ * {@link #DEFAULT} or {@link #CREATE} if child should be created
+ * without any attempts to find already existing type member.
+ */
IValue createChild(String name, int flags);
IRType getDeclaredType();
View
20 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ImmutableValue.java
@@ -11,6 +11,7 @@
import org.eclipse.dltk.javascript.typeinference.ReferenceKind;
import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
+import org.eclipse.dltk.javascript.typeinfo.IRLocalType;
import org.eclipse.dltk.javascript.typeinfo.IRType;
import org.eclipse.dltk.javascript.typeinfo.ITypeSystem;
import org.eclipse.dltk.javascript.typeinfo.JSTypeSet;
@@ -241,14 +242,25 @@ public void processOther(IValue value, Set<IValue> result) {
}
}
- public Set<String> getDirectChildren() {
+ public Set<String> getDirectChildren(int flags) {
+ final Set<String> result = new HashSet<String>();
if (hasReferences()) {
- final Set<String> result = new HashSet<String>();
execute(this, GET_DIRECT_CHILDREN, result, new HashSet<IValue>());
- return result;
} else {
- return children.keySet();
+ result.addAll(children.keySet());
+ }
+ if ((flags & NO_LOCAL_TYPES) == 0) {
+ if (getDeclaredType() instanceof IRLocalType) {
+ result.addAll(((IRLocalType) getDeclaredType())
+ .getDirectChildren());
+ }
+ for (IRType irType : getTypes()) {
+ if (irType instanceof IRLocalType) {
+ result.addAll(((IRLocalType) irType).getDirectChildren());
+ }
+ }
}
+ return result;
}
public Set<String> getDeletedChildren() {
View
58 ...g.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ImmutableValueCollection.java
@@ -64,9 +64,8 @@ public void init(boolean scope, boolean reference, IValueCollection parent,
this.reference = reference;
this.parent = parent;
this.value = value;
- this.thisValue = new ValueWrapper(thisValue);
- this.returnValue = new ValueWrapper(returnValue);
-
+ this.thisValue = new AnonymousValue(thisValue);
+ this.returnValue = new AnonymousValue(returnValue);
}
public boolean isReference() {
@@ -81,8 +80,12 @@ public IValue createValue() {
return getValue();
}
- public Set<String> getDirectChildren() {
- return value.getDirectChildren();
+ public final Set<String> getDirectChildren() {
+ return getDirectChildren(IValue.DEFAULT);
+ }
+
+ public Set<String> getDirectChildren(int flags) {
+ return value.getDirectChildren(flags);
}
public Set<String> getDeletedChildren() {
@@ -117,49 +120,4 @@ public IValueReference getReturnValue() {
public IValueReference getThis() {
return thisValue;
}
-
- public static class ValueWrapper extends AbstractReference {
-
- private final IValue value;
-
- ValueWrapper(IValue value) {
- this.value = value;
- }
-
- public boolean isReference() {
- return false;
- }
-
- @Override
- public IValue getValue() {
- return value;
- }
-
- @Override
- public IValue createValue() {
- return getValue();
- }
-
- public void delete(boolean force) {
- }
-
- public String getName() {
- return "";
- }
-
- public IValueReference getParent() {
- return null;
- }
-
- protected String getToStringPrefix() {
- return "AnonymousValue";
- }
-
- @Override
- public String toString() {
- return getToStringPrefix() + "@" + System.identityHashCode(value);
- }
-
- }
-
}
View
39 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/LazyTypeReference.java
@@ -3,7 +3,6 @@
import java.util.StringTokenizer;
import org.eclipse.dltk.internal.javascript.validation.JavaScriptValidations;
-import org.eclipse.dltk.javascript.core.Types;
import org.eclipse.dltk.javascript.typeinference.IValueCollection;
import org.eclipse.dltk.javascript.typeinference.IValueReference;
import org.eclipse.dltk.javascript.typeinference.ReferenceKind;
@@ -11,8 +10,6 @@
import org.eclipse.dltk.javascript.typeinfo.IRType;
import org.eclipse.dltk.javascript.typeinfo.RTypes;
import org.eclipse.dltk.javascript.typeinfo.model.Type;
-import org.eclipse.dltk.javascript.typeinfo.model.TypeInfoModelFactory;
-import org.eclipse.dltk.javascript.typeinfo.model.TypeKind;
public class LazyTypeReference extends AbstractReference {
@@ -47,26 +44,16 @@ private void doResolve() {
IValueCollection collection = (IValueCollection) createChild
.getAttribute(IReferenceAttributes.FUNCTION_SCOPE);
if (collection != null && collection.getThis() != null) {
- createChild = collection.getThis();
- }
-
- IValue src = ((IValueProvider) createChild).getValue();
- // if i enable this then the type added below takes
- // precedance some time
- // for example a toString() on a javasccript object will
- // then return the toString of Object
- // if (src instanceof Value) {
- // this.references.add((Value) src);
- // } else
- if (src != null) {
- addValue(src);
+ addValue(((IValueProvider) collection.getThis()).getValue());
+ } else {
+ IValue src = ((IValueProvider) createChild).getValue();
+ if (src != null) {
+ addValue(src);
+ }
}
setKind(ReferenceKind.TYPE);
- Type type = TypeInfoModelFactory.eINSTANCE.createType();
- type.setSuperType(Types.OBJECT);
- type.setKind(TypeKind.JAVASCRIPT);
- type.setName(className);
- setDeclaredType(RTypes.simple(context, type));
+ setDeclaredType(RTypes.localType(context, className,
+ createChild));
resolved = true;
} else if (className.indexOf('.') != -1) {
StringTokenizer st = new StringTokenizer(className, ".");
@@ -97,14 +84,8 @@ private void doResolve() {
.getValue());
else
addValue(src);
- // also set it as a declared type, because
- // LazyTypeReference is used to evaluate jsdoc type
- // tags, which should be set as a declared type.
- Type type = TypeInfoModelFactory.eINSTANCE.createType();
- type.setSuperType(Types.OBJECT);
- type.setKind(TypeKind.JAVASCRIPT);
- type.setName(className);
- setDeclaredType(RTypes.simple(context, type));
+ setDeclaredType(RTypes.localType(context, className,
+ child));
}
setKind(ReferenceKind.TYPE);
resolved = true;
View
4 .../org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/NestedValueCollection.java
@@ -52,11 +52,13 @@ public boolean equals(Object obj) {
public int hashCode() {
return getParent().hashCode();
}
+
protected static void mergeTo(IValueCollection parent,
final List<NestedValueCollection> collections) {
final Set<String> names = new HashSet<String>();
for (NestedValueCollection collection : collections) {
- names.addAll(collection.getValue().getDirectChildren());
+ names.addAll(collection.getValue()
+ .getDirectChildren(IValue.DEFAULT));
}
List<IValueReference> childValues = new ArrayList<IValueReference>();
for (String childName : names) {
View
2  plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/PhantomValue.java
@@ -26,7 +26,7 @@ public boolean hasChild(String name) {
return false;
}
- public Set<String> getDirectChildren() {
+ public Set<String> getDirectChildren(int flags) {
return Collections.emptySet();
}
View
4 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TopValueThis.java
@@ -28,8 +28,8 @@ public TopValueThis(TopValueCollection collection) {
}
@Override
- public Set<String> getDirectChildren() {
- return owner.getDirectChildren();
+ public Set<String> getDirectChildren(int flags) {
+ return owner.getDirectChildren(flags);
}
@Override
View
34 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencer2.java
@@ -29,6 +29,7 @@
import org.eclipse.dltk.javascript.parser.JSProblem;
import org.eclipse.dltk.javascript.parser.JSProblemReporter;
import org.eclipse.dltk.javascript.typeinference.IValueCollection;
+import org.eclipse.dltk.javascript.typeinference.IValueParent;
import org.eclipse.dltk.javascript.typeinference.IValueReference;
import org.eclipse.dltk.javascript.typeinference.ReferenceKind;
import org.eclipse.dltk.javascript.typeinfo.AttributeKey;
@@ -36,6 +37,7 @@
import org.eclipse.dltk.javascript.typeinfo.ILocalTypeReference;
import org.eclipse.dltk.javascript.typeinfo.IMemberEvaluator;
import org.eclipse.dltk.javascript.typeinfo.IModelBuilder;
+import org.eclipse.dltk.javascript.typeinfo.IRLocalType;
import org.eclipse.dltk.javascript.typeinfo.IRMember;
import org.eclipse.dltk.javascript.typeinfo.IRType;
import org.eclipse.dltk.javascript.typeinfo.IRTypeDeclaration;
@@ -114,6 +116,8 @@ public void doInferencing(Script script) {
} catch (PositionReachedException e) {
// visitor = null;
throw e;
+ } catch (TypeInferencerVisitorBase.TIWrappedException e) {
+ log(e.getCause());
} catch (RuntimeException e) {
log(e);
} catch (AssertionError e) {
@@ -705,4 +709,34 @@ public IRType contextualize(JSType type) {
return null;
}
}
+
+ public IRLocalType resolveLocalType(String name) {
+ if (visitor == null)
+ return null;
+ IValueReference result = null;
+ IValueCollection currentCollection = currentCollection();
+ if (name.indexOf('.') != -1) {
+ String[] scopes = name.split("\\.");
+ IValueParent child = currentCollection;
+ for (String scope : scopes) {
+ child = child.getChild(scope);
+ }
+ result = (IValueReference) child;
+ } else {
+ while (currentCollection != null) {
+ IValueReference child = currentCollection.getChild(name);
+ if (child.exists()) {
+ result = child;
+ break;
+ } else {
+ currentCollection = currentCollection.getParent();
+ }
+
+ }
+ }
+ if (result != null && result.getKind() == ReferenceKind.FUNCTION) {
+ return RTypes.localType(this, name, result);
+ }
+ return null;
+ }
}
View
47 .../org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java
@@ -92,7 +92,6 @@
import org.eclipse.dltk.javascript.ast.YieldOperator;
import org.eclipse.dltk.javascript.core.JavaScriptPlugin;
import org.eclipse.dltk.javascript.core.JavaScriptProblems;
-import org.eclipse.dltk.javascript.core.Types;
import org.eclipse.dltk.javascript.internal.core.RRecordMember;
import org.eclipse.dltk.javascript.parser.ISuppressWarningsState;
import org.eclipse.dltk.javascript.parser.JSParser;
@@ -113,6 +112,7 @@
import org.eclipse.dltk.javascript.typeinfo.IModelBuilder;
import org.eclipse.dltk.javascript.typeinfo.IModelBuilder.IMethod;
import org.eclipse.dltk.javascript.typeinfo.IModelBuilder.IParameter;
+import org.eclipse.dltk.javascript.typeinfo.IModelBuilder.IVariable;
import org.eclipse.dltk.javascript.typeinfo.IModelBuilderExtension;
import org.eclipse.dltk.javascript.typeinfo.IRArrayType;
import org.eclipse.dltk.javascript.typeinfo.IRClassType;
@@ -142,7 +142,6 @@
import org.eclipse.dltk.javascript.typeinfo.model.Parameter;
import org.eclipse.dltk.javascript.typeinfo.model.ParameterizedType;
import org.eclipse.dltk.javascript.typeinfo.model.Type;
-import org.eclipse.dltk.javascript.typeinfo.model.TypeInfoModelFactory;
import org.eclipse.dltk.javascript.typeinfo.model.TypeKind;
import org.eclipse.dltk.javascript.typeinfo.model.TypeVariableClassType;
import org.eclipse.dltk.javascript.typeinfo.model.TypeVariableReference;
@@ -633,13 +632,6 @@ protected IValueReference createVariable(IValueCollection context,
reference.setLocation(ReferenceLocation.create(getSource(),
declaration.sourceStart(), declaration.sourceEnd(),
identifier.sourceStart(), identifier.sourceEnd()));
- final IRVariable rvar = RModelBuilder.create(getContext(), variable);
- reference.setAttribute(IReferenceAttributes.R_VARIABLE, rvar);
- if (rvar.getType() != null) {
- setIRType(reference, rvar.getType(), true);
- // typed - make sure it wasn't initialized with the phantom value.
- reference.removeReference(PhantomValueReference.REFERENCE);
- }
return reference;
}
@@ -661,6 +653,10 @@ protected void initializeVariable(final IValueReference reference,
if (variable.getType() == null) {
// assign only if no declared type specified
assign(reference, assignment);
+ } else {
+ // else just add it as a value on top of what we already
+ // have. So that we don't clear the current one.
+ reference.addValue(assignment, false);
}
if (assignment.getKind() == ReferenceKind.FUNCTION
&& reference.getAttribute(IReferenceAttributes.METHOD) != null)
@@ -773,8 +769,6 @@ private void initializeFunction(JSMethod method, IValueReference function) {
function.setKind(ReferenceKind.FUNCTION);
function.setDeclaredType(RTypes.FUNCTION);
function.setAttribute(IReferenceAttributes.METHOD, method);
- function.setAttribute(IReferenceAttributes.R_METHOD,
- RModelBuilder.create(getContext(), method));
function.setAttribute(IReferenceAttributes.RESOLVING, Boolean.TRUE);
}
@@ -791,6 +785,8 @@ public IValueReference visitFunctionStatement(FunctionStatement node) {
method = createMethod(node);
result = new AnonymousValue();
initializeFunction(method, result);
+ result.setAttribute(IReferenceAttributes.R_METHOD,
+ RModelBuilder.create(getContext(), method));
}
final ThisValue thisValue = new ThisValue();
thisValue.setDeclaredType(this.context.contextualize(method
@@ -1078,12 +1074,8 @@ protected VisitNewResult visitNew(NewExpression node) {
String className = PropertyExpressionUtils
.getPath(objectClass);
if (className != null) {
- Type type = TypeInfoModelFactory.eINSTANCE.createType();
- type.setSuperType(Types.OBJECT);
- type.setKind(TypeKind.JAVASCRIPT);
- type.setName(className);
- result.value.setDeclaredType(RTypes.simple(context,
- type));
+ result.value.setDeclaredType(RTypes.localType(context,
+ className, result.typeValue));
} else {
result.value.setDeclaredType(RTypes.OBJECT);
}
@@ -1321,6 +1313,7 @@ public IValueReference visitScript(Script node) {
}
private void handleDeclarations(JSScope scope) {
+ ArrayList<IValueReference> variables = new ArrayList<IValueReference>();
final IValueCollection context = peekContext();
for (JSDeclaration declaration : scope.getDeclarations()) {
if (declaration instanceof FunctionStatement) {
@@ -1339,8 +1332,28 @@ private void handleDeclarations(JSScope scope) {
if (varDeclaration.getParent() instanceof ConstStatement) {
var.setAttribute(IAssignProtection.ATTRIBUTE, PROTECT_CONST);
}
+ variables.add(var);
+ }
+ }
+ for (ForwardDeclaration decl : forwardDeclarations.values()) {
+ decl.reference.setAttribute(IReferenceAttributes.R_METHOD,
+ RModelBuilder.create(getContext(), decl.method));
+ }
+
+ for (IValueReference reference : variables) {
+ final IRVariable rvar = RModelBuilder.create(getContext(),
+ (IVariable) reference
+ .getAttribute(IReferenceAttributes.VARIABLE));
+ reference.setAttribute(IReferenceAttributes.R_VARIABLE, rvar);
+ if (rvar.getType() != null) {
+ setIRType(reference, rvar.getType(), true);
+ // typed - make sure it wasn't initialized with the phantom
+ // value.
+ reference.removeReference(PhantomValueReference.REFERENCE);
}
+
}
+
}
@Override
View
13 ....eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitorBase.java
@@ -118,12 +118,21 @@ public IValueReference visit(ASTNode node) {
return super.visit(node);
} catch (PositionReachedException e) {
throw e;
+ } catch (TIWrappedException e) {
+ throw e;
} catch (RuntimeException e) {
JavaScriptPlugin.error(buildNodeErrorMessage(node), e);
- throw e;
+ throw new TIWrappedException(e);
} catch (AssertionError e) {
JavaScriptPlugin.error(buildNodeErrorMessage(node), e);
- throw e;
+ throw new TIWrappedException(e);
+ }
+ }
+
+ @SuppressWarnings("serial")
+ static class TIWrappedException extends RuntimeException {
+ public TIWrappedException(Throwable cause) {
+ super(cause);
}
}
View
8 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ValueCollection.java
@@ -56,8 +56,12 @@ public IValue createValue() {
return getValue();
}
- public Set<String> getDirectChildren() {
- return value.getDirectChildren();
+ public final Set<String> getDirectChildren() {
+ return getDirectChildren(IValue.DEFAULT);
+ }
+
+ public Set<String> getDirectChildren(int options) {
+ return value.getDirectChildren(options);
}
public Set<String> getDeletedChildren() {
View
4 ...ns/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/WithValueCollection.java
@@ -43,6 +43,10 @@ public IValueReference getThis() {
return with.getDirectChildren();
}
+ public Set<String> getDirectChildren(int flags) {
+ return with.getDirectChildren(flags);
+ }
+
public Set<String> getDeletedChildren() {
return with.getDeletedChildren();
}
View
156 ....eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/TypeInfoValidator.java
@@ -15,12 +15,15 @@
import static org.eclipse.dltk.internal.javascript.ti.IReferenceAttributes.R_METHOD;
import static org.eclipse.dltk.internal.javascript.validation.JavaScriptValidations.typeOf;
import static org.eclipse.dltk.javascript.typeinfo.RUtils.locationOf;
+import static org.eclipse.osgi.util.NLS.bind;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -243,6 +246,10 @@ public ISuppressWarningsState getSuppressed() {
public void setSuppressed(ISuppressWarningsState suppressed) {
this.suppressed = suppressed;
}
+
+ public boolean isRelatedTo(IValueReference reference) {
+ return false;
+ }
}
private static class CallExpressionValidator extends ExpressionValidator {
@@ -267,6 +274,16 @@ public void call(ValidationVisitor visitor) {
visitor.validateCallExpression(scope, node, reference, arguments,
methods);
}
+
+ @Override
+ public boolean isRelatedTo(IValueReference reference) {
+ return reference.isParentOf(this.reference);
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " - " + reference + "()";
+ }
}
private static class ReturnNode {
@@ -377,24 +394,10 @@ public void call(ValidationVisitor visitor) {
}
}
}
- }
-
- private static class NotExistingIdentiferValidator extends
- ExpressionValidator {
- private final FunctionScope scope;
- private final Expression identifer;
- private final IValueReference reference;
-
- public NotExistingIdentiferValidator(FunctionScope scope,
- Expression identifer, IValueReference reference) {
- this.scope = scope;
- this.identifer = identifer;
- this.reference = reference;
- }
@Override
- public void call(ValidationVisitor visitor) {
- visitor.validate(scope, identifer, reference);
+ public String toString() {
+ return getClass().getSimpleName() + " - " + jsMethod.getName();
}
}
@@ -423,6 +426,10 @@ public void call(ValidationVisitor visitor) {
node.getObjectClass(), reference, typeReference, arguments);
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " - " + reference;
+ }
}
private static class PropertyExpressionHolder extends ExpressionValidator {
@@ -444,6 +451,11 @@ public PropertyExpressionHolder(FunctionScope scope,
public void call(ValidationVisitor visitor) {
visitor.validateProperty(scope, node, reference, exists);
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " - " + reference;
+ }
}
static class FunctionScope {
@@ -599,16 +611,48 @@ public void done() {
* Executes all the delayed validations collected so far.
*/
public void runDelayedValidations() {
+ if (expressionValidators.isEmpty()) {
+ return;
+ }
+ final ExpressionValidator[] copy = expressionValidators
+ .toArray(new ExpressionValidator[expressionValidators
+ .size()]);
+ expressionValidators.clear();
+ runExpressionValidations(Arrays.asList(copy));
+ }
+
+ /**
+ * Executes the delayed validations for the specified references.
+ */
+ public void runDelayedValidationsFor(IValueReference... references) {
+ if (expressionValidators.isEmpty() || references.length == 0) {
+ return;
+ }
+ final List<ExpressionValidator> selected = new ArrayList<ExpressionValidator>();
+ for (Iterator<ExpressionValidator> i = expressionValidators
+ .iterator(); i.hasNext();) {
+ final ExpressionValidator validator = i.next();
+ for (IValueReference reference : references) {
+ if (validator.isRelatedTo(reference)) {
+ selected.add(validator);
+ i.remove();
+ break;
+ }
+ }
+ }
+ if (!selected.isEmpty()) {
+ runExpressionValidations(selected);
+ }
+ }
+
+ private void runExpressionValidations(
+ Iterable<ExpressionValidator> validators) {
final ISuppressWarningsState suppressWarnings = reporter
.getSuppressWarnings();
try {
- final ExpressionValidator[] copy = expressionValidators
- .toArray(new ExpressionValidator[expressionValidators
- .size()]);
- expressionValidators.clear();
- for (ExpressionValidator call : copy) {
- reporter.restoreSuppressWarnings(call.getSuppressed());
- call.call(this);
+ for (ExpressionValidator validator : validators) {
+ reporter.restoreSuppressWarnings(validator.getSuppressed());
+ validator.call(this);
}
} finally {
reporter.restoreSuppressWarnings(suppressWarnings);
@@ -990,15 +1034,15 @@ protected void validateCallExpression(FunctionScope scope,
}
final Object attrRMethod = reference.getAttribute(R_METHOD, true);
if (attrRMethod instanceof IRMethod) {
- validateCallExpressionRMethod(node, reference, arguments,
- methodNode, (IRMethod) attrRMethod);
+ validateCallExpressionRMethod(reference, arguments, methodNode,
+ (IRMethod) attrRMethod);
return;
}
final IRType expressionType = JavaScriptValidations
.typeOf(reference);
if (expressionType != null) {
if (expressionType instanceof IRFunctionType) {
- validateCallExpressionRMethod(node, reference, arguments,
+ validateCallExpressionRMethod(reference, arguments,
methodNode, new RMethodFunctionWrapper(
(IRFunctionType) expressionType));
return;
@@ -1114,7 +1158,7 @@ protected void validateCallExpression(FunctionScope scope,
}
}
- private void validateCallExpressionRMethod(CallExpression node,
+ private void validateCallExpressionRMethod(
final IValueReference reference, IValueReference[] arguments,
final Expression methodNode, IRMethod method) {
if (method.isDeprecated()) {
@@ -1313,8 +1357,6 @@ private TypeCompatibility validateParameters(
TypeCompatibility result = TypeCompatibility.TRUE;
for (int i = 0; i < testTypesSize; i++) {
final IValueReference argument = arguments[i];
- final IRType argumentType = JavaScriptValidations
- .typeOf(argument);
final IRParameter parameter = parameters.get(i);
if (parameter.getType() instanceof IRTypeExtension) {
final IValidationStatus status = ((IRTypeExtension) parameter
@@ -1559,17 +1601,6 @@ protected boolean validate(FunctionScope scope, Expression expr,
final IValueReference parent = reference.getParent();
if (parent == null) {
// top level
- if (expr instanceof Identifier && !reference.exists()) {
- scope.add(path(expr, reference));
- reporter.reportProblem(
- JavaScriptProblems.UNDECLARED_VARIABLE, NLS.bind(
- ValidationMessages.UndeclaredVariable,
- reference.getName()), expr.sourceStart(),
- expr.sourceEnd());
- return false;
- } else
- validateAccessibility(expr, reference, null);
-
} else if (expr instanceof PropertyExpression
&& validate(scope, ((PropertyExpression) expr).getObject(),
parent)) {
@@ -1633,8 +1664,12 @@ public IValueReference visitIdentifier(Identifier node) {
reportDeprecatedProperty(property, null, node);
} else {
if (!result.exists() && !isParentCallOrNew(node)) {
- pushExpressionValidator(new NotExistingIdentiferValidator(
- peekFunctionScope(), node, result));
+ peekFunctionScope().add(path(node, result));
+ reporter.reportProblem(
+ JavaScriptProblems.UNDECLARED_VARIABLE, NLS.bind(
+ ValidationMessages.UndeclaredVariable,
+ node.getName()), node.sourceStart(), node
+ .sourceEnd());
} else {
validateAccessibility(node, result, null);
if (result.exists()
@@ -2118,12 +2153,23 @@ protected void validateNewExpression(FunctionScope scope,
}
}
} else {
- final String lazyName = ValueReferenceUtil
- .getLazyName(reference);
- if (lazyName != null) {
- reportUnknownType(JavaScriptProblems.WRONG_TYPE_EXPRESSION,
- ValidationMessages.UndefinedJavascriptType, node,
- lazyName);
+ if (typeReference.getKind() == ReferenceKind.FUNCTION) {
+ final Object attrRMethod = typeReference.getAttribute(
+ R_METHOD, true);
+ if (attrRMethod instanceof IRMethod) {
+ validateCallExpressionRMethod(reference, arguments,
+ problemNode, (IRMethod) attrRMethod);
+ return;
+ }
+ } else {
+ final String lazyName = ValueReferenceUtil
+ .getLazyName(reference);
+ if (lazyName != null) {
+ reportProblem(
+ JavaScriptProblems.WRONG_TYPE_EXPRESSION,
+ bind(ValidationMessages.UndefinedJavascriptType,
+ lazyName), node);
+ }
}
}
}
@@ -2268,16 +2314,22 @@ private void validateAccessibility(Expression expression,
}
}
+ @Deprecated
public void reportUnknownType(IProblemIdentifier identifier,
String message, ASTNode node, String name) {
- reporter.reportProblem(identifier, NLS.bind(message, name),
- node.sourceStart(), node.sourceEnd());
+ reportProblem(identifier, NLS.bind(message, name), node);
}
public void reportUnknownType(IProblemIdentifier identifier,
ASTNode node, String name) {
- reportUnknownType(identifier, ValidationMessages.UnknownType, node,
- name);
+ reportProblem(identifier,
+ bind(ValidationMessages.UnknownType, name), node);
+ }
+
+ public void reportProblem(IProblemIdentifier identifier,
+ String message, ISourceNode node) {
+ reporter.reportProblem(identifier, message, node.start(),
+ node.end());
}
private static boolean stronglyTyped(IValueReference reference) {
View
2  plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinference/IValueParent.java
@@ -17,6 +17,8 @@
Set<String> getDirectChildren();
+ Set<String> getDirectChildren(int flags);
+
Set<String> getDeletedChildren();
boolean hasChild(String name);
View
4 ...rg.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinference/PhantomValueReference.java
@@ -29,6 +29,10 @@
return Collections.emptySet();
}
+ public Set<String> getDirectChildren(int options) {
+ return Collections.emptySet();
+ }
+
public Set<String> getDeletedChildren() {
return Collections.emptySet();
}
View
3  ...g.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinference/ValueCollectionFactory.java
@@ -124,7 +124,8 @@ public static void copyInto(IValueCollection target, IValueCollection source) {
IValue sourceValue = ((IValueProvider) source).getValue();
if (targetValue instanceof Value
&& sourceValue instanceof ImmutableValue) {
- Set<String> children = sourceValue.getDirectChildren();
+ Set<String> children = sourceValue
+ .getDirectChildren(IValue.DEFAULT);
for (String childName : children) {
((Value) targetValue).putDirectChild(childName,
(ImmutableValue) sourceValue.getChild(childName,
View
33 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/IRLocalType.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Servoy
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Servoy - initial API and Implementation (Johan Compagner)
+ *******************************************************************************/
+package org.eclipse.dltk.javascript.typeinfo;
+
+import java.util.Set;
+
+import org.eclipse.dltk.annotations.Nullable;
+import org.eclipse.dltk.javascript.typeinference.IValueReference;
+import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
+
+/**
+ * @author jcompagner
+ */
+public interface IRLocalType extends IRType, IRTypeExtension {
+ public IValueReference getValue();
+
+ @Nullable
+ public IValueReference getDirectChild(String name);
+
+ public ReferenceLocation getReferenceLocation();
+
+ public Set<String> getDirectChildren();
+
+}
View
8 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/ITypeInfoContext.java
@@ -123,4 +123,12 @@
* the value of {@link #CONTEXTUALIZE_WITH} attribute.
*/
IRType contextualize(JSType type);
+
+ /**
+ * looks if it can generate an IValue type from the given JSType
+ *
+ * @param type
+ * @return
+ */
+ IRLocalType resolveLocalType(String name);
}
View
7 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/JSDocTypeParser.java
@@ -11,6 +11,9 @@
*******************************************************************************/
package org.eclipse.dltk.javascript.typeinfo;
+import static org.eclipse.dltk.javascript.parser.util.CharStreamUtil.match;
+import static org.eclipse.dltk.javascript.parser.util.CharStreamUtil.skipSpaces;
+
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@@ -34,7 +37,7 @@
import org.eclipse.emf.common.util.EList;
import org.eclipse.osgi.util.NLS;
-public class JSDocTypeParser extends JSDocTypeParserBase {
+public class JSDocTypeParser {
public static final String FUNCTION = "function";
public static final String CLASS = "Class";
@@ -85,7 +88,7 @@ public JSType parse(String input) throws ParseException {
* declaration should be enclosed in parenthesis -
* <code>'('</code> and <code>')'</code>.
*/
- protected JSType parse(CharStream input, boolean autoUnion)
+ public JSType parse(CharStream input, boolean autoUnion)
throws ParseException {
skipSpaces(input);
final List<JSType> types = new ArrayList<JSType>();
View
92 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RLocalType.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Servoy
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Servoy - initial API and Implementation (Johan Compagner)
+ *******************************************************************************/
+package org.eclipse.dltk.javascript.typeinfo;
+
+import java.util.Set;
+
+import org.eclipse.dltk.compiler.problem.IValidationStatus;
+import org.eclipse.dltk.internal.javascript.ti.IReferenceAttributes;
+import org.eclipse.dltk.internal.javascript.ti.IValue;
+import org.eclipse.dltk.internal.javascript.validation.JavaScriptValidations;
+import org.eclipse.dltk.javascript.typeinference.IValueCollection;
+import org.eclipse.dltk.javascript.typeinference.IValueReference;
+import org.eclipse.dltk.javascript.typeinference.PhantomValueReference;
+import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
+
+/**
+ * @author jcompagner
+ */
+class RLocalType extends RType implements IRLocalType {
+
+ private final IValueReference functionValue;
+ private final String name;
+
+ RLocalType(ITypeSystem typeSystem, String name,
+ IValueReference functionValue) {
+ super(typeSystem);
+ this.name = name;
+ this.functionValue = functionValue;
+ }
+
+ public IValueReference getValue() {
+ IValueCollection value = (IValueCollection) functionValue.getAttribute(
+ IReferenceAttributes.FUNCTION_SCOPE, false);
+ if (value != null) {
+ return value.getThis();
+ }
+ // backup value, target is not known to be a function.
+ return PhantomValueReference.REFERENCE;
+ }
+
+ public IValueReference getDirectChild(String name) {
+ final IValueReference value = getValue();
+ return value.getDirectChildren(IValue.NO_LOCAL_TYPES).contains(name) ? value
+ .getChild(name) : null;
+ }
+
+ public Set<String> getDirectChildren() {
+ return getValue().getDirectChildren(IValue.NO_LOCAL_TYPES);
+ }
+
+ public ReferenceLocation getReferenceLocation() {
+ return functionValue.getLocation();
+ }
+
+ @Override
+ public TypeCompatibility isAssignableFrom(IRType type) {
+ if (type instanceof IRLocalType) {
+ if (getReferenceLocation().equals(
+ ((IRLocalType) type).getReferenceLocation())) {
+ return TypeCompatibility.TRUE;
+ }
+ }
+ return super.isAssignableFrom(type);
+ }
+
+ public IValidationStatus isAssignableFrom(IValueReference argument) {
+ Set<IRType> types = JavaScriptValidations.getTypes(argument);
+ for (IRType irType : types) {
+ if (irType instanceof IRLocalType) {
+ if (getReferenceLocation().equals(
+ ((IRLocalType) irType).getReferenceLocation())) {
+ return TypeCompatibility.TRUE;
+ }
+ }
+ }
+ return TypeCompatibility.FALSE;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}
View
10 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RSimpleType.java
@@ -86,6 +86,16 @@ public TypeCompatibility isAssignableFrom(IRType type) {
final IRTypeDeclaration other = ((RSimpleType) type)
.getDeclaration();
return declaration.isAssignableFrom(other);
+ } else if (type instanceof IRLocalType
+ && getTarget().getKind() == TypeKind.UNKNOWN
+ && type.getName().equals(getName())) {
+ // if this RSimpleType was a result of an IRIValueType not being
+ // able to be resolved.
+ // just make this assignable if this type is unknown and has the
+ // same name..
+ // this happens when you have something like @return {init.Node} as
+ // function doc, and that Node is not there yet.
+ return TypeCompatibility.TRUE;
}
return testAssignableTo(type);
}
View
15 plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RTypes.java
@@ -275,7 +275,15 @@ public static IRRecordType recordType(Collection<IRRecordMember> members) {
public static IRRecordType recordType(@Nullable IValueReference argument) {
if (argument != null) {
final Set<String> directChildren = argument.getDirectChildren();
- final IRType type = JavaScriptValidations.typeOf(argument);
+ IRType type = JavaScriptValidations.typeOf(argument);
+ if (type instanceof IRUnionType) {
+ for (IRType unionTarget : ((IRUnionType) type).getTargets()) {
+ if (unionTarget instanceof IRRecordType) {
+ type = unionTarget;
+ break;
+ }
+ }
+ }
if (type instanceof IRRecordType) {
if (directChildren.isEmpty()) {
return (IRRecordType) type;
@@ -357,6 +365,11 @@ public static IRArrayType arrayOf(ITypeSystem typeSystem,
return new RArrayType(typeSystem, itemType);
}
+ public static IRLocalType localType(ITypeSystem typeSystem, String name,
+ IValueReference value) {
+ return new RLocalType(typeSystem, name, value);
+ }
+
@Deprecated
public static IRType create(JSType type) {
ITypeSystem current = ITypeSystem.CURRENT.get();
View
9 ...org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/model/impl/SimpleTypeImpl.java
@@ -11,13 +11,16 @@
*/
package org.eclipse.dltk.javascript.typeinfo.model.impl;
+import org.eclipse.dltk.javascript.typeinfo.IRLocalType;
import org.eclipse.dltk.javascript.typeinfo.IRType;
+import org.eclipse.dltk.javascript.typeinfo.ITypeInfoContext;
import org.eclipse.dltk.javascript.typeinfo.ITypeSystem;
import org.eclipse.dltk.javascript.typeinfo.RTypes;
import org.eclipse.dltk.javascript.typeinfo.TypeUtil;
import org.eclipse.dltk.javascript.typeinfo.model.SimpleType;
import org.eclipse.dltk.javascript.typeinfo.model.Type;
import org.eclipse.dltk.javascript.typeinfo.model.TypeInfoModelPackage;
+import org.eclipse.dltk.javascript.typeinfo.model.TypeKind;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
@@ -131,6 +134,12 @@ public IRType toRType(ITypeSystem typeSystem) {
if (t.isProxy() && typeSystem != null) {
t = typeSystem.resolveType(t);
}
+ if (typeSystem instanceof ITypeInfoContext
+ && t.getKind() == TypeKind.UNKNOWN) {
+ IRLocalType valueType = ((ITypeInfoContext) typeSystem).resolveLocalType(t.getName());
+ if (valueType != null)
+ return valueType;
+ }
return RTypes.simple(typeSystem, t);
}
View
2  ...e.dltk.javascript.formatter/src/org/eclipse/dltk/javascript/formatter/internal/FormatterNodeBuilder.java
@@ -729,7 +729,7 @@ public IFormatterNode visitFunctionStatement(FunctionStatement node) {
|| isEmptyBody(node.getBody());
IBracesConfiguration bodyConfiguration;
- if (node.getName() != null)
+ if (node.isDeclaration())
bodyConfiguration = new FunctionBodyBracesConfiguration(
document, emptyBody);
else
View
3  plugins/org.eclipse.dltk.javascript.parser/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.dltk.javascript.ast,
org.eclipse.dltk.javascript.parser,
- org.eclipse.dltk.javascript.parser.jsdoc
+ org.eclipse.dltk.javascript.parser.jsdoc,
+ org.eclipse.dltk.javascript.parser.util
Bundle-Localization: plugin
Bundle-Vendor: %pluginProvider
Bundle-Activator: org.eclipse.dltk.javascript.parser.JavaScriptParserPlugin
View
417 plugins/org.eclipse.dltk.javascript.parser/src/org/eclipse/dltk/javascript/ast/ASTVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 xored software, Inc.
+ * Copyright (c) 2009-2013 xored software, Inc and NumberFour AG.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* xored software, Inc. - initial API and Implementation (Vladimir Belov)
+ * NumberFour AG - multiple API improvements (Alex Panchenko)
*******************************************************************************/
package org.eclipse.dltk.javascript.ast;
@@ -33,279 +34,177 @@ protected void visitList(Collection<? extends ASTNode> nodes) {
}
}
- private static interface Handler {
- <E> E handle(ASTVisitor<E> visitor, ASTNode node);
- }
-
- private static final Map<Class<? extends ASTNode>, Handler> HANDLERS = new HashMap<Class<? extends ASTNode>, Handler>();
+ private static final Map<Class<? extends ASTNode>, Integer> HANDLERS = new HashMap<Class<? extends ASTNode>, Integer>();
+ // generated block
static {
- HANDLERS.put(ArrayInitializer.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitArrayInitializer((ArrayInitializer) node);
- }
- });
- HANDLERS.put(BinaryOperation.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitBinaryOperation((BinaryOperation) node);
- }
- });
- HANDLERS.put(BooleanLiteral.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitBooleanLiteral((BooleanLiteral) node);
- }
- });
- HANDLERS.put(BreakStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitBreakStatement((BreakStatement) node);
- }
- });
- HANDLERS.put(CallExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitCallExpression((CallExpression) node);
- }
- });
- HANDLERS.put(CommaExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitCommaExpression((CommaExpression) node);
- }
- });
- HANDLERS.put(ConditionalOperator.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitConditionalOperator((ConditionalOperator) node);
- }
- });
- HANDLERS.put(ConstStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitConstDeclaration((ConstStatement) node);
- }
- });
- HANDLERS.put(ContinueStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitContinueStatement((ContinueStatement) node);
- }
- });
- HANDLERS.put(DecimalLiteral.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitDecimalLiteral((DecimalLiteral) node);
- }
- });
- HANDLERS.put(DoWhileStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitDoWhileStatement((DoWhileStatement) node);
- }
- });
- HANDLERS.put(EmptyExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitEmptyExpression((EmptyExpression) node);
- }
- });
- HANDLERS.put(ForStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitForStatement((ForStatement) node);
- }
- });
- HANDLERS.put(Script.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitScript((Script) node);
- }
- });
- HANDLERS.put(ForInStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitForInStatement((ForInStatement) node);
- }
- });
- HANDLERS.put(ForEachInStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitForEachInStatement((ForEachInStatement) node);
- }
- });
- HANDLERS.put(FunctionStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitFunctionStatement((FunctionStatement) node);
- }
- });
- HANDLERS.put(Identifier.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitIdentifier((Identifier) node);
- }
- });
- HANDLERS.put(IfStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitIfStatement((IfStatement) node);
- }
- });
- HANDLERS.put(NewExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitNewExpression((NewExpression) node);
- }
- });
- HANDLERS.put(NullExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitNullExpression((NullExpression) node);
- }
- });
- HANDLERS.put(ObjectInitializer.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitObjectInitializer((ObjectInitializer) node);
- }
- });
- HANDLERS.put(ParenthesizedExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitParenthesizedExpression((ParenthesizedExpression) node);
- }
- });
- HANDLERS.put(RegExpLiteral.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitRegExpLiteral((RegExpLiteral) node);
- }
- });
- HANDLERS.put(ReturnStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitReturnStatement((ReturnStatement) node);
- }
- });
- HANDLERS.put(StringLiteral.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitStringLiteral((StringLiteral) node);
- }
- });
- HANDLERS.put(SwitchStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitSwitchStatement((SwitchStatement) node);
- }
- });
- HANDLERS.put(ThrowStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitThrowStatement((ThrowStatement) node);
- }
- });
- HANDLERS.put(GetArrayItemExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitGetArrayItemExpression((GetArrayItemExpression) node);
- }
- });
- HANDLERS.put(LabelledStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitLabelledStatement((LabelledStatement) node);
- }
- });
- HANDLERS.put(PropertyExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitPropertyExpression((PropertyExpression) node);
- }
- });
- HANDLERS.put(StatementBlock.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitStatementBlock((StatementBlock) node);
- }
- });
- HANDLERS.put(ThisExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitThisExpression((ThisExpression) node);
- }
- });
- HANDLERS.put(TryStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitTryStatement((TryStatement) node);
- }
- });
- HANDLERS.put(UnaryOperation.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitUnaryOperation((UnaryOperation) node);
- }
- });
- HANDLERS.put(VariableStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitVariableStatement((VariableStatement) node);
- }
- });
- HANDLERS.put(VoidExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitVoidExpression((VoidExpression) node);
- }
- });
- HANDLERS.put(WhileStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitWhileStatement((WhileStatement) node);
- }
- });
- HANDLERS.put(WithStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitWithStatement((WithStatement) node);
- }
- });
- HANDLERS.put(XmlLiteral.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitXmlLiteral((XmlLiteral) node);
- }
- });
- HANDLERS.put(DefaultXmlNamespaceStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitDefaultXmlNamespace((DefaultXmlNamespaceStatement) node);
- }
- });
- HANDLERS.put(XmlAttributeIdentifier.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitXmlPropertyIdentifier((XmlAttributeIdentifier) node);
- }
- });
- HANDLERS.put(AsteriskExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitAsteriskExpression((AsteriskExpression) node);
- }
- });
- HANDLERS.put(GetAllChildrenExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitGetAllChildrenExpression((GetAllChildrenExpression) node);
- }
- });
- HANDLERS.put(GetLocalNameExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor
- .visitGetLocalNameExpression((GetLocalNameExpression) node);
- }
- });
- HANDLERS.put(YieldOperator.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitYieldOperator((YieldOperator) node);
- }
- });
- HANDLERS.put(ErrorExpression.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitErrorExpression((ErrorExpression) node);
- }
- });
- HANDLERS.put(EmptyStatement.class, new Handler() {
- public <E> E handle(ASTVisitor<E> visitor, ASTNode node) {
- return visitor.visitEmptyStatement((EmptyStatement) node);
- }
- });
+ HANDLERS.put(ArrayInitializer.class, 0);
+ HANDLERS.put(BinaryOperation.class, 1);
+ HANDLERS.put(BooleanLiteral.class, 2);
+ HANDLERS.put(BreakStatement.class, 3);
+ HANDLERS.put(CallExpression.class, 4);
+ HANDLERS.put(CommaExpression.class, 5);
+ HANDLERS.put(ConditionalOperator.class, 6);
+ HANDLERS.put(ConstStatement.class, 7);
+ HANDLERS.put(ContinueStatement.class, 8);
+ HANDLERS.put(DecimalLiteral.class, 9);
+ HANDLERS.put(DoWhileStatement.class, 10);
+ HANDLERS.put(EmptyExpression.class, 11);
+ HANDLERS.put(ForStatement.class, 12);
+ HANDLERS.put(ForInStatement.class, 13);
+ HANDLERS.put(ForEachInStatement.class, 14);
+ HANDLERS.put(FunctionStatement.class, 15);
+ HANDLERS.put(GetArrayItemExpression.class, 16);
+ HANDLERS.put(Identifier.class, 17);
+ HANDLERS.put(IfStatement.class, 18);
+ HANDLERS.put(LabelledStatement.class, 19);
+ HANDLERS.put(NewExpression.class, 20);
+ HANDLERS.put(NullExpression.class, 21);
+ HANDLERS.put(ObjectInitializer.class, 22);
+ HANDLERS.put(ParenthesizedExpression.class, 23);
+ HANDLERS.put(PropertyExpression.class, 24);
+ HANDLERS.put(RegExpLiteral.class, 25);
+ HANDLERS.put(ReturnStatement.class, 26);
+ HANDLERS.put(Script.class, 27);
+ HANDLERS.put(StatementBlock.class, 28);
+ HANDLERS.put(StringLiteral.class, 29);
+ HANDLERS.put(SwitchStatement.class, 30);
+ HANDLERS.put(ThisExpression.class, 31);
+ HANDLERS.put(ThrowStatement.class, 32);
+ HANDLERS.put(TryStatement.class, 33);
+ HANDLERS.put(UnaryOperation.class, 34);
+ HANDLERS.put(VariableStatement.class, 35);
+ HANDLERS.put(VoidExpression.class, 36);
+ HANDLERS.put(YieldOperator.class, 37);
+ HANDLERS.put(WhileStatement.class, 38);
+ HANDLERS.put(WithStatement.class, 39);
+ HANDLERS.put(XmlLiteral.class, 40);
+ HANDLERS.put(DefaultXmlNamespaceStatement.class, 41);
+ HANDLERS.put(XmlAttributeIdentifier.class, 42);
+ HANDLERS.put(AsteriskExpression.class, 43);
+ HANDLERS.put(GetAllChildrenExpression.class, 44);
+ HANDLERS.put(GetLocalNameExpression.class, 45);
+ HANDLERS.put(ErrorExpression.class, 46);
+ HANDLERS.put(EmptyStatement.class, 47);
+ }
+
+ // generated function
+ private final E handle(ASTNode node, int handlerIndex) {
+ switch (handlerIndex) {
+ case 0:
+ return visitArrayInitializer((ArrayInitializer) node);
+ case 1:
+ return visitBinaryOperation((BinaryOperation) node);
+ case 2:
+ return visitBooleanLiteral((BooleanLiteral) node);
+ case 3:
+ return visitBreakStatement((BreakStatement) node);
+ case 4:
+ return visitCallExpression((CallExpression) node);
+ case 5:
+ return visitCommaExpression((CommaExpression) node);
+ case 6:
+ return visitConditionalOperator((ConditionalOperator) node);
+ case 7:
+ return visitConstDeclaration((ConstStatement) node);
+ case 8:
+ return visitContinueStatement((ContinueStatement) node);
+ case 9:
+ return visitDecimalLiteral((DecimalLiteral) node);
+ case 10:
+ return visitDoWhileStatement((DoWhileStatement) node);
+ case 11:
+ return visitEmptyExpression((EmptyExpression) node);
+ case 12:
+ return visitForStatement((ForStatement) node);
+ case 13:
+ return visitForInStatement((ForInStatement) node);
+ case 14:
+ return visitForEachInStatement((ForEachInStatement) node);
+ case 15:
+ return visitFunctionStatement((FunctionStatement) node);
+ case 16:
+ return visitGetArrayItemExpression((GetArrayItemExpression) node);
+ case 17:
+ return visitIdentifier((Identifier) node);
+ case 18:
+ return visitIfStatement((IfStatement) node);
+ case 19:
+ return visitLabelledStatement((LabelledStatement) node);
+ case 20:
+ return visitNewExpression((NewExpression) node);
+ case 21:
+ return visitNullExpression((NullExpression) node);
+ case 22:
+ return visitObjectInitializer((ObjectInitializer) node);
+ case 23:
+ return visitParenthesizedExpression((ParenthesizedExpression) node);
+ case 24:
+ return visitPropertyExpression((PropertyExpression) node);
+ case 25:
+ return visitRegExpLiteral((RegExpLiteral) node);
+ case 26:
+ return visitReturnStatement((ReturnStatement) node);
+ case 27:
+ return visitScript((Script) node);
+ case 28:
+ return visitStatementBlock((StatementBlock) node);
+ case 29:
+ return visitStringLiteral((StringLiteral) node);
+ case 30:
+ return visitSwitchStatement((SwitchStatement) node);
+ case 31:
+ return visitThisExpression((ThisExpression) node);
+ case 32:
+ return visitThrowStatement((ThrowStatement) node);
+ case 33:
+ return visitTryStatement((TryStatement) node);
+ case 34:
+ return visitUnaryOperation((UnaryOperation) node);
+ case 35:
+ return visitVariableStatement((VariableStatement) node);
+ case 36:
+ return visitVoidExpression((VoidExpression) node);
+ case 37:
+ return visitYieldOperator((YieldOperator) node);
+ case 38:
+ return visitWhileStatement((WhileStatement) node);
+ case 39:
+ return visitWithStatement((WithStatement) node);
+ case 40:
+ return visitXmlLiteral((XmlLiteral) node);
+ case 41:
+ return visitDefaultXmlNamespace((DefaultXmlNamespaceStatement) node);
+ case 42:
+ return visitXmlPropertyIdentifier((XmlAttributeIdentifier) node);
+ case 43:
+ return visitAsteriskExpression((AsteriskExpression) node);
+ case 44:
+ return visitGetAllChildrenExpression((GetAllChildrenExpression) node);
+ case 45:
+ return visitGetLocalNameExpression((GetLocalNameExpression) node);
+ case 46:
+ return visitErrorExpression((ErrorExpression) node);
+ case 47:
+ return visitEmptyStatement((EmptyStatement) node);
+ }
+ return visitUnknownNode(node);
}
public E visit(ASTNode node) {
if (node == null) {
return null;
}
- Handler handler = HANDLERS.get(node.getClass());
+ Integer handler = HANDLERS.get(node.getClass());
if (handler != null) {
- return handler.handle(this, node);
+ return handle(node, handler.intValue());
} else {
if (node instanceof JSUserNode) {
final ASTNode original = ((JSUserNode) node).getOriginal();
if (original != null) {
handler = HANDLERS.get(original.getClass());
if (handler != null) {
- return handler.handle(this, original);
+ return handle(original, handler.intValue());
}
}
}
View
14 ...dltk/javascript/typeinfo/JSDocTypeParserBase.java → ...e/dltk/javascript/parser/util/CharStreamUtil.java
@@ -9,15 +9,16 @@
* Contributors:
* NumberFour AG - initial API and Implementation (Alex Panchenko)
*******************************************************************************/
-package org.eclipse.dltk.javascript.typeinfo;
+package org.eclipse.dltk.javascript.parser.util;
import java.text.ParseException;
import org.antlr.runtime.CharStream;
-public class JSDocTypeParserBase {
+public class CharStreamUtil {
- public void match(CharStream input, char expected) throws ParseException {
+ public static void match(CharStream input, char expected)
+ throws ParseException {
if (input.LT(1) == expected) {
input.consume();
} else {
@@ -25,9 +26,10 @@ public void match(CharStream input, char expected) throws ParseException {
}
}
- protected void skipSpaces(CharStream input) {
- while (input.LT(1) != CharStream.EOF
- && Character.isWhitespace(input.LT(1))) {
+ public static void skipSpaces(CharStream input) {
+ int ch;
+ while ((ch = input.LT(1)) != CharStream.EOF
+ && Character.isWhitespace(ch)) {
input.consume();
}
}
View
49 plugins/org.eclipse.dltk.javascript.parser/tools/generator.js
@@ -0,0 +1,49 @@
+var fs = require('fs');
+
+function trim(str) {
+ return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
+}
+
+function replaceStatic(contents, body) {
+ return contents.replace(/(static\s*\{)[\s\S]+?(\})/m, '$1\n' + body + '\t$2');
+}
+
+function replaceHandle(contents, body) {
+ return contents.replace(/(switch\s*\(\w+\)\s*\{)[\s\S]+?(\})/m, '$1\n' + body + '\t\t$2');
+}
+
+function joinLines(lines, indent) {
+ return indent + lines.join('\n' + indent) + '\n';
+}
+
+var visitorFile = __dirname + '/../src/org/eclipse/dltk/javascript/ast/ASTVisitor.java';
+var contents = fs.readFileSync(visitorFile, 'UTF-8');
+contents = replaceStatic(contents, '');
+contents = replaceHandle(contents, '');
+
+var matches = [];
+var methodPattern = /public\s+(abstract\s+)?E\s+(visit\w+)\(\s*(\w+)\s+\w+\)/g;
+var m;
+while (m = methodPattern.exec(contents)) {
+ if (m[3] == 'ASTNode') {
+ continue; // skip visitUnknownNode
+ }
+ matches.push({method: m[2], type: m[3] });
+}
+console.log('Number of matched methods: ' + matches.length);
+
+var staticInit = [];
+for (var i in matches) {
+ staticInit.push('HANDLERS.put(' + matches[i].type + '.class, ' + i + ');');
+}
+var handle = [];
+for (var i in matches) {
+ handle.push('case ' + i + ':');
+ handle.push('\treturn ' + matches[i].method + '((' + matches[i].type + ') node);');
+}
+
+var newContents = contents;
+newContents = replaceStatic(newContents, joinLines(staticInit, '\t\t'));
+newContents = replaceHandle(newContents, joinLines(handle, '\t\t'));
+
+fs.writeFileSync(visitorFile, newContents, 'UTF-8');
View
1  plugins/org.eclipse.dltk.javascript.ui/templates/jsdoc-templates.properties
@@ -9,6 +9,7 @@
###############################################################################
param.description=parameter declaration
type.description=variable type declaration
+this.description=this type declaration
throws.description=thrown exception declaration
return.decription=function return type declaration
author.description=author name
View
8 plugins/org.eclipse.dltk.javascript.ui/templates/jsdoc-templates.xml
@@ -31,6 +31,14 @@
deleted="false"
autoinsert="true">@return {${type}}</template>
<template
+ id="org.eclipse.dltk.javascript.ui.templates.jsdoc.this"
+ name="@this"
+ description="%this.description"
+ context="JSDocTemplateContextType"
+ enabled="true"
+ deleted="false"
+ autoinsert="true">@this {${type}}</template>
+<template
id="org.eclipse.dltk.javascript.ui.templates.jsdoc.author"
name="@author"
description="%author.description"
View
20 ....dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/contentassist/CodeCompletion.java
@@ -726,8 +726,6 @@ public void testVariableTypedAsTypedArrayThroughDoc() {
}
public void testVariableTypedAsCustomTypeArrayThroughDoc() {
- if (notYetImplemented(this))
- return;
final StringList code = new StringList();
code.add("function MyObject() {");
code.add(" this.num = 10;");
@@ -744,8 +742,6 @@ public void testVariableTypedAsCustomTypeArrayThroughDoc() {
}
public void testVariableTypedAsCustomTypeReferecingItselfArrayThroughDoc() {
- if (notYetImplemented(this))
- return;
final StringList code = new StringList();
code.add("function MyObject() {");
code.add(" this.num = 10;");
@@ -767,4 +763,20 @@ public void testVariableTypedAsCustomTypeReferecingItselfArrayThroughDoc() {
int position = lastPositionInFile(".", module);
basicTest(module, position, names);
}
+
+
+ public void testRecordTypeWithDeclaration() {
+ final StringList code = new StringList();
+ code.add("function test() {");
+ code.add("/** @type {Object<Number>} */");
+ code.add("var y = {");
+ code.add(" KEY:1");
+ code.add("}");
+ code.add("y.");
+ code.add("}");
+ final IModuleSource module = new TestModule(code.toString());
+ String[] names = concat(getMembersOfObject(), "KEY");
+ int position = lastPositionInFile(".", module);
+ basicTest(module, position, names);
+ }
}
View
105 ...javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/validation/TypeInfoValidationTests.java
@@ -2676,9 +2676,6 @@ public void testMapRecordCompatibilityError() {
}
public void testReturnWith2NewInstances() throws Exception {
- if (notYetImplemented(this)) {
- return;
- }
StringList code = new StringList();