/** APSTUD-4116 */ @Test public void testFunctionDocumentationWithoutParamTag() { TestBuildContext myContext = new TestBuildContext("indexing/functionDocsWithoutParam.js"); try { IParseRootNode ast = myContext.getAST(); JSFileIndexingParticipant indexParticipant = new JSFileIndexingParticipant(); Index index = getIndex(); indexParticipant.processParseResults(myContext, index, ast, new NullProgressMonitor()); JSIndexQueryHelper queryHelper = new JSIndexQueryHelper(index); Collection<PropertyElement> types = queryHelper.getGlobals("functionDocsWithoutParam.js", "abc"); assertNotNull(types); assertTrue("Expected at least a single property for 'abc'", !types.isEmpty()); PropertyElement property = types.iterator().next(); assertTrue("Expected a FunctionElement", property instanceof FunctionElement); FunctionElement function = (FunctionElement) property; List<String> parameters = function.getParameterNames(); assertNotNull(parameters); assertEquals("Expected 3 parameters for 'abc'", 3, parameters.size()); assertEquals("Expected parameter 1's name to be 'a'", "a", parameters.get(0)); assertEquals("Expected parameter 2's name to be 'b'", "b", parameters.get(1)); assertEquals("Expected parameter 3's name to be 'c'", "c", parameters.get(2)); } catch (CoreException e) { fail(e.getMessage()); } }
/** APSTUD-4117 */ @Test public void testFunctionDocumentationWithoutReturnTag() { TestBuildContext myContext = new TestBuildContext("indexing/functionDocsWithoutReturn.js"); try { IParseRootNode ast = myContext.getAST(); JSFileIndexingParticipant indexParticipant = new JSFileIndexingParticipant(); Index index = getIndex(); indexParticipant.processParseResults(myContext, index, ast, new NullProgressMonitor()); JSIndexQueryHelper queryHelper = new JSIndexQueryHelper(index); Collection<PropertyElement> types = queryHelper.getGlobals("functionDocsWithoutReturn.js", "abc"); assertNotNull(types); assertTrue("Expected at least a single property for 'abc'", !types.isEmpty()); PropertyElement property = types.iterator().next(); assertTrue("Expected a FunctionElement", property instanceof FunctionElement); FunctionElement function = (FunctionElement) property; List<String> returnTypes = function.getReturnTypeNames(); assertNotNull(returnTypes); assertEquals("Expected a single return type for 'abc'", 1, returnTypes.size()); assertEquals("Expected 'Number' return type", "Number", returnTypes.get(0)); } catch (CoreException e) { fail(e.getMessage()); } }
/** testMethod */ @Test public void testMethod() { String typeName = "MyClass"; String methodName = "myMethod"; // create type TypeElement type = new TypeElement(); type.setName(typeName); // create method within type FunctionElement method = new FunctionElement(); method.setName(methodName); type.addProperty(method); // write type to index this.writeType(type); // then retrieve it List<TypeElement> retrievedTypes = this.getType(typeName); TypeElement retrievedType = retrievedTypes.get(0); assertNotNull(retrievedType); assertEquals(typeName, retrievedType.getName()); // make sure we have one property List<PropertyElement> properties = retrievedType.getProperties(); assertNotNull(properties); assertTrue(properties.size() == 1); // make sure it is a function PropertyElement property = properties.get(0); assertTrue(property instanceof FunctionElement); // make sure it is the function we added earlier FunctionElement retrievedMethod = (FunctionElement) property; assertEquals(methodName, retrievedMethod.getName()); }
/** * FunctionElement * * @param base */ public FunctionElement(FunctionElement base) { super(base); // NOTE: this is a shallow clone, so references are shared in lists this._parameters = new ArrayList<ParameterElement>(base.getParameters()); this._references = new ArrayList<String>(base.getReferences()); this._exceptions = new ArrayList<ExceptionElement>(base.getExceptions()); this._returnTypes = new ArrayList<ReturnTypeElement>(base.getReturnTypes()); this._isConstructor = base.isConstructor(); this._isMethod = base.isMethod(); }
@Test public void testEventPropertyWithConstantValues() { String typeName = "MyClass"; String functionName = "convertUnits"; String paramName = "convertToUnits"; List<String> constants = CollectionsUtil.newList( "Titanium.UI.UNIT_CM", "Titanium.UI.UNIT_MM", "Titanium.UI.UNIT_DIP", "Titanium.UI.UNIT_IN", "Titanium.UI.UNIT_PX"); // create type TypeElement type = new TypeElement(); type.setName(typeName); // create function within type FunctionElement function = new FunctionElement(); function.setName(functionName); ParameterElement parameter = new ParameterElement(); parameter.setName(paramName); parameter.fromJSON( CollectionsUtil.newTypedMap( String.class, Object.class, IHasPredefinedValues.CONSTANTS_PROPERTY, constants)); function.addParameter(parameter); type.addProperty(function); // write type to index this.writeType(type); // then retrieve it List<TypeElement> retrievedTypes = this.getType(typeName); TypeElement retrievedType = retrievedTypes.get(0); assertNotNull(retrievedType); assertEquals(typeName, retrievedType.getName()); // make sure we have one property List<PropertyElement> properties = retrievedType.getProperties(); assertNotNull(properties); assertEquals(1, properties.size()); // make sure the name is correct PropertyElement retrievedProperty = properties.get(0); assertEquals(functionName, retrievedProperty.getName()); assertTrue(retrievedProperty instanceof FunctionElement); FunctionElement retrievedFunction = (FunctionElement) retrievedProperty; List<ParameterElement> retrievedParams = retrievedFunction.getParameters(); assertNotNull(retrievedParams); assertEquals(1, retrievedParams.size()); ParameterElement retrievedParam = retrievedParams.get(0); // Check constants List<String> retrievedConstants = retrievedParam.getConstants(); assertEquals(constants.size(), retrievedConstants.size()); for (String constant : constants) { assertTrue(retrievedConstants.contains(constant)); } }