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

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/EncodingTests.java (-2 / +252 lines)
Lines 28-33 Link Here
28
import org.eclipse.core.runtime.content.IContentDescription;
28
import org.eclipse.core.runtime.content.IContentDescription;
29
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
29
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
30
import org.eclipse.core.runtime.preferences.InstanceScope;
30
import org.eclipse.core.runtime.preferences.InstanceScope;
31
import org.eclipse.jdt.core.IClasspathAttribute;
31
import org.eclipse.jdt.core.IClasspathEntry;
32
import org.eclipse.jdt.core.IClasspathEntry;
32
import org.eclipse.jdt.core.ICompilationUnit;
33
import org.eclipse.jdt.core.ICompilationUnit;
33
import org.eclipse.jdt.core.IJavaProject;
34
import org.eclipse.jdt.core.IJavaProject;
Lines 62-68 Link Here
62
	// Use this static initializer to specify subset for tests
63
	// Use this static initializer to specify subset for tests
63
	// All specified tests which do not belong to the class are skipped...
64
	// All specified tests which do not belong to the class are skipped...
64
	static {
65
	static {
65
//		TESTS_NAMES = new String[] { "testBug110576" };
66
//		TESTS_NAMES = new String[] { "testBug361356" };
66
//		TESTS_NUMBERS = new int[] { 2, 12 };
67
//		TESTS_NUMBERS = new int[] { 2, 12 };
67
//		TESTS_RANGE = new int[] { 16, -1 };
68
//		TESTS_RANGE = new int[] { 16, -1 };
68
	}
69
	}
Lines 1217-1223 Link Here
1217
			getWorkspaceRoot().setDefaultCharset(wkspEncoding, null);
1218
			getWorkspaceRoot().setDefaultCharset(wkspEncoding, null);
1218
		}
1219
		}
1219
	}
1220
	}
1220
	
1221
	public void testBug361356() throws Exception {
1222
		String oldEncoding = this.encodingProject.getDefaultCharset();
1223
		try{
1224
			String encoding = "Shift-JIS";
1225
			if (wkspEncoding.equals(encoding))
1226
				getWorkspaceRoot().setDefaultCharset("UTF-8", null);
1227
			this.encodingProject.setDefaultCharset("UTF-8", null);
1228
			IJavaProject project = this.createJavaProject("Encoding2", new String[] {""}, "");
1229
			IFile zipFile = (IFile) this.encodingProject.findMember("testShiftJIS.zip"); //$NON-NLS-1$
1230
			IFile sourceFile = (IFile) this.encodingProject.findMember("src/testShiftJIS/A.java");
1231
			
1232
			IClasspathEntry[] entries = this.encodingJavaProject.getRawClasspath();
1233
			IClasspathEntry newEntry = null;
1234
			for (int index = 0; index < entries.length; index++) {
1235
				IClasspathEntry entry = entries[index];
1236
				if (entry.getPath().toOSString().endsWith("testShiftJIS.jar")) {
1237
					newEntry = entries[index]; 
1238
				}
1239
			}
1240
1241
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding);
1242
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/src"), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1243
			sourceFile.setCharset(null, null);
1244
			
1245
			IPackageFragmentRoot root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1246
			ISourceReference sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1247
			assertNotNull(sourceRef);
1248
			String source = sourceRef.getSource();
1249
			assertNotNull(source);
1250
			String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1251
			char[] charArray = encodedContents.toCharArray();
1252
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1253
			charArray = source.toCharArray();
1254
			source = new String(CharOperation.remove(charArray, '\r'));
1255
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1256
1257
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8");
1258
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/src"), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1259
			sourceFile.setCharset(encoding, null);
1260
			
1261
			root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1262
			sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1263
			assertNotNull(sourceRef);
1264
			source = sourceRef.getSource();
1265
			assertNotNull(source);
1266
			encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1267
			charArray = encodedContents.toCharArray();
1268
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1269
			charArray = source.toCharArray();
1270
			source = new String(CharOperation.remove(charArray, '\r'));
1271
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1272
1273
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding);
1274
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1275
			zipFile.setCharset(null, null);
