1 11 package org.eclipse.jdt.internal.corext.util; 12 13 import java.net.URI ; 14 15 import org.eclipse.core.filesystem.EFS; 16 import org.eclipse.core.filesystem.IFileInfo; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.Path; 21 22 import org.eclipse.core.filebuffers.FileBuffers; 23 import org.eclipse.core.filebuffers.ITextFileBuffer; 24 import org.eclipse.core.filebuffers.ITextFileBufferManager; 25 26 import org.eclipse.core.resources.IResource; 27 import org.eclipse.core.resources.IWorkspaceRoot; 28 import org.eclipse.core.resources.ResourcesPlugin; 29 30 import org.eclipse.jdt.core.IJavaElement; 31 import org.eclipse.jdt.core.JavaCore; 32 import org.eclipse.jdt.core.search.IJavaSearchScope; 33 34 37 public class IFileTypeInfo extends TypeInfo { 38 39 private final String fProject; 40 private final String fFolder; 41 private final String fFile; 42 private final String fExtension; 43 44 public IFileTypeInfo(String pkg, String name, char[][] enclosingTypes, int modifiers, String project, String sourceFolder, String file, String extension) { 45 super(pkg, name, enclosingTypes, modifiers); 46 fProject= project; 47 fFolder= sourceFolder; 48 fFile= file; 49 fExtension= extension; 50 } 51 52 public boolean equals(Object obj) { 53 if (this == obj) 54 return true; 55 if (!IFileTypeInfo.class.equals(obj.getClass())) 56 return false; 57 IFileTypeInfo other= (IFileTypeInfo)obj; 58 return doEquals(other) && fProject.equals(other.fProject) && equals(fFolder, other.fFolder) && 59 fFile.equals(other.fFile) && fExtension.equals(other.fExtension); 60 } 61 62 public int getElementType() { 63 return TypeInfo.IFILE_TYPE_INFO; 64 } 65 66 protected IJavaElement getContainer(IJavaSearchScope scope) { 67 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 68 IPath path= new Path(getPath()); 69 IResource resource= root.findMember(path); 70 if (resource != null) { 71 IJavaElement elem= JavaCore.create(resource); 72 if (elem != null && elem.exists()) { 73 return elem; 74 } 75 } 76 return null; 77 } 78 79 public IPath getPackageFragmentRootPath() { 80 StringBuffer buffer= new StringBuffer (); 81 buffer.append(TypeInfo.SEPARATOR); 82 buffer.append(fProject); 83 if (fFolder != null && fFolder.length() > 0) { 84 buffer.append(TypeInfo.SEPARATOR); 85 buffer.append(fFolder); 86 } 87 return new Path(buffer.toString()); 88 } 89 90 public String getPackageFragmentRootName() { 91 StringBuffer buffer= new StringBuffer (); 92 buffer.append(fProject); 93 if (fFolder != null && fFolder.length() > 0) { 94 buffer.append(TypeInfo.SEPARATOR); 95 buffer.append(fFolder); 96 } 97 return buffer.toString(); 98 } 99 100 public String getPath() { 101 StringBuffer result= new StringBuffer (); 102 result.append(TypeInfo.SEPARATOR); 103 result.append(fProject); 104 result.append(TypeInfo.SEPARATOR); 105 if (fFolder != null && fFolder.length() > 0) { 106 result.append(fFolder); 107 result.append(TypeInfo.SEPARATOR); 108 } 109 if (fPackage != null && fPackage.length() > 0) { 110 result.append(fPackage.replace(TypeInfo.PACKAGE_PART_SEPARATOR, TypeInfo.SEPARATOR)); 111 result.append(TypeInfo.SEPARATOR); 112 } 113 result.append(fFile); 114 result.append('.'); 115 result.append(fExtension); 116 return result.toString(); 117 } 118 119 public String getProject() { 120 return fProject; 121 } 122 123 public String getFolder() { 124 return fFolder; 125 } 126 127 public String getFileName() { 128 return fFile; 129 } 130 131 public String getExtension() { 132 return fExtension; 133 } 134 135 public long getContainerTimestamp() { 136 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 137 IPath path= new Path(getPath()); 138 IResource resource= root.findMember(path); 139 if (resource != null) { 140 URI location= resource.getLocationURI(); 141 if (location != null) { 142 try { 143 IFileInfo info= EFS.getStore(location).fetchInfo(); 144 if (info.exists()) { 145 IJavaElement element= JavaCore.create(resource); 148 if (element != null && element.exists()) 149 return info.getLastModified(); 150 } 151 } catch (CoreException e) { 152 } 154 } 155 } 156 return IResource.NULL_STAMP; 157 } 158 159 public boolean isContainerDirty() { 160 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 161 IPath path= new Path(getPath()); 162 IResource resource= root.findMember(path); 163 ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); 164 ITextFileBuffer textFileBuffer= manager.getTextFileBuffer(resource.getFullPath()); 165 if (textFileBuffer != null) { 166 return textFileBuffer.isDirty(); 167 } 168 return false; 169 } 170 } 171 | Popular Tags |