本文整理汇总了Java中org.eclipse.jdt.core.dom.FieldAccess类的典型用法代码示例。如果您正苦于以下问题:Java FieldAccess类的具体用法?Java FieldAccess怎么用?Java FieldAccess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldAccess类属于org.eclipse.jdt.core.dom包,在下文中一共展示了FieldAccess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: needsOuterParantheses
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
private static boolean needsOuterParantheses(ASTNode nodeToCast) {
ASTNode parent = nodeToCast.getParent();
if (parent instanceof MethodInvocation) {
if (((MethodInvocation) parent).getExpression() == nodeToCast) {
return true;
}
} else if (parent instanceof QualifiedName) {
if (((QualifiedName) parent).getQualifier() == nodeToCast) {
return true;
}
} else if (parent instanceof FieldAccess) {
if (((FieldAccess) parent).getExpression() == nodeToCast) {
return true;
}
}
return false;
}
示例2: handleSimpleName
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
private void handleSimpleName(SimpleName node) {
ASTNode firstExpression = node.getParent();
if (firstExpression instanceof FieldAccess) {
while (firstExpression instanceof FieldAccess) {
firstExpression = ((FieldAccess) firstExpression).getExpression();
}
if (!(firstExpression instanceof SimpleName)) return;
node = (SimpleName) firstExpression;
} else if (firstExpression instanceof SuperFieldAccess) return;
StructuralPropertyDescriptor parentDescription = node.getLocationInParent();
if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY
|| parentDescription == SwitchCase.EXPRESSION_PROPERTY) return;
IBinding binding = node.resolveBinding();
if (!(binding instanceof IVariableBinding)) return;
handleVariable(node, (IVariableBinding) binding);
}
示例3: createWithMethodBody
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
private Block createWithMethodBody(AST ast, BuilderField builderField) {
String originalFieldName = builderField.getOriginalFieldName();
String builderFieldName = builderField.getBuilderFieldName();
Block newBlock = ast.newBlock();
ReturnStatement builderReturnStatement = ast.newReturnStatement();
builderReturnStatement.setExpression(ast.newThisExpression());
Assignment newAssignment = ast.newAssignment();
FieldAccess fieldAccess = ast.newFieldAccess();
fieldAccess.setExpression(ast.newThisExpression());
fieldAccess.setName(ast.newSimpleName(originalFieldName));
newAssignment.setLeftHandSide(fieldAccess);
newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));
newBlock.statements().add(ast.newExpressionStatement(newAssignment));
newBlock.statements().add(builderReturnStatement);
return newBlock;
}
示例4: createWithMethodBody
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
private Block createWithMethodBody(AST ast, String originalFieldName, String builderFieldName) {
Block newBlock = ast.newBlock();
ReturnStatement builderReturnStatement = ast.newReturnStatement();
builderReturnStatement.setExpression(ast.newThisExpression());
Assignment newAssignment = ast.newAssignment();
FieldAccess fieldAccess = ast.newFieldAccess();
fieldAccess.setExpression(ast.newThisExpression());
fieldAccess.setName(ast.newSimpleName(originalFieldName));
newAssignment.setLeftHandSide(fieldAccess);
newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));
newBlock.statements().add(ast.newExpressionStatement(newAssignment));
newBlock.statements().add(builderReturnStatement);
return newBlock;
}
示例5: getAssignedVariable
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
/**
* Returns the binding of the variable written in an Assignment.
* @param assignment The assignment
* @return The binding or <code>null</code> if no bindings are available.
*/
public static IVariableBinding getAssignedVariable(Assignment assignment) {
Expression leftHand = assignment.getLeftHandSide();
switch (leftHand.getNodeType()) {
case ASTNode.SIMPLE_NAME:
return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
case ASTNode.QUALIFIED_NAME:
return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
case ASTNode.FIELD_ACCESS:
return ((FieldAccess) leftHand).resolveFieldBinding();
case ASTNode.SUPER_FIELD_ACCESS:
return ((SuperFieldAccess) leftHand).resolveFieldBinding();
default:
return null;
}
}
示例6: needsExplicitBoxing
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
/**
* Returns whether an expression at the given location needs explicit boxing.
*
* @param expression the expression
* @return <code>true</code> iff an expression at the given location needs explicit boxing
* @since 3.6
*/
private static boolean needsExplicitBoxing(Expression expression) {
StructuralPropertyDescriptor locationInParent= expression.getLocationInParent();
if (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return needsExplicitBoxing((ParenthesizedExpression) expression.getParent());
}
if (locationInParent == ClassInstanceCreation.EXPRESSION_PROPERTY
|| locationInParent == FieldAccess.EXPRESSION_PROPERTY
|| locationInParent == MethodInvocation.EXPRESSION_PROPERTY) {
return true;
}
return false;
}
示例7: isLeftHandSideOfAssignment
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
static boolean isLeftHandSideOfAssignment(ASTNode node) {
Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
if (assignment != null) {
Expression leftHandSide = assignment.getLeftHandSide();
if (leftHandSide == node) {
return true;
}
if (ASTNodes.isParent(node, leftHandSide)) {
switch (leftHandSide.getNodeType()) {
case ASTNode.SIMPLE_NAME:
return true;
case ASTNode.FIELD_ACCESS:
return node == ((FieldAccess) leftHandSide).getName();
case ASTNode.QUALIFIED_NAME:
return node == ((QualifiedName) leftHandSide).getName();
case ASTNode.SUPER_FIELD_ACCESS:
return node == ((SuperFieldAccess) leftHandSide).getName();
default:
return false;
}
}
}
return false;
}
示例8: needsOuterParantheses
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
private static boolean needsOuterParantheses(ASTNode nodeToCast) {
ASTNode parent= nodeToCast.getParent();
if (parent instanceof MethodInvocation) {
if (((MethodInvocation)parent).getExpression() == nodeToCast) {
return true;
}
} else if (parent instanceof QualifiedName) {
if (((QualifiedName)parent).getQualifier() == nodeToCast) {
return true;
}
} else if (parent instanceof FieldAccess) {
if (((FieldAccess)parent).getExpression() == nodeToCast) {
return true;
}
}
return false;
}
示例9: getLeftHandSideVarBinding
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
/**
* for an assignment x = y returns the variable binding of x
*
* @param varBinding
* @param assignment
* @return
*/
private static IVariableBinding getLeftHandSideVarBinding(Assignment assignment) {
Expression leftHnsd = assignment.getLeftHandSide();
if (leftHnsd instanceof SimpleName) {
IBinding bind = ((SimpleName) leftHnsd).resolveBinding();
if (bind instanceof IVariableBinding) {
return ((IVariableBinding) bind).getVariableDeclaration();
}
}
if (leftHnsd instanceof FieldAccess) {
FieldAccess fa = (FieldAccess) leftHnsd;
return fa.resolveFieldBinding();
}
// Leave it null - cannot determine actual domains for arrays
// workaround for bugs related to objects created in complex expression
// if (leftHnsd instanceof ArrayAccess) {
// ArrayAccess aa = (ArrayAccess) leftHnsd;
// return getArrayAccessVarBinding(aa);
// }
return null;
}
示例10: getSimpleAssignName
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
/**
* returns the name associated with an assignment instruction
*
* @param instr
* @return
*/
public static String getSimpleAssignName(AssignmentInstruction instr) {
if (instr instanceof LoadLiteralInstruction)
return ((LoadLiteralInstruction) instr).getLiteral().toString();
ASTNode parentInstr = instr.getNode().getParent();
if (parentInstr instanceof VariableDeclarationFragment) {
return ((VariableDeclarationFragment) parentInstr).getName().getFullyQualifiedName();
}
if (parentInstr instanceof Assignment) {
Expression leftHnsd = ((Assignment) parentInstr).getLeftHandSide();
if (leftHnsd instanceof SimpleName) {
return ((SimpleName) leftHnsd).getFullyQualifiedName();
}
else if (leftHnsd instanceof FieldAccess) {
return ((FieldAccess) leftHnsd).getName().getFullyQualifiedName();
}
}
throw new IllegalStateException("cannot find local variable associated with " + instr);
}
示例11: ExpressionVisitor
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
public ExpressionVisitor(ASTNode enclosingDeclartion, BaseTraceability trace) {
AstNode expression = trace.getExpression();
if(expression instanceof ast.ClassInstanceCreation){
expressionType = ExpressionType.CLASS_INSTANCE_CREATION;
expressionToFind =((ast.ClassInstanceCreation) expression).complexExpression;
}else if(expression instanceof ast.FieldWrite){
expressionType = ExpressionType.FIELD_WRITE;
expressionToFind = ((ast.FieldWrite) expression).complexExpression;
}else if(expression instanceof ast.FieldAccess){
expressionType = ExpressionType.FIELD_ACCESS;
expressionToFind = ((ast.FieldAccess) expression).complexExpression;
}else if(expression instanceof ast.MethodInvocation){
expressionToFind =((ast.MethodInvocation) expression).complexExpression;
expressionType = ExpressionType.METHOD_INVOCATION;
}
enclosingDeclaration = enclosingDeclartion;
enclosingDeclaration.accept(this);
}
示例12: getAssignedVariable
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
/**
* Returns the binding of the variable written in an Assignment.
*
* @param assignment The assignment
* @return The binding or <code>null</code> if no bindings are available.
*/
public static IVariableBinding getAssignedVariable(Assignment assignment) {
Expression leftHand = assignment.getLeftHandSide();
switch (leftHand.getNodeType()) {
case ASTNode.SIMPLE_NAME:
return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
case ASTNode.QUALIFIED_NAME:
return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
case ASTNode.FIELD_ACCESS:
return ((FieldAccess) leftHand).resolveFieldBinding();
case ASTNode.SUPER_FIELD_ACCESS:
return ((SuperFieldAccess) leftHand).resolveFieldBinding();
default:
return null;
}
}
示例13: rewriteAST
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
throws CoreException {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TextEditGroup group = createTextEditGroup(getDescription(), cuRewrite);
AST ast = rewrite.getAST();
FieldAccess fieldAccess = ast.newFieldAccess();
ThisExpression thisExpression = ast.newThisExpression();
if (fQualifier != null) thisExpression.setQualifier(ast.newName(fQualifier));
fieldAccess.setExpression(thisExpression);
fieldAccess.setName((SimpleName) rewrite.createMoveTarget(fName));
rewrite.replace(fName, fieldAccess, group);
}
示例14: newFieldAssignment
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
private Statement newFieldAssignment(
AST ast, SimpleName fieldNameNode, Expression initializer, boolean useThisAccess) {
Assignment assignment = ast.newAssignment();
if (useThisAccess) {
FieldAccess access = ast.newFieldAccess();
access.setExpression(ast.newThisExpression());
access.setName(fieldNameNode);
assignment.setLeftHandSide(access);
} else {
assignment.setLeftHandSide(fieldNameNode);
}
assignment.setOperator(Assignment.Operator.ASSIGN);
assignment.setRightHandSide(initializer);
return ast.newExpressionStatement(assignment);
}
示例15: isLeftHandSideOfAssignment
import org.eclipse.jdt.core.dom.FieldAccess; //导入依赖的package包/类
private static boolean isLeftHandSideOfAssignment(ASTNode node) {
Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
if (assignment != null) {
Expression leftHandSide = assignment.getLeftHandSide();
if (leftHandSide == node) {
return true;
}
if (ASTNodes.isParent(node, leftHandSide)) {
switch (leftHandSide.getNodeType()) {
case ASTNode.SIMPLE_NAME:
return true;
case ASTNode.FIELD_ACCESS:
return node == ((FieldAccess) leftHandSide).getName();
case ASTNode.QUALIFIED_NAME:
return node == ((QualifiedName) leftHandSide).getName();
case ASTNode.SUPER_FIELD_ACCESS:
return node == ((SuperFieldAccess) leftHandSide).getName();
default:
return false;
}
}
}
return false;
}