1276
			
1277
			root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1278
			sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1279
			assertNotNull(sourceRef);
1280
			source = sourceRef.getSource();
1281
			assertNotNull(source);
1282
			encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1283
			charArray = encodedContents.toCharArray();
1284
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1285
			charArray = source.toCharArray();
1286
			source = new String(CharOperation.remove(charArray, '\r'));
1287
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1288
1289
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8");
1290
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1291
			zipFile.setCharset(encoding, null);
1292
			
1293
			root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1294
			sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1295
			assertNotNull(sourceRef);
1296
			source = sourceRef.getSource();
1297
			assertNotNull(source);
1298
			encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1299
			charArray = encodedContents.toCharArray();
1300
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1301
			charArray = source.toCharArray();
1302
			source = new String(CharOperation.remove(charArray, '\r'));
1303
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1304
1305
		}
1306
		finally {
1307
			this.encodingProject.setDefaultCharset(oldEncoding, null);
1308
			deleteProject("Encoding2");
1309
			getWorkspaceRoot().setDefaultCharset(wkspEncoding, null);
1310
		}		
1311
	}
1312
	public void testBug361356a() throws Exception {
1313
		String oldEncoding = this.encodingProject.getDefaultCharset();
1314
		try{
1315
			String encoding = "Shift-JIS";
1316
			if (wkspEncoding.equals(encoding))
1317
				getWorkspaceRoot().setDefaultCharset("UTF-8", null);
1318
			this.encodingProject.setDefaultCharset("UTF-8", null);
1319
			IJavaProject project = this.createJavaProject("Encoding2", new String[] {""}, "");
1320
			IFile zipFile = (IFile) this.encodingProject.findMember("testShiftJIS.zip"); //$NON-NLS-1$
1321
			IFile sourceFile = (IFile) this.encodingProject.findMember("src/testShiftJIS/A.java");
1322
			
1323
			IClasspathEntry[] entries = this.encodingJavaProject.getRawClasspath();
1324
			IClasspathEntry newEntry = null;
1325
			for (int index = 0; index < entries.length; index++) {
1326
				IClasspathEntry entry = entries[index];
1327
				if (entry.getPath().toOSString().endsWith("testShiftJIS.jar")) {
1328
					newEntry = entries[index]; 
1329
				}
1330
			}
1331
1332
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding);
1333
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding);
1334
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1335
			zipFile.setCharset(null, null);
1336
			
1337
			IPackageFragmentRoot root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1338
			ISourceReference sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1339
			assertNotNull(sourceRef);
1340
			String source = sourceRef.getSource();
1341
			assertNotNull(source);
1342
			String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1343
			char[] charArray = encodedContents.toCharArray();
1344
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1345
			charArray = source.toCharArray();
1346
			source = new String(CharOperation.remove(charArray, '\r'));
1347
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1348
1349
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8");
1350
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1351
			zipFile.setCharset(encoding, null);
1352
			
1353
			root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1354
			sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1355
			assertNotNull(sourceRef);
1356
			source = sourceRef.getSource();
1357
			assertNotNull(source);
1358
			encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1359
			charArray = encodedContents.toCharArray();
1360
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1361
			charArray = source.toCharArray();
1362
			source = new String(CharOperation.remove(charArray, '\r'));
1363
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1364
		}
1365
		finally {
1366
			this.encodingProject.setDefaultCharset(oldEncoding, null);
1367
			deleteProject("Encoding2");
1368
			getWorkspaceRoot().setDefaultCharset(wkspEncoding, null);
1369
		}		
1370
	}
