Exemplo n.º 1
0
  public static synchronized Map<String, IJstType> getJstTypes() {

    if (s_jstTypes != null) {
      return s_jstTypes;
    }

    Map<String, IJstType> jstTypes = new HashMap<String, IJstType>();
    try {
      Class<?> anchorClass = TestDataHelper.class;
      String jstFilename = TEST_DATA_JAR;
      InputStream fio = ResourceUtil.getMandatoryResourceAsStream(anchorClass, jstFilename);
      List<IJstType> deserialize = JstTypeSerializer.getInstance().deserialize(fio);
      for (IJstType t : deserialize) {
        jstTypes.put(t.getName(), t);
      }
      s_jstTypes = jstTypes;
      return jstTypes;
    } catch (RuntimeException e) {
      e.printStackTrace(); // KEEPME
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return jstTypes;
  }
Exemplo n.º 2
0
 @Test
 @Category({P1, FAST, UNIT})
 @Description(
     "Test incomplete VJET itype should parse non-null jst. "
         + "Also it should have bare minimum information baout vjet type")
 public void testProcessIType() {
   CompilationUnitDeclaration ast = prepareAst("iTypeTranslatorTestFile.txt", null);
   IJstType jstType = SyntaxTreeFactory2.createJST(ast, new TranslateCtx());
   assertNotNull(jstType);
   assertTrue(jstType.isInterface());
 }
Exemplo n.º 3
0
  @Test
  @Category({P1, FAST, UNIT})
  @Description(
      "Test VJET mtype should parse non-null jst. "
          + "Also it should have required statements and expressions in jst type")
  public void testProcessMType() {
    CompilationUnitDeclaration ast = prepareAst("mTypeTranslatorTestFile.txt", null);
    IJstType jstType = SyntaxTreeFactory2.createJST(ast, new TranslateCtx());

    assertNotNull(jstType);
    assertTrue(jstType.isMixin());
  }
Exemplo n.º 4
0
  @Test
  @Category({P5, FAST, UNIT})
  @Description(
      "Test incomplete VJET atype should parse non-null jst. "
          + "Also it should have bare minimum information baout vjet type")
  public void testProcessType1() {
    CompilationUnitDeclaration ast = prepareAst("typeTranslatorTestFile.js.txt", null);
    IJstType jstType = SyntaxTreeFactory2.createJST(ast, new TranslateCtx());

    List<? extends IJstMethod> staticMethods = jstType.getStaticMethods();
    assertNotNull(staticMethods);
    assertEquals(2, JstTypeHelper.getDeclaredMethods(staticMethods).size());
    IJstMethod jstMethod = getMethodByName(staticMethods, "getRate");
    assertNotNull(jstMethod);
    IJstMethod jstMethod2 = getMethodByName(staticMethods, "getDiscount");
    assertNotNull(jstMethod2);
    assertNotNull(jstType.getMethod("chase"));
  }
Exemplo n.º 5
0
  public void loadTypesFinished() {

    try {

      final NullProgressMonitor monitor = new NullProgressMonitor();
      isConsistent = false;
      reconcile(true, null, monitor);

      // added by [email protected]
      // this logic is to find the dependents types of the saving jst type
      // and update their validations result accordingly
      try {
        if (jstType != null
            && jstType.getPackage() != null
            && jstType.getPackage().getGroupName() != null
            && jstType.getName() != null) {
          final List<IJstType> dependents =
              mgr.getTypeSpace()
                  .getAllDependents(
                      new TypeName(jstType.getPackage().getGroupName(), jstType.getName()));
          if (dependents != null) {
            final List<ISourceModule> selectedSourceModules = new LinkedList<ISourceModule>();
            final StandardScriptBuilder scriptBuild = new StandardScriptBuilder();
            final ScriptProject scriptProject =
                CodeassistUtils.getScriptProject(jstType.getPackage().getGroupName());
            VjoSourceHelper.getAllSourceModulesFromJst(
                selectedSourceModules, dependents, scriptProject);
            if (selectedSourceModules.size() > 0) {
              scriptBuild.initialize(scriptProject);
              scriptBuild.buildModelElements(
                  scriptProject, selectedSourceModules, new SubProgressMonitor(monitor, 1), 1);
            }
          }
        }
      } catch (Exception e) {
        DLTKCore.error(e.toString(), e);
      } finally {
        monitor.done();
      }

    } catch (CoreException e) {
      DLTKCore.error(e.toString(), e);
    }
  }
Exemplo n.º 6
0
  @Test // @Description("Partial Mtype JS file should produce meaningful JSTType. " +
  //	"Type name and package should be proper along with expects for itype")
  public void testExpects() {
    CompilationUnitDeclaration ast = prepareAst("expectsTranslatorTestFile.js.txt", null);

    IJstType jstType = SyntaxTreeFactory2.createJST(ast, new TranslateCtx());
    assertNotNull(jstType);
    assertTrue(jstType.isMixin());

    assertEquals("com.ebay.vjet", jstType.getPackage().getName());
    assertEquals("M", jstType.getSimpleName());

    List<? extends IJstType> expects = jstType.getExpects();
    assertNotNull(expects);
    assertEquals(1, expects.size());

    assertEquals("com.ebay.vjet", expects.get(0).getPackage().getName());
    assertEquals("I", expects.get(0).getSimpleName());
  }
Exemplo n.º 7
0
  public boolean refreshSourceFields() throws ModelException {
    if (jstType == null || !jstType.hasMixins()) { // only refresh types
      // with mixins
      return false;
    }

    ModelManager manager = ModelManager.getModelManager();

    // mixin types maybe changed, refresh the member fields
    try {
      final String natureId = getNatureId();
      final VjoSourceElementParser parser =
          (VjoSourceElementParser) getSourceElementParser(natureId);
      HashMap newElements = new HashMap();
      JSSourceModuleElementInfo info = (JSSourceModuleElementInfo) createElementInfo();

      final VjoSourceModuleStructureRequestor requestor =
          new VjoSourceModuleStructureRequestor(this, info, newElements);

      if (!isReadOnly()) {
        ((ISourceElementParserExtension) parser).setScriptProject(this.getScriptProject());
      }

      parser.setRequestor(requestor);

      final AccumulatingProblemReporter problemReporter = getAccumulatingProblemReporter();
      parser.setReporter(problemReporter);

      SourceParserUtil.parseSourceModule(this, parser);

      manager.putInfos(this, newElements);

      return true;
    } catch (CoreException e) {
      throw new ModelException(e);
    }
  }
Exemplo n.º 8
0
  public void printTypes(PrintStream p) {
    p.println("ref types in cache");
    for (IJstType t : m_refTypes.values()) {
      p.println(t.getName());
    }
    p.println("types in cache");
    for (IJstType t : m_types.values()) {
      p.println(t.getName());
    }

    p.println("types in temp");
    for (IJstType t : m_temp) {
      p.println(t.getName());
    }

    p.println("type in lib");
    for (IJstLib lib : m_lib.values()) {

      for (JstType t : lib.getAllTypes(true)) {
        p.println(t.getName());
      }
    }
  }
Exemplo n.º 9
0
  @Test
  @Category({P1, FAST, UNIT})
  @Description("Test Ctype mixin with mtype. check the package and type information.")
  public void testMixin() {
    CompilationUnitDeclaration ast = prepareAst("mixinTranslatorTestFile.js.txt", null);
    //		ITypeManager typeManager1 = ctx.getTypeManager();
    IJstType jstType = SyntaxTreeFactory2.createJST(ast, ctx);
    assertNotNull(jstType);
    //		ITypeManager typeManager2 = ctx.getTypeManager();

    //		assertTrue(typeManager1.equals(typeManager2));

    assertEquals("com.ebay.vjet", jstType.getPackage().getName());
    assertEquals("A", jstType.getSimpleName());

    List<? extends IJstTypeReference> mixins = jstType.getMixinsRef();
    assertNotNull(mixins);
    assertEquals(2, mixins.size());

    IJstType mixin = mixins.get(0).getReferencedType();
    assertTrue(mixin.isMixin());
    IJstType mixin2 = mixins.get(1).getReferencedType();
    assertTrue(mixin2.isMixin());

    assertEquals("com.ebay.vjet.fld", mixin.getPackage().getName());
    assertEquals("B", mixin.getSimpleName());
    assertEquals(3, mixin.getMethods().size());
    assertEquals(4, JstTypeHelper.getDeclaredProperties(mixin.getProperties()).size());
  }
Exemplo n.º 10
0
 @Override
 protected String getName(IJstType type) {
   return type.getName();
 }
Exemplo n.º 11
0
 protected boolean typeTypeCheck(IJstType jstType) {
   if (jstType.isInterface() || jstType.isOType()) {
     return false;
   }
   return true;
 }