Package org.eclipse.cdt.core.dom.ast

Examples of org.eclipse.cdt.core.dom.ast.IASTFileLocation


      return;
    }
    final String file = node.getContainingFilename();
    final List<IIndexName> exps = macroExpansion.get(file);
    if ((exps != null) && !exps.isEmpty()) {
      final IASTFileLocation fileLocation = getFileLocation(node);
      if (fileLocation != null) {
        final int nOff = fileLocation.getNodeOffset();
        for (final IIndexName iIndexName : exps) {
          if (iIndexName instanceof PDOMMacroReferenceName) {
            final PDOMMacroReferenceName mName = (PDOMMacroReferenceName) iIndexName;
            final int eOff = mName.getFileLocation().getNodeOffset();
            final int eLength = mName.getFileLocation().getNodeLength();
View Full Code Here


      try{
        int offset = getOffset(commandLine);
        int length = commandLine.getIntValue(Options.LENGTH_OPTION);
        IName[] names = findElement(src, scope, context, offset, length);
        for (IName iname : names){
          IASTFileLocation loc = iname.getFileLocation();
          String filename = loc.getFileName().replace('\\', '/');
          results.add(
              Position.fromOffset(filename, null, loc.getNodeOffset(), 0));
        }
      }finally{
        index.releaseReadLock();
      }
    }
View Full Code Here

    }
  }

  @Override
  public int visit(final IASTTranslationUnit tu) {
    final IASTFileLocation location = tu.getFileLocation();
    processedOffset = location.getNodeOffset();
    return super.visit(tu);
  }
View Full Code Here

  private void handleReplace(final IASTNode node) {
    final List<ASTModification> modifications = getModifications(node, ModificationKind.REPLACE);
    final String source = node.getTranslationUnit().getRawSignature();
    final ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
    final IASTFileLocation fileLocation = node.getFileLocation();
    addToRootEdit(node);
    if ((modifications.size() == 1) && (modifications.get(0).getNewNode() == null)) {
      // There is no replacement. We are deleting a piece of existing code.
      int offset = getOffsetIncludingComments(node);
      int endOffset = getEndOffsetIncludingComments(node);
      offset = Math.max(skipPrecedingBlankLines(source, offset), processedOffset);
      endOffset = skipTrailingBlankLines(source, endOffset);
      final IASTNode[] siblingsList = getContainingNodeList(node);
      if (siblingsList != null) {
        if (siblingsList.length > 1) {
          if (node == siblingsList[0]) {
            endOffset = skipToTrailingDelimiter(source, ',', endOffset);
          } else {
            offset = skipToPrecedingDelimiter(source, ',', offset);
          }
        } else if (node.getPropertyInParent() == ICPPASTFunctionDefinition.MEMBER_INITIALIZER) {
          offset = skipToPrecedingDelimiter(source, ':', offset);
        }
      }
      final IASTNode prevNode = getPreviousSiblingOrPreprocessorNode(node);
      final IASTNode nextNode = getNextSiblingOrPreprocessorNode(node);
      if ((prevNode != null) && (nextNode != null)) {
        if (ASTWriter.requireBlankLineInBetween(prevNode, nextNode)) {
          writer.newLine();
        }
      } else if (node.getParent() instanceof ICPPASTNamespaceDefinition) {
        writer.newLine();
      }
      final String code = writer.toString();
      if (endOffset > offset) {
        addChildEdit(new DeleteEdit(offset, endOffset - offset));
      }
      if (!code.isEmpty()) {
        addChildEdit(new InsertEdit(endOffset, code));
      }
    } else {
      node.accept(writer);
      String code = writer.toString();
      final int offset = fileLocation.getNodeOffset();
      final int endOffset = offset + fileLocation.getNodeLength();
      final String lineSeparator = writer.getScribe().getLineSeparator();
      if (code.endsWith(lineSeparator)) {
        code = code.substring(0, code.length() - lineSeparator.length());
      }
      addChildEdit(new ReplaceEdit(offset, endOffset - offset, code));
View Full Code Here

  private ReplaceEdit getAppendAnchor(final IASTNode node) {
    if (!((node instanceof IASTCompositeTypeSpecifier) || (node instanceof IASTCompoundStatement) || (node instanceof ICPPASTNamespaceDefinition))) {
      return null;
    }
    final String code = node.getRawSignature();
    final IASTFileLocation location = node.getFileLocation();
    final int pos = location.getNodeOffset() + location.getNodeLength();
    final int len = code.endsWith("}") ? 1 : 0; //$NON-NLS-1$
    final int insertPos = code.length() - len;
    final int startOfLine = skipPrecedingBlankLines(code, insertPos);
    if (startOfLine == insertPos) {
      // Include the closing brace in the region that will be reformatted.
      return new ReplaceEdit(pos - len, len, code.substring(insertPos));
    }
    return new ReplaceEdit(location.getNodeOffset() + startOfLine, insertPos - startOfLine, ""); //$NON-NLS-1$
  }
View Full Code Here

  }

  private int getEndOffsetIncludingComments(IASTNode node) {
    int endOffset = 0;
    while (true) {
      final IASTFileLocation fileLocation = node.getFileLocation();
      if (fileLocation != null) {
        endOffset = Math.max(endOffset, endOffset(fileLocation));
      }
      final List<IASTComment> comments = commentMap.getAllCommentsForNode(node);
      if (!comments.isEmpty()) {
View Full Code Here

  }

  private int getEndOffsetIncludingTrailingComments(IASTNode node) {
    int endOffset = 0;
    while (true) {
      final IASTFileLocation fileLocation = node.getFileLocation();
      if (fileLocation != null) {
        endOffset = Math.max(endOffset, endOffset(fileLocation));
      }
      final List<IASTComment> comments = commentMap.getTrailingCommentsForNode(node);
      if (!comments.isEmpty()) {
View Full Code Here

TOP

Related Classes of org.eclipse.cdt.core.dom.ast.IASTFileLocation

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.