Package com.sun.source.tree

Examples of com.sun.source.tree.ClassTree


    if (ASTHelpers.getSymbol(modified).isConstructor()) {
      Symbol annotationSymbol = ASTHelpers.getSymbol(annotationTree);
      if (annotationSymbol.equals(state.getSymbolFromString(JAVAX_INJECT_ANNOTATION))
          || annotationSymbol.equals(state.getSymbolFromString(GUICE_INJECT_ANNOTATION))
          || annotationSymbol.equals(state.getSymbolFromString(ASSISTED_INJECT_ANNOTATION))) {
        ClassTree enclosingClass =
            (ClassTree) state.getPath().getParentPath().getParentPath().getParentPath().getLeaf();
        if (constructorsWithInjectAndAssistedInjectMatcher.matches(enclosingClass, state)) {
          return describeMatch(annotationTree, SuggestedFix.delete(annotationTree));
        }
      }
View Full Code Here


  };
     
  @Override
  public final Description matchAnnotation(AnnotationTree annotationTree, VisitorState state) {
    if (QUALIFIER_OR_SCOPE_MATCHER.matches(annotationTree, state)) {
      ClassTree annotationType = getAnnotationTypeFromMetaAnnotation(state);
      if (HAS_QUALIFIER_ANNOTATION_MATCHER.matches(annotationType, state)
          && HAS_SCOPE_ANNOTATION_MATCHER.matches(annotationType, state)) {
        return describeMatch(annotationTree, SuggestedFix.delete(annotationTree));
      }
    }
View Full Code Here

* this check verifies that you don't call a method from the outer type as in javaScript this scope is not accessible.
* @author acraciun
*/
public class MethodInvocationOuterScopeCheck implements CheckContributor<MethodInvocationTree> {
  private void checkScope(Element methodElement, MethodInvocationTree tree, GenerationContext<Void> context) {
    ClassTree enclosingClassTree = IdentifierAccessOuterScopeCheck.enclosingClassSkipAnonymousInitializer(context.getCurrentPath());

    TypeElement currentScopeClassElement = TreeUtils.elementFromDeclaration(enclosingClassTree);
    TypeElement methodOwnerElement = (TypeElement) methodElement.getEnclosingElement();
    if (IdentifierAccessOuterScopeCheck.isOuterType(context, methodOwnerElement, currentScopeClassElement)) {
      context.addError(tree, "In Javascript you cannot call methods or fields from the outer type. "
View Full Code Here

    Element fieldElement = TreeUtils.elementFromUse(tree);
    if (!isRegularInstanceField(fieldElement, tree)) {
      return null;
    }

    ClassTree enclosingClassTree = enclosingClassSkipAnonymousInitializer(context.getCurrentPath());

    TypeElement currentScopeClassElement = TreeUtils.elementFromDeclaration(enclosingClassTree);
    TypeElement fieldOwnerElement = (TypeElement) fieldElement.getEnclosingElement();
    if (isOuterType(context, fieldOwnerElement, currentScopeClassElement)) {
      context.addError(
View Full Code Here

        String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}";

        JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code)));
        CompilationUnitTree cut = ct.parse().iterator().next();
        ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
        MethodTree method = (MethodTree) clazz.getMembers().get(0);
        VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1);
        BinaryTree cond = (BinaryTree) condSt.getInitializer();
        JCTree condJC = (JCTree) cond;

        if (condJC.pos != 93)
View Full Code Here

        List<JavaFileObject> compilationUnits =
                Collections.<JavaFileObject>singletonList(new MyFileObject());
        JavacTask task = (JavacTask)javac.getTask(null, null, null, null, null, compilationUnits);
        Trees trees = Trees.instance(task);
        CompilationUnitTree toplevel = task.parse().iterator().next();
        ClassTree classTree = (ClassTree)toplevel.getTypeDecls().get(0);
        List<? extends Tree> annotations = classTree.getModifiers().getAnnotations();
        Tree tree1 = annotations.get(0);
        Tree tree2 = annotations.get(1);
        long pos = trees.getSourcePositions().getStartPosition(toplevel, tree1);
        if (pos != 0)
            throw new AssertionError(String.format("Start pos for %s is incorrect (%s)!",
View Full Code Here

    return ret;
  }

  private ClassTree classTree() {
     // Checked implicitly in CompilationTestUtils by Tree.Kind parameter
    @SuppressWarnings("unchecked")
    ClassTree ret = (ClassTree) MoreTrees.findSubtree(baseTree(), Tree.Kind.CLASS, "TestClass");
    return ret;
  }
View Full Code Here

    public String href(Element e) {
        return visit(e).toString();
    }

    public StringBuilder visitType(TypeElement t, Void _) {
        ClassTree ct = trees.getTree(t);
        if(ct ==null)
            return new StringBuilder();    // not a part of compiled source files. return a bogus value

        switch(t.getNestingKind()) {
        case ANONYMOUS:
            String binaryName = elements.getBinaryName(t).toString();
            int idx = binaryName.lastIndexOf('$');
            String name = "~"+binaryName.substring(idx); // #$1 is ambiguous between field and anonyous type, so use '~' as the prefix for type
            return combine(getEnclosingTypeOrPackage(t).accept(this,null)).append(name);
        case TOP_LEVEL:
            // check if this class is the 'primary type' of the compilation unit
            CompilationUnitTree owner = pss.getTreePathByClass().get(ct).getCompilationUnit();
            String primaryTypeName = TreeUtil.getPrimaryTypeName(owner);
            String simpleName = ct.getSimpleName().toString();

            StringBuilder buf = new StringBuilder();
            if(!primaryTypeName.equals(simpleName)) {
                buf.append("~").append(simpleName);
            }
View Full Code Here

        // generate redireciton files for classes that live inside another class's compilation unit
        for(TypeElement e : pss.getClassElements()) {
            Element pkg = e.getEnclosingElement();
            if(pkg.getKind()!=ElementKind.PACKAGE)
                continue;
            ClassTree ct = pss.getTrees().getTree(e);
            if(ct==null)    continue;
            TreePath treePath = pss.getTreePathByClass().get(ct);

            if (treePath == null || treePath.getCompilationUnit() == null) {
                continue;
            }

            String primaryName = TreeUtil.getPrimaryTypeName(treePath.getCompilationUnit());
            if(ct.getSimpleName().toString().equals(primaryName))
                continue; // a primary type

            String prefix = ((PackageElement)pkg).getQualifiedName().toString().replace('.','/')+'/';
            if (prefix.equals("/")) { // default package
                prefix = "";
            }
            PrintWriter w = new PrintWriter(openDefault(outDir,
                prefix+ct.getSimpleName()+".js"));
            w.println("redirect('"+ct.getSimpleName()+"','"+primaryName +".js');");
            w.close();
        }

        System.out.println("Generating usage index");
        {// "find usage" index
View Full Code Here

TOP

Related Classes of com.sun.source.tree.ClassTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.