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

The following examples show how to use org.eclipse.jdt.core.dom.ThisExpression. 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: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private MethodDeclaration createGetOuterHelper() {
	String outerTypeName= fType.getDeclaringClass().getTypeDeclaration().getName();

	MethodDeclaration helperMethod= fAst.newMethodDeclaration();
	helperMethod.modifiers().addAll(ASTNodeFactory.newModifiers(fAst, Modifier.PRIVATE));
	helperMethod.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));
	helperMethod.setConstructor(false);
	helperMethod.setReturnType2(fAst.newSimpleType(fAst.newSimpleName(outerTypeName)));

	Block body= fAst.newBlock();
	helperMethod.setBody(body);

	ThisExpression thisExpression= fAst.newThisExpression();
	thisExpression.setQualifier(fAst.newSimpleName(outerTypeName));

	ReturnStatement endReturn= fAst.newReturnStatement();
	endReturn.setExpression(thisExpression);
	body.statements().add(endReturn);

	return helperMethod;
}
 
Example #2
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 #3
Source File: MethodObject.java    From JDeodorant with MIT License 6 votes vote down vote up
public boolean containsFieldAccessOfEnclosingClass() {
	//check for field access like SegmentedTimeline.this.segmentsIncluded
	List<FieldInstructionObject> fieldInstructions = getFieldInstructions();
	for(FieldInstructionObject fieldInstruction : fieldInstructions) {
		SimpleName simpleName = fieldInstruction.getSimpleName();
		if(simpleName.getParent() instanceof FieldAccess) {
			FieldAccess fieldAccess = (FieldAccess)simpleName.getParent();
			Expression fieldAccessExpression = fieldAccess.getExpression();
			if(fieldAccessExpression instanceof ThisExpression) {
				ThisExpression thisExpression = (ThisExpression)fieldAccessExpression;
				if(thisExpression.getQualifier() != null) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #4
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(final ThisExpression node) {
	Assert.isNotNull(node);
	Name name= node.getQualifier();
	if (fCreateInstanceField && name != null) {
		ITypeBinding binding= node.resolveTypeBinding();
		if (binding != null && Bindings.equals(binding, fTypeBinding.getDeclaringClass())) {
			AST ast= node.getAST();
			Expression expression= null;
			if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
				FieldAccess access= ast.newFieldAccess();
				access.setExpression(ast.newThisExpression());
				access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
				expression= access;
			} else {
				expression= ast.newSimpleName(fEnclosingInstanceFieldName);
			}
			fSourceRewrite.getASTRewrite().replace(node, expression, null);
		}
	}
	return super.visit(node);
}
 
Example #5
Source File: SurroundWith.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void qualifyThisExpressions(ASTNode node, final ASTRewrite rewrite, final ImportRewrite importRewrite, final ImportRewriteContext importRewriteContext) {
	node.accept(new GenericVisitor() {
		/**
		 * {@inheritDoc}
		 */
		@Override
		public boolean visit(ThisExpression thisExpr) {
			if (thisExpr.getQualifier() == null) {
				ITypeBinding typeBinding= thisExpr.resolveTypeBinding();
				if (typeBinding != null) {
					String typeName= importRewrite.addImport(typeBinding.getTypeDeclaration(), importRewriteContext);
					SimpleName simpleName= thisExpr.getAST().newSimpleName(typeName);
					rewrite.set(thisExpr, ThisExpression.QUALIFIER_PROPERTY, simpleName, null);
				}
			}
			return super.visit(thisExpr);
		}
	});
}
 
Example #6
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example #7
Source File: PolymorphismRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
protected void replaceThisExpressionWithContextParameterInClassInstanceCreationArguments(Statement newStatement, AST subclassAST, ASTRewrite subclassRewriter) {
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
	List<Expression> classInstanceCreations = expressionExtractor.getClassInstanceCreations(newStatement);
	for(Expression creation : classInstanceCreations) {
		ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation)creation;
		List<Expression> arguments = classInstanceCreation.arguments();
		for(Expression argument : arguments) {
			if(argument instanceof ThisExpression) {
				String parameterName = sourceTypeDeclaration.getName().getIdentifier();
				parameterName = parameterName.substring(0,1).toLowerCase() + parameterName.substring(1,parameterName.length());
				ListRewrite argumentsRewrite = subclassRewriter.getListRewrite(classInstanceCreation, ClassInstanceCreation.ARGUMENTS_PROPERTY);
				argumentsRewrite.replace(argument, subclassAST.newSimpleName(parameterName), null);
			}
		}
	}
}
 
Example #8
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void replaceThisExpressionWithSourceClassParameterInClassInstanceCreationArguments(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter) {
	ExpressionExtractor extractor = new ExpressionExtractor();
	List<Expression> classInstanceCreations = extractor.getClassInstanceCreations(newMethodDeclaration.getBody());
	for(Expression creation : classInstanceCreations) {
		ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation)creation;
		List<Expression> arguments = classInstanceCreation.arguments();
		for(Expression argument : arguments) {
			if(argument instanceof ThisExpression) {
				SimpleName parameterName = null;
				if(!additionalArgumentsAddedToMovedMethod.contains("this")) {
					parameterName = addSourceClassParameterToMovedMethod(newMethodDeclaration, targetRewriter);
				}
				else {
					AST ast = newMethodDeclaration.getAST();
					String sourceTypeName = sourceTypeDeclaration.getName().getIdentifier();
					parameterName = ast.newSimpleName(sourceTypeName.replaceFirst(Character.toString(sourceTypeName.charAt(0)), Character.toString(Character.toLowerCase(sourceTypeName.charAt(0)))));
				}
				ListRewrite argumentRewrite = targetRewriter.getListRewrite(classInstanceCreation, ClassInstanceCreation.ARGUMENTS_PROPERTY);
				argumentRewrite.replace(argument, parameterName, null);
			}
		}
	}
}
 
Example #9
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void replaceThisExpressionWithSourceClassParameterInMethodInvocationArguments(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter) {
	ExpressionExtractor extractor = new ExpressionExtractor();
	List<Expression> methodInvocations = extractor.getMethodInvocations(newMethodDeclaration.getBody());
	for(Expression invocation : methodInvocations) {
		if(invocation instanceof MethodInvocation) {
			MethodInvocation methodInvocation = (MethodInvocation)invocation;
			List<Expression> arguments = methodInvocation.arguments();
			for(Expression argument : arguments) {
				if(argument instanceof ThisExpression) {
					SimpleName parameterName = null;
					if(!additionalArgumentsAddedToMovedMethod.contains("this")) {
						parameterName = addSourceClassParameterToMovedMethod(newMethodDeclaration, targetRewriter);
					}
					else {
						AST ast = newMethodDeclaration.getAST();
						String sourceTypeName = sourceTypeDeclaration.getName().getIdentifier();
						parameterName = ast.newSimpleName(sourceTypeName.replaceFirst(Character.toString(sourceTypeName.charAt(0)), Character.toString(Character.toLowerCase(sourceTypeName.charAt(0)))));
					}
					ListRewrite argumentRewrite = targetRewriter.getListRewrite(methodInvocation, MethodInvocation.ARGUMENTS_PROPERTY);
					argumentRewrite.replace(argument, parameterName, null);
				}
			}
		}
	}
}
 
Example #10
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private FieldAccess wrapAsFieldAccess(SimpleName fieldName, AST ast) {
	Name qualifierName = null;
	try {
		if (isDeclaredInLambdaExpression()) {
			String enclosingTypeName = getEnclosingTypeName();
			qualifierName = ast.newSimpleName(enclosingTypeName);
		}
	} catch (JavaModelException e) {
		// do nothing.
	}

	FieldAccess fieldAccess = ast.newFieldAccess();
	ThisExpression thisExpression = ast.newThisExpression();
	if (qualifierName != null) {
		thisExpression.setQualifier(qualifierName);
	}
	fieldAccess.setExpression(thisExpression);
	fieldAccess.setName(fieldName);
	return fieldAccess;
}
 
Example #11
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void checkMethodDeclaration(RefactoringStatus result, int severity) {
	MethodDeclaration methodDeclaration= fSourceProvider.getDeclaration();
	// it is not allowed to inline constructor invocation only if it is used for class instance creation
	// if constructor is invoked from another constructor then we can inline such invocation
	if (fInvocation.getNodeType() != ASTNode.CONSTRUCTOR_INVOCATION && methodDeclaration.isConstructor()) {
		result.addEntry(new RefactoringStatusEntry(
			severity,
			RefactoringCoreMessages.CallInliner_constructors,
			JavaStatusContext.create(fCUnit, fInvocation)));
	}
	if (fSourceProvider.hasSuperMethodInvocation() && fInvocation.getNodeType() == ASTNode.METHOD_INVOCATION) {
		Expression receiver= ((MethodInvocation)fInvocation).getExpression();
		if (receiver instanceof ThisExpression) {
			result.addEntry(new RefactoringStatusEntry(
				severity,
				RefactoringCoreMessages.CallInliner_super_into_this_expression,
				JavaStatusContext.create(fCUnit, fInvocation)));
		}
	}
}
 
Example #12
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Expression createQualifiedReadAccessExpressionForEnclosingInstance(AST ast) {
	ThisExpression expression= ast.newThisExpression();
	expression.setQualifier(ast.newName(new String[] { fType.getElementName()}));
	FieldAccess access= ast.newFieldAccess();
	access.setExpression(expression);
	access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
	return access;
}
 
Example #13
Source File: Visitor.java    From RefactoringMiner with MIT License 5 votes vote down vote up
private void processArgument(Expression argument) {
	if(argument instanceof SuperMethodInvocation ||
			argument instanceof Name ||
			argument instanceof StringLiteral ||
			argument instanceof BooleanLiteral ||
			(argument instanceof FieldAccess && ((FieldAccess)argument).getExpression() instanceof ThisExpression) ||
			(argument instanceof ArrayAccess && invalidArrayAccess((ArrayAccess)argument)) ||
			(argument instanceof InfixExpression && invalidInfix((InfixExpression)argument)))
		return;
	this.arguments.add(argument.toString());
	if(current.getUserObject() != null) {
		AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
		anonymous.getArguments().add(argument.toString());
	}
}
 
Example #14
Source File: Visitor.java    From RefactoringMiner with MIT License 5 votes vote down vote up
public boolean visit(ThisExpression node) {
	if(!(node.getParent() instanceof FieldAccess)) {
		variables.add(node.toString());
		if(current.getUserObject() != null) {
			AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
			anonymous.getVariables().add(node.toString());
		}
	}
	return super.visit(node);
}
 
Example #15
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final ThisExpression it) {
  Name _qualifier = it.getQualifier();
  boolean _tripleNotEquals = (_qualifier != null);
  if (_tripleNotEquals) {
    it.getQualifier().accept(this);
    this.appendToBuffer(".");
  }
  this.appendToBuffer("this");
  return false;
}
 
