1 11 package org.eclipse.jdt.internal.ui.compare; 12 13 import org.eclipse.core.resources.IFile; 14 15 import org.eclipse.jdt.core.ICompilationUnit; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.IMember; 18 19 import org.eclipse.team.ui.history.ElementLocalHistoryPageSource; 20 21 public class JavaElementHistoryPageSource extends ElementLocalHistoryPageSource { 22 23 private static JavaElementHistoryPageSource instance; 24 25 public static JavaElementHistoryPageSource getInstance() { 26 if (instance == null) 27 instance = new JavaElementHistoryPageSource(); 28 return instance; 29 } 30 31 37 public static boolean hasEdition(IJavaElement je) { 38 39 if (je instanceof IMember && ((IMember)je).isBinary()) 40 return false; 41 42 switch (je.getElementType()) { 43 case IJavaElement.COMPILATION_UNIT: 44 case IJavaElement.TYPE: 45 case IJavaElement.FIELD: 46 case IJavaElement.METHOD: 47 case IJavaElement.INITIALIZER: 48 case IJavaElement.PACKAGE_DECLARATION: 49 case IJavaElement.IMPORT_CONTAINER: 50 case IJavaElement.IMPORT_DECLARATION: 51 return true; 52 } 53 return false; 54 } 55 56 59 public IFile getFile(Object input) { 60 ICompilationUnit cu= null; 62 if (input instanceof ICompilationUnit) 63 cu= (ICompilationUnit) input; 64 else if (input instanceof IMember) 65 cu= ((IMember)input).getCompilationUnit(); 66 67 if (cu == null || !cu.exists()) 68 return null; 69 70 cu= cu.getPrimary(); 72 73 IFile file= (IFile) cu.getResource(); 75 if (file != null && file.exists()) 76 return file; 77 return null; 78 } 79 } 80 | Popular Tags |