當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。