org.eclipse.jdt.core.dom.VariableDeclaration Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.VariableDeclaration.
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: PDGSlice.java From JDeodorant with MIT License | 6 votes |
private boolean duplicatedSliceNodeWithClassInstantiationHasDependenceOnRemovableNode() { Set<PDGNode> duplicatedNodes = new LinkedHashSet<PDGNode>(); duplicatedNodes.addAll(sliceNodes); duplicatedNodes.retainAll(indispensableNodes); for(PDGNode duplicatedNode : duplicatedNodes) { if(duplicatedNode.containsClassInstanceCreation()) { Map<VariableDeclaration, ClassInstanceCreation> classInstantiations = duplicatedNode.getClassInstantiations(); for(VariableDeclaration variableDeclaration : classInstantiations.keySet()) { for(GraphEdge edge : duplicatedNode.outgoingEdges) { PDGDependence dependence = (PDGDependence)edge; if(edges.contains(dependence) && dependence instanceof PDGDependence) { PDGDependence dataDependence = (PDGDependence)dependence; PDGNode dstPDGNode = (PDGNode)dataDependence.dst; if(removableNodes.contains(dstPDGNode)) { if(dstPDGNode.changesStateOfReference(variableDeclaration) || dstPDGNode.assignsReference(variableDeclaration) || dstPDGNode.accessesReference(variableDeclaration)) return true; } } } } } } return false; }
Example #3
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the type node for the given declaration. * * @param declaration the declaration * @return the type node or <code>null</code> if the given declaration represents a type * inferred parameter in lambda expression */ public static Type getType(VariableDeclaration declaration) { if (declaration instanceof SingleVariableDeclaration) { return ((SingleVariableDeclaration)declaration).getType(); } else if (declaration instanceof VariableDeclarationFragment) { ASTNode parent= ((VariableDeclarationFragment)declaration).getParent(); if (parent instanceof VariableDeclarationExpression) return ((VariableDeclarationExpression)parent).getType(); else if (parent instanceof VariableDeclarationStatement) return ((VariableDeclarationStatement)parent).getType(); else if (parent instanceof FieldDeclaration) return ((FieldDeclaration)parent).getType(); else if (parent instanceof LambdaExpression) return null; } Assert.isTrue(false, "Unknown VariableDeclaration"); //$NON-NLS-1$ return null; }
Example #4
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 #5
Source File: RefactoringUtility.java From JDeodorant with MIT License | 6 votes |
private static Type extractType(VariableDeclaration variableDeclaration) { Type returnedVariableType = null; if(variableDeclaration instanceof SingleVariableDeclaration) { SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration)variableDeclaration; returnedVariableType = singleVariableDeclaration.getType(); } else if(variableDeclaration instanceof VariableDeclarationFragment) { VariableDeclarationFragment fragment = (VariableDeclarationFragment)variableDeclaration; if(fragment.getParent() instanceof VariableDeclarationStatement) { VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)fragment.getParent(); returnedVariableType = variableDeclarationStatement.getType(); } else if(fragment.getParent() instanceof VariableDeclarationExpression) { VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression)fragment.getParent(); returnedVariableType = variableDeclarationExpression.getType(); } else if(fragment.getParent() instanceof FieldDeclaration) { FieldDeclaration fieldDeclaration = (FieldDeclaration)fragment.getParent(); returnedVariableType = fieldDeclaration.getType(); } } return returnedVariableType; }
Example #6
Source File: PDGSliceUnion.java From JDeodorant with MIT License | 6 votes |
private boolean duplicatedSliceNodeWithClassInstantiationHasDependenceOnRemovableNode() { Set<PDGNode> duplicatedNodes = new LinkedHashSet<PDGNode>(); duplicatedNodes.addAll(sliceNodes); duplicatedNodes.retainAll(indispensableNodes); for(PDGNode duplicatedNode : duplicatedNodes) { if(duplicatedNode.containsClassInstanceCreation()) { Map<VariableDeclaration, ClassInstanceCreation> classInstantiations = duplicatedNode.getClassInstantiations(); for(VariableDeclaration variableDeclaration : classInstantiations.keySet()) { for(GraphEdge edge : duplicatedNode.outgoingEdges) { PDGDependence dependence = (PDGDependence)edge; if(subgraph.edgeBelongsToBlockBasedRegion(dependence) && dependence instanceof PDGDependence) { PDGDependence dataDependence = (PDGDependence)dependence; PDGNode dstPDGNode = (PDGNode)dataDependence.dst; if(removableNodes.contains(dstPDGNode)) { if(dstPDGNode.changesStateOfReference(variableDeclaration) || dstPDGNode.assignsReference(variableDeclaration) || dstPDGNode.accessesReference(variableDeclaration)) return true; } } } } } } return false; }
Example #7
Source File: RefactoringUtility.java From JDeodorant with MIT License | 6 votes |
public static VariableDeclaration findFieldDeclaration(AbstractVariable variable, TypeDeclaration typeDeclaration) { for(FieldDeclaration fieldDeclaration : typeDeclaration.getFields()) { List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments(); for(VariableDeclarationFragment fragment : fragments) { if(variable.getVariableBindingKey().equals(fragment.resolveBinding().getKey())) { return fragment; } } } //fragment was not found in typeDeclaration Type superclassType = typeDeclaration.getSuperclassType(); if(superclassType != null) { String superclassQualifiedName = superclassType.resolveBinding().getQualifiedName(); SystemObject system = ASTReader.getSystemObject(); ClassObject superclassObject = system.getClassObject(superclassQualifiedName); if(superclassObject != null) { AbstractTypeDeclaration superclassTypeDeclaration = superclassObject.getAbstractTypeDeclaration(); if(superclassTypeDeclaration instanceof TypeDeclaration) { return findFieldDeclaration(variable, (TypeDeclaration)superclassTypeDeclaration); } } } return null; }
Example #8
Source File: TempOccurrenceAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(SimpleName node){ if (node.getParent() instanceof VariableDeclaration){ if (((VariableDeclaration)node.getParent()).getName() == node) return true; //don't include declaration } if (fTempBinding != null && fTempBinding == node.resolveBinding()) { if (fIsInJavadoc) fJavadocNodes.add(node); else fReferenceNodes.add(node); } return true; }
Example #9
Source File: CodeFragmentDecomposer.java From JDeodorant with MIT License | 6 votes |
public CodeFragmentDecomposer(Set<PDGNode> nodes, Set<VariableDeclaration> accessedFields) { this.objectNodeMap = new LinkedHashMap<PlainVariable, Set<PDGNode>>(); Set<PlainVariable> declaredVariables = getDeclaredVariables(nodes); for(PlainVariable objectReference : declaredVariables) { Set<PDGNode> nodesDefiningAttributes = getNodesDefiningAttributesOfReference(objectReference, nodes); if(!nodesDefiningAttributes.isEmpty()) { Set<PDGNode> objectNodes = new LinkedHashSet<PDGNode>(); PDGNode nodeDeclaringReference = getNodeDeclaringReference(objectReference, nodes); if(nodeDeclaringReference != null) objectNodes.add(nodeDeclaringReference); objectNodes.addAll(nodesDefiningAttributes); objectNodeMap.put(objectReference, objectNodes); } } Map<PlainVariable, Set<PDGNode>> definedFieldMap = getDefinedFieldMap(nodes, accessedFields); objectNodeMap.putAll(definedFieldMap); }
Example #10
Source File: PromoteTempToFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates a new promote temp to field refactoring. * @param declaration the variable declaration node to convert to a field */ public PromoteTempToFieldRefactoring(VariableDeclaration declaration) { Assert.isTrue(declaration != null); fTempDeclarationNode= declaration; IVariableBinding resolveBinding= declaration.resolveBinding(); Assert.isTrue(resolveBinding != null && !resolveBinding.isParameter() && !resolveBinding.isField()); ASTNode root= declaration.getRoot(); Assert.isTrue(root instanceof CompilationUnit); fCompilationUnitNode= (CompilationUnit) root; IJavaElement input= fCompilationUnitNode.getJavaElement(); Assert.isTrue(input instanceof ICompilationUnit); fCu= (ICompilationUnit) input; fSelectionStart= declaration.getStartPosition(); fSelectionLength= declaration.getLength(); fFieldName= ""; //$NON-NLS-1$ fVisibility= Modifier.PRIVATE; fDeclareStatic= false; fDeclareFinal= false; fInitializeIn= INITIALIZE_IN_METHOD; fLinkedProposalModel= null; }
Example #11
Source File: PreconditionExaminer.java From JDeodorant with MIT License | 6 votes |
public ITypeBinding getReturnTypeBinding() { List<VariableDeclaration> returnedVariables1 = new ArrayList<VariableDeclaration>(getVariablesToBeReturnedG1()); List<VariableDeclaration> returnedVariables2 = new ArrayList<VariableDeclaration>(getVariablesToBeReturnedG2()); ITypeBinding returnTypeBinding = null; if(returnedVariables1.size() == 1 && returnedVariables2.size() == 1) { ITypeBinding returnTypeBinding1 = extractTypeBinding(returnedVariables1.get(0)); ITypeBinding returnTypeBinding2 = extractTypeBinding(returnedVariables2.get(0)); if(returnTypeBinding1.isEqualTo(returnTypeBinding2) && returnTypeBinding1.getQualifiedName().equals(returnTypeBinding2.getQualifiedName())) returnTypeBinding = returnTypeBinding1; else returnTypeBinding = ASTNodeMatcher.commonSuperType(returnTypeBinding1, returnTypeBinding2); } else { returnTypeBinding = findReturnTypeBinding(); } return returnTypeBinding; }
Example #12
Source File: ExtractMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void initializeParameterInfos() { IVariableBinding[] arguments= fAnalyzer.getArguments(); fParameterInfos= new ArrayList<ParameterInfo>(arguments.length); ASTNode root= fAnalyzer.getEnclosingBodyDeclaration(); ParameterInfo vararg= null; for (int i= 0; i < arguments.length; i++) { IVariableBinding argument= arguments[i]; if (argument == null) continue; VariableDeclaration declaration= ASTNodes.findVariableDeclaration(argument, root); boolean isVarargs= declaration instanceof SingleVariableDeclaration ? ((SingleVariableDeclaration)declaration).isVarargs() : false; ParameterInfo info= new ParameterInfo(argument, getType(declaration, isVarargs), argument.getName(), i); if (isVarargs) { vararg= info; } else { fParameterInfos.add(info); } } if (vararg != null) { fParameterInfos.add(vararg); } }
Example #13
Source File: JavaVariableFeatureExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Set<String> variableFeatures(final Set<ASTNode> boundNodesOfVariable) { // Find the declaration and extract features final Set<String> features = Sets.newHashSet(); for (final ASTNode node : boundNodesOfVariable) { if (!(node.getParent() instanceof VariableDeclaration)) { continue; } getDeclarationFeatures(features, node); if (activeFeatures .contains(AvailableFeatures.IMPLEMENTOR_VOCABULARY)) { JavaFeatureExtractor.addImplementorVocab(node, features); } break; } return features; }
Example #14
Source File: JavaVariableFeatureExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Set<String> variableFeatures(final Set<ASTNode> boundNodesOfVariable) { // Find the declaration and extract features final Set<String> features = Sets.newHashSet(); for (final ASTNode node : boundNodesOfVariable) { if (!(node.getParent() instanceof VariableDeclaration)) { continue; } getDeclarationFeatures(features, node); if (activeFeatures .contains(AvailableFeatures.IMPLEMENTOR_VOCABULARY)) { JavaFeatureExtractor.addImplementorVocab(node, features); } break; } return features; }
Example #15
Source File: SurroundWith.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private SplitUnselectedOperator(List<VariableDeclaration> accessedInside, ListRewrite blockRewrite, ASTRewrite rewrite) { super(); fAccessedInside= accessedInside; fBlockRewrite= blockRewrite; fRewrite= rewrite; fLastStatement= null; }
Example #16
Source File: PDGNode.java From JDeodorant with MIT License | 5 votes |
public boolean changesStateOfReference(VariableDeclaration variableDeclaration) { for(AbstractVariable abstractVariable : definedVariables) { if(abstractVariable instanceof CompositeVariable) { CompositeVariable compositeVariable = (CompositeVariable)abstractVariable; if(variableDeclaration.resolveBinding().getKey().equals(compositeVariable.getVariableBindingKey())) return true; } } return false; }
Example #17
Source File: SurroundWithTryCatchRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private List<ASTNode> getSpecialVariableDeclarationStatements() { List<ASTNode> result= new ArrayList<ASTNode>(3); VariableDeclaration[] locals= fAnalyzer.getAffectedLocals(); for (int i= 0; i < locals.length; i++) { ASTNode parent= locals[i].getParent(); if (parent instanceof VariableDeclarationStatement && !result.contains(parent)) result.add(parent); } return result; }
Example #18
Source File: ScopeAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(VariableDeclaration node) { if (hasFlag(VARIABLES, fFlags) && fPosition < node.getStartPosition()) { fBreak= fRequestor.acceptBinding(node.resolveBinding()); } return false; }
Example #19
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 #20
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static VariableDeclaration findVariableDeclaration(IVariableBinding binding, ASTNode root) { if (binding.isField()) return null; ASTNode result= findDeclaration(binding, root); if (result instanceof VariableDeclaration) return (VariableDeclaration)result; return null; }
Example #21
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean isExplicitlyTypedLambda(Expression expression) { if (!(expression instanceof LambdaExpression)) return false; LambdaExpression lambda= (LambdaExpression) expression; List<VariableDeclaration> parameters= lambda.parameters(); if (parameters.isEmpty()) return true; return parameters.get(0) instanceof SingleVariableDeclaration; }
Example #22
Source File: InlineTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public InlineTempRefactoring(VariableDeclaration decl) { fVariableDeclaration= decl; ASTNode astRoot= decl.getRoot(); Assert.isTrue(astRoot instanceof CompilationUnit); fASTRoot= (CompilationUnit) astRoot; Assert.isTrue(fASTRoot.getJavaElement() instanceof ICompilationUnit); fSelectionStart= decl.getStartPosition(); fSelectionLength= decl.getLength(); fCu= (ICompilationUnit) fASTRoot.getJavaElement(); }
Example #23
Source File: ExtractMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String getType(VariableDeclaration declaration, boolean isVarargs) { String type= ASTNodes.asString(ASTNodeFactory.newType(declaration.getAST(), declaration, fImportRewriter, new ContextSensitiveImportRewriteContext(declaration, fImportRewriter))); if (isVarargs) return type + ParameterInfo.ELLIPSIS; else return type; }
Example #24
Source File: TempDeclarationFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visitNode(ASTNode node) { if (node instanceof VariableDeclaration) return visitVariableDeclaration((VariableDeclaration)node); else if (node instanceof SimpleName) return visitSimpleName((SimpleName)node); else return super.visitNode(node); }
Example #25
Source File: LocalVariableDeclarationObject.java From JDeodorant with MIT License | 5 votes |
public VariableDeclaration getVariableDeclaration() { //return variableDeclaration; ASTNode node = this.variableDeclaration.recoverASTNode(); if(node instanceof SimpleName) { return (VariableDeclaration)node.getParent(); } else { return (VariableDeclaration)node; } }
Example #26
Source File: TempOccurrenceAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TempOccurrenceAnalyzer(VariableDeclaration tempDeclaration, boolean analyzeJavadoc){ Assert.isNotNull(tempDeclaration); fReferenceNodes= new HashSet<SimpleName>(); fJavadocNodes= new HashSet<SimpleName>(); fAnalyzeJavadoc= analyzeJavadoc; fTempDeclaration= tempDeclaration; fTempBinding= tempDeclaration.resolveBinding(); fIsInJavadoc= false; }
Example #27
Source File: SurroundWith.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Makes the given statement final. * * @param statement the statment * @param rewrite the AST rewrite */ protected static void makeFinal(VariableDeclarationStatement statement, ASTRewrite rewrite) { VariableDeclaration fragment= (VariableDeclaration)statement.fragments().get(0); if (ASTNodes.findModifierNode(Modifier.FINAL, ASTNodes.getModifiers(fragment)) == null) { ModifierRewrite.create(rewrite, statement).setModifiers(Modifier.FINAL, Modifier.NONE, null); } }
Example #28
Source File: JavaDebugElementCodeMiningASTVisitor.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(VariableDeclaration node) { if (inFrame) { AbstractDebugVariableCodeMining<IJavaStackFrame> m = new JavaDebugElementCodeMining(node.getName(), fFrame, viewer, provider); minings.add(m); } return super.visit(node); }
Example #29
Source File: ReachingAliasSet.java From JDeodorant with MIT License | 5 votes |
public boolean containsAlias(AbstractVariable variable) { for(LinkedHashSet<VariableDeclaration> aliasSet : aliasSets) { for(VariableDeclaration alias : aliasSet) { if(alias.resolveBinding().getKey().equals(variable.getVariableBindingKey())) return true; } } return false; }
Example #30
Source File: PreconditionExaminer.java From JDeodorant with MIT License | 5 votes |
public Set<VariableDeclaration> getDeclaredLocalVariablesInAdditionallyMatchedNodesG1() { Set<VariableDeclaration> declaredVariables = new LinkedHashSet<VariableDeclaration>(); Set<VariableDeclaration> variableDeclarationsAndAccessedFieldsInMethod1 = pdg1.getVariableDeclarationsAndAccessedFieldsInMethod(); for(AbstractVariable variable : this.declaredLocalVariablesInAdditionallyMatchedNodesG1) { for(VariableDeclaration variableDeclaration : variableDeclarationsAndAccessedFieldsInMethod1) { if(variableDeclaration.resolveBinding().getKey().equals(variable.getVariableBindingKey())) { declaredVariables.add(variableDeclaration); break; } } } return declaredVariables; }