org.eclipse.jdt.core.dom.SuperFieldAccess Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.SuperFieldAccess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntroduceParameterObjectProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void updateSimpleName(ASTRewrite rewriter, ParameterInfo pi, SimpleName node, List<SingleVariableDeclaration> enclosingParameters, IJavaProject project) {
	AST ast= rewriter.getAST();
	IBinding binding= node.resolveBinding();
	Expression replacementNode= fParameterObjectFactory.createFieldReadAccess(pi, getParameterName(), ast, project, false, null);
	if (binding instanceof IVariableBinding) {
		IVariableBinding variable= (IVariableBinding) binding;
		if (variable.isParameter() && variable.getName().equals(getNameInScope(pi, enclosingParameters))) {
			rewriter.replace(node, replacementNode, null);
		}
	} else {
		ASTNode parent= node.getParent();
		if (!(parent instanceof QualifiedName || parent instanceof FieldAccess || parent instanceof SuperFieldAccess)) {
			if (node.getIdentifier().equals(getNameInScope(pi, enclosingParameters))) {
				rewriter.replace(node, replacementNode, null);
			}
		}
	}
}
 
Example #2
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example #3
Source File: ExpressionVariable.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static IBinding resolveBinding(Expression expression){
	if (expression instanceof Name)
		return ((Name)expression).resolveBinding();
	if (expression instanceof ParenthesizedExpression)
		return resolveBinding(((ParenthesizedExpression)expression).getExpression());
	else if (expression instanceof Assignment)
		return resolveBinding(((Assignment)expression).getLeftHandSide());//TODO ???
	else if (expression instanceof MethodInvocation)
		return ((MethodInvocation)expression).resolveMethodBinding();
	else if (expression instanceof SuperMethodInvocation)
		return ((SuperMethodInvocation)expression).resolveMethodBinding();
	else if (expression instanceof FieldAccess)
		return ((FieldAccess)expression).resolveFieldBinding();
	else if (expression instanceof SuperFieldAccess)
		return ((SuperFieldAccess)expression).resolveFieldBinding();
	else if (expression instanceof ConditionalExpression)
		return resolveBinding(((ConditionalExpression)expression).getThenExpression());
	return null;
}
 
Example #4
Source File: ASTNodeMatcher.java    From JDeodorant with MIT License 6 votes vote down vote up
protected boolean isTypeHolder(Object o) {
	if(o.getClass().equals(MethodInvocation.class) || o.getClass().equals(SuperMethodInvocation.class)			
			|| o.getClass().equals(NumberLiteral.class) || o.getClass().equals(StringLiteral.class)
			|| o.getClass().equals(CharacterLiteral.class) || o.getClass().equals(BooleanLiteral.class)
			|| o.getClass().equals(TypeLiteral.class) || o.getClass().equals(NullLiteral.class)
			|| o.getClass().equals(ArrayCreation.class)
			|| o.getClass().equals(ClassInstanceCreation.class)
			|| o.getClass().equals(ArrayAccess.class) || o.getClass().equals(FieldAccess.class)
			|| o.getClass().equals(SuperFieldAccess.class) || o.getClass().equals(ParenthesizedExpression.class)
			|| o.getClass().equals(SimpleName.class) || o.getClass().equals(QualifiedName.class)
			|| o.getClass().equals(CastExpression.class) || o.getClass().equals(InfixExpression.class)
			|| o.getClass().equals(PrefixExpression.class) || o.getClass().equals(InstanceofExpression.class)
			|| o.getClass().equals(ThisExpression.class) || o.getClass().equals(ConditionalExpression.class))
		return true;
	return false;
}
 
Example #5
Source File: SnippetFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: ParameterObjectFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Expression generateQualifier(String paramName, AST ast, boolean useSuper, Expression qualifier) {
	SimpleName paramSimpleName= ast.newSimpleName(paramName);
	if (useSuper) {
		SuperFieldAccess sf= ast.newSuperFieldAccess();
		sf.setName(paramSimpleName);
		if (qualifier instanceof Name) {
			sf.setQualifier((Name) qualifier);
		}
		return sf;
	}
	if (qualifier != null) {
		FieldAccess parameterAccess= ast.newFieldAccess();
		parameterAccess.setExpression(qualifier);
		parameterAccess.setName(paramSimpleName);
		return parameterAccess;
	}
	return paramSimpleName;
}
 
