当前位置: 首页>>代码示例>>Java>>正文


Java InfixExpression.getLocationInParent方法代码示例

本文整理汇总了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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:41,代码来源:QuickAssistProcessor.java


注:本文中的org.eclipse.jdt.core.dom.InfixExpression.getLocationInParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。