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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/SourceMapper.java (-9 / +39 lines)
Lines 27-32 Link Here
27
import org.eclipse.core.resources.IContainer;
27
import org.eclipse.core.resources.IContainer;
28
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.resources.IFolder;
29
import org.eclipse.core.resources.IFolder;
30
import org.eclipse.core.resources.IProject;
30
import org.eclipse.core.resources.IResource;
31
import org.eclipse.core.resources.IResource;
31
import org.eclipse.core.resources.ResourcesPlugin;
32
import org.eclipse.core.resources.ResourcesPlugin;
32
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.CoreException;
Lines 868-879 Link Here
868
869
869
		char[] source = null;
870
		char[] source = null;
870
871
872
		IProject project = pkgFrag.getPackageFragmentRoot().getJavaProject().getProject();
871
		JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager();
873
		JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager();
872
		try {
874
		try {
873
			javaModelManager.cacheZipFiles(this); // Cache any zip files we open during this operation
875
			javaModelManager.cacheZipFiles(this); // Cache any zip files we open during this operation
874
876
875
			if (this.rootPath != null) {
877
			if (this.rootPath != null) {
876
				source = getSourceForRootPath(this.rootPath, name);
878
				source = getSourceForRootPath(this.rootPath, name, project);
877
			}
879
			}
878
	
880
	
879
			if (source == null) {
881
			if (source == null) {
Lines 882-888 Link Here
882
					loop: for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext(); ) {
884
					loop: for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext(); ) {
883
						String currentRootPath = (String) iterator.next();
885
						String currentRootPath = (String) iterator.next();
884
						if (!currentRootPath.equals(this.rootPath)) {
886
						if (!currentRootPath.equals(this.rootPath)) {
885
							source = getSourceForRootPath(currentRootPath, name);
887
							source = getSourceForRootPath(currentRootPath, name, project);
886
							if (source != null) {
888
							if (source != null) {
887
								// remember right root path
889
								// remember right root path
888
								this.rootPath = currentRootPath;
890
								this.rootPath = currentRootPath;
Lines 901-907 Link Here
901
		return source;
903
		return source;
902
	}
904
	}
903
905
904
	private char[] getSourceForRootPath(String currentRootPath, String name) {
906
	private char[] getSourceForRootPath(String currentRootPath, String name, IProject project) {
905
		String newFullName;
907
		String newFullName;
906
		if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
908
		if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
907
			if (currentRootPath.endsWith("/")) { //$NON-NLS-1$
909
			if (currentRootPath.endsWith("/")) { //$NON-NLS-1$
Lines 912-933 Link Here
912
		} else {
914
		} else {
913
			newFullName = name;
915
			newFullName = name;
914
		}
916
		}
915
		return this.findSource(newFullName);
917
		return this.findSource(newFullName, project);
916
	}
918
	}
917
919
918
	public char[] findSource(String fullName) {
920
	public char[] findSource(String fullName, IProject project) {
919
		char[] source = null;
921
		char[] source = null;
920
		Object target = JavaModel.getTarget(this.sourcePath, true);
922
		Object target = JavaModel.getTarget(this.sourcePath, true);
923
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303511
924
		// Use the character encoding set by the user than the default one
925
		String charSet = null;
921
		if (target instanceof IContainer) {
926
		if (target instanceof IContainer) {
927
			// For external folders, get use the project's encoding
928
			if (project != null && ExternalFoldersManager.isInternalPathForExternalFolder(((IContainer)target).getFullPath())) {
929
				try {
930
					charSet = project.getDefaultCharset();
931
				} catch (CoreException e) {
932
					// Proceed with null encoding
933
				}
934
			}
922
			IResource res = ((IContainer)target).findMember(fullName);
935
			IResource res = ((IContainer)target).findMember(fullName);
923
			if (res instanceof IFile) {
936
			if (res instanceof IFile) {
924
				try {
937
				try {
925
					source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
938
					if (charSet == null)
939
						source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
940
					else 
941
						source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res, charSet);
926
				} catch (JavaModelException e) {
942
				} catch (JavaModelException e) {
927
					// ignore
943
					// ignore
928
				}
944
				}
929
			}
945
			}
930
		} else {
946
		} else {
947
			try {
948
				// If the archive (IResource) is available from the workspace, use it's encoding
949
				// Else take it from the project
950
				if (target instanceof IFile)
951
					charSet = ((IFile)target).getCharset();
952
				else if (project != null)
953
					charSet = project.getDefaultCharset();
954
			} catch (CoreException e) {
955
				// Ignore
956
			}
957
			
931
			// try to get the entry
958
			// try to get the entry
932
			ZipEntry entry = null;
959
			ZipEntry entry = null;
933
			ZipFile zip = null;
960
			ZipFile zip = null;
Lines 937-943 Link Here
937
				entry = zip.getEntry(fullName);
964
				entry = zip.getEntry(fullName);
938
				if (entry != null) {
965
				if (entry != null) {
939
					// now read the source code
966
					// now read the source code
940
					source = readSource(entry, zip);
967
					source = readSource(entry, zip, charSet);
941
				}
968
				}
942
			} catch (CoreException e) {
969
			} catch (CoreException e) {
943
				return null;
970
				return null;
Lines 948-953 Link Here
948
		return source;
975
		return source;
949
	}
976
	}
950
977
978
	public char[] findSource(String fullName) {
979
		return findSource(fullName, null);
980
	}
951
981
952
982
953
	/**
983
	/**
Lines 1275-1285 Link Here
1275
			this.typeDepth = -1;
1305
			this.typeDepth = -1;
1276
		}
1306
		}
1277
	}
1307
	}
1278
	private char[] readSource(ZipEntry entry, ZipFile zip) {
1308
	private char[] readSource(ZipEntry entry, ZipFile zip, String charSet) {
1279
		try {
1309
		try {
1280
			byte[] bytes = Util.getZipEntryByteContent(entry, zip);
1310
			byte[] bytes = Util.getZipEntryByteContent(entry, zip);
1281
			if (bytes != null) {
1311
			if (bytes != null) {
1282
				return Util.bytesToChar(bytes, this.encoding);
1312
				return Util.bytesToChar(bytes, charSet == null ? this.encoding : charSet);
1283
			}
1313
			}
1284
		} catch (IOException e) {
1314
		} catch (IOException e) {
1285
			// ignore
1315
			// ignore

Return to bug 303511