Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.ASTNode


   * @param parentClass the class of the parent type
   * @return an ASTNode
   * @since 31/08/2013
   */
  public static ASTNode getParentASTNode(ASTNode node, Class<?> parentClass) {
    ASTNode parent = node.getParent();
    while (parent.getClass() != parentClass
        && parent.getClass() != CompilationUnit.class) {
      parent = parent.getParent();
    }
    if (parent.getClass() == parentClass) {// requested parent is found
      return parent;
    } else {// requested parent not found
      return null;
    }
  }
View Full Code Here


        operateCounter(o);
        return o;
      }

      if (object instanceof ASTNode) {// ASTNode
        ASTNode node = (ASTNode) object;
        if (property.equals("type")) {// ASTNode.type
          operateCounter(object);
          return ASTNode.nodeClassForType(node.getNodeType());
        }
      }

      if (object instanceof CompilationUnit) {// JavaFile
        Object o = CompilationUnitProperties.getProperty(property).run(
            (ASTNode) object);
        operateCounter(o);
        return o;
      }

      if (object instanceof TypeDeclaration) {// Class
        Object o = TypeDecProperties.getProperty(property).run(
            (ASTNode) object);
        operateCounter(o);
        return o;
      }

      if (object instanceof EnumDeclaration) {// Enumeration
        Object o = EnumDecProperties.getProperty(property).run(
            (ASTNode) object);
        operateCounter(o);
        return o;
      }

      if (object instanceof FieldDeclaration) {// Field
        Object o = Properties.getProperty(property).run(
            (ASTNode) object);
        operateCounter(o);
        return o;
      }

      if (object instanceof MethodDeclaration) {// Method
        Object o = Properties.getProperty(property).run(
            (ASTNode) object);
        operateCounter(o);
        return o;
      }

      if (object instanceof VariableDeclaration) {// VariableDeclaration
        if (object instanceof SingleVariableDeclaration) {
          Object o = SingleVariableDecProperties
              .getProperty(property).run((ASTNode) object);
          operateCounter(o);
          return o;
        }

        if (object instanceof VariableDeclarationFragment) {
          Object o = VariableDecFragProperties.getProperty(property)
              .run((ASTNode) object);
          operateCounter(o);
          return o;
        }
      }
      // Statement or Expression
      if ((object instanceof Statement) || (object instanceof Expression)
          || (object instanceof CatchClause)) {
        ASTNode node = (ASTNode) object;
        Object o = Properties.getProperty(property).run(node);
        operateCounter(o);
        return o;
      }
    } catch (NullPointerException e) {
View Full Code Here

    if (instance instanceof IPackageFragment) {
      return IJavaProject.class.toString();
    }

    if (instance instanceof ASTNode) {
      ASTNode node = (ASTNode) instance;
      return ASTNode.nodeClassForType(node.getNodeType()).toString();
    }

    return "";
  }
View Full Code Here

    return null;
  }

  private String getFieldNameFromGetMethodName(
      MethodInvocation methodInvocation, String getMethodName) {
    ASTNode node = methodInvocation;
    while (node != null && !(node instanceof TypeDeclaration)) {
      node = node.getParent();
    }
    if (node == null)
      return NamespaceUtil.getFieldNameFromGetMethodName(getMethodName);
    TypeDeclaration type = (TypeDeclaration) node;
    MethodDeclaration[] methods = type.getMethods();
View Full Code Here

    return OK;
  }

  private MethodDeclaration getMethodDeclaration() {
    String name = invocation.getName().getIdentifier();
    ASTNode root = invocation.getRoot();
    CompilationUnit unit = (CompilationUnit) root;
    TypeDeclaration typeDec = (TypeDeclaration) unit.types().get(0);
    MethodDeclaration[] methods = typeDec.getMethods();
    MethodDeclaration mi = null;
con:    for (MethodDeclaration method : methods) {
View Full Code Here

      public boolean visit(ReturnStatement node) {
        Expression exp = node.getExpression();
        if(exp!=null&&exp instanceof SimpleName){
          String retName = ((SimpleName)exp).getFullyQualifiedName();
          if(retName.equals(fieldName)){
            ASTNode current = node;
            while(current!=null&&!(current instanceof MethodDeclaration))
              current = current.getParent();
            if(current!=null){
              MethodDeclaration bingo=(MethodDeclaration) current;
              ret[0]=bingo.getName().getFullyQualifiedName();
              return false;
            }
View Full Code Here

        if (logger.isLoggable(Level.FINER))
          logger.finer("Scanning annotations of analyzed compilation units");
        for (ICompilationUnit compUnit : command.compilationUnits()) {
          if (compUnit == null)
            continue;
          ASTNode node = WorkspaceUtilities.getASTNodeFromCompilationUnit(compUnit);
          if (monitor != null && monitor.isCanceled())
            // cancel here in case cancellation can produce null or incomplete ASTs
            return;
          if (!(node instanceof CompilationUnit))
            continue;
View Full Code Here

  public IVariableBinding resolveBinding() {
    return getNode().resolveBinding();
  }

  public boolean isCaughtVariable() {
    ASTNode parent = this.getNode().getParent();
    if( parent instanceof CatchClause ) {
      // This is not enough. We must make sure that this variable
      // is being declared inside the declaration part.
      CatchClause catch_clause = (CatchClause)parent;
      if( catch_clause.getException().equals(this.getNode()) ) {
View Full Code Here

  public static ControlFlowNode getControlFlowNode(ASTNode inNode) {
    if(controlFlowNodes == null)
      return null;
    if(inNode == null)
      throw new CrystalRuntimeException("null ASTNode argument");
    ASTNode node = inNode;
    ControlFlowNode cfn;
    // Find the CFN associated with this ASTNode
    while(node != null) {
      if(controlFlowNodes.containsKey(node)) {
        cfn = controlFlowNodes.get(node);
        // Cache the discovered knowledge
        if(node != inNode)
          addControlFlowNode(node, cfn);
        return cfn;
      }
      node = node.getParent();
    }
    return null;
  }
View Full Code Here

  protected IResult<LE> transferNode(ICFGNode<ASTNode> cfgNode, LE incoming,
      ILabel transferLabel) throws CancellationException {
    // are we canceled?
    checkCancel();

    final ASTNode astNode = cfgNode.getASTNode();
    if(astNode == null) {
      // dummy node
      // return immediately using the incoming result
      return new SingleResult<LE>(incoming);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.ASTNode

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.