Example #7
Source File: SnippetFinder.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
private SuperFieldAcc visit(SuperFieldAccess node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	SuperFieldAcc superFieldAcc = new SuperFieldAcc(startLine, endLine, node);
	
	SName identifier = (SName) process(node.getName());
	identifier.setParent(superFieldAcc);
	superFieldAcc.setIdentifier(identifier);
	
	if(node.getQualifier() != null){
		Label name = (Label) process(node.getQualifier());
		name.setParent(superFieldAcc);
		superFieldAcc.setName(name);
	}
	
	Pair<String, String> pair = NodeUtils.getTypeDecAndMethodDec(node);
	Type exprType = ProjectInfo.getVariableType(pair.getFirst(), pair.getSecond(), node.getName().getFullyQualifiedName());
	superFieldAcc.setType(exprType);
	
	return superFieldAcc;
}
 
Example #9
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(SuperFieldAccess expr) {
	if (expr.getQualifier() != null) {
		handleExpression(expr.getQualifier());
	}
	handleExpression(expr.getName());
	return false;
}
 
Example #10
Source File: FullConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ITypeConstraint[] create(SuperFieldAccess access){
	SimpleName name= access.getName();
	IBinding binding= name.resolveBinding();
	if (! (binding instanceof IVariableBinding))
		return new ITypeConstraint[0];
	IVariableBinding vb= (IVariableBinding)binding;
	return createConstraintsForAccessToField(vb, null, access);
}
 
Example #11
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(SuperFieldAccess node) {
	if (skipNode(node)) {
		return;
	}
	processSequential(node, node.getQualifier(), node.getName());
}
 
Example #12
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(SuperFieldAccess expr) {
	/*
	 * SuperFieldAccess: [ ClassName . ] super . Identifier
	 */
	activateDiffStyle(expr);
	if (expr.getQualifier() != null) {
		handleExpression(expr.getQualifier());
		appendPeriod();
	}
	styledString.append("super", determineDiffStyle(expr, new StyledStringStyler(keywordStyle)));
	appendPeriod();
	handleExpression(expr.getName());
	deactivateDiffStyle(expr);
	return false;
}
 
Example #13
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final boolean visit(final SuperFieldAccess node) {
	if (!fAnonymousClassDeclaration && !fTypeDeclarationStatement) {
		final AST ast= node.getAST();
		final FieldAccess access= ast.newFieldAccess();
		access.setExpression(ast.newThisExpression());
		access.setName(ast.newSimpleName(node.getName().getIdentifier()));
		fRewrite.replace(node, access, null);
		if (!fSourceRewriter.getCu().equals(fTargetRewriter.getCu()))
			fSourceRewriter.getImportRemover().registerRemovedNode(node);
		return true;
	}
	return false;
}
 
Example #14
Source File: SuperTypeConstraintsCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final void endVisit(final SuperFieldAccess node) {
	final Name name= node.getName();
	final IBinding binding= name.resolveBinding();
	if (binding instanceof IVariableBinding)
		endVisit((IVariableBinding) binding, null, node);
}
 
Example #15
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final boolean visit(final SuperFieldAccess node) {
	Assert.isNotNull(node);
	fStatus.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_uses_super, JavaStatusContext.create(fMethod.getCompilationUnit(), node)));
	fResult.add(node);
	return false;
}
 
Example #16
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Is the specified name a qualified entity, e.g. preceded by 'this',
 * 'super' or part of a method invocation?
 *
 * @param name
 *            the name to check
 * @return <code>true</code> if this entity is qualified,
 *         <code>false</code> otherwise
 */
protected static boolean isQualifiedEntity(final Name name) {
	Assert.isNotNull(name);
	final ASTNode parent= name.getParent();
	if (parent instanceof QualifiedName && ((QualifiedName) parent).getName().equals(name) || parent instanceof FieldAccess && ((FieldAccess) parent).getName().equals(name) || parent instanceof SuperFieldAccess)
		return true;
	else if (parent instanceof MethodInvocation) {
		final MethodInvocation invocation= (MethodInvocation) parent;
		return invocation.getExpression() != null && invocation.getName().equals(name);
	}
	return false;
}
 
Example #17
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final SuperFieldAccess node) {
  Name _qualifier = node.getQualifier();
  boolean _tripleNotEquals = (_qualifier != null);
  if (_tripleNotEquals) {
    node.getQualifier().accept(this);
    this.appendToBuffer(".");
  }
  this.appendToBuffer("super.");
  node.getName().accept(this);
  return false;
}
 
