本文整理汇总了Java中org.eclipse.jdt.core.dom.InfixExpression.getLocationInParent方法的典型用法代码示例。如果您正苦于以下问题:Java InfixExpression.getLocationInParent方法的具体用法?Java InfixExpression.getLocationInParent怎么用?Java InfixExpression.getLocationInParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.InfixExpression
的用法示例。
在下文中一共展示了InfixExpression.getLocationInParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEnclosingAppendBuffer
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
/**
* Checks
* <ul>
* <li>whether the given infix expression is the argument of a StringBuilder#append() or
* StringBuffer#append() invocation, and</li>
* <li>the append method is called on a simple variable, and</li>
* <li>the invocation occurs in a statement (not as nested expression)</li>
* </ul>
*
* @param infixExpression the infix expression
* @return the name of the variable we were appending to, or <code>null</code> if not matching
*/
private static SimpleName getEnclosingAppendBuffer(InfixExpression infixExpression) {
if (infixExpression.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) {
MethodInvocation methodInvocation= (MethodInvocation)infixExpression.getParent();
// ..not in an expression.. (e.g. not sb.append("high" + 5).append(6);)
if (methodInvocation.getParent() instanceof Statement) {
// ..of a function called append:
if ("append".equals(methodInvocation.getName().getIdentifier())) { //$NON-NLS-1$
Expression expression= methodInvocation.getExpression();
// ..and the append is being called on a Simple object:
if (expression instanceof SimpleName) {
IBinding binding= ((SimpleName)expression).resolveBinding();
if (binding instanceof IVariableBinding) {
String typeName= ((IVariableBinding)binding).getType().getQualifiedName();
// And the object's type is a StringBuilder or StringBuffer:
if ("java.lang.StringBuilder".equals(typeName) || "java.lang.StringBuffer".equals(typeName)) { //$NON-NLS-1$ //$NON-NLS-2$
return (SimpleName)expression;
}
}
}
}
}
}
return null;
}