Java Code Examples for org.eclipse.jdt.core.dom.VariableDeclarationFragment#resolveBinding()
The following examples show how to use
org.eclipse.jdt.core.dom.VariableDeclarationFragment#resolveBinding() .
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: AddDelegateMethodsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
AddDelegateMethodsContentProvider(CompilationUnit astRoot, IType type, IField[] fields) throws JavaModelException { final ITypeBinding binding= ASTNodes.getTypeBinding(astRoot, type); if (binding != null) { fDelegateEntries= StubUtility2.getDelegatableMethods(binding); List<IVariableBinding> expanded= new ArrayList<IVariableBinding>(); for (int index= 0; index < fields.length; index++) { VariableDeclarationFragment fragment= ASTNodeSearchUtil.getFieldDeclarationFragmentNode(fields[index], astRoot); if (fragment != null) { IVariableBinding variableBinding= fragment.resolveBinding(); if (variableBinding != null) expanded.add(variableBinding); } } fExpanded= expanded.toArray(new IVariableBinding[expanded.size()]); } }
Example 2
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { if (fVisibility < 0) fVisibility= (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate)); RefactoringStatus result= new RefactoringStatus(); result.merge(Checks.checkAvailability(fField)); if (result.hasFatalError()) return result; fRoot= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm); ISourceRange sourceRange= fField.getNameRange(); ASTNode node= NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength()); if (node == null) { return mappingErrorFound(result, node); } fFieldDeclaration= (VariableDeclarationFragment)ASTNodes.getParent(node, VariableDeclarationFragment.class); if (fFieldDeclaration == null) { return mappingErrorFound(result, node); } if (fFieldDeclaration.resolveBinding() == null) { if (!processCompilerError(result, node)) result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable); return result; } computeUsedNames(); return result; }
Example 3
Source File: InJavaImporter.java From jdt2famix with Eclipse Public License 1.0 | 6 votes |
/** * We pass both the fragment and the field because we need the field type when * the binding cannot be resolved */ public Attribute ensureAttributeForFragment(VariableDeclarationFragment fragment, FieldDeclaration field) { IVariableBinding binding = fragment.resolveBinding(); Attribute attribute; if (binding == null) attribute = ensureAttributeFromFragmentIntoParentType(fragment, field, this.topFromContainerStack(Type.class)); else { attribute = ensureAttributeForVariableBinding(binding); extractBasicModifiersFromBinding(binding.getModifiers(), attribute); if (Modifier.isStatic(binding.getModifiers())) attribute.setHasClassScope(true); } attribute.setIsStub(true); return attribute; }
Example 4
Source File: SuperTypeConstraintsCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * End of visit the variable declaration fragment list. * * @param fragments the fragments (element type: <code>VariableDeclarationFragment</code>) * @param type the type of the fragments * @param parent the parent of the fragment list */ private void endVisit(final List<VariableDeclarationFragment> fragments, final Type type, final ASTNode parent) { final ConstraintVariable2 ancestor= (ConstraintVariable2) type.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (ancestor != null) { IVariableBinding binding= null; ConstraintVariable2 descendant= null; VariableDeclarationFragment fragment= null; for (int index= 0; index < fragments.size(); index++) { fragment= fragments.get(index); descendant= (ConstraintVariable2) fragment.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) fModel.createSubtypeConstraint(descendant, ancestor); binding= fragment.resolveBinding(); if (binding != null) { descendant= fModel.createVariableVariable(binding); if (descendant != null) fModel.createEqualityConstraint(ancestor, descendant); } } parent.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor); } }
Example 5
Source File: SrcTreeGenerator.java From sahagin-java with Apache License 2.0 | 5 votes |
private IVariableBinding getVariableBinding(FieldDeclaration declaration) { for (Object fragment : declaration.fragments()) { if (fragment instanceof VariableDeclarationFragment) { VariableDeclarationFragment varDecl = (VariableDeclarationFragment) fragment; IVariableBinding binding = varDecl.resolveBinding(); if (binding != null) { return binding; } } } return null; }
Example 6
Source File: FieldDiff.java From apidiff with MIT License | 5 votes |
/** * Checking deprecated fields * @param field * @return */ private Boolean isDeprecatedField(FieldDeclaration field){ if(field != null){ List<VariableDeclarationFragment> variableFragments = field.fragments(); for (VariableDeclarationFragment variableDeclarationFragment : variableFragments) { if(variableDeclarationFragment.resolveBinding() != null && variableDeclarationFragment.resolveBinding().isDeprecated()){ return true; } } } return false; }
Example 7
Source File: FullConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Collection<ITypeConstraint> getConstraintsForHiding(VariableDeclarationFragment fragment) { Collection<ITypeConstraint> result= new ArrayList<ITypeConstraint>(); IVariableBinding fieldBinding= fragment.resolveBinding(); Assert.isTrue(fieldBinding.isField()); Set<ITypeBinding> declaringTypes= getDeclaringSuperTypes(fieldBinding); ConstraintVariable hiddingFieldVar= fConstraintVariableFactory.makeDeclaringTypeVariable(fieldBinding); for (Iterator<ITypeBinding> iter= declaringTypes.iterator(); iter.hasNext();) { ITypeBinding declaringSuperType= iter.next(); IVariableBinding hiddenField= findField(fieldBinding, declaringSuperType); Assert.isTrue(hiddenField.isField()); ConstraintVariable hiddenFieldVar= fConstraintVariableFactory.makeDeclaringTypeVariable(hiddenField); result.addAll(Arrays.asList(fTypeConstraintFactory.createStrictSubtypeConstraint(hiddingFieldVar, hiddenFieldVar))); } return result; }
Example 8
Source File: FullConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Collection<ITypeConstraint> getConstraintsForFieldDeclaringTypes(FieldDeclaration fd) { Collection<ITypeConstraint> result= new ArrayList<ITypeConstraint>(fd.fragments().size()); for (Iterator<VariableDeclarationFragment> iter= fd.fragments().iterator(); iter.hasNext();) { VariableDeclarationFragment varDecl= iter.next(); IVariableBinding binding= varDecl.resolveBinding(); Assert.isTrue(binding.isField()); result.addAll(Arrays.asList(fTypeConstraintFactory.createDefinesConstraint( fConstraintVariableFactory.makeDeclaringTypeVariable(binding), fConstraintVariableFactory.makeRawBindingVariable(binding.getDeclaringClass())))); } return result; }
Example 9
Source File: ExtractTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static List<IVariableBinding> getForInitializedVariables(VariableDeclarationExpression variableDeclarations) { List<IVariableBinding> forInitializerVariables= new ArrayList<IVariableBinding>(1); for (Iterator<VariableDeclarationFragment> iter= variableDeclarations.fragments().iterator(); iter.hasNext();) { VariableDeclarationFragment fragment= iter.next(); IVariableBinding binding= fragment.resolveBinding(); if (binding != null) forInitializerVariables.add(binding); } return forInitializerVariables; }
Example 10
Source File: FlowAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void endVisit(VariableDeclarationFragment node) { if (skipNode(node)) return; IVariableBinding binding= node.resolveBinding(); LocalFlowInfo nameInfo= null; Expression initializer= node.getInitializer(); if (binding != null && !binding.isField() && initializer != null) { nameInfo= new LocalFlowInfo(binding, FlowInfo.WRITE, fFlowContext); } GenericSequentialFlowInfo info= processSequential(node, initializer); info.merge(nameInfo, fFlowContext); }
Example 11
Source File: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * The selection corresponds to a FieldDeclaration * @param fieldDeclaration the field * @return the message */ private String fieldDeclarationSelected(FieldDeclaration fieldDeclaration) { if (fieldDeclaration.fragments().size() != 1) { return RefactoringCoreMessages.ChangeTypeRefactoring_multiDeclarationsNotSupported; } else { VariableDeclarationFragment elem= (VariableDeclarationFragment) fieldDeclaration.fragments().iterator().next(); fFieldBinding= elem.resolveBinding(); SimpleName name= elem.getName(); setSelectionRanges(name); return simpleNameSelected(name); } }
Example 12
Source File: ExtractFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static List<IVariableBinding> getForInitializedVariables(VariableDeclarationExpression variableDeclarations) { List<IVariableBinding> forInitializerVariables = new ArrayList<>(1); for (Iterator<VariableDeclarationFragment> iter = variableDeclarations.fragments().iterator(); iter.hasNext();) { VariableDeclarationFragment fragment = iter.next(); IVariableBinding binding = fragment.resolveBinding(); if (binding != null) { forInitializerVariables.add(binding); } } return forInitializerVariables; }
Example 13
Source File: ExtractTempRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static List<IVariableBinding> getForInitializedVariables(VariableDeclarationExpression variableDeclarations) { List<IVariableBinding> forInitializerVariables = new ArrayList<>(1); for (Iterator<VariableDeclarationFragment> iter = variableDeclarations.fragments().iterator(); iter.hasNext();) { VariableDeclarationFragment fragment = iter.next(); IVariableBinding binding = fragment.resolveBinding(); if (binding != null) { forInitializerVariables.add(binding); } } return forInitializerVariables; }
Example 14
Source File: FlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void endVisit(VariableDeclarationFragment node) { if (skipNode(node)) { return; } IVariableBinding binding = node.resolveBinding(); LocalFlowInfo nameInfo = null; Expression initializer = node.getInitializer(); if (binding != null && !binding.isField() && initializer != null) { nameInfo = new LocalFlowInfo(binding, FlowInfo.WRITE, fFlowContext); } GenericSequentialFlowInfo info = processSequential(node, initializer); info.merge(nameInfo, fFlowContext); }
Example 15
Source File: UtilTools.java From apidiff with MIT License | 5 votes |
public static String getFieldName(FieldDeclaration field){ String name = null; List<VariableDeclarationFragment> variableFragments = field.fragments(); for (VariableDeclarationFragment variableDeclarationFragment : variableFragments) { if(variableDeclarationFragment.resolveBinding() != null){ name = variableDeclarationFragment.resolveBinding().getName(); } } return name; }
Example 16
Source File: InOutFlowAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void clearAccessMode(FlowInfo info, VariableDeclarationFragment fragment) { IVariableBinding binding= fragment.resolveBinding(); if (binding != null && !binding.isField()) info.clearAccessMode(binding, fFlowContext); }
Example 17
Source File: ExtractClassRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private FieldDeclaration performFieldRewrite(IType type, ParameterObjectFactory pof, RefactoringStatus status) throws CoreException { fBaseCURewrite= new CompilationUnitRewrite(type.getCompilationUnit()); SimpleName name= (SimpleName) NodeFinder.perform(fBaseCURewrite.getRoot(), type.getNameRange()); TypeDeclaration typeNode= (TypeDeclaration) ASTNodes.getParent(name, ASTNode.TYPE_DECLARATION); ASTRewrite rewrite= fBaseCURewrite.getASTRewrite(); int modifier= Modifier.PRIVATE; TextEditGroup removeFieldGroup= fBaseCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_remove_field); FieldDeclaration lastField= null; initializeDeclaration(typeNode); for (Iterator<FieldInfo> iter= fVariables.values().iterator(); iter.hasNext();) { FieldInfo pi= iter.next(); if (isCreateField(pi)) { VariableDeclarationFragment vdf= pi.declaration; FieldDeclaration parent= (FieldDeclaration) vdf.getParent(); if (lastField == null) lastField= parent; else if (lastField.getStartPosition() < parent.getStartPosition()) lastField= parent; ListRewrite listRewrite= rewrite.getListRewrite(parent, FieldDeclaration.FRAGMENTS_PROPERTY); removeNode(vdf, removeFieldGroup, fBaseCURewrite); if (listRewrite.getRewrittenList().size() == 0) { removeNode(parent, removeFieldGroup, fBaseCURewrite); } if (fDescriptor.isCreateTopLevel()) { IVariableBinding binding= vdf.resolveBinding(); ITypeRoot typeRoot= fBaseCURewrite.getCu(); if (binding == null || binding.getType() == null){ status.addFatalError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_fatal_error_cannot_resolve_binding, BasicElementLabels.getJavaElementName(pi.name)), JavaStatusContext.create(typeRoot, vdf)); } else { ITypeBinding typeBinding= binding.getType(); if (Modifier.isPrivate(typeBinding.getModifiers())){ status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_referencing_private_class, BasicElementLabels.getJavaElementName(typeBinding.getName())), JavaStatusContext.create(typeRoot, vdf)); } else if (Modifier.isProtected(typeBinding.getModifiers())){ ITypeBinding declaringClass= typeBinding.getDeclaringClass(); if (declaringClass != null) { IPackageBinding package1= declaringClass.getPackage(); if (package1 != null && !fDescriptor.getPackage().equals(package1.getName())){ status.addError(Messages.format(RefactoringCoreMessages.ExtractClassRefactoring_error_referencing_protected_class, new String[] {BasicElementLabels.getJavaElementName(typeBinding.getName()), BasicElementLabels.getJavaElementName(fDescriptor.getPackage())}), JavaStatusContext.create(typeRoot, vdf)); } } } } } Expression initializer= vdf.getInitializer(); if (initializer != null) pi.initializer= initializer; int modifiers= parent.getModifiers(); if (!MemberVisibilityAdjustor.hasLowerVisibility(modifiers, modifier)){ modifier= modifiers; } } } FieldDeclaration fieldDeclaration= createParameterObjectField(pof, typeNode, modifier); ListRewrite bodyDeclList= rewrite.getListRewrite(typeNode, TypeDeclaration.BODY_DECLARATIONS_PROPERTY); if (lastField != null) bodyDeclList.insertAfter(fieldDeclaration, lastField, null); else bodyDeclList.insertFirst(fieldDeclaration, null); return fieldDeclaration; }
Example 18
Source File: AssignToVariableAssistProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private ASTRewrite doAddField(ASTRewrite rewrite, ASTNode nodeToAssign, ITypeBinding typeBinding, int index) { boolean isParamToField= nodeToAssign.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION; ASTNode newTypeDecl= ASTResolving.findParentType(nodeToAssign); if (newTypeDecl == null) { return null; } Expression expression= isParamToField ? ((SingleVariableDeclaration) nodeToAssign).getName() : ((ExpressionStatement) nodeToAssign).getExpression(); AST ast= newTypeDecl.getAST(); createImportRewrite((CompilationUnit) nodeToAssign.getRoot()); BodyDeclaration bodyDecl= ASTResolving.findParentBodyDeclaration(nodeToAssign); Block body; if (bodyDecl instanceof MethodDeclaration) { body= ((MethodDeclaration) bodyDecl).getBody(); } else if (bodyDecl instanceof Initializer) { body= ((Initializer) bodyDecl).getBody(); } else { return null; } IJavaProject project= getCompilationUnit().getJavaProject(); boolean isAnonymous= newTypeDecl.getNodeType() == ASTNode.ANONYMOUS_CLASS_DECLARATION; boolean isStatic= Modifier.isStatic(bodyDecl.getModifiers()) && !isAnonymous; int modifiers= Modifier.PRIVATE; if (isStatic) { modifiers |= Modifier.STATIC; } VariableDeclarationFragment newDeclFrag= addFieldDeclaration(rewrite, newTypeDecl, modifiers, expression, nodeToAssign, typeBinding, index); String varName= newDeclFrag.getName().getIdentifier(); Assignment assignment= ast.newAssignment(); assignment.setRightHandSide((Expression) rewrite.createCopyTarget(expression)); boolean needsThis= StubUtility.useThisForFieldAccess(project); if (isParamToField) { needsThis |= varName.equals(((SimpleName) expression).getIdentifier()); } SimpleName accessName= ast.newSimpleName(varName); if (needsThis) { FieldAccess fieldAccess= ast.newFieldAccess(); fieldAccess.setName(accessName); if (isStatic) { String typeName= ((AbstractTypeDeclaration) newTypeDecl).getName().getIdentifier(); fieldAccess.setExpression(ast.newSimpleName(typeName)); } else { fieldAccess.setExpression(ast.newThisExpression()); } assignment.setLeftHandSide(fieldAccess); } else { assignment.setLeftHandSide(accessName); } ASTNode selectionNode; if (isParamToField) { // assign parameter to field ExpressionStatement statement= ast.newExpressionStatement(assignment); int insertIdx= findAssignmentInsertIndex(body.statements(), nodeToAssign) + index; rewrite.getListRewrite(body, Block.STATEMENTS_PROPERTY).insertAt(statement, insertIdx, null); selectionNode= statement; } else { if (needsSemicolon(expression)) { rewrite.replace(expression, ast.newExpressionStatement(assignment), null); } else { rewrite.replace(expression, assignment, null); } selectionNode= nodeToAssign; } addLinkedPosition(rewrite.track(newDeclFrag.getName()), false, KEY_NAME + index); if (!isParamToField) { FieldDeclaration fieldDeclaration= (FieldDeclaration) newDeclFrag.getParent(); addLinkedPosition(rewrite.track(fieldDeclaration.getType()), false, KEY_TYPE); } addLinkedPosition(rewrite.track(accessName), true, KEY_NAME + index); IVariableBinding variableBinding= newDeclFrag.resolveBinding(); if (variableBinding != null) { SimpleName[] linkedNodes= LinkedNodeFinder.findByBinding(nodeToAssign.getRoot(), variableBinding); for (int i= 0; i < linkedNodes.length; i++) { addLinkedPosition(rewrite.track(linkedNodes[i]), false, KEY_NAME + index); } } setEndPosition(rewrite.track(selectionNode)); return rewrite; }
Example 19
Source File: InOutFlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private void clearAccessMode(FlowInfo info, VariableDeclarationFragment fragment) { IVariableBinding binding = fragment.resolveBinding(); if (binding != null && !binding.isField()) { info.clearAccessMode(binding, fFlowContext); } }
Example 20
Source File: DOMFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public boolean visit(VariableDeclarationFragment node) { if (found(node, node.getName()) && this.resolveBinding) this.foundBinding = node.resolveBinding(); return true; }