org.eclipse.jdt.core.dom.IVariableBinding Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.IVariableBinding.
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: ConvertAnonymousToNestedRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean accessesAnonymousFields() { List<IVariableBinding> anonymousInnerFieldTypes = getAllEnclosingAnonymousTypesField(); List<IBinding> accessedField = getAllAccessedFields(); final Iterator<IVariableBinding> it = anonymousInnerFieldTypes.iterator(); while(it.hasNext()) { final IVariableBinding variableBinding = it.next(); final Iterator<IBinding> it2 = accessedField.iterator(); while (it2.hasNext()) { IVariableBinding variableBinding2 = (IVariableBinding) it2.next(); if(Bindings.equals(variableBinding, variableBinding2)) { return true; } } } return false; }
Example #2
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void computeUsedNames() { fUsedReadNames = new ArrayList<>(0); fUsedModifyNames = new ArrayList<>(0); IVariableBinding binding = fFieldDeclaration.resolveBinding(); ITypeBinding type = binding.getType(); IMethodBinding[] methods = binding.getDeclaringClass().getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { IMethodBinding method = methods[i]; ITypeBinding[] parameters = methods[i].getParameterTypes(); if (parameters == null || parameters.length == 0) { fUsedReadNames.add(method); } else if (parameters.length == 1 && parameters[0] == type) { fUsedModifyNames.add(method); } } }
Example #3
Source File: ExtractMethodAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void adjustArgumentsAndMethodLocals() { for (int i= 0; i < fArguments.length; i++) { IVariableBinding argument= fArguments[i]; // Both arguments and locals consider FlowInfo.WRITE_POTENTIAL. But at the end a variable // can either be a local of an argument. Fix this based on the compute return type which // didn't exist when we computed the locals and arguments (see computeInput()) if (fInputFlowInfo.hasAccessMode(fInputFlowContext, argument, FlowInfo.WRITE_POTENTIAL)) { if (argument != fReturnValue) fArguments[i]= null; // We didn't remove the argument. So we have to remove the local declaration if (fArguments[i] != null) { for (int l= 0; l < fMethodLocals.length; l++) { if (fMethodLocals[l] == argument) fMethodLocals[l]= null; } } } } }
Example #4
Source File: FlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public void endVisit(SimpleName node) { if (skipNode(node) || node.isDeclaration()) { return; } IBinding binding = node.resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding variable = (IVariableBinding) binding; if (!variable.isField()) { setFlowInfo(node, new LocalFlowInfo(variable, FlowInfo.READ, fFlowContext)); } } else if (binding instanceof ITypeBinding) { ITypeBinding type = (ITypeBinding) binding; if (type.isTypeVariable()) { setFlowInfo(node, new TypeVariableFlowInfo(type, fFlowContext)); } } }
Example #5
Source File: AddArgumentCorrectionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private Expression evaluateArgumentExpressions(AST ast, ITypeBinding requiredType, String key) { CompilationUnit root= (CompilationUnit) fCallerNode.getRoot(); int offset= fCallerNode.getStartPosition(); Expression best= null; ITypeBinding bestType= null; ScopeAnalyzer analyzer= new ScopeAnalyzer(root); IBinding[] bindings= analyzer.getDeclarationsInScope(offset, ScopeAnalyzer.VARIABLES); for (int i= 0; i < bindings.length; i++) { IVariableBinding curr= (IVariableBinding) bindings[i]; ITypeBinding type= curr.getType(); if (type != null && canAssign(type, requiredType) && testModifier(curr)) { if (best == null || isMoreSpecific(bestType, type)) { best= ast.newSimpleName(curr.getName()); bestType= type; } } } Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, requiredType); if (best == null) { best= defaultExpression; } return best; }
Example #6
Source File: ConvertAnonymousToNestedRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void createFieldsForAccessedLocals(CompilationUnitRewrite rewrite, IVariableBinding[] varBindings, String[] fieldNames, List<BodyDeclaration> newBodyDeclarations) throws CoreException { final ImportRewrite importRewrite= rewrite.getImportRewrite(); final ASTRewrite astRewrite= rewrite.getASTRewrite(); final AST ast= astRewrite.getAST(); for (int i= 0; i < varBindings.length; i++) { VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment(); fragment.setInitializer(null); fragment.setName(ast.newSimpleName(fieldNames[i])); FieldDeclaration field= ast.newFieldDeclaration(fragment); ITypeBinding varType= varBindings[i].getType(); field.setType(importRewrite.addImport(varType, ast)); field.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.FINAL)); if (doAddComments()) { String string= CodeGeneration.getFieldComment(rewrite.getCu(), varType.getName(), fieldNames[i], StubUtility.getLineDelimiterUsed(fCu)); if (string != null) { Javadoc javadoc= (Javadoc) astRewrite.createStringPlaceholder(string, ASTNode.JAVADOC); field.setJavadoc(javadoc); } } newBodyDeclarations.add(field); addLinkedPosition(KEY_FIELD_NAME_EXT + i, fragment.getName(), astRewrite, false); } }
Example #7
Source File: AddCustomConstructorOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates a new add custom constructor operation. * * @param astRoot the compilation unit ast node * @param parentType the type to add the methods to * @param variables the variable bindings to use in the constructor * @param constructor the method binding of the super constructor * @param insert the insertion point, or <code>null</code> * @param settings the code generation settings to use * @param apply <code>true</code> if the resulting edit should be applied, <code>false</code> otherwise * @param save <code>true</code> if the changed compilation unit should be saved, <code>false</code> otherwise */ public AddCustomConstructorOperation(CompilationUnit astRoot, ITypeBinding parentType, IVariableBinding[] variables, IMethodBinding constructor, IJavaElement insert, CodeGenerationSettings settings, boolean apply, boolean save) { Assert.isTrue(astRoot != null && astRoot.getTypeRoot() instanceof ICompilationUnit); Assert.isNotNull(parentType); Assert.isNotNull(variables); Assert.isNotNull(constructor); Assert.isNotNull(settings); fParentType= parentType; fInsert= insert; fASTRoot= astRoot; fFieldBindings= variables; fConstructorBinding= constructor; fSettings= settings; fSave= save; fApply= apply; }
Example #8
Source File: UnresolvedElementsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static String getExpressionBaseName(Expression expr) { IBinding argBinding= Bindings.resolveExpressionBinding(expr, true); if (argBinding instanceof IVariableBinding) { IJavaProject project= null; ASTNode root= expr.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot(); if (typeRoot != null) project= typeRoot.getJavaProject(); } return StubUtility.getBaseName((IVariableBinding)argBinding, project); } if (expr instanceof SimpleName) return ((SimpleName) expr).getIdentifier(); return null; }
Example #9
Source File: ScopeAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Evaluates if the declaration is visible in a certain context. * @param binding The binding of the declaration to examine * @param context The context to test in * @return Returns */ public static boolean isVisible(IBinding binding, ITypeBinding context) { if (binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) { return true; // all local variables found are visible } ITypeBinding declaring= getDeclaringType(binding); if (declaring == null) { return false; } declaring= declaring.getTypeDeclaration(); int modifiers= binding.getModifiers(); if (Modifier.isPublic(modifiers) || declaring.isInterface()) { return true; } else if (Modifier.isProtected(modifiers) || !Modifier.isPrivate(modifiers)) { if (declaring.getPackage() == context.getPackage()) { return true; } return isTypeInScope(declaring, context, Modifier.isProtected(modifiers)); } // private visibility return isTypeInScope(declaring, context, false); }
Example #10
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 #11
Source File: ExtractMethodAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private IVariableBinding[] compressArray(IVariableBinding[] array) { if (array == null) { return null; } int size = 0; for (int i = 0; i < array.length; i++) { if (array[i] != null) { size++; } } if (size == array.length) { return array; } IVariableBinding[] result = new IVariableBinding[size]; for (int i = 0, r = 0; i < array.length; i++) { if (array[i] != null) { result[r++] = array[i]; } } return result; }
Example #12
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 6 votes |
private Expression convert(org.eclipse.jdt.core.dom.QualifiedName expression) { IBinding binding = expression.resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding variableBinding = (IVariableBinding) binding; checkArgument( variableBinding.isField(), internalCompilerErrorMessage("Unexpected QualifiedName that is not a field")); Expression qualifier = convert(expression.getQualifier()); return JdtUtils.createFieldAccess(qualifier, variableBinding); } if (binding instanceof ITypeBinding) { return null; } throw internalCompilerError( "Unexpected type for QualifiedName binding: %s ", binding.getClass().getName()); }
Example #13
Source File: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static ASTRewriteCorrectionProposal createNoSideEffectProposal(IInvocationContext context, SimpleName nodeToQualify, IVariableBinding fieldBinding, String label, int relevance) { AST ast= nodeToQualify.getAST(); Expression qualifier; if (Modifier.isStatic(fieldBinding.getModifiers())) { ITypeBinding declaringClass= fieldBinding.getDeclaringClass(); qualifier= ast.newSimpleName(declaringClass.getTypeDeclaration().getName()); } else { qualifier= ast.newThisExpression(); } ASTRewrite rewrite= ASTRewrite.create(ast); FieldAccess access= ast.newFieldAccess(); access.setName((SimpleName) rewrite.createCopyTarget(nodeToQualify)); access.setExpression(qualifier); rewrite.replace(nodeToQualify, access, null); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); return new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, relevance, image); }
Example #14
Source File: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static boolean evaluateMissingSwitchCases(ITypeBinding enumBindings, List<Statement> switchStatements, ArrayList<String> enumConstNames) { IVariableBinding[] fields= enumBindings.getDeclaredFields(); for (int i= 0; i < fields.length; i++) { if (fields[i].isEnumConstant()) { enumConstNames.add(fields[i].getName()); } } boolean hasDefault=false; List<Statement> statements= switchStatements; for (int i= 0; i < statements.size(); i++) { Statement curr= statements.get(i); if (curr instanceof SwitchCase) { Expression expression= ((SwitchCase) curr).getExpression(); if (expression instanceof SimpleName) { enumConstNames.remove(((SimpleName) expression).getFullyQualifiedName()); } else if(expression== null){ hasDefault=true; } } } return hasDefault; }
Example #15
Source File: ExtractMethodRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void initializeParameterInfos() { IVariableBinding[] arguments = fAnalyzer.getArguments(); fParameterInfos = new ArrayList<>(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 #16
Source File: AccessAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean considerBinding(IBinding binding, ASTNode node) { if (!(binding instanceof IVariableBinding)) return false; boolean result= Bindings.equals(fFieldBinding, ((IVariableBinding)binding).getVariableDeclaration()); if (!result || fEncapsulateDeclaringClass) return result; if (binding instanceof IVariableBinding) { AbstractTypeDeclaration type= (AbstractTypeDeclaration)ASTNodes.getParent(node, AbstractTypeDeclaration.class); if (type != null) { ITypeBinding declaringType= type.resolveBinding(); return !Bindings.equals(fDeclaringClassBinding, declaringType); } } return true; }
Example #17
Source File: GenerateToStringDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public GenerateToStringDialog(Shell shell, CompilationUnitEditor editor, IType type, IVariableBinding[] fields, IVariableBinding[] inheritedFields, IVariableBinding[] selectedFields, IMethodBinding[] methods, IMethodBinding[] inheritededMethods) throws JavaModelException { super(shell, new BindingLabelProvider(), new GenerateToStringContentProvider(fields, inheritedFields, methods, inheritededMethods), editor, type, false); setEmptyListMessage(JavaUIMessages.GenerateHashCodeEqualsDialog_no_entries); List<Object> selected= new ArrayList<Object>(Arrays.asList(selectedFields)); if (selectedFields.length == fields.length && selectedFields.length > 0) selected.add(getContentProvider().getParent(selectedFields[0])); setInitialElementSelections(selected); setTitle(JavaUIMessages.GenerateToStringDialog_dialog_title); setMessage(JavaUIMessages.GenerateToStringDialog_select_fields_to_include); setValidator(new GenerateToStringValidator(fields.length + inheritedFields.length, methods.length + inheritededMethods.length)); setSize(60, 18); setInput(new Object()); fGenerationSettings= new ToStringGenerationSettings(getDialogSettings()); }
Example #18
Source File: GenerateHashCodeEqualsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override boolean generateCandidates() { IVariableBinding[] fCandidateFields= fTypeBinding.getDeclaredFields(); allFields= new ArrayList<IVariableBinding>(); selectedFields= new ArrayList<IVariableBinding>(); for (int i= 0; i < fCandidateFields.length; i++) { if (!Modifier.isStatic(fCandidateFields[i].getModifiers())) { allFields.add(fCandidateFields[i]); if (!Modifier.isTransient(fCandidateFields[i].getModifiers())) selectedFields.add(fCandidateFields[i]); } } if (allFields.isEmpty()) { return false; } return true; }
Example #19
Source File: UnusedCodeFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private String getDisplayString(IBinding binding) { switch (binding.getKind()) { case IBinding.TYPE: return FixMessages.UnusedCodeFix_RemoveUnusedType_description; case IBinding.METHOD: if (((IMethodBinding) binding).isConstructor()) { return FixMessages.UnusedCodeFix_RemoveUnusedConstructor_description; } else { return FixMessages.UnusedCodeFix_RemoveUnusedPrivateMethod_description; } case IBinding.VARIABLE: if (((IVariableBinding) binding).isField()) { return FixMessages.UnusedCodeFix_RemoveUnusedField_description; } else { return FixMessages.UnusedCodeFix_RemoveUnusedVariabl_description; } default: return ""; //$NON-NLS-1$ } }
Example #20
Source File: TypeChangeCorrectionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void sortTypes(ITypeBinding[] typeProposals) { ITypeBinding oldType; if (fBinding instanceof IMethodBinding) { oldType= ((IMethodBinding) fBinding).getReturnType(); } else { oldType= ((IVariableBinding) fBinding).getType(); } if (! oldType.isParameterizedType()) return; final ITypeBinding oldTypeDeclaration= oldType.getTypeDeclaration(); Arrays.sort(typeProposals, new Comparator<ITypeBinding>() { public int compare(ITypeBinding o1, ITypeBinding o2) { return rank(o2) - rank(o1); } private int rank(ITypeBinding type) { if (type.getTypeDeclaration().equals(oldTypeDeclaration)) return 1; return 0; } }); }
Example #21
Source File: GenerateToStringAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override SourceActionDialog createDialog(Shell shell, IType type) throws JavaModelException { IVariableBinding[] fieldBindings= fFields.toArray(new IVariableBinding[0]); IVariableBinding[] inheritedFieldBindings= fInheritedFields.toArray(new IVariableBinding[0]); IVariableBinding[] selectedFieldBindings= fSelectedFields.toArray(new IVariableBinding[0]); IMethodBinding[] methodBindings= fMethods.toArray(new IMethodBinding[0]); IMethodBinding[] inheritededMethodBindings= fInheritedMethods.toArray(new IMethodBinding[0]); return new GenerateToStringDialog(shell, fEditor, type, fieldBindings, inheritedFieldBindings, selectedFieldBindings, methodBindings, inheritededMethodBindings); }
Example #22
Source File: LocalDeclarationAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(SimpleName node) { IVariableBinding binding= null; if (node.isDeclaration() || !considerNode(node) || (binding= ASTNodes.getLocalVariableBinding(node)) == null) return false; handleReferenceToLocal(node, binding); return true; }
Example #23
Source File: TypeCheckElimination.java From JDeodorant with MIT License | 5 votes |
public TypeCheckElimination() { this.typeCheckMap = new LinkedHashMap<Expression, ArrayList<Statement>>(); this.defaultCaseStatements = new ArrayList<Statement>(); this.staticFieldMap = new LinkedHashMap<Expression, List<SimpleName>>(); this.subclassTypeMap = new LinkedHashMap<Expression, List<Type>>(); this.typeField = null; this.typeFieldGetterMethod = null; this.typeFieldSetterMethod = null; this.typeCheckCodeFragment = null; this.typeCheckMethod = null; this.typeCheckClass = null; this.additionalStaticFields = new LinkedHashSet<SimpleName>(); this.accessedFields = new LinkedHashSet<VariableDeclarationFragment>(); this.assignedFields = new LinkedHashSet<VariableDeclarationFragment>(); this.superAccessedFieldMap = new LinkedHashMap<VariableDeclarationFragment, MethodDeclaration>(); this.superAccessedFieldBindingMap = new LinkedHashMap<IVariableBinding, IMethodBinding>(); this.superAssignedFieldMap = new LinkedHashMap<VariableDeclarationFragment, MethodDeclaration>(); this.superAssignedFieldBindingMap = new LinkedHashMap<IVariableBinding, IMethodBinding>(); this.accessedParameters = new LinkedHashSet<SingleVariableDeclaration>(); this.assignedParameters = new LinkedHashSet<SingleVariableDeclaration>(); this.accessedLocalVariables = new LinkedHashSet<VariableDeclaration>(); this.assignedLocalVariables = new LinkedHashSet<VariableDeclaration>(); this.accessedMethods = new LinkedHashSet<MethodDeclaration>(); this.superAccessedMethods = new LinkedHashSet<IMethodBinding>(); this.typeLocalVariable = null; this.typeMethodInvocation = null; this.foreignTypeField = null; this.existingInheritanceTree = null; this.inheritanceTreeMatchingWithStaticTypes = null; this.staticFieldSubclassTypeMap = new LinkedHashMap<SimpleName, String>(); this.remainingIfStatementExpressionMap = new LinkedHashMap<Expression, DefaultMutableTreeNode>(); this.abstractMethodName = null; }
Example #24
Source File: GenerateToStringAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static <T extends IBinding> boolean contains(List<T> inheritedFields, T member) { for (Iterator<T> iterator= inheritedFields.iterator(); iterator.hasNext();) { T object= iterator.next(); if (object instanceof IVariableBinding && member instanceof IVariableBinding) if (((IVariableBinding) object).getName().equals(((IVariableBinding) member).getName())) return true; if (object instanceof IMethodBinding && member instanceof IMethodBinding) if (((IMethodBinding) object).getName().equals(((IMethodBinding) member).getName())) return true; } return false; }
Example #25
Source File: AddDelegateMethodsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Object[] getChildren(Object element) { if (element instanceof IVariableBinding) { List<DelegateEntry> result= new ArrayList<DelegateEntry>(); for (int i= 0; i < fDelegateEntries.length; i++) { if (element == fDelegateEntries[i].field) { result.add(fDelegateEntries[i]); } } return result.toArray(); } return null; }
Example #26
Source File: FlowInfo.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Returns an array of <code>IVariableBinding</code> that conform to the * given access mode <code>mode</code>. * * @param context * the flow context object used to compute this flow info * @param mode * the access type. Valid values are <code>READ</code>, * <code>WRITE</code>, <code>UNKNOWN</code> and any combination * of them. * @return an array of local variable bindings conforming to the given type. */ public IVariableBinding[] get(FlowContext context, int mode) { List<IVariableBinding> result = new ArrayList<>(); int[] locals = getAccessModes(); if (locals == null) { return EMPTY_ARRAY; } for (int i = 0; i < locals.length; i++) { int accessMode = locals[i]; if ((accessMode & mode) != 0) { result.add(context.getLocalFromIndex(i)); } } return result.toArray(new IVariableBinding[result.size()]); }
Example #27
Source File: ConstantChecks.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private boolean isMemberReferenceValidInClassInitialization(Name name) { IBinding binding = name.resolveBinding(); Assert.isTrue(binding instanceof IVariableBinding || binding instanceof IMethodBinding); if (name instanceof SimpleName) { return Modifier.isStatic(binding.getModifiers()); } else { Assert.isTrue(name instanceof QualifiedName); return checkName(((QualifiedName) name).getQualifier()); } }
Example #28
Source File: NullAnnotationsRewriteOperations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static String findAffectedParameterName(ASTNode selectedNode) { VariableDeclaration argDecl= (selectedNode instanceof VariableDeclaration) ? (VariableDeclaration) selectedNode : (VariableDeclaration) ASTNodes.getParent(selectedNode, VariableDeclaration.class); if (argDecl != null) return argDecl.getName().getIdentifier(); if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME) { IBinding binding= ((SimpleName) selectedNode).resolveBinding(); if (binding.getKind() == IBinding.VARIABLE && ((IVariableBinding) binding).isParameter()) return ((SimpleName) selectedNode).getIdentifier(); } return null; }
Example #29
Source File: MoveMethodRefactoring.java From JDeodorant with MIT License | 5 votes |
private void addParameterToMovedMethod(MethodDeclaration newMethodDeclaration, IVariableBinding variableBinding, ASTRewrite targetRewriter) { AST ast = newMethodDeclaration.getAST(); SingleVariableDeclaration parameter = ast.newSingleVariableDeclaration(); ITypeBinding typeBinding = variableBinding.getType(); Type fieldType = RefactoringUtility.generateTypeFromTypeBinding(typeBinding, ast, targetRewriter); targetRewriter.set(parameter, SingleVariableDeclaration.TYPE_PROPERTY, fieldType, null); targetRewriter.set(parameter, SingleVariableDeclaration.NAME_PROPERTY, ast.newSimpleName(variableBinding.getName()), null); ListRewrite parametersRewrite = targetRewriter.getListRewrite(newMethodDeclaration, MethodDeclaration.PARAMETERS_PROPERTY); parametersRewrite.insertLast(parameter, null); this.additionalArgumentsAddedToMovedMethod.add(variableBinding.getName()); this.additionalTypeBindingsToBeImportedInTargetClass.add(variableBinding.getType()); addParamTagElementToJavadoc(newMethodDeclaration, targetRewriter, variableBinding.getName()); }
Example #30
Source File: JavadocHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static Object getVariableBindingConstValue(ASTNode node, IField field) { if (node != null && node.getNodeType() == ASTNode.SIMPLE_NAME) { IBinding binding= ((SimpleName) node).resolveBinding(); if (binding != null && binding.getKind() == IBinding.VARIABLE) { IVariableBinding variableBinding= (IVariableBinding) binding; if (field.equals(variableBinding.getJavaElement())) { return variableBinding.getConstantValue(); } } } return null; }