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();
}
}
Aggregations