List of usage examples for org.eclipse.jdt.core.dom VariableDeclaration getName
public SimpleName getName()
From source file:boa.datagen.util.Java8Visitor.java
License:Apache License
@Override public boolean visit(LambdaExpression node) { Method.Builder b = Method.newBuilder(); b.setName(""); boa.types.Ast.Type.Builder rt = boa.types.Ast.Type.newBuilder(); rt.setName(getIndex("")); rt.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(rt.build());/*from w ww .ja v a2 s . com*/ for (Object o : node.parameters()) { VariableDeclaration ex = (VariableDeclaration) o; Variable.Builder vb = Variable.newBuilder(); vb.setName(ex.getName().getFullyQualifiedName()); if (o instanceof SingleVariableDeclaration) { SingleVariableDeclaration svd = (SingleVariableDeclaration) o; boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(svd.getType()); // FIXME JLS8: Deprecated getExtraDimensions() and added extraDimensions() for (int i = 0; i < svd.getExtraDimensions(); i++) name += "[]"; if (svd.isVarargs()) name += "..."; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tp.build()); } else { VariableDeclarationFragment vdf = (VariableDeclarationFragment) o; boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex("")); tb.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tb.build()); } b.addArguments(vb.build()); } if (node.getBody() != null) { statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); if (node.getBody() instanceof org.eclipse.jdt.core.dom.Expression) { boa.types.Ast.Expression e = expressions.pop(); boa.types.Ast.Statement.Builder sb = boa.types.Ast.Statement.newBuilder(); sb.setKind(boa.types.Ast.Statement.StatementKind.EXPRESSION); sb.setExpression(e); statements.peek().add(sb.build()); } for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); } boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder(); eb.setKind(boa.types.Ast.Expression.ExpressionKind.LAMBDA); eb.setLambda(b.build()); expressions.push(eb.build()); return false; }
From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaAttributeModelAdapter.java
License:Open Source License
@Override public Object getMatchKey(Object modelElement) { VariableDeclaration var = (VariableDeclaration) getFieldDeclaration(modelElement).fragments().get(0); return var.getName().getIdentifier(); }
From source file:com.google.devtools.j2cpp.types.GeneratedVariableBinding.java
License:Open Source License
/** * For renaming variables: creates a new binding from a new declaration and * the original binding./*from w w w . j a v a2 s .c o m*/ */ public GeneratedVariableBinding(VariableDeclaration var, int modifiers, boolean isParameter, IVariableBinding oldBinding) { this(var.getName().getIdentifier(), modifiers, oldBinding.getType(), oldBinding.isField(), isParameter, oldBinding.getDeclaringClass(), oldBinding.getDeclaringMethod()); }
From source file:com.google.devtools.j2objc.translate.AnonymousClassConverterTest.java
License:Open Source License
public void testMethodVarInNestedAnonymousClass() throws IOException { String source = "class Test { " + " void bar() { " + " Runnable r1 = new Runnable() { " + " public void run() { " + " final Integer i = 1; " + " Runnable r2 = new Runnable() { " + " public void run() { int j = i + 1; } }; } }; } }"; // Verify method var in r1.run() isn't mistakenly made a field in r1. CompilationUnit unit = translateType("Test", source); List<TypeDeclaration> types = unit.types(); TypeDeclaration r1 = types.get(1);/*from w ww. jav a 2s .com*/ assertEquals("Test_$1", NameTable.getFullName(r1)); for (FieldDeclaration field : r1.getFields()) { List<VariableDeclarationFragment> vars = field.fragments(); for (VariableDeclaration var : vars) { if (var.getName().getIdentifier().equals("val$i")) { fail("found field that shouldn't be declared"); } } } // Method var in r1.run() becomes a field in r2. TypeDeclaration r2 = types.get(2); assertEquals("Test_$1_$1", NameTable.getFullName(r2)); boolean found = false; for (FieldDeclaration field : r2.getFields()) { List<VariableDeclarationFragment> vars = field.fragments(); for (VariableDeclaration var : vars) { if (var.getName().getIdentifier().equals("val$i")) { found = true; } } } assertTrue("required field not found", found); // Verify constructor takes both outer field and var. ObjectiveCImplementationGenerator.generate("Test.java", unit, source); String translation = getTranslatedFile("Test.m"); assertTranslation(translation, "r2 = [[[Test_$1_$1 alloc] initWithJavaLangInteger:i] autorelease]"); }
From source file:com.google.devtools.j2objc.translate.AnonymousClassConverterTest.java
License:Open Source License
public void testMethodVarInAnonymousClass() throws IOException { String source = "class Test { " + " void foo() { " + " if (true) {" + " if (false) {" + " final Integer i = 1;" + " Runnable r = new Runnable() { " + " public void run() { int j = i + 1; } }; }}}}"; // Verify method var in r1.run() isn't mistakenly made a field in r1. CompilationUnit unit = translateType("Test", source); List<TypeDeclaration> types = unit.types(); TypeDeclaration r1 = types.get(1);/* ww w . ja v a 2 s . c om*/ assertEquals("Test_$1", NameTable.getFullName(r1)); boolean found = false; for (FieldDeclaration field : r1.getFields()) { List<VariableDeclarationFragment> vars = field.fragments(); for (VariableDeclaration var : vars) { if (var.getName().getIdentifier().equals("val$i")) { found = true; } } } assertTrue("required field not found", found); // Verify method var is passed to constructor. ObjectiveCImplementationGenerator.generate("Test.java", unit, source); String translation = getTranslatedFile("Test.m"); assertTranslation(translation, "r = [[[Test_$1 alloc] initWithJavaLangInteger:i] autorelease]"); }
From source file:com.google.devtools.j2objc.translate.AnonymousClassConverterTest.java
License:Open Source License
public void testMethodVarInSwitch() throws IOException { String source = "class Test { " + " enum E { ONE, TWO };" + " void foo(E e) { " + " switch (e) {" + " case ONE: {" + " final Integer i = 1;" + " Runnable r = new Runnable() { " + " public void run() { int j = i + 1; } }; }}}}"; // Verify method var in r1.run() isn't mistakenly made a field in r1. CompilationUnit unit = translateType("Test", source); List<TypeDeclaration> types = unit.types(); TypeDeclaration r1 = types.get(2);/*from w ww . ja va2 s . com*/ assertEquals("Test_$1", NameTable.getFullName(r1)); boolean found = false; for (FieldDeclaration field : r1.getFields()) { List<VariableDeclarationFragment> vars = field.fragments(); for (VariableDeclaration var : vars) { if (var.getName().getIdentifier().equals("val$i")) { found = true; } } } assertTrue("required field not found", found); // Verify method var is passed to constructor. ObjectiveCImplementationGenerator.generate("Test.java", unit, source); String translation = getTranslatedFile("Test.m"); assertTranslation(translation, "r = [[[Test_$1 alloc] initWithJavaLangInteger:i] autorelease]"); }
From source file:com.google.gdt.eclipse.designer.uibinder.model.util.NameSupport.java
License:Open Source License
/** * @return the {@link VariableDeclaration} of "@UiField" with given name, may be <code>null</code> * .// ww w . j a v a 2 s .c o m */ public static VariableDeclaration getBinderField(TypeDeclaration typeDeclaration, final String name) { final VariableDeclaration[] result = { null }; typeDeclaration.accept(new ASTVisitor() { @Override public void endVisit(FieldDeclaration node) { if (isBinderField(node)) { for (VariableDeclaration fragment : DomGenerics.fragments(node)) { if (fragment.getName().getIdentifier().equals(name)) { result[0] = fragment; } } } } }); return result[0]; }
From source file:de.ovgu.cide.export.physical.internal.LocalVariableHelper.java
License:Open Source License
private static Formal createFormal(VariableDeclaration decl) { if (decl instanceof SingleVariableDeclaration) return new Formal(((SingleVariableDeclaration) decl).getType(), decl.getName().getIdentifier(), formalNr++);//www . j a v a 2s .c o m else { assert decl instanceof VariableDeclarationFragment; Type type = null; if (decl.getParent() instanceof VariableDeclarationStatement) { type = ((VariableDeclarationStatement) decl.getParent()).getType(); } else if (decl.getParent() instanceof VariableDeclarationExpression) { type = ((VariableDeclarationExpression) decl.getParent()).getType(); } else if (decl.getParent() instanceof FieldDeclaration) ;// not a local variable else assert false; if (type != null) return new Formal(type, decl.getName().getIdentifier(), formalNr++); } return null; }
From source file:edu.cmu.cs.crystal.cfg.eclipse.EclipseCFG.java
License:Open Source License
private EclipseCFGNode handleVariableDecl(VariableDeclaration node, EclipseCFGNode startPoint) { EclipseCFGNode decl = nodeMap.get(node); EclipseCFGNode name = nodeMap.get(node.getName()); EclipseCFGNode current = null;//from w w w . j av a 2 s . c om if (startPoint != null) { current = startPoint.getEnd(); } if (node.getInitializer() != null) { EclipseCFGNode init = nodeMap.get(node.getInitializer()); if (current != null) createEdge(current, init.getStart()); else startPoint = init; current = init.getEnd(); } if (current != null) createEdge(current, name.getStart()); else startPoint = name; createEdge(name.getEnd(), decl); decl.setStart(startPoint.getStart()); return decl; }
From source file:egovframework.mgt.fit.library.parser.visitor.ClassParsingVisitor.java
License:Apache License
/** * .//from w w w .j a va 2s .c om * @return */ @Override public boolean visit(FieldDeclaration node) { if (node.getNodeType() == ASTNode.FIELD_DECLARATION) { for (Object obj : node.fragments()) { if (obj instanceof VariableDeclaration) { VariableDeclaration vd = (VariableDeclaration) obj; Variable field = new Variable(); field.setModifier(node.getModifiers()); field.setType(project.resolveClass(ParsingHelper.getFullNameWithSimpleName( node.getType().toString(), javaClass.getPackage(), javaClass.getImports()))); field.setName(vd.getName().getFullyQualifiedName()); field.setValue(StringHelper.safeToString(vd.getInitializer())); node.accept(new AnnotationParsingVisitor(field, ASTNode.FIELD_DECLARATION)); field.setNode(vd); javaClass.addField(field); } } } return super.visit(node); }