コード例 #1
0
ファイル: TclIfProcessor.java プロジェクト: eclipse/dltk.tcl
  private Statement parseBranch(IfContext context, boolean wrapAsBlock, String message)
      throws IfStatementError {
    final ASTNode node = context.get();
    if (node instanceof TclBlockExpression) {
      final Block block = new Block(node.sourceStart(), node.sourceEnd());
      parseBlock(context.parser, block, (TclBlockExpression) node);
      return block;
    } else if (node instanceof SimpleReference) {
      final Block block = new Block(node.sourceStart(), node.sourceEnd());
      block.addStatement(node);
      return block;
    } else if (node instanceof TclStatement) {
      if (wrapAsBlock) {
        final Block block = new Block(node.sourceStart(), node.sourceEnd());
        block.addStatement(node);
        return block;
      } else {
        return (TclStatement) node;
      }
    } else if (node instanceof TclExecuteExpression) {
      if (wrapAsBlock) {
        final Block block = new Block(node.sourceStart(), node.sourceEnd());
        block.addStatement(node);
        return block;
      } else {
        return (TclExecuteExpression) node;
      }

    } else if (node instanceof Block) {
      return (Block) node;
    } else {
      throw new IfStatementError(message, context.start(), context.end());
    }
  }
コード例 #2
0
ファイル: ASTNode.java プロジェクト: eclipse/dltk.core
 /**
  * Tests if the specified node is located at the same location.
  *
  * @param other
  * @return
  */
 public boolean locationMatches(ASTNode other) {
   if (other == this) return true;
   if (other == null) {
     return false;
   }
   return other.sourceEnd() >= 0
       && other.sourceStart() >= 0
       && sourceStart() == other.sourceStart()
       && sourceEnd() == other.sourceEnd();
 }
コード例 #3
0
 private boolean isStringLiteralNeeded(ASTNode node) {
   if (stack.empty()) {
     return true;
   }
   final ASTNode top = stack.peek();
   if (top instanceof RubyDRegexpExpression) {
     return false;
   }
   if (top instanceof RubyDynamicStringExpression) {
     return node.sourceStart() >= top.sourceStart() && node.sourceEnd() <= top.sourceEnd();
   }
   return true;
 }
コード例 #4
0
 private void selectionOnVariable(ModuleDeclaration parsedUnit, VariableReference e) {
   String name = e.getName();
   if (name.startsWith("@")) { // $NON-NLS-1$
     IField[] fields =
         RubyModelUtils.findFields(mixinModel, sourceModule, parsedUnit, name, e.sourceStart());
     addArrayToCollection(fields, selectionElements);
   } else {
     /*
      * local vars (legacy, saved for speed reasons: we don't need to use
      * mixin model for local vars)
      */
     ASTNode parentScope = null;
     for (int i = wayToNode.length; --i >= 0; ) {
       final ASTNode node = wayToNode[i];
       if (node instanceof MethodDeclaration
           || node instanceof TypeDeclaration
           || node instanceof ModuleDeclaration
           || node instanceof RubyForStatement2) {
         parentScope = node;
         break;
       }
     }
     if (parentScope != null) {
       RubyAssignment[] assignments =
           RubyTypeInferencingUtils.findLocalVariableAssignments(parentScope, e, name);
       if (assignments.length > 0) {
         final ASTNode left = assignments[0].getLeft();
         selectionElements.add(createLocalVariable(name, left.sourceStart(), left.sourceEnd()));
       } else {
         selectionElements.add(createLocalVariable(name, e.sourceStart(), e.sourceEnd()));
       }
     }
   }
 }
