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


Java SimpleName.getParent方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.SimpleName.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleName.getParent方法的具体用法?Java SimpleName.getParent怎么用?Java SimpleName.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.SimpleName的用法示例。


在下文中一共展示了SimpleName.getParent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDeclarationNode

import org.eclipse.jdt.core.dom.SimpleName; //导入方法依赖的package包/类
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name
 *            the name of the node
 *
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
	ASTNode parent = name.getParent();
	if (!(parent instanceof AbstractTypeDeclaration)) {

		parent = parent.getParent();
		if (parent instanceof ParameterizedType || parent instanceof Type) {
			parent = parent.getParent();
		}
		if (parent instanceof ClassInstanceCreation) {

			final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
			parent = creation.getAnonymousClassDeclaration();
		}
	}
	return parent;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:PotentialProgrammingProblemsFix.java

示例2: needsImport

import org.eclipse.jdt.core.dom.SimpleName; //导入方法依赖的package包/类
private boolean needsImport(ITypeBinding typeBinding, SimpleName ref) {
	if (!typeBinding.isTopLevel() && !typeBinding.isMember() || typeBinding.isRecovered()) {
		return false; // no imports for anonymous, local, primitive types or parameters types
	}
	int modifiers= typeBinding.getModifiers();
	if (Modifier.isPrivate(modifiers)) {
		return false; // imports for privates are not required
	}
	ITypeBinding currTypeBinding= Bindings.getBindingOfParentType(ref);
	if (currTypeBinding == null) {
		if (ASTNodes.getParent(ref, ASTNode.PACKAGE_DECLARATION) != null) {
			return true; // reference in package-info.java
		}
		return false; // not in a type
	}
	if (!Modifier.isPublic(modifiers)) {
		if (!currTypeBinding.getPackage().getName().equals(typeBinding.getPackage().getName())) {
			return false; // not visible
		}
	}

	ASTNode parent= ref.getParent();
	while (parent instanceof Type) {
		parent= parent.getParent();
	}
	if (parent instanceof AbstractTypeDeclaration && parent.getParent() instanceof CompilationUnit) {
		return true;
	}

	if (typeBinding.isMember()) {
		if (fAnalyzer.isDeclaredInScope(typeBinding, ref, ScopeAnalyzer.TYPES | ScopeAnalyzer.CHECK_VISIBILITY)) {
			return false;
		}
	}
	return true;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:OrganizeImportsOperation.java

示例3: hasSideEffect

import org.eclipse.jdt.core.dom.SimpleName; //导入方法依赖的package包/类
private static boolean hasSideEffect(SimpleName reference) {
	ASTNode parent= reference.getParent();
	while (parent instanceof QualifiedName) {
		parent= parent.getParent();
	}
	if (parent instanceof FieldAccess) {
		parent= parent.getParent();
	}

	ASTNode node= null;
	int nameParentType= parent.getNodeType();
	if (nameParentType == ASTNode.ASSIGNMENT) {
		Assignment assignment= (Assignment) parent;
		node= assignment.getRightHandSide();
	} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
		SingleVariableDeclaration decl= (SingleVariableDeclaration)parent;
		node= decl.getInitializer();
		if (node == null) {
			return false;
		}
	} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
		node= parent;
	} else {
		return false;
	}

	ArrayList<Expression> sideEffects= new ArrayList<>();
	node.accept(new SideEffectFinder(sideEffects));
	return sideEffects.size() > 0;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:31,代码来源:UnusedCodeFix.java

示例4: isEnhancedForStatementVariable

import org.eclipse.jdt.core.dom.SimpleName; //导入方法依赖的package包/类
private boolean isEnhancedForStatementVariable(Statement statement, SimpleName name) {
	if (statement instanceof EnhancedForStatement) {
		EnhancedForStatement forStatement= (EnhancedForStatement) statement;
		SingleVariableDeclaration param= forStatement.getParameter();
		return param.getType() == name.getParent(); // strange recovery, see https://bugs.eclipse.org/180456
	}
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:9,代码来源:NewVariableCorrectionProposal.java

示例5: visit

import org.eclipse.jdt.core.dom.SimpleName; //导入方法依赖的package包/类
@Override
public boolean visit(SimpleName node) {
	if(!(node.getParent() instanceof QualifiedName))
		vars.add(node.getIdentifier());
	return true;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:7,代码来源:VarParser.java

示例6: isFormalParameterInEnhancedForStatement

import org.eclipse.jdt.core.dom.SimpleName; //导入方法依赖的package包/类
private static boolean isFormalParameterInEnhancedForStatement(SimpleName name) {
	return name.getParent() instanceof SingleVariableDeclaration && name.getParent().getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:4,代码来源:UnusedCodeFix.java


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