make sure that it maps to the right overriden function or variable when sub has the same function or property then a super
diff --git a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java index 14ee220..692bd35 100644 --- a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java +++ b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java
@@ -281,6 +281,20 @@ } } if (left != null && left.exists()) { + if (left.getParent() instanceof ThisValue) { + // this is an override, make sure that left is really + // created. + left.getParent().createChild(left.getName()); + Expression property = node.getLeftExpression(); + if (property instanceof PropertyExpression) { + left.setLocation(ReferenceLocation.create(getSource(), + property.sourceStart(), property.sourceEnd(), + ((PropertyExpression) property).getProperty() + .sourceStart(), + ((PropertyExpression) property).getProperty() + .sourceEnd())); + } + } left.setAttribute(IReferenceAttributes.RESOLVING, Boolean.TRUE); final IValueReference r; try {
diff --git a/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/contentassist/SelectionTests.java b/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/contentassist/SelectionTests.java index 791d1e3..78c53f2 100644 --- a/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/contentassist/SelectionTests.java +++ b/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/contentassist/SelectionTests.java
@@ -28,6 +28,7 @@ import org.eclipse.dltk.core.ISourceRange; import org.eclipse.dltk.core.ISourceReference; import org.eclipse.dltk.core.ModelException; +import org.eclipse.dltk.core.model.UnresolvedElement; import org.eclipse.dltk.core.search.IDLTKSearchConstants; import org.eclipse.dltk.core.search.SearchEngine; import org.eclipse.dltk.core.search.SearchMatch; @@ -354,4 +355,58 @@ selectAll(module, lastPositionInFile("String", module, false))); } + + public void testExtends() throws ModelException { + IModuleSource module = getModule("extends.js"); + IModelElement[] elements = select(module, + lastPositionInFile("myprop", module, false)); + assertEquals(1, elements.length); + final UnresolvedElement variable1 = (UnresolvedElement) elements[0]; + elements = select(module, + lastPositionInFile("myval", module, false)); + assertEquals(1, elements.length); + final UnresolvedElement variable2 = (UnresolvedElement) elements[0]; + final int offset1 = variable1.getSourceRange().getOffset(); + final int offset2 = variable2.getSourceRange().getOffset(); + + assertTrue(offset1 > offset2); + + ISourceRange nameRange = variable1.getNameRange(); + assertEquals( + "myprop", + module.getSourceContents().substring(nameRange.getOffset(), + nameRange.getOffset() + nameRange.getLength())); + nameRange = variable2.getNameRange(); + assertEquals( + "myval", + module.getSourceContents().substring(nameRange.getOffset(), + nameRange.getOffset() + nameRange.getLength())); + } + + + public void testExtends2() throws ModelException { + IModuleSource module = getModule("extends.js"); + IModelElement[] elements = select(module, + lastPositionInFile("mypublicfunction", module, false)); + assertEquals(1, elements.length); + IMethod method = (IMethod) elements[0]; + assertEquals("MySubConstructor", method.getParent().getElementName()); + ISourceRange nameRange = method.getNameRange(); + assertEquals( + "mypublicfunction", + module.getSourceContents().substring(nameRange.getOffset(), + nameRange.getOffset() + nameRange.getLength())); + + elements = select(module, + lastPositionInFile("myfunction", module, false)); + assertEquals(1, elements.length); + method = (IMethod) elements[0]; + assertEquals("MyConstructor", method.getParent().getElementName()); + nameRange = method.getNameRange(); + assertEquals( + "myfunction", + module.getSourceContents().substring(nameRange.getOffset(), + nameRange.getOffset() + nameRange.getLength())); + + } }
diff --git a/tests/org.eclipse.dltk.javascript.core.tests/workspace/selection/src/extends.js b/tests/org.eclipse.dltk.javascript.core.tests/workspace/selection/src/extends.js new file mode 100644 index 0000000..1eb776b --- /dev/null +++ b/tests/org.eclipse.dltk.javascript.core.tests/workspace/selection/src/extends.js
@@ -0,0 +1,30 @@ +/** + * @constructor + */ +function MyConstructor() { + this.mypublicfunction = function() { + + } + this.myfunction = function() { + + } + this.myprop = 10; + this.myval = 11; +} +/** + * @constructor + * @extends {MyConstructor} + */ +function MySubConstructor() { + this.mypublicfunction = function() { + } + + this.myprop = 11; +} +function test() { + var x = new MySubConstructor(); + x.mypublicfunction(); + x.myfunction(); + x.myprop; + x.myval; +} \ No newline at end of file