Lines 69-74
Link Here
|
69 |
import javax.lang.model.type.TypeKind; |
69 |
import javax.lang.model.type.TypeKind; |
70 |
import javax.lang.model.type.TypeMirror; |
70 |
import javax.lang.model.type.TypeMirror; |
71 |
import javax.lang.model.util.Types; |
71 |
import javax.lang.model.util.Types; |
|
|
72 |
import org.netbeans.api.annotations.common.CheckForNull; |
72 |
import org.netbeans.api.annotations.common.NonNull; |
73 |
import org.netbeans.api.annotations.common.NonNull; |
73 |
import org.netbeans.api.java.lexer.JavaTokenId; |
74 |
import org.netbeans.api.java.lexer.JavaTokenId; |
74 |
import org.netbeans.api.java.source.JavaSource.Phase; |
75 |
import org.netbeans.api.java.source.JavaSource.Phase; |
Lines 644-649
Link Here
|
644 |
return findNameSpan(var.getName().toString(), var); |
645 |
return findNameSpan(var.getName().toString(), var); |
645 |
} |
646 |
} |
646 |
|
647 |
|
|
|
648 |
/**Find span of the {@link MethodTree#getParameters()} parameter list in the source. |
649 |
* Returns the position of the opening and closing parentheses of the parameter list |
650 |
* in the source code that was parsed (ie. {@link CompilationInfo.getText()}, which |
651 |
* may differ from the positions in the source document if it has been already altered. |
652 |
* |
653 |
* @param method method which parameter list should be searched for |
654 |
* @return the span of the parameter list, or null if cannot be found |
655 |
* @since 0.81 |
656 |
*/ |
657 |
public @CheckForNull int[] findMethodParameterSpan(@NonNull MethodTree method) { |
658 |
JCTree jcTree = (JCTree) method; |
659 |
int pos = jcTree.pos; |
660 |
|
661 |
if (pos < 0) |
662 |
return null; |
663 |
|
664 |
TokenSequence<JavaTokenId> tokenSequence = info.getTokenHierarchy().tokenSequence(JavaTokenId.language()); |
665 |
tokenSequence.move(pos); |
666 |
|
667 |
int startPos = -1; |
668 |
int endPos = -1; |
669 |
while(tokenSequence.moveNext()) { |
670 |
if(tokenSequence.token().id() == JavaTokenId.LPAREN) { |
671 |
startPos = tokenSequence.offset(); |
672 |
} |
673 |
if(tokenSequence.token().id() == JavaTokenId.RPAREN) { |
674 |
endPos = tokenSequence.offset(); |
675 |
break; |
676 |
} |
677 |
if(tokenSequence.token().id() == JavaTokenId.LBRACE) { |
678 |
return null; |
679 |
} |
680 |
} |
681 |
|
682 |
if(startPos == -1 || endPos == -1) { |
683 |
return null; |
684 |
} |
685 |
|
686 |
return new int[] { |
687 |
startPos, |
688 |
endPos |
689 |
}; |
690 |
} |
691 |
|
647 |
/**Find span of the {@link MemberSelectTree#getIdentifier()} identifier in the source. |
692 |
/**Find span of the {@link MemberSelectTree#getIdentifier()} identifier in the source. |
648 |
* Returns starting and ending offset of the name in the source code that was parsed |
693 |
* Returns starting and ending offset of the name in the source code that was parsed |
649 |
* (ie. {@link CompilationInfo.getText()}, which may differ from the positions in the source |
694 |
* (ie. {@link CompilationInfo.getText()}, which may differ from the positions in the source |