Example #18
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Expression getQualifier(ASTNode parent) {
	switch (parent.getNodeType()) {
		case ASTNode.FIELD_ACCESS:
			return ((FieldAccess) parent).getExpression();
		case ASTNode.QUALIFIED_NAME:
			return ((QualifiedName)parent).getQualifier();
		case ASTNode.SUPER_FIELD_ACCESS:
			return ((SuperFieldAccess)parent).getQualifier();
		default:
			return null;
	}
}
 
Example #19
Source File: IdentifierPerType.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean visit(final SuperFieldAccess node) {
	addToMap(identifiers, node, node.getName().toString());
	return super.visit(node);
}
 
Example #20
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
private void handleExpression(Expression expression) {
	if (expression instanceof ArrayAccess) {
		visit((ArrayAccess) expression);
	} else if (expression instanceof ArrayCreation) {
		visit((ArrayCreation) expression);
	} else if (expression instanceof ArrayInitializer) {
		visit((ArrayInitializer) expression);
	} else if (expression instanceof Assignment) {
		visit((Assignment) expression);
	} else if (expression instanceof BooleanLiteral) {
		visit((BooleanLiteral) expression);
	} else if (expression instanceof CastExpression) {
		visit((CastExpression) expression);
	} else if (expression instanceof CharacterLiteral) {
		visit((CharacterLiteral) expression);
	} else if (expression instanceof ClassInstanceCreation) {
		visit((ClassInstanceCreation) expression);
	} else if (expression instanceof ConditionalExpression) {
		visit((ConditionalExpression) expression);
	} else if (expression instanceof FieldAccess) {
		visit((FieldAccess) expression);
	} else if (expression instanceof InfixExpression) {
		visit((InfixExpression) expression);
	} else if (expression instanceof InstanceofExpression) {
		visit((InstanceofExpression) expression);
	} else if (expression instanceof MethodInvocation) {
		visit((MethodInvocation) expression);
	} else if (expression instanceof NullLiteral) {
		visit((NullLiteral) expression);
	} else if (expression instanceof NumberLiteral) {
		visit((NumberLiteral) expression);
	} else if (expression instanceof ParenthesizedExpression) {
		visit((ParenthesizedExpression) expression);
	} else if (expression instanceof PostfixExpression) {
		visit((PostfixExpression) expression);
	} else if (expression instanceof PrefixExpression) {
		visit((PrefixExpression) expression);
	} else if ((expression instanceof QualifiedName)) {
		visit((QualifiedName) expression);
	} else if (expression instanceof SimpleName) {
		visit((SimpleName) expression);
	} else if (expression instanceof StringLiteral) {
		visit((StringLiteral) expression);
	} else if (expression instanceof SuperFieldAccess) {
		visit((SuperFieldAccess) expression);
	} else if (expression instanceof SuperMethodInvocation) {
		visit((SuperMethodInvocation) expression);
	} else if (expression instanceof ThisExpression) {
		visit((ThisExpression) expression);
	} else if (expression instanceof TypeLiteral) {
		visit((TypeLiteral) expression);
	} else if (expression instanceof VariableDeclarationExpression) {
		visit((VariableDeclarationExpression) expression);
	}
}
 
Example #21
Source File: InstanceOfSuperFieldAccess.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean instanceOf(Expression expression) {
	if(expression instanceof SuperFieldAccess)
		return true;
	else
		return false;
}
 
Example #22
Source File: LambdaExpressionsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SuperFieldAccess node) {
	throw new AbortSearchException();
}
 
Example #23
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SuperFieldAccess node) {
	return visitNode(node);
}
 
Example #24
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(SuperFieldAccess node) {
	endVisitNode(node);
}
 
Example #25
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Resolve the binding (<em>not</em> the type binding) for the expression or a nested expression
 * (e.g. nested in parentheses, cast, ...).
 * 
 * @param expression an expression node
 * @param goIntoCast iff <code>true</code>, go into a CastExpression's expression to resolve
 * @return the expression binding, or <code>null</code> if the expression has no binding or the
 *         binding could not be resolved
 * 
 * @see StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding, Expression, java.util.Collection)
 * @since 3.5
 */
