Java Code Examples for org.eclipse.jdt.core.dom.VariableDeclaration#getParent()
The following examples show how to use
org.eclipse.jdt.core.dom.VariableDeclaration#getParent() .
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: InlineTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private RefactoringStatus checkSelection(VariableDeclaration decl) { ASTNode parent= decl.getParent(); if (parent instanceof MethodDeclaration) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_method_parameter); } if (parent instanceof CatchClause) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_exceptions_declared); } if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == ForStatement.INITIALIZERS_PROPERTY) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_for_initializers); } if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_resource_in_try_with_resources); } if (decl.getInitializer() == null) { String message= Messages.format(RefactoringCoreMessages.InlineTempRefactoring_not_initialized, BasicElementLabels.getJavaElementName(decl.getName().getIdentifier())); return RefactoringStatus.createFatalErrorStatus(message); } return checkAssignments(decl); }
Example 2
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static int getDimensions(VariableDeclaration declaration) { int dim= declaration.getExtraDimensions(); if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) { LambdaExpression lambda= (LambdaExpression) declaration.getParent(); IMethodBinding methodBinding= lambda.resolveMethodBinding(); if (methodBinding != null) { ITypeBinding[] parameterTypes= methodBinding.getParameterTypes(); int index= lambda.parameters().indexOf(declaration); ITypeBinding typeBinding= parameterTypes[index]; return typeBinding.getDimensions(); } } else { Type type= getType(declaration); if (type instanceof ArrayType) { dim+= ((ArrayType) type).getDimensions(); } } return dim; }
Example 3
Source File: InlineTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RefactoringStatus checkIfTempSelected() { VariableDeclaration decl= getVariableDeclaration(); if (decl == null) { return CodeRefactoringUtil.checkMethodSyntaxErrors(fSelectionStart, fSelectionLength, getASTRoot(), RefactoringCoreMessages.InlineTempRefactoring_select_temp); } if (decl.getParent() instanceof FieldDeclaration) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTemRefactoring_error_message_fieldsCannotBeInlined); } return new RefactoringStatus(); }
Example 4
Source File: InlineTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void removeTemp(CompilationUnitRewrite cuRewrite) { VariableDeclaration variableDeclaration= getVariableDeclaration(); TextEditGroup groupDesc= cuRewrite.createGroupDescription(RefactoringCoreMessages.InlineTempRefactoring_remove_edit_name); ASTNode parent= variableDeclaration.getParent(); ASTRewrite rewrite= cuRewrite.getASTRewrite(); TightSourceRangeComputer sourceRangeComputer= new TightSourceRangeComputer(); rewrite.setTargetSourceRangeComputer(sourceRangeComputer); if (parent instanceof VariableDeclarationStatement && ((VariableDeclarationStatement) parent).fragments().size() == 1) { sourceRangeComputer.addTightSourceNode(parent); rewrite.remove(parent, groupDesc); } else { sourceRangeComputer.addTightSourceNode(variableDeclaration); rewrite.remove(variableDeclaration, groupDesc); } }
Example 5
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static List<IExtendedModifier> getModifiers(VariableDeclaration declaration) { Assert.isNotNull(declaration); if (declaration instanceof SingleVariableDeclaration) { return ((SingleVariableDeclaration)declaration).modifiers(); } else if (declaration instanceof VariableDeclarationFragment) { ASTNode parent= declaration.getParent(); if (parent instanceof VariableDeclarationExpression) return ((VariableDeclarationExpression)parent).modifiers(); else if (parent instanceof VariableDeclarationStatement) return ((VariableDeclarationStatement)parent).modifiers(); } return new ArrayList<IExtendedModifier>(0); }
Example 6
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isSingleDeclaration(VariableDeclaration declaration) { Assert.isNotNull(declaration); if (declaration instanceof SingleVariableDeclaration) { return true; } else if (declaration instanceof VariableDeclarationFragment) { ASTNode parent= declaration.getParent(); if (parent instanceof VariableDeclarationExpression) return ((VariableDeclarationExpression)parent).fragments().size() == 1; else if (parent instanceof VariableDeclarationStatement) return ((VariableDeclarationStatement)parent).fragments().size() == 1; } return false; }
Example 7
Source File: ConditionalLoop.java From JDeodorant with MIT License | 4 votes |
public List<ASTNode> getAdditionalFragments() { List<ASTNode> additionalFragments = new ArrayList<ASTNode>(); for(AbstractControlVariable currentControlVariable : conditionControlVariables.values()) { List<VariableUpdater> updaters = currentControlVariable.getVariableUpdaters(); for (VariableUpdater currentVariableUpdater : updaters) { additionalFragments.add(currentVariableUpdater.getUpdater()); } if (currentControlVariable instanceof ControlVariable) { ControlVariable controlVariable = (ControlVariable) currentControlVariable; VariableDeclaration variableDeclaration = AbstractLoopUtilities.getVariableDeclaration(controlVariable.getVariable()); if(variableDeclaration != null) { additionalFragments.add(variableDeclaration); if (variableDeclaration.getParent() instanceof FieldDeclaration && getLoopStatement().getParent() instanceof Block) { List<ASTNode> nodes = getAllVariableModifiersInParentBlock(controlVariable.getVariable(), (Block) getLoopStatement().getParent()); if(!nodes.isEmpty()) { additionalFragments.add(nodes.get(nodes.size() - 1)); } } } ASTNode dataStructureAccessExpression = controlVariable.getDataStructureAccessExpression(); if(dataStructureAccessExpression != null) { additionalFragments.add(dataStructureAccessExpression); } } } /*// if the current ConditionalLoop is a for loop, remove all for the updaters found in the for declaration if (this.getLoopStatement() instanceof ForStatement) { ForStatement forStatement = (ForStatement) this.getLoopStatement(); List<Expression> updaters = forStatement.updaters(); for (Expression currentUpdater : updaters) { if (additionalFragments.contains(currentUpdater)) { additionalFragments.remove(currentUpdater); } } }*/ return additionalFragments; }