1371
	public void testBug361356b() throws Exception {
1372
		String oldEncoding = this.encodingProject.getDefaultCharset();
1373
		File externalSourceZip = null;
1374
		File externalSource = null;
1375
		try{
1376
			String encoding = "Shift-JIS";
1377
			if (wkspEncoding.equals(encoding))
1378
				getWorkspaceRoot().setDefaultCharset("UTF-8", null);
1379
			this.encodingProject.setDefaultCharset("UTF-8", null);
1380
			IJavaProject project = this.createJavaProject("Encoding2", new String[] {""}, "");
1381
			IFile sourceFile = (IFile) this.encodingProject.findMember("src/testShiftJIS/A.java");
1382
			
1383
			File internalSourceZip = new File(getWorkspacePath(), "/Encoding/testShiftJIS.zip");
1384
			externalSourceZip = new File(getExternalPath(), "testShiftJIS.zip");
1385
			File internalSource = new File(getWorkspacePath(), "/Encoding/src");
1386
			externalSource = new File(getExternalPath(), "testShiftJIS");
1387
1388
			copyDirectory(internalSource, externalSource);
1389
			copy(internalSourceZip, externalSourceZip);
1390
			
1391
			IClasspathEntry[] entries = this.encodingJavaProject.getRawClasspath();
1392
			IClasspathEntry newEntry = null;
1393
			for (int index = 0; index < entries.length; index++) {
1394
				IClasspathEntry entry = entries[index];
1395
				if (entry.getPath().toOSString().endsWith("testShiftJIS.jar")) {
1396
					newEntry = entries[index]; 
1397
				}
1398
			}
1399
1400
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding);
1401
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding);
1402
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path(getExternalResourcePath("testShiftJIS.zip")), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1403
			
1404
			IPackageFragmentRoot root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1405
			ISourceReference sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1406
			assertNotNull(sourceRef);
1407
			String source = sourceRef.getSource();
1408
			assertNotNull(source);
1409
			String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1410
			char[] charArray = encodedContents.toCharArray();
1411
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1412
			charArray = source.toCharArray();
1413
			source = new String(CharOperation.remove(charArray, '\r'));
1414
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1415
1416
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8");
1417
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path(getExternalResourcePath("testShiftJIS.zip")), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1418
			
1419
			root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1420
			sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1421
			assertNotNull(sourceRef);
1422
			source = sourceRef.getSource();
1423
			assertNotNull(source);
1424
			encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1425
			charArray = encodedContents.toCharArray();
1426
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1427
			charArray = source.toCharArray();
1428
			source = new String(CharOperation.remove(charArray, '\r'));
1429
			assertFalse("Sources should not be decoded the same way", encodedContents.equals(source));
1430
			
1431
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding);
1432
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path(getExternalResourcePath("testShiftJIS")), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1433
			sourceFile.setCharset(null, null);
1434
			
1435
			root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1436
			sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1437
			assertNotNull(sourceRef);
1438
			source = sourceRef.getSource();
1439
			assertNotNull(source);
1440
			encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1441
			charArray = encodedContents.toCharArray();
1442
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1443
			charArray = source.toCharArray();
1444
			source = new String(CharOperation.remove(charArray, '\r'));
1445
			assertTrue("Sources should be decoded the same way", encodedContents.equals(source));
1446
1447
			attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8");
1448
			project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path(getExternalResourcePath("testShiftJIS")), null, null, new IClasspathAttribute[]{attribute}, false)}, null);
1449
			sourceFile.setCharset(encoding, null);
1450
			
1451
			root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar");
1452
			sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class");
1453
			assertNotNull(sourceRef);
1454
			source = sourceRef.getSource();
1455
			assertNotNull(source);
1456
			encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1457
			charArray = encodedContents.toCharArray();
1458
			encodedContents = new String(CharOperation.remove(charArray, '\r'));
1459
			charArray = source.toCharArray();
1460
			source = new String(CharOperation.remove(charArray, '\r'));
1461
			assertFalse("Sources should not be decoded the same way", encodedContents.equals(source));
1462
		}
