ITextViewer viewer = javaContext.getViewer();
if (viewer instanceof SourceViewer) {
ICompilationUnit cu = javaContext.getCompilationUnit();
SourceViewer sourceViewer = (SourceViewer) javaContext.getViewer();
int invocationOffset = javaContext.getInvocationOffset();
AssistContext assistContext = new AssistContext(cu, sourceViewer, invocationOffset, 0,
SharedASTProvider.WAIT_NO);
ASTNode node = ((SourceRefElement) a).findNode(assistContext.getASTRoot());
if (node == null) {
node = assistContext.getCoveredNode();
}
if (!(node instanceof Annotation)) {
return proposals;
}
LocationInformation locationInfo = null;
if (node instanceof NormalAnnotation) {
NormalAnnotation normalAnnotation = (NormalAnnotation) node;
@SuppressWarnings("unchecked")
List<MemberValuePair> pairs = normalAnnotation.values();
for (MemberValuePair pair : pairs) {
Expression expression = pair.getValue();
if (expression instanceof StringLiteral) {
locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
}
}
}
else if (node instanceof SingleMemberAnnotation) {
SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) node;
Expression expression = singleMemberAnnotation.getValue();
if (expression instanceof StringLiteral) {
locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
}
}
if (locationInfo == null) {
return proposals;
}
int locationOffset = locationInfo.getOffset();
int locationLength = locationInfo.getLength();
String content = locationInfo.getFilter();
if (invocationOffset >= locationOffset && invocationOffset <= locationOffset + locationLength) {
int startIndex;
int index = 0;
boolean found = false;
while (!found) {
startIndex = content.indexOf("{");
if (startIndex < 0 || startIndex + locationOffset >= invocationOffset) {
break;
}
content = content.substring(startIndex + 1);
index += startIndex + 1;
if (!(content.contains("{"))) {
found = true;
}
}
locationOffset += 1; // ignore opening quote
if (found) {
ISourceRange sourceRange = element.getSourceRange();
//Now get the 'real' ast.
assistContext = new AssistContext(javaContext.getCompilationUnit(), sourceViewer,
sourceRange.getOffset(), sourceRange.getLength(), SharedASTProvider.WAIT_YES);
node = assistContext.getCoveringNode();
Annotation annotation = (Annotation) ((SourceRefElement) a).findNode(assistContext.getASTRoot());
if (content.endsWith("}")) {
content = content.substring(0, content.length() - 1);
}