// check if project is a spring project
if (SpringCoreUtils.isSpringProject(javaContext.getProject().getProject())) {
ICompilationUnit cu = javaContext.getCompilationUnit();
if (ProposalCalculatorUtil.hasAnnotationOnType(cu, "Controller")) {
ITextViewer viewer = javaContext.getViewer();
if (viewer instanceof SourceViewer) {
SourceViewer sourceViewer = (SourceViewer) viewer;
int invocationOffset = context.getInvocationOffset();
AssistContext assistContext = new AssistContext(cu, sourceViewer, invocationOffset, 0, SharedASTProvider.WAIT_NO);
ASTNode node = assistContext.getCoveringNode();
// cursor is at the beginning of an empty param list
// [method(^)}
if (node instanceof MethodDeclaration) {
MethodDeclaration methodDecl = (MethodDeclaration) node;
if (ProposalCalculatorUtil.hasAnnotation("RequestMapping", methodDecl)) {
try {
// We need to discover if we're actually
// inside the parameter declaration -- node
// is reported as MethodDeclaration when
// we're inside annotation
IDocument document = sourceViewer.getDocument();
int relativeOffset = invocationOffset - methodDecl.getStartPosition();
String methodText = document.get(methodDecl.getStartPosition(),
methodDecl.getLength());
String methodName = methodDecl.getName().getFullyQualifiedName();
int getterLocation = methodText.indexOf(methodName) + methodName.length();
if (getterLocation < relativeOffset) {
return getProposals(methodDecl, "", invocationOffset, null, javaContext);
}
}
catch (BadLocationException e) {
StatusHandler
.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
}
}
}
else if (node instanceof SimpleName) {
SimpleName name = (SimpleName) node;
ASTNode parentNode = name.getParent();
// cursor is at the start of a param at the end of
// the
// param
// list [metohd(param, ^)]
if (parentNode instanceof VariableDeclarationFragment) {
parentNode = parentNode.getParent();
if (parentNode instanceof VariableDeclarationStatement) {
VariableDeclarationStatement varDeclStmt = (VariableDeclarationStatement) parentNode;
Type varDeclType = varDeclStmt.getType();
if (varDeclType instanceof SimpleType) {
SimpleType sType = (SimpleType) varDeclType;
parentNode = parentNode.getParent();
if (parentNode instanceof Block) {
Block block = (Block) parentNode;
try {
if (viewer.getDocument().getChar(block.getStartPosition()) != '{') {
parentNode = parentNode.getParent();
if (parentNode instanceof MethodDeclaration) {
MethodDeclaration methodDecl = (MethodDeclaration) parentNode;
return getProposals(methodDecl, sType.getName()
.getFullyQualifiedName(), invocationOffset,
varDeclStmt, javaContext);
}
}
}
catch (BadLocationException e) {
StatusHandler.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e
.getMessage(), e));
}
}
}
}
}
// cursor is at the start of a param type
else if (parentNode instanceof SimpleType) {
SimpleType sType = (SimpleType) parentNode;
parentNode = sType.getParent();
if (parentNode instanceof SingleVariableDeclaration) {
SingleVariableDeclaration varDecl = (SingleVariableDeclaration) parentNode;
parentNode = varDecl.getParent();
if (parentNode instanceof MethodDeclaration) {
MethodDeclaration methodDecl = (MethodDeclaration) parentNode;
return getProposals(methodDecl, sType.getName().getFullyQualifiedName(),
invocationOffset, sType, javaContext);
}
}
}
}
// param at the end of a method param list
// [method(param,
// w^)]
else if (node instanceof Block) {
Block block = (Block) node;
ASTNode parentNode = block.getParent();
if (parentNode instanceof MethodDeclaration) {
MethodDeclaration methodDecl = (MethodDeclaration) parentNode;
try {
String blockContent = viewer.getDocument().get(block.getStartPosition(),
block.getLength());
if (blockContent.startsWith(",")) {
blockContent = blockContent.substring(1);
boolean isAnnotation = false;