1463
		finally {
1464
			if (externalSourceZip != null) externalSourceZip.delete();
1465
			if (externalSource != null) deleteExternalResource("testShiftJIS");
1466
			this.encodingProject.setDefaultCharset(oldEncoding, null);
1467
			deleteProject("Encoding2");
1468
			getWorkspaceRoot().setDefaultCharset(wkspEncoding, null);
1469
		}		
1470
	}
1221
	private void verifyUtf8BOM(IFile file) throws CoreException {
1471
	private void verifyUtf8BOM(IFile file) throws CoreException {
1222
		assertNull("File should not have any explicit charset", file.getCharset(false));
1472
		assertNull("File should not have any explicit charset", file.getCharset(false));
1223
		IContentDescription contentDescription = file.getContentDescription();
1473
		IContentDescription contentDescription = file.getContentDescription();
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java (+16 lines)
Lines 70-75 Link Here
70
	String INDEX_LOCATION_ATTRIBUTE_NAME = "index_location"; //$NON-NLS-1$
70
	String INDEX_LOCATION_ATTRIBUTE_NAME = "index_location"; //$NON-NLS-1$
71
71
72
	/**
72
	/**
73
	 * Constant for the name of the encoding to be used for source attachments. 
74
	 * <p>The value of this attribute has to be a string representation of a valid encoding. The encoding
75
	 * for a source attachment is determined in the following order: </p>
76
	 *
77
	 * <ul> 
78
	 * <li>	Encoding explicitly set on the source file (java or zip), i.e. <code>org.eclipse.core.resources.IFile#getCharset(false)</code> </li>
79
	 * <li>	Encoding set on the corresponding classpath entry </li>
80
	 * <li> If the source attachment is a member of the project, then the project's default charSet</li>
81
	 * <li> Workspace default charSet </li>
82
	 * </ul>
83
	 * 
84
	 * @since 3.8
85
	 */
86
	String SOURCE_ATTACHMENT_ENCODING = "source_encoding"; //$NON-NLS-1$
87
	
88
	/**
73
	 * Constant for the name of the optional attribute. The possible values
89
	 * Constant for the name of the optional attribute. The possible values
74
	 * for this attribute are <code>"true"</code> or <code>"false"</code>.
90
	 * for this attribute are <code>"true"</code> or <code>"false"</code>.
75
	 * When not present, <code>"false"</code> is assumed.
91
	 * When not present, <code>"false"</code> is assumed.
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java (+9 lines)
Lines 1271-1276 Link Here
1271
		return false;
1271
		return false;
1272
	}
1272
	}
1273
1273
1274
	public String getSourceAttachmentEncoding() {
1275
		for (int i = 0, length = this.extraAttributes.length; i < length; i++) {
1276
			IClasspathAttribute attribute = this.extraAttributes[i];
1277
			if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attribute.getName()))
1278
				return attribute.getValue();
1279
		}
1280
		return null;
1281
	}
1282
	
1274
	/**
1283
	/**
1275
	 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
1284
	 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
1276
	 */
1285
	 */
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (-2 / +6 lines)
Lines 154-164 Link Here
154
	return computeChildren(info, underlyingResource);
154
	return computeChildren(info, underlyingResource);
155
}
155
}
156
156
157
SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) {
157
SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) throws JavaModelException {
158
	IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(getPath());
159
	String encoding = (entry== null) ? null : ((ClasspathEntry) entry).getSourceAttachmentEncoding();
158
	SourceMapper mapper = new SourceMapper(
160
	SourceMapper mapper = new SourceMapper(
159
		sourcePath,
161
		sourcePath,
160
		rootPath == null ? null : rootPath.toOSString(),
162
		rootPath == null ? null : rootPath.toOSString(),
161
		getJavaProject().getOptions(true)); // cannot use workspace options if external jar is 1.5 jar and workspace options are 1.4 options
163
		getJavaProject().getOptions(true),// cannot use workspace options if external jar is 1.5 jar and workspace options are 1.4 options
164
		encoding);
165
162
	return mapper;
166
	return mapper;
163
}
167
}
164
/*
168
/*
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java (-6 / +19 lines)
Lines 250-255 Link Here
250
	 *Options to be used
250
	 *Options to be used
251
	 */
