List of usage examples for org.eclipse.jdt.core.dom VariableDeclaration resolveBinding
public IVariableBinding resolveBinding()
From source file:de.jevopi.j2og.simpleParser.Visitor.java
License:Open Source License
/** * {@inheritDoc}//from w w w. j a va2 s .co m * * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration) * @since Aug 18, 2011 */ @Override public boolean visit(MethodDeclaration i_node) { IMethodBinding binding = i_node.resolveBinding(); if (binding != null && !binding.isConstructor()) { IJavaElement javaElement = binding.getJavaElement(); Operation operation = new Operation(binding.getName()); ITypeBinding returnTypeBinding = binding.getReturnType(); Type type = getType(returnTypeBinding, true); operation.setType(type); operation.setScope(getScope(binding.getModifiers())); classifierStack.peek().addOperation(operation); operationStack.push(operation); if (Modifier.isStatic(binding.getModifiers())) { operation.setStatic(true); } for (int i = 0; i < i_node.parameters().size(); i++) { VariableDeclaration parNode = (VariableDeclaration) i_node.parameters().get(i); IVariableBinding parBinding = parNode.resolveBinding(); TypedElement typedElement = new TypedElement(parBinding.getName()); initTypedElement(typedElement, parBinding); operation.addFormalParameter(typedElement); } } return super.visit(i_node); }
From source file:de.ovgu.cide.typing.jdt.JDTCheckGenerator.java
License:Open Source License
private void visitVD(VariableDeclaration node) { IVariableBinding binding = node.resolveBinding(); if (binding != null) knownVariableDeclarations.put(binding, bridge(node)); }
From source file:edu.cmu.cs.crystal.internal.WorkspaceUtilities.java
License:Open Source License
public boolean visit(VariableDeclaration node) { addNewBinding(node.resolveBinding(), node); return true; }
From source file:edu.cmu.cs.crystal.tac.eclipse.EclipseTACTargetSelectionTest.java
License:Open Source License
@Test public void testInitializers() throws Exception { CompilationUnit simple = EclipseTACSimpleTestDriver.parseCode("Initializers", INITIALIZERS); MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(simple); EclipseTAC tac = new EclipseTAC(m.resolveBinding()); List<Statement> stmts = m.getBody().statements(); Assert.assertTrue(stmts.size() == 5); TACInstruction decl, init;/*from www . ja v a 2s . c o m*/ for (int i = 0; i < 4; i++) { VariableDeclarationStatement s = (VariableDeclarationStatement) stmts.get(i); Assert.assertTrue("Statement: " + s, s.fragments().size() == 1); VariableDeclaration d = (VariableDeclaration) s.fragments().get(0); decl = tac.instruction(d); Assert.assertNotNull("Statement: " + s, decl); Assert.assertNotNull("Statement: " + s, d.getInitializer()); if (d.getInitializer() instanceof ParenthesizedExpression) init = tac.instruction(((ParenthesizedExpression) d.getInitializer()).getExpression()); else init = tac.instruction(d.getInitializer()); Assert.assertNotNull("Statement: " + s, init); Assert.assertTrue("Statement: " + s, init instanceof AssignmentInstruction); Variable t = ((AssignmentInstruction) init).getTarget(); Variable declared = null; // if(decl instanceof SourceVariableDeclaration) { // declared = ((SourceVariableDeclaration) decl).getDeclaredVariable(); // Assert.assertEquals("Statement: " + s, declared, t); // } // else if (decl instanceof EclipseInstructionSequence) { TACInstruction[] seq = ((EclipseInstructionSequence) decl).getInstructions(); Assert.assertTrue("Statement: " + s, seq.length == 2); Assert.assertTrue("Statement: " + s, seq[0] instanceof SourceVariableDeclaration); declared = ((SourceVariableDeclaration) seq[0]).getDeclaredVariable(); Assert.assertTrue("Statement: " + s, seq[1] instanceof CopyInstruction); Assert.assertEquals("Statement: " + s, declared, ((CopyInstruction) seq[1]).getTarget()); Assert.assertEquals("Statement: " + s, t, ((CopyInstruction) seq[1]).getOperand()); } else Assert.fail("Statement has unexpected translation: " + s); Assert.assertEquals("Statement: " + s, tac.sourceVariable(d.resolveBinding()), declared); } }
From source file:edu.cmu.cs.crystal.tac.eclipse.SourceVariableDeclarationImpl.java
License:Open Source License
/** * @param node/*from w w w.j a v a 2 s . c om*/ * @param tac * @see AbstractTACInstruction#AbstractTACInstruction(ASTNode, IEclipseVariableQuery) */ public SourceVariableDeclarationImpl(VariableDeclaration node, IEclipseVariableQuery tac) { super(node, tac); IVariableBinding b = node.resolveBinding(); if (b == null) return; if (b.isField()) throw new IllegalArgumentException("Field declaration: " + node); if (b.isEnumConstant()) throw new IllegalArgumentException("Enum declaration: " + node); }
From source file:edu.cmu.cs.plural.track.FractionalTransfer.java
License:Open Source License
private Option<ForcePackAnnotation> findForcePackAnno(SourceVariableDeclaration decl_) { VariableDeclaration decl = decl_.getNode(); List<ICrystalAnnotation> annos = this.getAnnoDB().getAnnosForVariable(decl.resolveBinding()); for (ICrystalAnnotation anno : annos) { if (anno instanceof ForcePackAnnotation) return Option.some(((ForcePackAnnotation) anno)); }// ww w.j a v a 2 s. com return Option.none(); }
From source file:lang.java.jdt.internal.BindingsResolver.java
License:Open Source License
public void resolveBindings(VariableDeclaration node) { IVariableBinding variableBinding = node.resolveBinding(); importBinding(variableBinding);//from w w w.ja v a 2 s . co m importBinding(variableBinding.getType()); }
From source file:org.autorefactor.refactoring.rules.VariableDefinitionsUsesVisitor.java
License:Open Source License
/** * Builds from a {@link VariableDeclaration} and infers the variable binding and the scope from it. * * @param variableDeclaration the variable declaration, cannot be {@code null} *///from w w w . j av a 2 s. c om public VariableDefinitionsUsesVisitor(VariableDeclaration variableDeclaration) { this(variableDeclaration.resolveBinding(), getDeclaringScope(variableDeclaration)); }
From source file:org.eclipse.objectteams.internal.jdt.nullity.quickfix.QuickFixes.java
License:Open Source License
boolean isComplainingAboutArgument(ASTNode selectedNode) { if (!(selectedNode instanceof SimpleName)) { return false; }/*from w w w.jav a 2 s .c o m*/ SimpleName nameNode = (SimpleName) selectedNode; IBinding binding = nameNode.resolveBinding(); if (binding.getKind() == IBinding.VARIABLE && ((IVariableBinding) binding).isParameter()) return true; VariableDeclaration argDecl = (VariableDeclaration) ASTNodes.getParent(selectedNode, VariableDeclaration.class); if (argDecl != null) binding = argDecl.resolveBinding(); if (binding.getKind() == IBinding.VARIABLE && ((IVariableBinding) binding).isParameter()) return true; return false; }
From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java
License:Open Source License
/** * @param simpleName/* w w w . j a va 2s. c o m*/ * the not <code>null</code> {@link SimpleName} * * @return {@link IVariableBinding} or <code>null</code> for given {@link SimpleName}. */ public static IVariableBinding getVariableBinding(ASTNode node) { Assert.isNotNull(node); // try to get binding from property (copy of binding added by DesignerAST) { IVariableBinding binding = (IVariableBinding) node.getProperty(AstParser.KEY_VARIABLE_BINDING); if (binding != null) { return binding; } } // VariableDeclaration if (node instanceof VariableDeclaration) { VariableDeclaration variableDeclaration = (VariableDeclaration) node; IVariableBinding binding = variableDeclaration.resolveBinding(); if (binding != null) { return binding; } } // check for SimpleName if (node instanceof SimpleName) { SimpleName simpleName = (SimpleName) node; // get standard binding { IBinding binding = simpleName.resolveBinding(); if (binding instanceof IVariableBinding) { return (IVariableBinding) binding; } } } // check for FieldAccess if (node instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess) node; return fieldAccess.resolveFieldBinding(); } // not a variable return null; }