org.eclipse.jdt.core.dom.MethodInvocation Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.MethodInvocation.
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 | 7 votes |
private Statement createArrayComparison(String name) { MethodInvocation invoc= fAst.newMethodInvocation(); invoc.setName(fAst.newSimpleName(METHODNAME_EQUALS)); invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS)); invoc.arguments().add(getThisAccessForEquals(name)); invoc.arguments().add(getOtherAccess(name)); PrefixExpression pe= fAst.newPrefixExpression(); pe.setOperator(PrefixExpression.Operator.NOT); pe.setOperand(invoc); IfStatement ifSt= fAst.newIfStatement(); ifSt.setExpression(pe); ifSt.setThenStatement(getThenStatement(getReturnFalse())); return ifSt; }
Example #2
Source File: TryPurifyByException.java From SimFix with GNU General Public License v2.0 | 7 votes |
private Set<Integer> findAllMethodCall(){ Set<Integer> methodStmt = new HashSet<>(); if(_backupBody != null){ Block body = _backupBody; for(int i = 0; i < body.statements().size(); i++){ ASTNode stmt = (ASTNode) body.statements().get(i); if(stmt instanceof ExpressionStatement){ stmt = ((ExpressionStatement) stmt).getExpression(); if(stmt instanceof MethodInvocation){ methodStmt.add(i); } else if(stmt instanceof Assignment){ Assignment assign = (Assignment) stmt; if(assign.getRightHandSide() instanceof MethodInvocation){ methodStmt.add(i); } } } } } return methodStmt; }
Example #3
Source File: Invocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 7 votes |
public static Expression getExpression(ASTNode invocation) { switch (invocation.getNodeType()) { case ASTNode.METHOD_INVOCATION: return ((MethodInvocation)invocation).getExpression(); case ASTNode.SUPER_METHOD_INVOCATION: return null; case ASTNode.CONSTRUCTOR_INVOCATION: return null; case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return ((SuperConstructorInvocation)invocation).getExpression(); case ASTNode.CLASS_INSTANCE_CREATION: return ((ClassInstanceCreation)invocation).getExpression(); case ASTNode.ENUM_CONSTANT_DECLARATION: return null; default: throw new IllegalArgumentException(invocation.toString()); } }
Example #4
Source File: CodeStyleFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 7 votes |
/** * {@inheritDoc} */ @Override public boolean visit(MethodInvocation node) { if (!fFindUnqualifiedMethodAccesses && !fFindUnqualifiedStaticMethodAccesses) return true; if (node.getExpression() != null) return true; IBinding binding= node.getName().resolveBinding(); if (!(binding instanceof IMethodBinding)) return true; handleMethod(node.getName(), (IMethodBinding)binding); return true; }
Example #5
Source File: DelegateMethodCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 7 votes |
/** * Creates the corresponding statement for the method invocation, based on * the return type. * * @param declaration the method declaration where the invocation statement * is inserted * @param invocation the method invocation being encapsulated by the * resulting statement * @return the corresponding statement */ protected Statement createMethodInvocation(final MethodDeclaration declaration, final MethodInvocation invocation) { Assert.isNotNull(declaration); Assert.isNotNull(invocation); Statement statement= null; final Type type= declaration.getReturnType2(); if (type == null) { statement= createExpressionStatement(invocation); } else { if (type instanceof PrimitiveType) { final PrimitiveType primitive= (PrimitiveType) type; if (primitive.getPrimitiveTypeCode().equals(PrimitiveType.VOID)) { statement= createExpressionStatement(invocation); } else { statement= createReturnStatement(invocation); } } else { statement= createReturnStatement(invocation); } } return statement; }
Example #6
Source File: GenerateHashCodeEqualsOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 7 votes |
private Statement createAddArrayHashCode(IVariableBinding binding) { MethodInvocation invoc= fAst.newMethodInvocation(); if (JavaModelUtil.is50OrHigher(fRewrite.getCu().getJavaProject())) { invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE)); invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS)); invoc.arguments().add(getThisAccessForHashCode(binding.getName())); } else { invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE)); final IJavaElement element= fType.getJavaElement(); if (element != null && !"".equals(element.getElementName())) //$NON-NLS-1$ invoc.setExpression(fAst.newSimpleName(element.getElementName())); invoc.arguments().add(getThisAccessForHashCode(binding.getName())); ITypeBinding type= binding.getType().getElementType(); if (!Bindings.isVoidType(type)) { if (!type.isPrimitive() || binding.getType().getDimensions() >= 2) type= fAst.resolveWellKnownType(JAVA_LANG_OBJECT); if (!fCustomHashCodeTypes.contains(type)) fCustomHashCodeTypes.add(type); } } return prepareAssignment(invoc); }
Example #7
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(MethodInvocation node) { Expression expression= node.getExpression(); if (expression == null) { IMethodBinding binding= node.resolveMethodBinding(); if (binding != null) { if (isAccessToOuter(binding.getDeclaringClass())) { fMethodAccesses.add(node); } } } else { expression.accept(this); } List<Expression> arguments= node.arguments(); for (int i= 0; i < arguments.size(); i++) { arguments.get(i).accept(this); } return false; }
Example #8
Source File: GenerateForLoopAssistProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Helper to generate an index based <code>for</code> loop to iterate over a {@link List} * implementation. * * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for * @return an applicable {@link ASTRewrite} instance */ private ASTRewrite generateIndexBasedForRewrite(AST ast) { ASTRewrite rewrite= ASTRewrite.create(ast); ForStatement loopStatement= ast.newForStatement(); SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); //$NON-NLS-1$ loopStatement.initializers().add(getForInitializer(ast, loopVariableName)); MethodInvocation listSizeExpression= ast.newMethodInvocation(); listSizeExpression.setName(ast.newSimpleName("size")); //$NON-NLS-1$ Expression listExpression= (Expression) rewrite.createCopyTarget(fCurrentExpression); listSizeExpression.setExpression(listExpression); loopStatement.setExpression(getLinkedInfixExpression(rewrite, loopVariableName.getIdentifier(), listSizeExpression, InfixExpression.Operator.LESS)); loopStatement.updaters().add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier())); Block forLoopBody= ast.newBlock(); forLoopBody.statements().add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName))); forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite)); loopStatement.setBody(forLoopBody); rewrite.replace(fCurrentNode, loopStatement, null); return rewrite; }
Example #9
Source File: InlineMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public RefactoringStatus setCurrentMode(Mode mode) throws JavaModelException { if (fCurrentMode == mode) return new RefactoringStatus(); Assert.isTrue(getInitialMode() == Mode.INLINE_SINGLE); fCurrentMode= mode; if (mode == Mode.INLINE_SINGLE) { if (fInitialNode instanceof MethodInvocation) fTargetProvider= TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (MethodInvocation)fInitialNode); else if (fInitialNode instanceof SuperMethodInvocation) fTargetProvider= TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (SuperMethodInvocation)fInitialNode); else if (fInitialNode instanceof ConstructorInvocation) fTargetProvider= TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (ConstructorInvocation)fInitialNode); else throw new IllegalStateException(String.valueOf(fInitialNode)); } else { fTargetProvider= TargetProvider.create(fSourceProvider.getDeclaration()); } return fTargetProvider.checkActivation(); }
Example #10
Source File: MovedMemberAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(MethodInvocation node) { IBinding binding= node.resolveMethodBinding(); if (isSourceAccess(binding)) { if (isMovedMember(binding)) { if (node.getExpression() != null) rewrite(node, fTarget); } else rewrite(node, fSource); } else if (isTargetAccess(binding)) { if (node.getExpression() != null) { fCuRewrite.getASTRewrite().remove(node.getExpression(), null); fCuRewrite.getImportRemover().registerRemovedNode(node.getExpression()); } } return super.visit(node); }
Example #11
Source File: SignatureHelpHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private IMethod getMethod(ASTNode node) throws JavaModelException { IBinding binding; if (node instanceof MethodInvocation) { binding = ((MethodInvocation) node).resolveMethodBinding(); } else if (node instanceof MethodRef) { binding = ((MethodRef) node).resolveBinding(); } else if (node instanceof ClassInstanceCreation) { binding = ((ClassInstanceCreation) node).resolveConstructorBinding(); } else { binding = null; } if (binding != null) { IJavaElement javaElement = binding.getJavaElement(); if (javaElement instanceof IMethod) { IMethod method = (IMethod) javaElement; return method; } } return null; }
Example #12
Source File: Invocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static boolean isResolvedTypeInferredFromExpectedType(Expression invocation) { if (invocation == null) return false; switch (invocation.getNodeType()) { case ASTNode.METHOD_INVOCATION: return ((MethodInvocation) invocation).isResolvedTypeInferredFromExpectedType(); case ASTNode.SUPER_METHOD_INVOCATION: return ((SuperMethodInvocation) invocation).isResolvedTypeInferredFromExpectedType(); case ASTNode.CLASS_INSTANCE_CREATION: return ((ClassInstanceCreation) invocation).isResolvedTypeInferredFromExpectedType(); default: return false; } }
Example #13
Source File: ASTNodeMatcher.java From JDeodorant with MIT License | 6 votes |
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 #14
Source File: ExpressionVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 #15
Source File: JavaDebugElementCodeMiningASTVisitor.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(MethodInvocation node) { if (inFrame) { List arguments = node.arguments(); if (arguments.size() > 0) { for (int i = 0; i < arguments.size(); i++) { Expression exp = (Expression) arguments.get(i); if (exp instanceof SimpleName) { AbstractDebugVariableCodeMining<IJavaStackFrame> m = new JavaDebugElementCodeMining( (SimpleName) exp, fFrame, viewer, provider); minings.add(m); } } } } return super.visit(node); }
Example #16
Source File: ReplaceInvocationsRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RefactoringStatus setCurrentMode(Mode mode) throws JavaModelException { if (fTargetProvider.isSingle() == (mode == Mode.REPLACE_SINGLE)) return new RefactoringStatus(); Assert.isTrue(canReplaceSingle()); if (mode == Mode.REPLACE_SINGLE) { fTargetProvider= TargetProvider.create((ICompilationUnit) fSelectionTypeRoot, (MethodInvocation) fSelectionNode); } else { fTargetProvider= TargetProvider.create(fSourceProvider.getDeclaration()); } return fTargetProvider.checkActivation(); }
Example #17
Source File: CodeStyleFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { TextEditGroup group= createTextEditGroup(FixMessages.CodeStyleFix_ChangeAccessUsingDeclaring_description, cuRewrite); if (fQualifier instanceof MethodInvocation || fQualifier instanceof ClassInstanceCreation) extractQualifier(fQualifier, cuRewrite, group); Type type= importType(fDeclaringTypeBinding, fQualifier, cuRewrite.getImportRewrite(), cuRewrite.getRoot()); cuRewrite.getASTRewrite().replace(fQualifier, type, group); }
Example #18
Source File: JavaCodeMiningASTVisitor.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(MethodInvocation node) { /* * if (Utils.isGeneratedByLombok(node)) { return super.visit(node); } */ if (showParameterName || showParameterType) { List arguments = node.arguments(); if (arguments.size() > 0 && acceptMethod(node)) { for (int i = 0; i < arguments.size(); i++) { Expression exp = (Expression) arguments.get(i); if (showParameterOnlyForLiteral && !isLiteral(exp)) { continue; } // Ignore empty parameter if (exp instanceof SimpleName) { if ("$missing$".equals(((SimpleName) exp).getIdentifier())) { continue; } } minings.add(new JavaMethodParameterCodeMining(node, exp, i, cu, provider, showParameterName, showParameterType, showParameterByUsingFilters)); } } } return super.visit(node); }
Example #19
Source File: AbstractToStringGenerator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected Expression createSubListInvocation(Expression memberAccess, Expression sizeAccess) { MethodInvocation subListInvocation= fAst.newMethodInvocation(); subListInvocation.setExpression(memberAccess); subListInvocation.setName(fAst.newSimpleName("subList")); //$NON-NLS-1$ subListInvocation.arguments().add(fAst.newNumberLiteral(String.valueOf(0))); MethodInvocation minInvocation= createMethodInvocation(addImport("java.lang.Math"), "min", sizeAccess); //$NON-NLS-1$ //$NON-NLS-2$ minInvocation.arguments().add(fAst.newSimpleName(fMaxLenVariableName)); subListInvocation.arguments().add(minInvocation); needMaxLenVariable= true; return subListInvocation; }
Example #20
Source File: PolymorphismRefactoring.java From JDeodorant with MIT License | 5 votes |
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 #21
Source File: StructCache.java From junion with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Entry get(Expression type) { ITypeBinding ib = type.resolveTypeBinding(); if(ib == null) { if(type instanceof MethodInvocation) { IMethodBinding mi = ((MethodInvocation)type).resolveMethodBinding(); if(mi != null) ib = mi.getReturnType(); } } if(ib == null) { CompilerError.exec(CompilerError.TYPE_NOT_FOUND, type.toString() + ", " + type.getClass()); return null; } else return get(ib); }
Example #22
Source File: ParameterObjectFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Expression createFieldWriteAccess(ParameterInfo pi, String paramName, AST ast, IJavaProject project, Expression assignedValue, boolean useSuper, Expression qualifier) { Expression completeQualifier= generateQualifier(paramName, ast, useSuper, qualifier); if (fCreateSetter) { MethodInvocation mi= ast.newMethodInvocation(); mi.setName(ast.newSimpleName(getSetterName(pi, ast, project))); mi.setExpression(completeQualifier); mi.arguments().add(assignedValue); return mi; } return createFieldAccess(pi, ast, completeQualifier); }
Example #23
Source File: SequenceExporter.java From txtUML with Eclipse Public License 1.0 | 5 votes |
@Override public boolean validElement(ASTNode curElement) { if (super.validElement(curElement)) { String fullName = ExporterUtils.getFullyQualifiedName((MethodInvocation) curElement); return fullName.equals("hu.elte.txtuml.api.model.seqdiag.Sequence.assertSend") || fullName.equals("hu.elte.txtuml.api.model.seqdiag.Sequence.fromActor"); } return false; }
Example #24
Source File: AbstractControlStructureUtilities.java From JDeodorant with MIT License | 5 votes |
private static Integer getTernaryArgumentIndex(MethodInvocation ternaryMethodInvocation, ConditionalExpression conditionalExpression) { List<Expression> arguments = ternaryMethodInvocation.arguments(); for (int i = 0; i < arguments.size(); i++) { if (arguments.get(i).equals(conditionalExpression)) { return i; } } return null; }
Example #25
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void modifyAccessToMethodsFromEnclosingInstance(CompilationUnitRewrite targetRewrite, MethodInvocation[] methodInvocations, AbstractTypeDeclaration declaration) { IMethodBinding binding= null; MethodInvocation invocation= null; for (int index= 0; index < methodInvocations.length; index++) { invocation= methodInvocations[index]; binding= invocation.resolveMethodBinding(); if (binding != null) { final Expression target= invocation.getExpression(); if (target == null) { final Expression expression= createAccessExpressionToEnclosingInstanceFieldText(invocation, binding, declaration); targetRewrite.getASTRewrite().set(invocation, MethodInvocation.EXPRESSION_PROPERTY, expression, null); } else { if (!(invocation.getExpression() instanceof ThisExpression) || !(((ThisExpression) invocation.getExpression()).getQualifier() != null)) continue; targetRewrite.getASTRewrite().replace(target, createAccessExpressionToEnclosingInstanceFieldText(invocation, binding, declaration), null); targetRewrite.getImportRemover().registerRemovedNode(target); } } } }
Example #26
Source File: Utils.java From txtUML with Eclipse Public License 1.0 | 5 votes |
public static Type getReturnTypeFromInvocation(MethodInvocation methodInvocation) { IMethodBinding binding = methodInvocation.resolveMethodBinding(); try { CompilationUnit cu = getCompilationUnit(binding); MethodDeclaration decl = (MethodDeclaration) cu.findDeclaringNode(binding.getKey()); Type returnType = decl.getReturnType2(); return returnType; } catch (NullPointerException ex) { return null; } }
Example #27
Source File: SuperTypeConstraintsCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * End of visit the return type of a method invocation. * * @param invocation the method invocation * @param binding the method binding */ private void endVisit(final MethodInvocation invocation, final IMethodBinding binding) { if (!binding.isConstructor()) { final ConstraintVariable2 variable= fModel.createReturnTypeVariable(binding); if (variable != null) invocation.setProperty(PROPERTY_CONSTRAINT_VARIABLE, variable); } }
Example #28
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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; }
Example #29
Source File: GenerateForLoopAssistProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates an {@link Assignment} as first expression appearing in an index based * <code>for</code> loop's body. This Assignment declares a local variable and initializes it * using the {@link List}'s current element identified by the loop index. * * @param rewrite the current {@link ASTRewrite} instance * @param loopVariableName the name of the index variable in String representation * @return a completed {@link Assignment} containing the mentioned declaration and * initialization */ private Expression getIndexBasedForBodyAssignment(ASTRewrite rewrite, SimpleName loopVariableName) { AST ast= rewrite.getAST(); ITypeBinding loopOverType= extractElementType(ast); Assignment assignResolvedVariable= ast.newAssignment(); // left hand side SimpleName resolvedVariableName= resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false); VariableDeclarationFragment resolvedVariableDeclarationFragment= ast.newVariableDeclarationFragment(); resolvedVariableDeclarationFragment.setName(resolvedVariableName); VariableDeclarationExpression resolvedVariableDeclaration= ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment); resolvedVariableDeclaration.setType(getImportRewrite().addImport(loopOverType, ast, new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite()))); assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration); // right hand side MethodInvocation invokeGetExpression= ast.newMethodInvocation(); invokeGetExpression.setName(ast.newSimpleName("get")); //$NON-NLS-1$ SimpleName indexVariableName= ast.newSimpleName(loopVariableName.getIdentifier()); addLinkedPosition(rewrite.track(indexVariableName), LinkedPositionGroup.NO_STOP, indexVariableName.getIdentifier()); invokeGetExpression.arguments().add(indexVariableName); invokeGetExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression)); assignResolvedVariable.setRightHandSide(invokeGetExpression); assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN); return assignResolvedVariable; }
Example #30
Source File: ReplaceConditionalWithPolymorphism.java From JDeodorant with MIT License | 5 votes |
private void replaceCastExpressionWithThisExpression(List<Expression> oldCastExpressions, List<Expression> newCastExpressions, TypeDeclaration subclassTypeDeclaration, AST subclassAST, ASTRewrite subclassRewriter) { int j = 0; for(Expression expression : oldCastExpressions) { CastExpression castExpression = (CastExpression)expression; if(castExpression.getType().resolveBinding().isEqualTo(subclassTypeDeclaration.resolveBinding())) { if(castExpression.getExpression() instanceof SimpleName) { SimpleName castSimpleName = (SimpleName)castExpression.getExpression(); if(typeVariable != null && typeVariable.getName().resolveBinding().isEqualTo(castSimpleName.resolveBinding())) { subclassRewriter.replace(newCastExpressions.get(j), subclassAST.newThisExpression(), null); } } else if(castExpression.getExpression() instanceof MethodInvocation) { MethodInvocation castMethodInvocation = (MethodInvocation)castExpression.getExpression(); if(typeMethodInvocation != null && typeMethodInvocation.subtreeMatch(new ASTMatcher(), castMethodInvocation)) { subclassRewriter.replace(newCastExpressions.get(j), subclassAST.newThisExpression(), null); } } } j++; } }