private Set<PhpVariable> parseAction(final FileObject view) {
    final FileObject controller = CakePhpUtils.getController(view);
    if (controller == null) {
      return Collections.emptySet();
    }
    final Set<PhpVariable> phpVariables = new HashSet<PhpVariable>();
    try {
      ParserManager.parse(
          Collections.singleton(Source.create(controller)),
          new UserTask() {
            @Override
            public void run(ResultIterator resultIterator) throws Exception {
              ParserResult parseResult = (ParserResult) resultIterator.getParserResult();
              final CakePhpControllerVisitor controllerVisitor =
                  new CakePhpControllerVisitor(view, getPhpClass(view));
              controllerVisitor.scan(Utils.getRoot(parseResult));
              phpVariables.addAll(controllerVisitor.getPhpVariables());
            }
          });
    } catch (ParseException ex) {
      LOGGER.log(Level.WARNING, null, ex);
    }

    return phpVariables;
  }
Ejemplo n.º 2
0
  private void processFaceletsCompositeLibraries(
      Iterable<? extends FileObject> files, Context context) {
    if (files == null) {
      return;
    }
    try {
      // look for /META-INF/resources/<folder>/*.xhtml
      // ...and index as normal composite library
      final JsfPageModelFactory compositeComponentModelFactory =
          JsfPageModelFactory.getFactory(CompositeComponentModel.Factory.class);
      final IndexingSupport sup = IndexingSupport.getInstance(context);
      for (final FileObject file : files) {
        if (CompositeComponentModel.isCompositeLibraryMember(file)) {
          Source source = Source.create(file);
          try {
            ParserManager.parse(
                Collections.singleton(source),
                new UserTask() {

                  @Override
                  public void run(ResultIterator resultIterator) throws Exception {
                    for (Embedding e : resultIterator.getEmbeddings()) {
                      if (e.getMimeType().equals("text/html")) {
                        // NOI18N
                        HtmlParserResult result =
                            (HtmlParserResult)
                                resultIterator.getResultIterator(e).getParserResult();
                        CompositeComponentModel ccmodel =
                            (CompositeComponentModel)
                                compositeComponentModelFactory.getModel(result);
                        if (ccmodel != null) {
                          // looks like a composite component
                          IndexDocument doc = sup.createDocument(file);
                          ccmodel.storeToIndex(doc);
                          sup.addDocument(doc);

                          LOGGER.log(
                              Level.FINE,
                              "Composite Libraries Scan: Model created for file {0}",
                              file); // NOI18N
                        }
                      }
                    }
                  }
                });
          } catch (ParseException ex) {
            Exceptions.printStackTrace(ex);
          }
        }
      }
    } catch (IOException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
Ejemplo n.º 3
0
  private static void checkJsDocBlock(Source source, final int offset, final String expected)
      throws Exception {
    ParserManager.parse(
        Collections.singleton(source),
        new UserTask() {
          public @Override void run(ResultIterator resultIterator) throws Exception {
            Parser.Result result = resultIterator.getParserResult();
            assertTrue(result instanceof JsParserResult);
            JsParserResult parserResult = (JsParserResult) result;

            JsDocumentationHolder documentationHolder =
                getDocumentationHolder(parserResult, new ExtDocDocumentationProvider());
            JsComment comment =
                documentationHolder.getCommentForOffset(
                    offset, documentationHolder.getCommentBlocks());
            checkExtDocElements(expected, ((ExtDocComment) comment).getTags());
          }
        });
  }
  private Set<PhpClass> parseFields(final FileObject fo) {
    FileObject tmp = fo;
    if (CakePhpUtils.isView(fo) || fo.getExt().equals(CakePhp.CTP)) {
      tmp = CakePhpUtils.getController(fo);
      if (tmp == null) {
        return Collections.singleton(getViewPhpClass());
      }
    }

    final FileObject target = tmp;
    final Set<PhpClass> phpClasses = new HashSet<PhpClass>();
    try {
      ParserManager.parse(
          Collections.singleton(Source.create(target)),
          new UserTask() {
            @Override
            public void run(ResultIterator resultIterator) throws Exception {
              ParserResult parseResult = (ParserResult) resultIterator.getParserResult();
              final CakePhpFieldsVisitor visitor;
              if (isView || isController) {
                visitor = new CakePhpControllerVisitor(fo, getPhpClass(fo));
              } else if (isComponent) {
                visitor = new CakePhpComponentVisitor(fo, getPhpClass(fo));
              } else if (isHelper) {
                visitor = new CakePhpHelperVisitor(fo, getPhpClass(fo));
              } else {
                visitor = null;
              }

              if (visitor != null) {
                visitor.scan(Utils.getRoot(parseResult));
                phpClasses.addAll(Collections.singleton(visitor.getPhpClass()));
              }
            }
          });
    } catch (ParseException ex) {
      LOGGER.log(Level.WARNING, null, ex);
    }

    return phpClasses;
  }