|
Lines 34-68
Link Here
|
| 34 |
import org.eclipse.jdt.core.compiler.CharOperation; |
34 |
import org.eclipse.jdt.core.compiler.CharOperation; |
| 35 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
35 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
| 36 |
import org.eclipse.jdt.internal.compiler.ast.*; |
36 |
import org.eclipse.jdt.internal.compiler.ast.*; |
| 37 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
|
|
| 38 |
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
| 39 |
import org.eclipse.jdt.internal.compiler.ast.Argument; |
| 40 |
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference; |
| 41 |
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; |
| 42 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
| 43 |
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; |
| 44 |
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; |
| 45 |
import org.eclipse.jdt.internal.compiler.ast.ImportReference; |
| 46 |
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; |
| 47 |
import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference; |
| 48 |
import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference; |
| 49 |
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; |
| 50 |
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; |
| 51 |
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; |
| 52 |
import org.eclipse.jdt.internal.compiler.ast.TypeParameter; |
37 |
import org.eclipse.jdt.internal.compiler.ast.TypeParameter; |
| 53 |
import org.eclipse.jdt.internal.compiler.ast.TypeReference; |
|
|
| 54 |
import org.eclipse.jdt.internal.compiler.ast.Wildcard; |
| 55 |
import org.eclipse.jdt.internal.compiler.env.*; |
38 |
import org.eclipse.jdt.internal.compiler.env.*; |
| 56 |
import org.eclipse.jdt.internal.compiler.env.ISourceImport; |
|
|
| 57 |
import org.eclipse.jdt.internal.compiler.env.ISourceType; |
| 58 |
|
39 |
|
| 59 |
import org.eclipse.jdt.internal.compiler.lookup.CompilerModifiers; |
40 |
import org.eclipse.jdt.internal.compiler.lookup.CompilerModifiers; |
| 60 |
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
41 |
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
| 61 |
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; |
42 |
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; |
| 62 |
import org.eclipse.jdt.internal.core.*; |
43 |
import org.eclipse.jdt.internal.core.*; |
| 63 |
import org.eclipse.jdt.internal.core.JavaElement; |
|
|
| 64 |
import org.eclipse.jdt.internal.core.SourceFieldElementInfo; |
| 65 |
import org.eclipse.jdt.internal.core.SourceTypeElementInfo; |
| 66 |
|
44 |
|
| 67 |
public class SourceTypeConverter implements CompilerModifiers { |
45 |
public class SourceTypeConverter implements CompilerModifiers { |
| 68 |
|
46 |
|
|
Lines 158-169
Link Here
|
| 158 |
} |
136 |
} |
| 159 |
/* convert type(s) */ |
137 |
/* convert type(s) */ |
| 160 |
int typeCount = sourceTypes.length; |
138 |
int typeCount = sourceTypes.length; |
| 161 |
this.unit.types = new TypeDeclaration[typeCount]; |
139 |
final TypeDeclaration[] types = new TypeDeclaration[typeCount]; |
|
|
140 |
/* |
| 141 |
* We used a temporary types collection to prevent this.unit.types from being null during a call to |
| 142 |
* convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types. |
| 143 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466 |
| 144 |
*/ |
| 162 |
for (int i = 0; i < typeCount; i++) { |
145 |
for (int i = 0; i < typeCount; i++) { |
| 163 |
SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i]; |
146 |
SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i]; |
| 164 |
this.unit.types[i] = |
147 |
types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult); |
| 165 |
convert((SourceType) typeInfo.getHandle(), compilationResult); |
|
|
| 166 |
} |
148 |
} |
|
|
149 |
this.unit.types = types; |
| 167 |
return this.unit; |
150 |
return this.unit; |
| 168 |
} |
151 |
} |
| 169 |
|
152 |
|
|
Lines 555-567
Link Here
|
| 555 |
if (positions == null) return null; |
538 |
if (positions == null) return null; |
| 556 |
int length = positions.length; |
539 |
int length = positions.length; |
| 557 |
Annotation[] annotations = new Annotation[length]; |
540 |
Annotation[] annotations = new Annotation[length]; |
|
|
541 |
int recordedAnnotations = 0; |
| 558 |
for (int i = 0; i < length; i++) { |
542 |
for (int i = 0; i < length; i++) { |
| 559 |
long position = positions[i]; |
543 |
long position = positions[i]; |
| 560 |
int start = (int) (position >>> 32); |
544 |
int start = (int) (position >>> 32); |
| 561 |
int end = (int) position; |
545 |
int end = (int) position; |
| 562 |
char[] annotationSource = CharOperation.subarray(cuSource, start, end+1); |
546 |
char[] annotationSource = CharOperation.subarray(cuSource, start, end+1); |
| 563 |
Expression expression = parseMemberValue(annotationSource); |
547 |
Expression expression = parseMemberValue(annotationSource); |
| 564 |
annotations[i] = (Annotation) expression; |
548 |
/* |
|
|
549 |
* expression can be null or not an annotation if the source has changed between |
| 550 |
* the moment where the annotation source positions have been retrieved and the moment were |
| 551 |
* this parsing occured. |
| 552 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=90916 |
| 553 |
*/ |
| 554 |
if (expression instanceof Annotation) { |
| 555 |
annotations[i] = (Annotation) expression; |
| 556 |
recordedAnnotations++; |
| 557 |
} |
| 558 |
} |
| 559 |
if (length != recordedAnnotations) { |
| 560 |
// resize to remove null annotations |
| 561 |
System.arraycopy(annotations, 0, (annotations = new Annotation[recordedAnnotations]), 0, recordedAnnotations); |
| 565 |
} |
562 |
} |
| 566 |
return annotations; |
563 |
return annotations; |
| 567 |
} |
564 |
} |