Package org.eclipse.cdt.core.model

Examples of org.eclipse.cdt.core.model.ITranslationUnit


  }

  private String contentsOf(CEditor cEditor) {
    ICElement input = cEditor.getInputCElement();
    if (input instanceof ITranslationUnit) {
      ITranslationUnit translationUnit = (ITranslationUnit) input;
      return new String(translationUnit.getContents());
    }
    return null;
  }
View Full Code Here


            return;
        IStructuredSelection structured = (IStructuredSelection) selection;
        Object el = structured.getFirstElement();
        IFile file;
        if (el instanceof ITranslationUnit) {
            ITranslationUnit test = (ITranslationUnit) el;
            //Assert.isTrue(test.getResource() instanceof IFile,"What?? Translation unit should be a file...");
            file = (IFile) test.getResource();
        } else
            file = (IFile) el;
            
        AnalysisJob job = new AnalysisJob(file);
        job.schedule();
View Full Code Here

  public static ITranslationUnit getTranslationUnit(
      ICProject project, String file)
    throws Exception
  {
    Path path = new Path(ProjectUtils.getFilePath(project.getProject(), file));
    ITranslationUnit src =
      CoreModelUtil.findTranslationUnitForLocation(path, project);
    if(src == null || !src.exists()){
      throw new IllegalArgumentException(
          Services.getMessage("cdt.src.file.not.found", file));
    }

    // force sync w/ file on disk
    src.close();
    src.open(null);

    return src;
  }
View Full Code Here

      CommandLine commandLine, ICProject cproject)
    throws Exception
  {
    ArrayList<Position> results = new ArrayList<Position>();
    String file = commandLine.getValue(Options.FILE_OPTION);
    ITranslationUnit src = CUtils.getTranslationUnit(cproject, file);
    if(src != null){
      int context = getContext(
          commandLine.getValue(Options.CONTEXT_OPTION), FIND_CONTEXT);

      ICProject[] scope = new ICProject[]{cproject};
View Full Code Here

    String projectName = commandLine.getValue(Options.PROJECT_OPTION);

    IProject project = ProjectUtils.getProject(projectName);
    ICProject cproject = CUtils.getCProject(project);
    if(cproject.exists()){
      ITranslationUnit src = CUtils.getTranslationUnit(cproject, file);

      // refresh the index
      CCorePlugin.getIndexManager().update(
          new ICElement[]{src}, IIndexManager.UPDATE_ALL);

      if(commandLine.hasOption(Options.VALIDATE_OPTION)){
        List<IProblem> problems = getProblems(src);
        ArrayList<Error> errors = new ArrayList<Error>();
        String filename = src.getResource()
          .getLocation().toOSString().replace('\\', '/');
        FileOffsets offsets = FileOffsets.compile(filename);
        for(IProblem problem : problems){
          int[] lineColumn = offsets.offsetToLineColumn(problem.getSourceStart());
          errors.add(new Error(
View Full Code Here

    int length = commandLine.getIntValue(Options.LENGTH_OPTION);

    ICProject cproject = CUtils.getCProject(projectName);

    CUIPlugin cuiPlugin = CUIPlugin.getDefault();
    ITranslationUnit src = CUtils.getTranslationUnit(cproject, file);
    CCorePlugin.getIndexManager().update(
        new ICElement[]{src}, IIndexManager.UPDATE_ALL);
    CCorePlugin.getIndexManager().joinIndexer(3000, new NullProgressMonitor());
    src = src.getWorkingCopy();

    IEditorInput input = new FileEditorInput((IFile)src.getResource());

    // hack... there has to be a better way
    WorkingCopyManager manager = (WorkingCopyManager)
      cuiPlugin.getWorkingCopyManager();
    manager.connect(input);
View Full Code Here

    }

    IPath path = curResource.getFullPath();// ff.getFullPath().append(inoFile);

    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(file);
    if (tu == null) {
        body += "\n";
        body += "#error the file: " + curResource.getName() + " is not found in the indexer though it exists on the file system.\n";
        body += "#error this is probably due to a bad eclipse configuration : ino and pde are not marked as c++ file.\n";
        body += "#error please check wether *.ino and *.pde are marked as C++ source code in windows->preferences->C/C++->file types.\n";
    } else {
        IASTTranslationUnit asttu = tu.getAST(index, ITranslationUnit.AST_SKIP_FUNCTION_BODIES | ITranslationUnit.AST_SKIP_ALL_HEADERS);
        IASTNode astNodes[] = asttu.getChildren();
        for (IASTNode astNode : astNodes) {
      if (astNode instanceof CPPASTFunctionDefinition) {
          String addString = astNode.getRawSignature();
          addString = addString.replaceAll("\r\n", "\n");
          addString = addString.replaceAll("\r", "\n");
          addString = addString.replaceAll("//[^\n]+\n", " ");
          addString = addString.replaceAll("\n", " ");
          addString = addString.replaceAll("\\{.+\\}", "");
          if (addString.contains("=")) {
        // ignore when there are assignements in the declaration
          } else {
        body += addString + ";\n";
          }

      }
        }
        IInclude includes[] = tu.getIncludes();
        for (IInclude include : includes) {
      includeHeaderPart += include.getSource();
      includeHeaderPart += "\n";
        }
    }
View Full Code Here

    if (rootEdit == null) {
      return;
    }
    final IASTTranslationUnit ast = rootNode.getTranslationUnit();
    final String source = ast.getRawSignature();
    final ITranslationUnit tu = ast.getOriginatingTranslationUnit();
    formatChangedCode(source, tu);
    final TextFileChange subchange = ASTRewriteAnalyzer.createCTextFileChange((IFile) tu.getResource());
    subchange.setEdit(rootEdit);
    change.add(subchange);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.cdt.core.model.ITranslationUnit

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.