Example #16
Source File: PolymorphismRefactoring.java    From JDeodorant with MIT License 5 votes vote down vote up
protected void replaceThisExpressionWithContextParameterInMethodInvocationArguments(List<Expression> newMethodInvocations, AST subclassAST, ASTRewrite subclassRewriter) {
	for(Expression expression : newMethodInvocations) {
		if(expression instanceof MethodInvocation) {
			MethodInvocation newMethodInvocation = (MethodInvocation)expression;
			List<Expression> arguments = newMethodInvocation.arguments();
			for(Expression argument : arguments) {
				if(argument instanceof ThisExpression) {
					String parameterName = sourceTypeDeclaration.getName().getIdentifier();
					parameterName = parameterName.substring(0,1).toLowerCase() + parameterName.substring(1,parameterName.length());
					ListRewrite argumentsRewrite = subclassRewriter.getListRewrite(newMethodInvocation, MethodInvocation.ARGUMENTS_PROPERTY);
					argumentsRewrite.replace(argument, subclassAST.newSimpleName(parameterName), null);
				}
			}
		}
	}
}
 
Example #17
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(ThisExpression expr) {
	/*
	 * ThisExpression: [ ClassName . ] this
	 */
	activateDiffStyle(expr);
	if (expr.getQualifier() != null) {
		handleExpression(expr.getQualifier());
		appendPeriod();
	}
	styledString.append("this", determineDiffStyle(expr, new StyledStringStyler(keywordStyle)));
	deactivateDiffStyle(expr);
	return false;
}
 