public static IBinding resolveExpressionBinding(Expression expression, boolean goIntoCast) {
	//TODO: search for callers of resolve*Binding() methods and replace with call to this method
	
	// similar to StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding, Expression, Collection)
	switch (expression.getNodeType()) {
		case ASTNode.SIMPLE_NAME:
		case ASTNode.QUALIFIED_NAME:
			return ((Name) expression).resolveBinding();
			
		case ASTNode.FIELD_ACCESS:
			return ((FieldAccess) expression).resolveFieldBinding();
		case ASTNode.SUPER_FIELD_ACCESS:
			return ((SuperFieldAccess) expression).resolveFieldBinding();
			
		case ASTNode.METHOD_INVOCATION:
			return ((MethodInvocation) expression).resolveMethodBinding();
		case ASTNode.SUPER_METHOD_INVOCATION:
			return ((SuperMethodInvocation) expression).resolveMethodBinding();
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ((ClassInstanceCreation) expression).resolveConstructorBinding();
			
		case ASTNode.MARKER_ANNOTATION:
		case ASTNode.SINGLE_MEMBER_ANNOTATION:
		case ASTNode.NORMAL_ANNOTATION:
			return ((Annotation) expression).resolveAnnotationBinding();
			
		case ASTNode.ARRAY_ACCESS:
			return resolveExpressionBinding(((ArrayAccess) expression).getArray(), goIntoCast);
		case ASTNode.CAST_EXPRESSION:
			if (goIntoCast) {
				return resolveExpressionBinding(((CastExpression) expression).getExpression(), true);
			} else {
				return null;
			}
		case ASTNode.PARENTHESIZED_EXPRESSION:
			return resolveExpressionBinding(((ParenthesizedExpression) expression).getExpression(), goIntoCast);
		case ASTNode.PREFIX_EXPRESSION:
			return resolveExpressionBinding(((PrefixExpression) expression).getOperand(), goIntoCast);
		case ASTNode.POSTFIX_EXPRESSION:
			return resolveExpressionBinding(((PostfixExpression) expression).getOperand(), goIntoCast);
		default:
			return null;
	}
}
 
Example #26
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
private void handleExpression(Expression expression) {
	if (expression instanceof ArrayAccess) {
		visit((ArrayAccess) expression);
	} else if (expression instanceof ArrayCreation) {
		visit((ArrayCreation) expression);
	} else if (expression instanceof ArrayInitializer) {
		visit((ArrayInitializer) expression);
	} else if (expression instanceof Assignment) {
		visit((Assignment) expression);
	} else if (expression instanceof BooleanLiteral) {
		visit((BooleanLiteral) expression);
	} else if (expression instanceof CastExpression) {
		visit((CastExpression) expression);
	} else if (expression instanceof CharacterLiteral) {
		visit((CharacterLiteral) expression);
	} else if (expression instanceof ClassInstanceCreation) {
		visit((ClassInstanceCreation) expression);
	} else if (expression instanceof ConditionalExpression) {
		visit((ConditionalExpression) expression);
	} else if (expression instanceof FieldAccess) {
		visit((FieldAccess) expression);
	} else if (expression instanceof InfixExpression) {
		visit((InfixExpression) expression);
	} else if (expression instanceof InstanceofExpression) {
		visit((InstanceofExpression) expression);
	} else if (expression instanceof MethodInvocation) {
		visit((MethodInvocation) expression);
	} else if (expression instanceof NullLiteral) {
		visit((NullLiteral) expression);
	} else if (expression instanceof NumberLiteral) {
		visit((NumberLiteral) expression);
	} else if (expression instanceof ParenthesizedExpression) {
		visit((ParenthesizedExpression) expression);
	} else if (expression instanceof PostfixExpression) {
		visit((PostfixExpression) expression);
	} else if (expression instanceof PrefixExpression) {
		visit((PrefixExpression) expression);
	} else if ((expression instanceof QualifiedName)) {
		visit((QualifiedName) expression);
	} else if (expression instanceof SimpleName) {
		visit((SimpleName) expression);
	} else if (expression instanceof StringLiteral) {
		visit((StringLiteral) expression);
	} else if (expression instanceof SuperFieldAccess) {
		visit((SuperFieldAccess) expression);
	} else if (expression instanceof SuperMethodInvocation) {
		visit((SuperMethodInvocation) expression);
	} else if (expression instanceof ThisExpression) {
		visit((ThisExpression) expression);
	} else if (expression instanceof TypeLiteral) {
		visit((TypeLiteral) expression);
	} else if (expression instanceof VariableDeclarationExpression) {
		visit((VariableDeclarationExpression) expression);
	}
}
 
Example #27
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SuperFieldAccess node) {
	add(fCreator.create(node));
	return true;
}
 
Example #28
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SuperFieldAccess node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #29
Source File: ConstantChecks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SuperFieldAccess node) {
	fResult= false;
	return false;
}
 
Example #30
Source File: ConstantChecks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SuperFieldAccess node) {
	fResult= false;
	return false;
}