/*
  * @see ASTVisitor#visit(ConstructorInvocation)
  */
 @Override
 public boolean visit(ConstructorInvocation node) {
   if (node.getAST().apiLevel() >= JLS3) {
     if (!node.typeArguments().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext(); ) {
         Type t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(","); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(">"); // $NON-NLS-1$
     }
   }
   this.fBuffer.append("this("); // $NON-NLS-1$
   for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext(); ) {
     Expression e = it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(");"); // $NON-NLS-1$
   return false;
 }
 /*
  * @see ASTVisitor#visit(ClassInstanceCreation)
  */
 @Override
 public boolean visit(ClassInstanceCreation node) {
   if (node.getExpression() != null) {
     node.getExpression().accept(this);
     this.fBuffer.append("."); // $NON-NLS-1$
   }
   this.fBuffer.append("new "); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= JLS3) {
     if (!node.typeArguments().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext(); ) {
         Type t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(","); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(">"); // $NON-NLS-1$
     }
     node.getType().accept(this);
   }
   this.fBuffer.append("("); // $NON-NLS-1$
   for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext(); ) {
     Expression e = it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   if (node.getAnonymousClassDeclaration() != null) {
     node.getAnonymousClassDeclaration().accept(this);
   }
   return false;
 }
 /*
  * @see ASTVisitor#visit(SuperMethodInvocation)
  */
 @Override
 public boolean visit(SuperMethodInvocation node) {
   if (node.getQualifier() != null) {
     node.getQualifier().accept(this);
     this.fBuffer.append("."); // $NON-NLS-1$
   }
   this.fBuffer.append("super."); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= JLS3) {
     if (!node.typeArguments().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext(); ) {
         Type t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(","); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(">"); // $NON-NLS-1$
     }
   }
   node.getName().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext(); ) {
     Expression e = it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   return false;
 }
Пример #4
0
 private void printTypeArgs(List<Type> args, Object arg) {
   if (args != null) {
     for (Iterator<Type> i = args.iterator(); i.hasNext(); ) {
       Type t = i.next();
       t.accept(this, arg);
       if (i.hasNext()) {}
     }
   }
 }
 /*
  * @see ASTVisitor#visit(IntersectionType)
  */
 @Override
 public boolean visit(IntersectionType node) {
   for (Iterator<Type> it = node.types().iterator(); it.hasNext(); ) {
     Type t = it.next();
     t.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(" & "); // $NON-NLS-1$
     }
   }
   return false;
 }
