View | Details | Raw Unified | Return to bug 185950 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/SourceMapper.java (-26 / +113 lines)
Lines 649-655 Link Here
649
			if (this.anonymousCounter == this.anonymousClassName) {
649
			if (this.anonymousCounter == this.anonymousClassName) {
650
				this.types[typeDepth] = this.getType(this.binaryType.getElementName());
650
				this.types[typeDepth] = this.getType(this.binaryType.getElementName());
651
			} else {
651
			} else {
652
				this.types[typeDepth] = this.getType(new String(typeInfo.name));				
652
				this.types[typeDepth] = this.getType(new String(typeInfo.name));
653
			}
653
			}
654
		} else {
654
		} else {
655
			this.types[typeDepth] = this.getType(new String(typeInfo.name));
655
			this.types[typeDepth] = this.getType(new String(typeInfo.name));
Lines 881-887 Link Here
881
		}
881
		}
882
		return findSource(type, simpleSourceFileName);
882
		return findSource(type, simpleSourceFileName);
883
	}
883
	}
884
	
884
885
	/**
885
	/**
886
	 * Locates and returns source code for the given (binary) type, in this
886
	 * Locates and returns source code for the given (binary) type, in this
887
	 * SourceMapper's ZIP file, or returns <code>null</code> if source
887
	 * SourceMapper's ZIP file, or returns <code>null</code> if source
Lines 900-944 Link Here
900
		char[] source = null;
900
		char[] source = null;
901
		
901
		
902
		if (this.rootPath != null) {
902
		if (this.rootPath != null) {
903
			source = getSourceForRootPath(this.rootPath, name);
903
			String newFullName;
904
			if (!this.rootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
905
				if (this.rootPath.endsWith("/")) { //$NON-NLS-1$
906
					newFullName = this.rootPath + name;
907
				} else {
908
					newFullName = this.rootPath + '/' + name;
909
				}
910
			} else {
911
				newFullName = name;
912
			}
913
			source = this.findSource(newFullName);
904
		}
914
		}
905
915
906
		if (source == null) {
916
		if (source == null) {
907
			computeAllRootPaths(type);
917
			computeAllRootPaths(type);
908
			if (this.rootPaths != null) {
918
			if (this.rootPaths != null) {
909
				loop: for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext(); ) {
919
				source = getSourceForRootPaths(name);
910
					String currentRootPath = (String) iterator.next();
911
					if (!currentRootPath.equals(this.rootPath)) {
912
						source = getSourceForRootPath(currentRootPath, name);
913
						if (source != null) {
914
							// remember right root path
915
							this.rootPath = currentRootPath;
916
							break loop;
917
						}
918
					}
919
				}
920
			}
920
			}
921
		}
921
		}
922
		if (VERBOSE) {
922
		if (VERBOSE) {
923
			System.out.println("spent " + (System.currentTimeMillis() - time) + "ms for " + type.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
923
			System.out.println("spent " + (System.currentTimeMillis() - time) + "ms for " + type.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
924
		}
924
		}
925
		if (source == null) {
926
			this.rootPath = null;
927
		}
925
		return source;
928
		return source;
926
	}
929
	}
927
930
928
	private char[] getSourceForRootPath(String currentRootPath, String name) {
931
	private char[] getSourceForRootPaths(String name) {
929
		String newFullName;
932
		char[] source = null;
930
		if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
933
		if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
931
			if (currentRootPath.endsWith("/")) { //$NON-NLS-1$
934
			// try to get the entry
932
				newFullName = currentRootPath + name;
935
			ZipEntry entry = null;
933
			} else {
936
			ZipFile zip = null;
934
				newFullName = currentRootPath + '/' + name;
937
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
938
			try {
939
				zip = manager.getZipFile(this.sourcePath);
940
				for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext(); ) {
941
					String currentRootPath = (String) iterator.next();
942
					String newFullName = null;
943
					if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
944
						if (currentRootPath.endsWith("/")) { //$NON-NLS-1$
945
							newFullName = currentRootPath + name;
946
						} else {
947
							newFullName = currentRootPath + '/' + name;
948
						}
949
					} else {
950
						newFullName = name;
951
					}
952
					entry = zip.getEntry(newFullName);
953
					if (entry != null) {
954
						// now read the source code
955
						source = readSource(entry, zip);
956
						if (source != null) {
957
							this.rootPath = currentRootPath;
958
							return source;
959
						}
960
					}
961
				}
962
			} catch (CoreException e) {
963
				return null;
964
			} finally {
965
				manager.closeZipFile(zip); // handle null case
935
			}
966
			}
936
		} else {
967
		} else {
937
			newFullName = name;
968
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.sourcePath, true);
969
			if (target instanceof IResource) {
970
				if (target instanceof IContainer) {
971
					for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext(); ) {
972
						String currentRootPath = (String) iterator.next();
973
						String newFullName = null;
974
						if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
975
							if (currentRootPath.endsWith("/")) { //$NON-NLS-1$
976
								newFullName = currentRootPath + name;
977
							} else {
978
								newFullName = currentRootPath + '/' + name;
979
							}
980
						} else {
981
							newFullName = name;
982
						}
983
						IResource res = ((IContainer)target).findMember(newFullName);
984
						if (res instanceof IFile) {
985
							try {
986
								source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
987
								if (source != null) {
988
									this.rootPath = currentRootPath;
989
									return source;
990
								}
991
							} catch (JavaModelException e) {
992
								// ignore
993
							}
994
						}
995
					}
996
				}
997
			} else if (target instanceof File) {
998
				File file = (File)target;
999
				if (file.isDirectory()) {
1000
					for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext(); ) {
1001
						String currentRootPath = (String) iterator.next();
1002
						String newFullName = null;
1003
						if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
1004
							if (currentRootPath.endsWith("/")) { //$NON-NLS-1$
1005
								newFullName = currentRootPath + name;
1006
							} else {
1007
								newFullName = currentRootPath + '/' + name;
1008
							}
1009
						} else {
1010
							newFullName = name;
1011
						}
1012
						File sourceFile = new File(file, newFullName);
1013
						if (sourceFile.isFile()) {
1014
							try {
1015
								source = Util.getFileCharContent(sourceFile, this.encoding);
1016
								if (source != null) {
1017
									this.rootPath = currentRootPath;
1018
									return source;
1019
								}
1020
							} catch (IOException e) {
1021
								// ignore
1022
							}
1023
						}
1024
					}
1025
				}
1026
			}
938
		}
1027
		}
939
		return this.findSource(newFullName);
1028
		return null;
940
	}
1029
	}
941
	
1030
942
	public char[] findSource(String fullName) {
1031
	public char[] findSource(String fullName) {
943
		char[] source = null;
1032
		char[] source = null;
944
		if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
1033
		if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
Lines 988-995 Link Here
988
		return source;
1077
		return source;
989
	}
1078
	}
990
1079
991
992
	
993
	/**
1080
	/**
994
	 * Returns the SourceRange for the name of the given element, or
1081
	 * Returns the SourceRange for the name of the given element, or
995
	 * {-1, -1} if no source range is known for the name of the element.
1082
	 * {-1, -1} if no source range is known for the name of the element.

Return to bug 185950