コード例 #5
0
ファイル: ASTPrintVisitor.java プロジェクト: anod/pdt
  protected Map<String, String> createInitialParameters(ASTNode s) throws Exception {
    Map<String, String> parameters = new LinkedHashMap<String, String>();

    // Print offset information:
    parameters.put("start", Integer.toString(s.sourceStart()));
    parameters.put("end", Integer.toString(s.sourceEnd()));

    // Print modifiers:
    if (s instanceof Declaration) {
      Declaration declaration = (Declaration) s;
      StringBuilder buf = new StringBuilder();
      if (declaration.isAbstract()) {
        buf.append(",abstract");
      }
      if (declaration.isFinal()) {
        buf.append(",final");
      }
      if (declaration.isPrivate()) {
        buf.append(",private");
      }
      if (declaration.isProtected()) {
        buf.append(",protected");
      }
      if (declaration.isPublic()) {
        buf.append(",public");
      }
      if (declaration.isStatic()) {
        buf.append(",static");
      }
      String modifiers = buf.toString();
      parameters.put("modifiers", modifiers.length() > 0 ? modifiers.substring(1) : modifiers);
    }

    return parameters;
  }
コード例 #6
0
ファイル: TclIfProcessor.java プロジェクト: eclipse/dltk.tcl
 private ASTNode parseCondition(IfContext context) throws IfStatementError {
   if (context.isEOF()) {
     throw new IfStatementError(
         Messages.TclIfProcessor_missingCondition, context.start(), context.end());
   }
   ASTNode node = context.get();
   if (node instanceof TclBlockExpression) {
     TclBlockExpression bl = (TclBlockExpression) node;
     List parseBlock = bl.parseBlockSimple(false);
     ASTListNode list = new ASTListNode(bl.sourceStart() + 1, bl.sourceEnd() - 1);
     for (int j = 0; j < parseBlock.size(); j++) {
       Object st = parseBlock.get(j);
       if (st instanceof TclStatement) {
         List expressions = ((TclStatement) st).getExpressions();
         for (int k = 0; k < expressions.size(); k++) {
           ASTNode expr = (ASTNode) expressions.get(k);
           list.addNode(expr);
         }
       }
     }
     return list;
   } else if (node instanceof SimpleReference) {
     return node;
   } else if (node instanceof TclAdvancedExecuteExpression) {
     TclAdvancedExecuteExpression ex = (TclAdvancedExecuteExpression) node;
     List childs = ex.getChilds();
     return new ASTListNode(node.sourceStart(), node.sourceEnd(), childs);
   } else if (node instanceof TclExecuteExpression) {
     return node;
   } else if (node instanceof Block) {
     return node;
   }
   throw new IfStatementError(Messages.TclIfProcessor_incorrectCondition, node);
 }
コード例 #7
0
 @Override
 public boolean visitGeneral(ASTNode node) throws Exception {
   if (!ACTIVE) {
     return true;
   }
   if (node instanceof RubyRegexpExpression || node instanceof RubyDRegexpExpression) {
     handleRegexp(node);
   } else if (node instanceof RubySymbolReference) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_SYMBOL);
   } else if (node instanceof VariableReference) {
     handleVariableReference((VariableReference) node);
   } else if (node instanceof RubyDVarExpression) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_LOCAL_VARIABLE);
   } else if (node instanceof RubyDAssgnExpression) {
     ASTNode var = ((RubyDAssgnExpression) node).getLeft();
     requestor.addPosition(var.sourceStart(), var.sourceEnd(), HL_LOCAL_VARIABLE);
   } else if (node instanceof StringLiteral) {
     if (isStringLiteralNeeded(node)) {
       requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_STRING);
     }
   } else if (node instanceof NumericLiteral
       || node instanceof FloatNumericLiteral
       || node instanceof BigNumericLiteral) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_NUMBER);
   } else if (node instanceof RubyEvaluatableStringExpression) {
     handleEvaluatableExpression(node);
   } else if (node instanceof CallExpression) {
     final CallExpression call = (CallExpression) node;
     if (!(RubySyntaxUtils.isRubyOperator(call.getName())
         || call.getReceiver() == null && RubyCodeScanner.isPseudoKeyword(call.getName()))) {
       final SimpleReference callName = call.getCallName();
       if (callName.sourceStart() >= 0 && callName.sourceEnd() > callName.sourceStart()) {
         requestor.addPosition(callName.sourceStart(), callName.sourceEnd(), HL_DEFAULT);
       }
     }
   } else if (node instanceof Declaration) {
     final Declaration declaration = (Declaration) node;
     requestor.addPosition(declaration.getNameStart(), declaration.getNameEnd(), HL_DEFAULT);
   } else if (node instanceof RubyConstantDeclaration) {
     final RubyConstantDeclaration declaration = (RubyConstantDeclaration) node;
     final SimpleReference name = declaration.getName();
     requestor.addPosition(name.sourceStart(), name.sourceEnd(), HL_CONST);
   }
   stack.push(node);
   return true;
 }
