Skip to content

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.
...
  • 2 commits
  • 17 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 24, 2012
@sgtcoolguy sgtcoolguy Fix APSTUD-4830 Font size changes the when you open up a new file f109bc8
@sgtcoolguy sgtcoolguy Fix APSTUD-4836 Unable to construct JS instances from built-in types …
…using the "new" operator

    - Update metadata for prototype properties for classes Array/RegExp/Error/Function/etc. to return their own type and not "Object"
    - Add unit tests for these cases
    - Add toString() impls for some metadata classes in JS just for dev purposes
    - Make use of some CollectionsUtil methods in JSSymbolTypeInferrer
540badd
Showing with 132 additions and 88 deletions.
  1. +12 −12 plugins/com.aptana.editor.js/metadata/dom_0.xml
  2. +7 −7 plugins/com.aptana.editor.js/metadata/js_core.xml
  3. +6 −2 plugins/com.aptana.editor.js/src/com/aptana/editor/js/contentassist/model/PropertyElement.java
  4. +8 −3 plugins/com.aptana.editor.js/src/com/aptana/editor/js/contentassist/model/ReturnTypeElement.java
  5. +12 −25 plugins/com.aptana.editor.js/src/com/aptana/editor/js/inferencing/JSSymbolTypeInferrer.java
  6. +16 −7 plugins/com.aptana.index.core.ui/src/com/aptana/index/core/ui/views/IndexViewLabelProvider.java
  7. +1 −2 plugins/com.aptana.scripting.ui/src/com/aptana/scripting/ui/views/BundleViewLabelProvider.java
  8. +17 −0 plugins/com.aptana.theme/src/com/aptana/theme/internal/TextViewerThemer.java
  9. +1 −0 tests/com.aptana.editor.js.tests/inferencing/constructed-array.js
  10. +1 −0 tests/com.aptana.editor.js.tests/inferencing/constructed-boolean.js
  11. +1 −0 tests/com.aptana.editor.js.tests/inferencing/constructed-date.js
  12. +1 −0 tests/com.aptana.editor.js.tests/inferencing/constructed-error.js
  13. +1 −0 tests/com.aptana.editor.js.tests/inferencing/constructed-function.js
  14. +1 −0 tests/com.aptana.editor.js.tests/inferencing/constructed-number.js
  15. +1 −0 tests/com.aptana.editor.js.tests/inferencing/constructed-regexp.js
  16. +45 −28 tests/com.aptana.editor.js.tests/src/com/aptana/editor/js/inferencing/FunctionInferencingTests.java
  17. +1 −2 tests/com.aptana.editor.js.tests/src/com/aptana/editor/js/inferencing/InferencingTestsBase.java