Пример #6
0
  @Override
  public Set<Symbol> getAllSymbols(Type type) {
    Set<OWLEntity> entities =
        type.accept(
            new TypeVisitorEx<Set<OWLEntity>>() {
              @Override
              public Set<OWLEntity> visitOWLAxiomType(OWLAxiomType owlAxiomType) {
                return Collections.emptySet();
              }

              @Override
              public Set<OWLEntity> visitNonOWLType(Type t) {
                return Collections.emptySet();
              }

              @Override
              public Set<OWLEntity> visitOWLType(OWLType owlType) {
                Set<OWLEntity> toReturn = new HashSet<>();
                switch (owlType) {
                  case OWL_CLASS:
                    toReturn.addAll(
                        OWLEntityCheckerScope.this.getEntityFinder().getMatchingOWLClasses("*"));
                    break;
                  case OWL_DATA_PROPERTY:
                    toReturn.addAll(
                        OWLEntityCheckerScope.this
                            .getEntityFinder()
                            .getMatchingOWLDataProperties("*"));
                    break;
                  case OWL_OBJECT_PROPERTY:
                    toReturn.addAll(
                        OWLEntityCheckerScope.this
                            .getEntityFinder()
                            .getMatchingOWLObjectProperties("*"));
                    break;
                  case OWL_INDIVIDUAL:
                    toReturn.addAll(
                        OWLEntityCheckerScope.this
                            .getEntityFinder()
                            .getMatchingOWLIndividuals("*"));
                    break;
                  default:
                    break;
                }
                return toReturn;
              }
            });
    Set<Symbol> toReturn = new HashSet<>(entities.size());
    for (OWLEntity owlEntity : entities) {
      toReturn.add(new OWLEntitySymbol(getOWLEntityRenderer().render(owlEntity), owlEntity));
    }
    return toReturn;
  }
 @Override
 public void visit(MethodReferenceExpr n, final A arg) {
   visitComment(n.getComment(), arg);
   if (n.getTypeArguments() != null) {
     for (final Type t : n.getTypeArguments()) {
       t.accept(this, arg);
     }
   }
   if (n.getScope() != null) {
     n.getScope().accept(this, arg);
   }
 }
 @Override
 public void visit(final ClassOrInterfaceType n, final A arg) {
   visitComment(n.getComment(), arg);
   visitAnnotations(n, arg);
   if (n.getScope() != null) {
     n.getScope().accept(this, arg);
   }
   if (n.getTypeArguments() != null) {
     for (final Type t : n.getTypeArguments()) {
       t.accept(this, arg);
     }
   }
 }
 private void printReferenceTypeArguments(List<Type> typeArguments) {
   this.fBuffer.append("::"); // $NON-NLS-1$
   if (!typeArguments.isEmpty()) {
     this.fBuffer.append('<');
     for (Iterator<Type> it = typeArguments.iterator(); it.hasNext(); ) {
       Type t = it.next();
       t.accept(this);
       if (it.hasNext()) {
         this.fBuffer.append(',');
       }
     }
     this.fBuffer.append('>');
   }
 }
 /*
  * @see ASTVisitor#visit(ParameterizedType)
  * @since 3.0
  */
 @Override
 public boolean visit(ParameterizedType node) {
   node.getType().accept(this);
   this.fBuffer.append("<"); // $NON-NLS-1$
   for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext(); ) {
     Type t = it.next();
     t.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(">"); // $NON-NLS-1$
   return false;
 }
 /*
  * @see ASTVisitor#visit(WildcardType)
  * @since 3.0
  */
 @Override
 public boolean visit(WildcardType node) {
   printTypeAnnotations(node);
   this.fBuffer.append("?"); // $NON-NLS-1$
   Type bound = node.getBound();
   if (bound != null) {
     if (node.isUpperBound()) {
       this.fBuffer.append(" extends "); // $NON-NLS-1$
     } else {
       this.fBuffer.append(" super "); // $NON-NLS-1$
     }
     bound.accept(this);
   }
   return false;
 }
 /*
  * @see ASTVisitor#visit(TypeParameter)
  * @since 3.0
  */
 @Override
 public boolean visit(TypeParameter node) {
   printModifiers(node.modifiers());
   node.getName().accept(this);
   if (!node.typeBounds().isEmpty()) {
     this.fBuffer.append(" extends "); // $NON-NLS-1$
     for (Iterator<Type> it = node.typeBounds().iterator(); it.hasNext(); ) {
       Type t = it.next();
       t.accept(this);
       if (it.hasNext()) {
         this.fBuffer.append(" & "); // $NON-NLS-1$
       }
     }
   }
   return false;
 }
 @Override
 public void visit(final ExplicitConstructorInvocationStmt n, final A arg) {
   visitComment(n.getComment(), arg);
   if (!n.isThis() && n.getExpr() != null) {
     n.getExpr().accept(this, arg);
   }
   if (n.getTypeArguments() != null) {
     for (final Type t : n.getTypeArguments()) {
       t.accept(this, arg);
     }
   }
   if (n.getArgs() != null) {
     for (final Expression e : n.getArgs()) {
       e.accept(this, arg);
     }
   }
 }
 @Override
 public void visit(final MethodCallExpr n, final A arg) {
   visitComment(n.getComment(), arg);
   if (n.getScope() != null) {
     n.getScope().accept(this, arg);
   }
   if (n.getTypeArguments() != null) {
     for (final Type t : n.getTypeArguments()) {
       t.accept(this, arg);
     }
   }
   n.getNameExpr().accept(this, arg);
   if (n.getArgs() != null) {
     for (final Expression e : n.getArgs()) {
       e.accept(this, arg);
     }
   }
 }
 /*
  * @see ASTVisitor#visit(EnumDeclaration)
  * @since 3.0
  */
 @Override
 public boolean visit(EnumDeclaration node) {
   if (node.getJavadoc() != null) {
     node.getJavadoc().accept(this);
   }
   printModifiers(node.modifiers());
   this.fBuffer.append("enum "); // $NON-NLS-1$
   node.getName().accept(this);
   this.fBuffer.append(" "); // $NON-NLS-1$
   if (!node.superInterfaceTypes().isEmpty()) {
     this.fBuffer.append("implements "); // $NON-NLS-1$
     for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
       Type t = it.next();
       t.accept(this);
       if (it.hasNext()) {
         this.fBuffer.append(", "); // $NON-NLS-1$
       }
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   this.fBuffer.append("{"); // $NON-NLS-1$
   for (Iterator<EnumConstantDeclaration> it = node.enumConstants().iterator(); it.hasNext(); ) {
     EnumConstantDeclaration d = it.next();
     d.accept(this);
     // enum constant declarations do not include punctuation
     if (it.hasNext()) {
       // enum constant declarations are separated by commas
       this.fBuffer.append(", "); // $NON-NLS-1$
     }
   }
   if (!node.bodyDeclarations().isEmpty()) {
     this.fBuffer.append("; "); // $NON-NLS-1$
     for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
       BodyDeclaration d = it.next();
       d.accept(this);
       // other body declarations include trailing punctuation
     }
   }
   this.fBuffer.append("}"); // $NON-NLS-1$
   return false;
 }
 @Override
 public void visit(final ObjectCreationExpr n, final A arg) {
   visitComment(n.getComment(), arg);
   if (n.getScope() != null) {
     n.getScope().accept(this, arg);
   }
   if (n.getTypeArguments() != null) {
     for (final Type t : n.getTypeArguments()) {
       t.accept(this, arg);
     }
   }
   n.getType().accept(this, arg);
   if (n.getArgs() != null) {
     for (final Expression e : n.getArgs()) {
       e.accept(this, arg);
     }
   }
   if (n.getAnonymousClassBody() != null) {
     for (final BodyDeclaration<?> member : n.getAnonymousClassBody()) {
       member.accept(this, arg);
     }
   }
 }
 /*
  * @see ASTVisitor#visit(ArrayCreation)
  */
 @Override
 public boolean visit(ArrayCreation node) {
   this.fBuffer.append("new "); // $NON-NLS-1$
   ArrayType at = node.getType();
   int dims = at.getDimensions();
   Type elementType = at.getElementType();
   elementType.accept(this);
   for (Iterator<Expression> it = node.dimensions().iterator(); it.hasNext(); ) {
     this.fBuffer.append("["); // $NON-NLS-1$
     Expression e = it.next();
     e.accept(this);
     this.fBuffer.append("]"); // $NON-NLS-1$
     dims--;
   }
   // add empty "[]" for each extra array dimension
   for (int i = 0; i < dims; i++) {
     this.fBuffer.append("[]"); // $NON-NLS-1$
   }
   if (node.getInitializer() != null) {
     node.getInitializer().accept(this);
   }
   return false;
 }