251
	 */
252
	String encoding;
252
	String encoding;
253
	String defaultEncoding;
253
	Map options;
254
	Map options;
254
255
255
	/**
256
	/**
Lines 261-275 Link Here
261
		this.areRootPathsComputed = false;
262
		this.areRootPathsComputed = false;
262
	}
263
	}
263
264
265
	public SourceMapper(IPath sourcePath, String rootPath, Map options) {
266
		this(sourcePath, rootPath, options, null);
267
	}
264
	/**
268
	/**
265
	 * Creates a <code>SourceMapper</code> that locates source in the zip file
269
	 * Creates a <code>SourceMapper</code> that locates source in the zip file
266
	 * at the given location in the specified package fragment root.
270
	 * at the given location in the specified package fragment root.
267
	 */
271
	 */
268
	public SourceMapper(IPath sourcePath, String rootPath, Map options) {
272
	public SourceMapper(IPath sourcePath, String rootPath, Map options, String encoding) {
269
		this.areRootPathsComputed = false;
273
		this.areRootPathsComputed = false;
270
		this.options = options;
274
		this.options = options;
275
		this.encoding = encoding;
271
		try {
276
		try {
272
			this.encoding = ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset();
277
			this.defaultEncoding = ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset();
273
		} catch (CoreException e) {
278
		} catch (CoreException e) {
274
			// use no encoding
279
			// use no encoding
275
		}
280
		}
Lines 1020-1028 Link Here
1020
			IResource res = ((IContainer)target).findMember(fullName);
1025
			IResource res = ((IContainer)target).findMember(fullName);
1021
			if (res instanceof IFile) {
1026
			if (res instanceof IFile) {
1022
				try {
1027
				try {
1023
					source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
1028
					// Order of preference: charSet supplied, this.encoding or this.defaultEncoding in that order
1029
					try {
1030
						charSet = ((IFile) res).getCharset(this.encoding == null);
1031
					} catch (CoreException e) {
1032
						// Ignore
1033
					}
1034
					source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile) res,
1035
									charSet == null ? (this.encoding == null ? this.defaultEncoding : this.encoding) : charSet);
1024
				} catch (JavaModelException e) {
1036
				} catch (JavaModelException e) {
1025
					// ignore
1037
					// Ignore
1026
				}
1038
				}
1027
			}
1039
			}
1028
		} else {
1040
		} else {
Lines 1030-1036 Link Here
1030
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303511
1042
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303511
1031
				// For a resource inside the workspace, use the encoding set on the resource
1043
				// For a resource inside the workspace, use the encoding set on the resource
1032
				if (target instanceof IFile)
1044
				if (target instanceof IFile)
1033
					charSet = ((IFile)target).getCharset();
1045
					charSet = ((IFile)target).getCharset(this.encoding == null);
1034
			} catch (CoreException e) {
1046
			} catch (CoreException e) {
1035
				// Ignore
1047
				// Ignore
1036
			}
1048
			}
Lines 1414-1420 Link Here
1414
		try {
1426
		try {
1415
			byte[] bytes = Util.getZipEntryByteContent(entry, zip);
1427
			byte[] bytes = Util.getZipEntryByteContent(entry, zip);
1416
			if (bytes != null) {
1428
			if (bytes != null) {
1417
				return Util.bytesToChar(bytes, charSet == null ? this.encoding : charSet);
1429
				// Order of preference: charSet supplied, this.encoding or this.defaultEncoding in that order
1430
				return Util.bytesToChar(bytes, charSet == null ? (this.encoding == null ? this.defaultEncoding : this.encoding) : charSet);
1418
			}
1431
			}
1419
		} catch (IOException e) {
1432
		} catch (IOException e) {
1420
			// ignore
1433
			// ignore

Return to bug 361356