There are 8 code examples for org.eclipse.core.resources.IFile.
The API names are highlighted below.
You can use
button
to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.
Project Name: codecover Package: org.codecover.eclipse.builder
Source Code: CodeCoverCompilationParticipant.java (Click to view .java file)
Method Code:
private boolean isCodeUnchanged(HierarchyLevel code,BuildContext[] files,InstrumentableItemsManager instrumentableItemsManager){
boolean result=true;
for ( BuildContext buildContext : files) {
final IFile file=buildContext.getFile();
final IJavaElement compilationUnit=JavaCore.create(file);
final HierarchyLevel codeFile=EclipseMASTLinkage.findSource(code,compilationUnit);
final boolean instrument=instrumentableItemsManager.containsIPath(file.getFullPath());
final boolean fileInTSC=codeFile != null;
if (instrument && fileInTSC) {
String mastText;
Location mastLocation;
mastLocation=codeFile.getLocation().getLocations().get(0);
mastText=mastLocation.getFile().getContent();
try {
InputStream inStream=file.getContents();
Charset charsetOfFile=Charset.forName(file.getCharset());
String contentOfFile=FileTool.getContentFromStream(inStream,charsetOfFile);
if (!mastText.equals(contentOfFile)) {
eclipseLogger.debug(file.getName() + " has changed (break)");
result=false;
break;
}
}
catch ( CoreException e) {
e.printStackTrace();
return false;
}
catch ( IOException e) {
e.printStackTrace();
return false;
}
}
else if (instrument && !fileInTSC) {
eclipseLogger.debug("was not found in the MAST (break)");
result=false;
break;
}
else if (!instrument && fileInTSC) {
result=false;
break;
}
}
return result;
}
Project Name: codecover Package: org.codecover.eclipse.tscmanager
Source Code: TSContainerManager.java (Click to view .java file)
Method Code:
/**
* Generates a unique name for a known test session container. The name is unique in the current session of
* Eclipse. The <code>TSContainerInfo</code> this name is used for must be added to the
* <code>TSContainerManager</code> before the write lock is released, else another thread could generate
* the same name.
* @param tsc the test session container the name is generated for
* @param file the file of the test session container the name is generated for
* @return a (session-)unique name for the given test session container
*/
private String generateTSContainerName(TestSessionContainer tsc,IFile file){
List<String> existingNames=new ArrayList<String>();
String name=file.getProject().getName() + " " + DateFormat.getDateTimeInstance().format(tsc.getDate());
String escapedName;
synchronized (this.writeLock) {
for ( TSContainerInfo tscInfo : this.getTestSessionContainers()) {
existingNames.add(tscInfo.getName());
}
escapedName=NameReoccurenceHelper.escapeName(existingNames,name);
}
return escapedName;
}
Project Name: codecover Package: org.codecover.eclipse.tscmanager
Source Code: TSContainerInfo.java (Click to view .java file)
Method Code:
/**
* Returns the project the represented test session container belongs to.
* @return the project the represented test session container belongs to.
*/
public IProject getProject(){
synchronized (this.lockFile) {
return this.file.getProject();
}
}
Project Name: codecover Package: org.codecover.eclipse.tscmanager
Source Code: TSContainerStorage.java (Click to view .java file)
Method Code:
/**
* Loads the <code>TestSessionContainer</code> from the given file.
* @param file the file which contains the test session container to load
* @param fully if <code>true</code> fully loads the test session container, else only loads some infos
* about the test session container (see {@link TestSessionContainer#loadInfoOnly(org.codecover.model.extensions.PluginManager,Logger,MASTBuilder,String)} for details)
* @param monitor a progress monitor or <code>null</code> if progress reporting is not desired
* @return the <code>TestSessionContainer</code> of the given file or <code>null</code> if the given
* file doesn't exist.
* @throws FileLoadException if the <code>TestSessionContainer</code> can't be read from the contents of
* the file
*/
static TestSessionContainer load(final IFile file,final boolean fully,IProgressMonitor monitor) throws FileLoadException {
Logger logger=CodeCoverPlugin.getDefault().getLogger();
MASTBuilder builder=new MASTBuilder(logger);
TestSessionContainer tsc=null;
monitor=(monitor != null) ? monitor : new NullProgressMonitor();
try {
monitor.beginTask(String.format(MONITOR_LOADING_TEST_SESSION_CONTAINER_FROM,file.getName()),2);
monitor.worked(1);
if (fully) {
tsc=TestSessionContainer.load(CodeCoverPlugin.getDefault().getEclipsePluginManager().getPluginManager(),logger,builder,file.getLocation().toOSString());
}
else {
tsc=TestSessionContainer.loadInfoOnly(CodeCoverPlugin.getDefault().getEclipsePluginManager().getPluginManager(),logger,builder,file.getLocation().toOSString());
}
monitor.worked(1);
}
finally {
monitor.done();
}
return tsc;
}
Project Name: codecover Package: org.codecover.eclipse.utils
Source Code: EclipseMASTLinkage.java (Click to view .java file)
Method Code:
/**
* Read a whole file into a String.
* @param filethe synchronized, existing, readable and local file
* @returnthe contents of the file
* @see IResource#isSynchronized(int)
* @see IResource#isLocal(int)
*/
public static String getContent(IFile file){
String contentOfFile=null;
try {
InputStream inStream=file.getContents();
Charset charsetOfFile=Charset.forName(file.getCharset());
contentOfFile=FileTool.getContentFromStream(inStream,charsetOfFile);
}
catch ( CoreException e) {
boolean isSynchronized=false;
boolean isLocal=false;
try {
isSynchronized=file.isSynchronized(IResource.DEPTH_ZERO);
isLocal=file.isLocal(IResource.DEPTH_ZERO);
}
catch ( Exception ex) {
CodeCoverPlugin.getDefault().getLogger().fatal("something is totally broken",ex);
}
if (!isSynchronized) {
throw new IllegalArgumentException("file is not in sync");
}
if (!isLocal) {
CodeCoverPlugin.getDefault().getLogger().error("Unexpected not local resource. Please " + "file a bug with the whole message.",e);
throw new IllegalArgumentException("file is not local");
}
}
catch ( IOException e) {
CodeCoverPlugin.getDefault().getLogger().debug("Can't read: " + file.getFullPath().toOSString(),e);
throw new IllegalArgumentException("File not readable.");
}
return contentOfFile;
}
Project Name: codecover Package: org.codecover.eclipse.utils.recommendationgenerator
Source Code: LineNumberDeterminator.java (Click to view .java file)
Method Code:
public static List<Integer> getLineNumbers(IResource resource,int offsetStart,int offsetEnd){
long a=new Date().getTime();
List<Integer> ret=new ArrayList<Integer>();
List<Integer> lineBreakPositions;
if (lineBreakPositionMap.containsKey(resource)) {
lineBreakPositions=lineBreakPositionMap.get(resource);
}
else {
lineBreakPositions=new ArrayList<Integer>();
IFile iFile=wsRoot.getFile(resource.getFullPath());
String portableString=iFile.getLocation().toPortableString();
File file=new File(portableString);
FileInputStream fis;
try {
fis=new FileInputStream(file);
int n=0;
int count=0;
while ((n=fis.read()) != -1) {
count++;
if (n == 10) {
lineBreakPositions.add(count);
}
}
fis.close();
}
catch ( FileNotFoundException e) {
e.printStackTrace();
}
catch ( IOException e) {
e.printStackTrace();
}
lineBreakPositionMap.put(resource,lineBreakPositions);
}
int beginline=1;
int endline=1;
for ( Integer lineBreakPosition : lineBreakPositions) {
if (lineBreakPosition < offsetStart) {
beginline++;
}
if (lineBreakPosition < offsetEnd) {
endline++;
}
}
for (int i=beginline; i <= endline; i++) {
ret.add(i);
}
return ret;
}
Project Name: codecover Package: org.codecover.eclipse.utils.recommendationgenerator.datacollectors
Source Code: CodeFileLineDataCollector.java (Click to view .java file)
Method Code:
@Override public void invoke() throws JavaModelException {
for ( IResource resource : getRelevantFiles()) {
double lineCnt=0.0;
if (resource instanceof IFile) {
IFile file=(IFile)resource;
try {
InputStream contents=file.getContents();
BufferedReader reader=new BufferedReader(new InputStreamReader(contents));
String strLine;
while ((strLine=reader.readLine()) != null) {
if (strLine.trim().length() > 0) {
lineCnt++;
}
}
}
catch ( CoreException e) {
e.printStackTrace();
}
catch ( IOException e) {
e.printStackTrace();
}
}
int max=((Integer)this.getErrorIndicator().getParameter("Grenze").getValue());
if (lineCnt > max) {
lineCnt=max;
}
System.out.print("Datei " + resource.getName() + " hat "+ lineCnt+ " Zeilen. Das gibt ");
lineCnt=lineCnt / 50;
System.out.println(lineCnt + " Punkte.");
this.getErrorIndicator().addProbabilityInformation(resource,lineCnt);
}
}
Project Name: eclemma-core Package: com.mountainminds.eclemma.internal.core.analysis
Source Code: ResourceTreeWalker.java (Click to view .java file)
Method Code:
private void walkResource(IResource resource,boolean root) throws CoreException, IOException {
switch (resource.getType()) {
case IResource.FILE:
if (resource.getName().endsWith(".class")) {
final IFile file=(IFile)resource;
final InputStream in=file.getContents(true);
try {
analyzer.analyzeAll(in);
}
finally {
in.close();
}
}
break;
case IResource.FOLDER:
case IResource.PROJECT:
if (root || isJavaIdentifier(resource.getName())) {
final IContainer container=(IContainer)resource;
for ( final IResource child : container.members()) {
walkResource(child,false);
}
}
break;
}
}