Example #18
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(ThisExpression node) {
	if (skipNode(node)) {
		return;
	}
	assignFlowInfo(node, node.getQualifier());
}
 
Example #19
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
private ThisExpr visit(ThisExpression node){
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	ThisExpr thisExpr = new ThisExpr(startLine, endLine, node);
	
	Pair<String, String> classAndMethodName = NodeUtils.getTypeDecAndMethodDec(node);
	Type type = ProjectInfo.getVariableType(classAndMethodName.getFirst(), classAndMethodName.getSecond(), "THIS");
	thisExpr.setType(type);
	
	return thisExpr;
}
 
Example #20
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 FieldAccess node) {
	Assert.isNotNull(node);
	final Expression expression= node.getExpression();
	final IVariableBinding variable= node.resolveFieldBinding();
	final AST ast= fRewrite.getAST();
	if (expression instanceof ThisExpression) {
		if (Bindings.equals(fTarget, variable)) {
			if (fAnonymousClass > 0) {
				final ThisExpression target= ast.newThisExpression();
				target.setQualifier(ast.newSimpleName(fTargetType.getElementName()));
				fRewrite.replace(node, target, null);
			} else
				fRewrite.replace(node, ast.newThisExpression(), null);
			return false;
		} else {
			expression.accept(this);
			return false;
		}
	} else if (expression instanceof FieldAccess) {
		final FieldAccess access= (FieldAccess) expression;
		final IBinding binding= access.getName().resolveBinding();
		if (access.getExpression() instanceof ThisExpression && Bindings.equals(fTarget, binding)) {
			ASTNode newFieldAccess= getFieldReference(node.getName(), fRewrite);
			fRewrite.replace(node, newFieldAccess, null);
			return false;
		}
	} else if (expression != null) {
		expression.accept(this);
		return false;
	}
	return true;
}
 