Пример #18
0
 /**
  * Get a localized string represenation for a given type.
  *
  * @param t type to be displayed
  * @param locale the locale in which the string is to be rendered
  * @return localized string representation
  */
 public String visit(Type t, Locale locale) {
   return t.accept(this, locale);
 }
 /*
  * @see ASTVisitor#visit(MethodDeclaration)
  */
 @Override
 public boolean visit(MethodDeclaration node) {
   if (node.getJavadoc() != null) {
     node.getJavadoc().accept(this);
   }
   if (node.getAST().apiLevel() >= JLS3) {
     printModifiers(node.modifiers());
     if (!node.typeParameters().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext(); ) {
         TypeParameter t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(", "); // $NON-NLS-1$
         }
       }
       this.fBuffer.append("> "); // $NON-NLS-1$
     }
   }
   if (!node.isConstructor()) {
     if (node.getReturnType2() != null) {
       node.getReturnType2().accept(this);
     } else {
       // methods really ought to have a return type
       this.fBuffer.append("void"); // $NON-NLS-1$
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   node.getName().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= AST.JLS8) {
     Type receiverType = node.getReceiverType();
     if (receiverType != null) {
       receiverType.accept(this);
       this.fBuffer.append(' ');
       SimpleName qualifier = node.getReceiverQualifier();
       if (qualifier != null) {
         qualifier.accept(this);
         this.fBuffer.append('.');
       }
       this.fBuffer.append("this"); // $NON-NLS-1$
       if (node.parameters().size() > 0) {
         this.fBuffer.append(',');
       }
     }
   }
   for (Iterator<SingleVariableDeclaration> it = node.parameters().iterator(); it.hasNext(); ) {
     SingleVariableDeclaration v = it.next();
     v.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(", "); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= AST.JLS8) {
     List<Dimension> dimensions = node.extraDimensions();
     for (Iterator<Dimension> it = dimensions.iterator(); it.hasNext(); ) {
       Dimension e = it.next();
       e.accept(this);
     }
   } else {
     for (int i = 0; i < node.getExtraDimensions(); i++) {
       this.fBuffer.append("[]"); // $NON-NLS-1$
     }
   }
   List<? extends ASTNode> thrownExceptions =
       node.getAST().apiLevel() >= AST.JLS8
           ? node.thrownExceptionTypes()
           : getThrownExceptions(node);
   if (!thrownExceptions.isEmpty()) {
     this.fBuffer.append(" throws "); // $NON-NLS-1$
     for (Iterator<? extends ASTNode> it = thrownExceptions.iterator(); it.hasNext(); ) {
       ASTNode n = it.next();
       n.accept(this);
       if (it.hasNext()) {
         this.fBuffer.append(", "); // $NON-NLS-1$
       }
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   if (node.getBody() == null) {
     this.fBuffer.append(";"); // $NON-NLS-1$
   } else {
     node.getBody().accept(this);
   }
   return false;
 }
 /*
  * @see ASTVisitor#visit(TypeDeclaration)
  */
 @Override
 public boolean visit(TypeDeclaration node) {
   if (node.getJavadoc() != null) {
     node.getJavadoc().accept(this);
   }
   if (node.getAST().apiLevel() >= JLS3) {
     printModifiers(node.modifiers());
   }
   this.fBuffer.append(node.isInterface() ? "interface " : "class "); // $NON-NLS-2$//$NON-NLS-1$
   node.getName().accept(this);
   if (node.getAST().apiLevel() >= JLS3) {
     if (!node.typeParameters().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext(); ) {
         TypeParameter t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(","); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(">"); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(" "); // $NON-NLS-1$
   if (node.getAST().apiLevel() >= JLS3) {
     if (node.getSuperclassType() != null) {
       this.fBuffer.append("extends "); // $NON-NLS-1$
       node.getSuperclassType().accept(this);
       this.fBuffer.append(" "); // $NON-NLS-1$
     }
     if (!node.superInterfaceTypes().isEmpty()) {
       this.fBuffer.append(
           node.isInterface() ? "extends " : "implements "); // $NON-NLS-2$//$NON-NLS-1$
       for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
         Type t = it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(", "); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(" "); // $NON-NLS-1$
     }
   }
   this.fBuffer.append("{"); // $NON-NLS-1$
   BodyDeclaration prev = null;
   for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
     BodyDeclaration d = it.next();
     if (prev instanceof EnumConstantDeclaration) {
       // enum constant declarations do not include punctuation
       if (d instanceof EnumConstantDeclaration) {
         // enum constant declarations are separated by commas
         this.fBuffer.append(", "); // $NON-NLS-1$
       } else {
         // semicolon separates last enum constant declaration from
         // first class body declarations
         this.fBuffer.append("; "); // $NON-NLS-1$
       }
     }
     d.accept(this);
     prev = d;
   }
   this.fBuffer.append("}"); // $NON-NLS-1$
   return false;
 }