コード例 #8
0
 public CompletionOnVariable(
     String completionToken,
     ASTNode completionNode,
     ASTNode node,
     ASTNode inNode,
     boolean canHandleEmpty) {
   super(completionNode.sourceStart(), completionNode.sourceEnd(), completionToken);
   this.parentNode = node;
   this.completionNode = completionNode;
   this.inNode = inNode;
   this.canHandleEmpty = canHandleEmpty;
 }
コード例 #9
0
 private void handleEvaluatableExpression(ASTNode node) {
   int start = node.sourceStart();
   int end = node.sourceEnd();
   if (content[start] == '#' && content[start + 1] == '{') {
     if (content[end - 1] == '\r') {
       // FIXME JRuby bug
       --end;
     }
     if (content[end - 1] == '}') {
       requestor.addPosition(start, start + 2, HL_EVAL_EXPR);
       requestor.addPosition(end - 1, end - 0, HL_EVAL_EXPR);
     }
   }
 }
コード例 #10
0
 private void handleRegexp(ASTNode node) {
   int start = node.sourceStart();
   int end = node.sourceEnd();
   if (start >= 1 && content[start - 1] == '/') {
     --start;
     if (end < content.length && content[end] == '/') {
       ++end;
     }
     while (end < content.length && RubySyntaxUtils.isValidRegexpModifier(content[end])) {
       ++end;
     }
   } else if (start >= 3 && content[start - 3] == '%' && content[start - 2] == 'r') {
     char terminator = RubySyntaxUtils.getPercentStringTerminator(content[start - 1]);
     if (terminator != 0 && end < content.length && content[end] == terminator) {
       start -= 3;
       ++end;
       while (end < content.length && RubySyntaxUtils.isValidRegexpModifier(content[end])) {
         ++end;
       }
     }
   }
   requestor.addPosition(start, end, HL_REGEXP);
 }
コード例 #11
0
ファイル: TclIfProcessor.java プロジェクト: eclipse/dltk.tcl
 public ASTNode process(TclStatement statement, ITclParser parser, ASTNode parent) {
   final IfContext context = new IfContext(parser, statement);
   IfStatement ifStatement = new IfStatement(context.start(), context.end());
   addToParent(parent, ifStatement);
   try {
     parseIf(context, ifStatement);
     if (!context.isEOF()) {
       final ASTNode extraBegin = context.get(context.index);
       final ASTNode extraEnd = context.get(context.size() - 1);
       report(
           parser,
           Messages.TclIfProcessor_unexpectedStatements,
           extraBegin.sourceStart(),
           extraEnd.sourceEnd(),
           ProblemSeverities.Error);
     }
   } catch (IfStatementError e) {
     // if (DLTKCore.DEBUG) {
     // e.printStackTrace();
     // }
     report(parser, e.getMessage(), e.start, e.end, ProblemSeverities.Error);
   }
   return ifStatement;
 }
コード例 #12
0
ファイル: TclIfProcessor.java プロジェクト: eclipse/dltk.tcl
 /**
  * @param message
  * @param node
  */
 public IfStatementError(String message, ASTNode node) {
   this(message, node.sourceStart(), node.sourceEnd());
 }