Example #21
Source File: DirectAceessFieldVisitor.java    From DesigniteJava with Apache License 2.0 5 votes vote down vote up
public boolean visit(FieldAccess node) {
	if (node.getExpression() instanceof ThisExpression) {
		if (!this.thisAccesses.contains(node)) {
			thisAccesses.add(node);
		}
	}
	return true;
}
 
Example #22
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 FieldAccess node) {
	Assert.isNotNull(node);
	if (node.getExpression() instanceof ThisExpression) {
		final IVariableBinding binding= (IVariableBinding) node.getName().resolveBinding();
		if (binding != null) {
			final String key= binding.getKey();
			if (!fFound.contains(key)) {
				fFound.add(key);
				fBindings.add(binding);
			}
		}
	}
	return true;
}
 
Example #23
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 MethodInvocation node) {
	Assert.isNotNull(node);
	final Expression expression= node.getExpression();
	final IMethodBinding binding= node.resolveMethodBinding();
	if (binding == null || !Modifier.isStatic(binding.getModifiers()) && Bindings.equals(binding, fBinding) && (expression == null || expression instanceof ThisExpression)) {
		fStatus.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_potentially_recursive, JavaStatusContext.create(fMethod.getCompilationUnit(), node)));
		fResult.add(node);
		return false;
	}
	return true;
}
 
Example #24
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 ThisExpression node) {
	Assert.isNotNull(node);
	fResult.add(node);
	fStatus.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_this_reference, JavaStatusContext.create(fMethod.getCompilationUnit(), node)));
	return false;
}
 
