Lines 15-23
Link Here
|
15 |
|
15 |
|
16 |
<h1>Eclipse JDT 3.3 Plug-in Migration FAQ</h1> |
16 |
<h1>Eclipse JDT 3.3 Plug-in Migration FAQ</h1> |
17 |
<ol> |
17 |
<ol> |
18 |
<li>None</li> |
18 |
<li><a href="#deprecatedWorkingCopyMethods">How can I remove deprecation warning I get on <code>*WorkingCopy(...IProblemRequestor...)</code> methods and keep same behavior?</a></li> |
|
|
19 |
</ol> |
20 |
<h2><a name="deprecatedWorkingCopyMethods">How can I remove deprecation warning I get on <code>*WorkingCopy(...IProblemRequestor...)</code> methods and keep same behavior?</a></h2> |
21 |
<p> |
22 |
While implementing bug <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=175243">175243</a>, following methods |
23 |
have been deprecated: |
24 |
<ol> |
25 |
<li><code>ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)</code></li> |
26 |
<li><code>ICompilationUnit#getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)</code></li> |
27 |
<li><code>IClassFile#becomeWorkingCopy(IProblemRequestor, WorkingCopyOwner, IProgressMonitor)</code></li> |
28 |
<li><code>WorkingCopyOwner#newWorkingCopy(String, IClasspathEntry[], IProblemRequestor, IProgressMonitor)</code></li> |
29 |
</ol> |
30 |
This answer gives some advice to use new API corresponding methods without changing |
31 |
the behavior of the existing code. |
32 |
</p> |
33 |
How to re-write the code depends on the fact that given problem requestor was null or not |
34 |
(i.e. if the client code was interested in reporting problems of the working copy): |
35 |
<ol> |
36 |
<li><strong>Problem requestor was null</strong> |
37 |
<p> |
38 |
There's no specific migration issue when the given requestor was null. |
39 |
</p><p> |
40 |
So, following snippet warned for calls to deprecated methods...: |
41 |
<pre> |
42 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/pack/X.java")); |
43 |
ICompilationUnit compilationUnit = (ICompilationUnit)JavaCore.create(file); |
44 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/bin/pack/Y.class")); |
45 |
IClassFile classFile = JavaCore.createClassFileFrom(file); |
46 |
WorkingCopyOwner owner = new WorkingCopyOwner() {}; |
47 |
IClasspathEntry[] entries = classFile.getJavaProject().getResolvedClasspath(true); |
48 |
<b> |
49 |
ICompilationUnit workingCopy = compilationUnit.getWorkingCopy(new WorkingCopyOwner() {}, null, null); |
50 |
ICompilationUnit newWorkingCopy = compilationUnit.becomeWorkingCopy(null, null); |
51 |
ICompilationUnit newWorkingCopy2 = owner.newWorkingCopy(new Path("FAQ/test/Z.java"), entries, null, null); |
52 |
ICompilationUnit classWorkingCopy = classFile.becomeWorkingCopy(null, owner, null);</b> |
53 |
</pre> |
54 |
</p><p> |
55 |
... can now be easily rewritten as follow due to the fact that default owner's problem requestor is null: |
56 |
<pre> |
57 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/pack/X.java")); |
58 |
ICompilationUnit compilationUnit = (ICompilationUnit)JavaCore.create(file); |
59 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/bin/pack/Y.class")); |
60 |
IClassFile classFile = JavaCore.createClassFileFrom(file); |
61 |
WorkingCopyOwner owner = new WorkingCopyOwner() {}; |
62 |
IClasspathEntry[] entries = classFile.getJavaProject().getResolvedClasspath(true); |
63 |
<b> |
64 |
// just remove the IProblemRequestor parameter |
65 |
ICompilationUnit workingCopy = compilationUnit.getWorkingCopy(new WorkingCopyOwner() {}, null); |
66 |
ICompilationUnit newWorkingCopy = compilationUnit.becomeWorkingCopy(null); |
67 |
ICompilationUnit newWorkingCopy2 = owner.newWorkingCopy(new Path("FAQ/test/Z.java"), entries, null); |
68 |
ICompilationUnit classWorkingCopy = classFile.becomeWorkingCopy(null, owner, null);</b> |
69 |
</pre> |
70 |
</p> |
71 |
</li> |
72 |
<li><strong>Problem requestor was not null</strong> |
73 |
<p> |
74 |
In this case, client must ensure that the working copy owner requestor is the same than |
75 |
the one given as parameter to the deprecated method. The simplest way to to this is to make |
76 |
the working copy owner returning this requestor. |
77 |
</p><p> |
78 |
So, following snippet warned for calls to deprecated methods...: |
79 |
<pre> |
80 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/pack/X.java")); |
81 |
ICompilationUnit compilationUnit = (ICompilationUnit)JavaCore.create(file); |
82 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/bin/pack/Y.class")); |
83 |
IClassFile classFile = JavaCore.createClassFileFrom(file); |
84 |
WorkingCopyOwner owner = new WorkingCopyOwner() {}; |
85 |
IClasspathEntry[] entries = classFile.getJavaProject().getResolvedClasspath(true); |
86 |
<b> |
87 |
IProblemRequestor requestor = new IProblemRequestor { |
88 |
public void acceptProblem(IProblem problem) {} |
89 |
public void beginReporting() {} |
90 |
public void endReporting() {} |
91 |
public boolean isActive() { |
92 |
return true; |
93 |
} |
94 |
}; |
95 |
ICompilationUnit workingCopy = compilationUnit.getWorkingCopy(new WorkingCopyOwner() {}, requestor, null); |
96 |
ICompilationUnit newWorkingCopy = compilationUnit.becomeWorkingCopy(requestor, null); |
97 |
ICompilationUnit newWorkingCopy2 = owner.newWorkingCopy(new Path("FAQ/test/Z.java"), entries, requestor, null); |
98 |
ICompilationUnit classWorkingCopy = classFile.becomeWorkingCopy(requestor, owner, null);</b> |
99 |
</pre> |
100 |
</p><p> |
101 |
... needs to be rewritten as follow to keep the same behavior: |
102 |
<pre> |
103 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/pack/X.java")); |
104 |
ICompilationUnit compilationUnit = (ICompilationUnit)JavaCore.create(file); |
105 |
IFile file = getWorkspaceRoot().getFile(new Path("FAQ/bin/pack/Y.class")); |
106 |
IClassFile classFile = JavaCore.createClassFileFrom(file); |
107 |
IClasspathEntry[] entries = classFile.getJavaProject().getResolvedClasspath(true); |
108 |
<b> |
109 |
// Make the requestor final... |
110 |
final IProblemRequestor requestor = new IProblemRequestor { |
111 |
public void acceptProblem(IProblem problem) {} |
112 |
public void beginReporting() {} |
113 |
public void endReporting() {} |
114 |
public boolean isActive() { |
115 |
return true; |
116 |
} |
117 |
}; |
118 |
// ...and let the created working copy owner returning it |
119 |
WorkingCopyOwner owner = new WorkingCopyOwner() { |
120 |
public IProblemRequestor getProblemRequestor(ICompilationUnit unit) { |
121 |
return requestor; |
122 |
} |
123 |
}; |
124 |
// Calls can now be done to the new API methods using this working copy owner |
125 |
ICompilationUnit workingCopy = compilationUnit.getWorkingCopy(owner, null); |
126 |
ICompilationUnit newWorkingCopy = compilationUnit.becomeWorkingCopy(null); |
127 |
ICompilationUnit newWorkingCopy2 = owner.newWorkingCopy(new Path("FAQ/test/Z.java"), entries, null); |
128 |
ICompilationUnit classWorkingCopy = classFile.becomeWorkingCopy(owner, null); |
129 |
</b> |
130 |
</pre> |
131 |
</p> |
132 |
</li> |
19 |
</ol> |
133 |
</ol> |
20 |
|
|
|
21 |
</body> |
134 |
</body> |
22 |
|
135 |
|
23 |
</html> |
136 |
</html> |