View
24 plugins/com.aptana.editor.js/metadata/dom_0.xml
@@ -6120,32 +6120,32 @@
</browsers>
</method>
- <method name = "getComputedStyle" scope = "instance" visibility = "basic">
+ <method name="getComputedStyle" scope="instance" visibility="basic">
<parameters>
- <parameter name = "elt" type = "Element" usage = "required">
+ <parameter name="elt" type="Element" usage="required">
<description>Document element to get the style information for.</description>
</parameter>
- <parameter name = "pseudoElt" type = "String" usage = "required">
+ <parameter name="pseudoElt" type="String" usage="required">
<description>CSS pseudoelement.</description>
</parameter>
</parameters>
<references>
- <reference name = "CSS2Properties"/>
- <reference name = "CSSStyleDeclaration"/>
- <reference name = "HTMLElement.style"/>
+ <reference name="CSS2Properties"/>
+ <reference name="CSSStyleDeclaration"/>
+ <reference name="HTMLElement.style"/>
</references>
<return-types>
- <return-type type = "CSSStyleDeclaration"/>
+ <return-type type="CSSStyleDeclaration"/>
</return-types>
<availability>
- <specification name = "HTML DOM Level 2"/>
+ <specification name="HTML DOM Level 2"/>
</availability>
<description>Computes style information and returns the CSSStyleDeclaration for the specified document Element.</description>
<browsers>
- <browser platform = "IE" version = "6.0+"/>
- <browser platform = "Mozilla" version = "1.0+"/>
- <browser platform = "Netscape" version = "6.0+"/>
- <browser platform = "Safari" version = "1.0+"/>
+ <browser platform="IE" version="6.0+"/>
+ <browser platform="Mozilla" version="1.0+"/>
+ <browser platform="Netscape" version="6.0+"/>
+ <browser platform="Safari" version="1.0+"/>
</browsers>
<return-description>Returns the CSSStyleDeclaration for the specified document Element.</return-description>
</method>
View
14 plugins/com.aptana.editor.js/metadata/js_core.xml
@@ -242,7 +242,7 @@ var result = makeFactorialFunc()(5); // returns 120 (5 * 4 * 3 * 2 * 1)
array still contains only 2 elements.&lt;/p&gt;
</remarks>
</property>
- <property name="prototype" type="Object" access="read-write">
+ <property name="prototype" type="Array" access="read-write">
<availability>
<specification name="JavaScript 1.1"/>
<specification name="JScript 2.0"/>
@@ -1499,7 +1499,7 @@ myArray = myRe.exec("cdbBdbsbz");&lt;/pre&gt;&lt;p&gt;The properties and element
<description>Specifies the function that creates the Boolean prototype.</description>
</property>
- <property name="prototype" type="Object">
+ <property name="prototype" type="Boolean">
<browsers>
<browser platform="IE" version="4.0+"/>
<browser platform="Mozilla" version="1.0+"/>
@@ -4300,7 +4300,7 @@ timeDifference = timeB - timeA;&lt;/pre&gt;
</browsers>
</property>
- <property name="prototype" type="Object">
+ <property name="prototype" type="Error">
<availability>
<specification name="JavaScript 1.5"/>
<specification name="JScript 5.0"/>
@@ -4649,7 +4649,7 @@ addNumbers(103,104) // returns 207&lt;/pre&gt;
function.&lt;/p&gt;
</remarks>
</property>
- <property name="prototype" type="Object" access="read-write">
+ <property name="prototype" type="Function" access="read-write">
<description>Creates an instance of a Function class.</description>
<browsers>
<browser platform="IE" version="4.0+"/>
@@ -7119,7 +7119,7 @@ if (month &amp;lt; 1 || month &amp;gt; 12) {
</browsers>
</property>
- <property name="prototype" type="Object">
+ <property name="prototype" type="Number">
<availability>
<specification name="JavaScript 1.1"/>
</availability>
@@ -8282,7 +8282,7 @@ o.p changed from undefined to 4&lt;/pre&gt;</example>
</browsers>
</property>
- <property name="prototype" type="Object" access="read-write">
+ <property name="prototype" type="RegExp" access="read-write">
<availability>
<specification name="JavaScript 1.2"/>
<specification name="JScript 3.0"/>
@@ -8865,7 +8865,7 @@ alert("The string length is " + x.length);&lt;/pre&gt;
</remarks>
</property>
- <property name="prototype" type="Object">
+ <property name="prototype" type="String">
<availability>
<specification name="JavaScript 1.1"/>
<specification name="JScript 2.0"/>
View
8 ...ns/com.aptana.editor.js/src/com/aptana/editor/js/contentassist/model/PropertyElement.java
@@ -13,8 +13,6 @@
import java.util.Map;
import java.util.Set;
-import com.aptana.jetty.util.epl.ajax.JSON.Output;
-
import com.aptana.core.util.CollectionsUtil;
import com.aptana.core.util.ObjectUtil;
import com.aptana.core.util.SourcePrinter;
@@ -22,6 +20,7 @@
import com.aptana.editor.js.JSTypeConstants;
import com.aptana.index.core.IndexUtil;
import com.aptana.index.core.ui.views.IPropertyInformation;
+import com.aptana.jetty.util.epl.ajax.JSON.Output;
public class PropertyElement extends BaseElement<PropertyElement.Property>
{
@@ -437,4 +436,9 @@ public void toSource(SourcePrinter printer)
printer.print(JSTypeConstants.UNDEFINED_TYPE);
}
}
+
+ public String toString()
+ {
+ return toSource();
+ }
}
View
11 .../com.aptana.editor.js/src/com/aptana/editor/js/contentassist/model/ReturnTypeElement.java
@@ -7,13 +7,13 @@
*/
package com.aptana.editor.js.contentassist.model;
+import java.text.MessageFormat;
import java.util.Map;
-import com.aptana.jetty.util.epl.ajax.JSON.Convertible;
-import com.aptana.jetty.util.epl.ajax.JSON.Output;
-
import com.aptana.core.util.ObjectUtil;
import com.aptana.core.util.StringUtil;
+import com.aptana.jetty.util.epl.ajax.JSON.Convertible;
+import com.aptana.jetty.util.epl.ajax.JSON.Output;
public class ReturnTypeElement implements Convertible
{
@@ -131,4 +131,9 @@ public void toJSON(Output out)
out.add(TYPE_PROPERTY, this.getType());
out.add(DESCRIPTION_PROPERTY, this.getDescription());
}
+
+ public String toString()
+ {
+ return MessageFormat.format("Type: ''{0}'', description: ''{1}''", _type, _description); //$NON-NLS-1$
+ }
}
View
37 plugins/com.aptana.editor.js/src/com/aptana/editor/js/inferencing/JSSymbolTypeInferrer.java
@@ -18,6 +18,8 @@
import java.util.Queue;
import java.util.Set;
+import com.aptana.core.IMap;
+import com.aptana.core.util.CollectionsUtil;
import com.aptana.core.util.StringUtil;
import com.aptana.editor.js.JSTypeConstants;
import com.aptana.editor.js.contentassist.JSIndexQueryHelper;
@@ -223,32 +225,19 @@ else if (node instanceof JSAssignmentNode)
*/
private PropertyElement createPropertyElement(Set<String> types)
{
- boolean isFunction = false;
- PropertyElement result;
-
// determine if any of the types are functions
- if (types != null && types.size() > 0)
+ if (!CollectionsUtil.isEmpty(types))
{
for (String type : types)
{
if (JSTypeUtil.isFunctionPrefix(type))
{
- isFunction = true;
- break;
+ return new FunctionElement();
}
}
}
- if (isFunction)
- {
- result = new FunctionElement();
- }
- else
- {
- result = new PropertyElement();
- }
-
- return result;
+ return new PropertyElement();
}
/**
@@ -285,16 +274,14 @@ private PropertyElement createPropertyElement(Set<String> types)
*/
public List<PropertyElement> getScopeProperties()
{
- List<PropertyElement> result = new ArrayList<PropertyElement>();
-
- for (String symbol : activeScope.getLocalSymbolNames())
+ List<String> symbolNames = activeScope.getLocalSymbolNames();
+ return CollectionsUtil.map(symbolNames, new IMap<String, PropertyElement>()
{
- PropertyElement p = this.getSymbolPropertyElement(symbol);
-
- result.add(p);
- }
-
- return result;
+ public PropertyElement map(String symbol)
+ {
+ return getSymbolPropertyElement(symbol);
+ }
+ });
}
/**
View
23 ...s/com.aptana.index.core.ui/src/com/aptana/index/core/ui/views/IndexViewLabelProvider.java
@@ -9,6 +9,7 @@
import java.util.List;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IFontProvider;
@@ -22,6 +23,7 @@
import com.aptana.theme.IThemeManager;
import com.aptana.theme.Theme;
import com.aptana.theme.ThemePlugin;
+import com.aptana.theme.preferences.IPreferenceConstants;
/**
* IndexViewLabelProvider
@@ -81,30 +83,37 @@ protected Theme getCurrentTheme()
*/
public Font getFont(Object element)
{
- Font font = JFaceResources.getFont(IThemeManager.VIEW_FONT_NAME);
+ if (!useEditorFont())
+ {
+ return null;
+ }
+ Font font = JFaceResources.getFont(IThemeManager.VIEW_FONT_NAME);
if (font == null)
{
font = JFaceResources.getTextFont();
}
-
return font;
}
+ protected boolean useEditorFont()
+ {
+ return Platform.getPreferencesService().getBoolean(ThemePlugin.PLUGIN_ID, IPreferenceConstants.INVASIVE_FONT,
+ false, null);
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
*/
public Color getForeground(Object element)
{
- Color result = null;
-
- if (getCurrentTheme().isInvasive())
+ if (ThemePlugin.applyToViews())
{
- result = getCurrentTheme().getForegroundColor();
+ return getCurrentTheme().getForegroundColor();
}
- return result;
+ return null;
}
/*
View
3 ...ns/com.aptana.scripting.ui/src/com/aptana/scripting/ui/views/BundleViewLabelProvider.java
@@ -46,7 +46,6 @@ public void dispose()
*/
public Color getBackground(Object element)
{
- // TODO Auto-generated method stub
return null;
}
@@ -81,7 +80,7 @@ protected boolean useEditorFont()
*/
public Color getForeground(Object element)
{
- if (getCurrentTheme().isInvasive())
+ if (ThemePlugin.applyToViews())
{
return getCurrentTheme().getForegroundColor();
}
View
17 plugins/com.aptana.theme/src/com/aptana/theme/internal/TextViewerThemer.java
@@ -8,10 +8,12 @@
package com.aptana.theme.internal;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
@@ -41,11 +43,17 @@ public TextViewerThemer(ITextViewer viewer)
super(viewer.getTextWidget());
}
+ /**
+ * Themes always apply to text viewers.
+ */
protected boolean invasiveThemesEnabled()
{
return true;
}
+ /**
+ * Always use the editor font.
+ */
protected boolean useEditorFont()
{
return true;
@@ -64,6 +72,15 @@ protected void applyTheme()
}
}
+ /**
+ * This is a TextViewer (usually editor contents), so use the text font explicitly, not the view font we set up in
+ * parent class.
+ */
+ protected Font getFont()
+ {
+ return JFaceResources.getTextFont();
+ }
+
private StyledText getTextWidget()
{
return (StyledText) getControl();
View
1 tests/com.aptana.editor.js.tests/inferencing/constructed-array.js
@@ -0,0 +1 @@
+var constructedArray = new Array;
View
1 tests/com.aptana.editor.js.tests/inferencing/constructed-boolean.js
@@ -0,0 +1 @@
+var constructedBoolean = new Boolean;
View
1 tests/com.aptana.editor.js.tests/inferencing/constructed-date.js
@@ -0,0 +1 @@
+var constructedDate = new Date;
View
1 tests/com.aptana.editor.js.tests/inferencing/constructed-error.js
@@ -0,0 +1 @@
+var constructedError = new Error;
View
1 tests/com.aptana.editor.js.tests/inferencing/constructed-function.js
@@ -0,0 +1 @@
+var constructedFunction = new Function;
View
1 tests/com.aptana.editor.js.tests/inferencing/constructed-number.js
@@ -0,0 +1 @@
+var constructedNumber = new Number;
View
1 tests/com.aptana.editor.js.tests/inferencing/constructed-regexp.js
@@ -0,0 +1 @@
+var constructedRegexp = new RegExp;
View
73 ...aptana.editor.js.tests/src/com/aptana/editor/js/inferencing/FunctionInferencingTests.java
@@ -1,6 +1,6 @@
/**
* Aptana Studio
- * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
+ * Copyright (c) 2005-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
* Please see the license.html included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
@@ -16,6 +16,7 @@
import com.aptana.core.IMap;
import com.aptana.core.util.CollectionsUtil;
import com.aptana.editor.common.tests.util.TestProject;
+import com.aptana.editor.epl.tests.EditorTestHelper;
import com.aptana.editor.js.contentassist.JSIndexQueryHelper;
import com.aptana.editor.js.contentassist.index.JSFileIndexingParticipant;
import com.aptana.editor.js.contentassist.model.PropertyElement;
@@ -26,74 +27,48 @@
public class FunctionInferencingTests extends InferencingTestsBase
{
- /**
- * testReturnsBoolean
- */
+
public void testReturnsBoolean()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-boolean.js"), "Boolean");
}
- /**
- * testReturnsFunction
- */
public void testReturnsFunction()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-function.js"), "Function");
}
- /**
- * testReturnsNumber
- */
public void testReturnsNumber()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-number.js"), "Number");
}
- /**
- * testReturnsRegExp
- */
public void testReturnsRegExp()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-regexp.js"), "RegExp");
}
- /**
- * testReturnsString
- */
public void testReturnsString()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-string.js"), "String");
}
- /**
- * testReturnsArray
- */
public void testReturnsArray()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-array.js"), "Array");
}
- /**
- * testReturnsArrayOfNumbers
- */
public void testReturnsArrayOfNumbers()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-array-of-numbers.js"),
"Array<Number>");
}
- /**
- * testReturnsObject
- */
public void testReturnsObject()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-object.js"), "Object");
}
- /**
- * testReturnsUserObject
- */
public void testReturnsUserObject()
{
this.lastStatementTypeTests(Path.fromPortableString("inferencing/function-returns-user-object.js"), "foo");
@@ -146,4 +121,46 @@ public String map(TypeElement item)
}
}
}
+
+ public void testConstructedArray() throws Exception
+ {
+ EditorTestHelper.joinBackgroundActivities();
+ this.lastStatementTypeTests(Path.fromPortableString("inferencing/constructed-array.js"), "Array");
+ }
+
+ public void testConstructedBoolean() throws Exception
+ {
+ EditorTestHelper.joinBackgroundActivities();
+ this.lastStatementTypeTests(Path.fromPortableString("inferencing/constructed-boolean.js"), "Boolean");
+ }
+
+ public void testConstructedDate() throws Exception
+ {
+ EditorTestHelper.joinBackgroundActivities();
+ this.lastStatementTypeTests(Path.fromPortableString("inferencing/constructed-date.js"), "Date");
+ }
+
+ public void testConstructedError() throws Exception
+ {
+ EditorTestHelper.joinBackgroundActivities();
+ this.lastStatementTypeTests(Path.fromPortableString("inferencing/constructed-error.js"), "Error");
+ }
+
+ public void testConstructedFunction() throws Exception
+ {
+ EditorTestHelper.joinBackgroundActivities();
+ this.lastStatementTypeTests(Path.fromPortableString("inferencing/constructed-function.js"), "Function");
+ }
+
+ public void testConstructedNumber() throws Exception
+ {
+ EditorTestHelper.joinBackgroundActivities();
+ this.lastStatementTypeTests(Path.fromPortableString("inferencing/constructed-number.js"), "Number");
+ }
+
+ public void testConstructedRegExp() throws Exception
+ {
+ EditorTestHelper.joinBackgroundActivities();
+ this.lastStatementTypeTests(Path.fromPortableString("inferencing/constructed-regexp.js"), "RegExp");
+ }
}
View
3 ...com.aptana.editor.js.tests/src/com/aptana/editor/js/inferencing/InferencingTestsBase.java
@@ -331,7 +331,7 @@ protected void assertStatementTypes(List<String> statementTypes, String... types
{
assertNotNull(statementTypes);
- assertEquals(types.length, statementTypes.size());
+ assertEquals("Number of types doesn't match", types.length, statementTypes.size());
for (String type : types)
{
@@ -369,7 +369,6 @@ protected void assertStatementTypes(List<String> statementTypes, String... types
@Override
protected void setUp() throws Exception
{
- // TODO Auto-generated method stub
super.setUp();
reader = new JSIndexReader();

No commit comments for this range

Something went wrong with that request. Please try again.