Example #25
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void computeReceiver() throws BadLocationException {
	Expression receiver= Invocations.getExpression(fInvocation);
	if (receiver == null)
		return;
	final boolean isName= receiver instanceof Name;
	if (isName)
		fContext.receiverIsStatic= ((Name)receiver).resolveBinding() instanceof ITypeBinding;
	if (ASTNodes.isLiteral(receiver) || isName || receiver instanceof ThisExpression) {
		fContext.receiver= fBuffer.getDocument().get(receiver.getStartPosition(), receiver.getLength());
		return;
	}
	switch(fSourceProvider.getReceiversToBeUpdated()) {
		case 0:
			// Make sure we evaluate the current receiver. Best is to assign to
			// local.
			fLocals.add(createLocalDeclaration(
				receiver.resolveTypeBinding(),
				fInvocationScope.createName("r", true),  //$NON-NLS-1$
				(Expression)fRewrite.createCopyTarget(receiver)));
			return;
		case 1:
			fContext.receiver= fBuffer.getDocument().get(receiver.getStartPosition(), receiver.getLength());
			return;
		default:
			String local= fInvocationScope.createName("r", true); //$NON-NLS-1$
				fLocals.add(createLocalDeclaration(
				receiver.resolveTypeBinding(),
				local,
				(Expression)fRewrite.createCopyTarget(receiver)));
			fContext.receiver= local;
			return;
	}
}
 
Example #26
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 SuperMethodInvocation node) {
	if (!fAnonymousClassDeclaration && !fTypeDeclarationStatement) {
		final IBinding superBinding= node.getName().resolveBinding();
		if (superBinding instanceof IMethodBinding) {
			final IMethodBinding extended= (IMethodBinding) superBinding;
			if (fEnclosingMethod != null && fEnclosingMethod.overrides(extended))
				return true;
			final ITypeBinding declaringBinding= extended.getDeclaringClass();
			if (declaringBinding != null) {
				final IType type= (IType) declaringBinding.getJavaElement();
				if (!fSuperReferenceType.equals(type))
					return true;
			}
		}
		final AST ast= node.getAST();
		final ThisExpression expression= ast.newThisExpression();
		final MethodInvocation invocation= ast.newMethodInvocation();
		final SimpleName simple= ast.newSimpleName(node.getName().getIdentifier());
		invocation.setName(simple);
		invocation.setExpression(expression);
		final List<Expression> arguments= node.arguments();
		if (arguments != null && arguments.size() > 0) {
			final ListRewrite rewriter= fRewrite.getListRewrite(invocation, MethodInvocation.ARGUMENTS_PROPERTY);
			ListRewrite superRewriter= fRewrite.getListRewrite(node, SuperMethodInvocation.ARGUMENTS_PROPERTY);
			ASTNode copyTarget= superRewriter.createCopyTarget(arguments.get(0), arguments.get(arguments.size() - 1));
			rewriter.insertLast(copyTarget, null);
		}
		fRewrite.replace(node, invocation, null);
		if (!fSourceRewriter.getCu().equals(fTargetRewriter.getCu()))
			fSourceRewriter.getImportRemover().registerRemovedNode(node);
		return true;
	}
	return false;
}
 
Example #27
Source File: InferTypeArgumentsConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Expression getSimpleNameReceiver(SimpleName node) {
	Expression receiver;
	if (node.getParent() instanceof QualifiedName && node.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
		receiver= ((QualifiedName) node.getParent()).getQualifier();
	} else if (node.getParent() instanceof FieldAccess && node.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
		receiver= ((FieldAccess) node.getParent()).getExpression();
	} else {
		//TODO other cases? (ThisExpression, SuperAccessExpression, ...)
		receiver= null;
	}
	if (receiver instanceof ThisExpression)
		return null;
	else
		return receiver;
}
 
Example #28
Source File: SourceAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ThisExpression node) {
	if (node.getQualifier() != null) {
		status.addFatalError(
			RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_qualified_this_expressions,
			JavaStatusContext.create(fTypeRoot, node));
		return false;
	}
	return true;
}
 
Example #29
Source File: SourceAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ThisExpression node) {
	if (fTypeCounter == 0) {
		fImplicitReceivers.add(node);
	}
	return true;
}
 
Example #30
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ThisExpression node) {
	int accessMode= fFormalArgument.getSimplifiedAccessMode();
	if (accessMode == FlowInfo.READ || accessMode == FlowInfo.UNUSED)
		return setResult(true);
	return setResult(false);
}