Search in sources :

Example 6 with IIndex

use of org.eclipse.cdt.core.index.IIndex in project arduino-eclipse-plugin by Sloeber.

the class PdePreprocessor method processProject.

public static void processProject(boolean canSkip, IProject iProject) throws CoreException {
    deleteTheGeneratedFileInPreviousBersionsOfSloeber(iProject);
    // loop through all the files in the project to see we need to generate a file
    // This way we can avoid hitting the indexer when we use .cpp files
    List<IResource> allResources = new ArrayList<>();
    List<IResource> inoResources = new ArrayList<>();
    allResources.addAll(Arrays.asList(iProject.members(0)));
    for (IResource curResource : allResources) {
        String extension = curResource.getFileExtension();
        // only process .pde and .ino files
        if (extension != null && ((extension.equals("pde") || extension.equals("ino")))) {
            inoResources.add(curResource);
        }
    }
    if (inoResources.isEmpty()) {
        // delete the generated .ino.cpp file this is to cope with
        // renaming ino files to cpp files removing the need for
        // .ino.cpp file
        deleteTheGeneratedFile(iProject);
        return;
    }
    if (canSkip && !CCorePlugin.getIndexManager().isIndexerIdle())
        return;
    ICProject tt = CoreModel.getDefault().create(iProject);
    IIndex index = CCorePlugin.getIndexManager().getIndex(tt);
    try {
        try {
            index.acquireReadLock();
        } catch (InterruptedException e) {
            // ignore
            e.printStackTrace();
            return;
        }
        String methodDeclarations = new String();
        String includeInoPart = NEWLINE;
        String header = "//This is a automatic generated file" + NEWLINE;
        header += "//Please do not modify this file" + NEWLINE;
        header += "//If you touch this file your change will be overwritten during the next build" + NEWLINE;
        header += "//This file has been generated on ";
        header += new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        header += NEWLINE;
        header += NEWLINE;
        header += "#include \"Arduino.h\"" + NEWLINE;
        // loop through all the files in the project
        for (IResource curResource : inoResources) {
            // check whether the indexer is properly configured.
            IPath path = curResource.getFullPath();
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(file);
            if (tu == null) {
                methodDeclarations = extendBodyWithFileNotFund(methodDeclarations, curResource);
            } else {
                includeInoPart = extendIncludedInoPartForFile(includeInoPart, curResource);
                methodDeclarations = extendMethodDeclarationsForFile(methodDeclarations, index, tu);
                header = extendHeaderForFile(header, index, tu);
            }
        }
        writeTheGeneratedFile(iProject, header + NEWLINE + methodDeclarations + NEWLINE + includeInoPart);
    } finally {
        index.releaseReadLock();
    }
}
Also used : IIndex(org.eclipse.cdt.core.index.IIndex) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) IResource(org.eclipse.core.resources.IResource) Date(java.util.Date) ITranslationUnit(org.eclipse.cdt.core.model.ITranslationUnit)

Aggregations

IIndex (org.eclipse.cdt.core.index.IIndex)6 CoreException (org.eclipse.core.runtime.CoreException)4 ICProject (org.eclipse.cdt.core.model.ICProject)3 IOException (java.io.IOException)2 IIndexFile (org.eclipse.cdt.core.index.IIndexFile)2 IIndexName (org.eclipse.cdt.core.index.IIndexName)2 ITranslationUnit (org.eclipse.cdt.core.model.ITranslationUnit)2 IFile (org.eclipse.core.resources.IFile)2 IPath (org.eclipse.core.runtime.IPath)2 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 IBinding (org.eclipse.cdt.core.dom.ast.IBinding)1 IFunction (org.eclipse.cdt.core.dom.ast.IFunction)1 ICPPFunction (org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction)1 IIndexBinding (org.eclipse.cdt.core.index.IIndexBinding)1 IIndexInclude (org.eclipse.cdt.core.index.IIndexInclude)1