List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration accept
public final void accept(ASTVisitor visitor)
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w .ja v a 2 s . c o m*/ public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } // @Inria pushNode(node, node.getName().toString()); visitListAsNode(EntityType.MODIFIERS, node.modifiers()); visitListAsNode(EntityType.TYPE_ARGUMENTS, node.typeParameters()); if (node.getSuperclassType() != null) { node.getSuperclassType().accept(this); } visitListAsNode(EntityType.SUPER_INTERFACE_TYPES, node.superInterfaceTypes()); // @Inria // Change Distiller does not check the changes at Class Field declaration for (FieldDeclaration fd : node.getFields()) { fd.accept(this); } // @Inria // Visit Declaration and Body (inside MD visiting) for (MethodDeclaration md : node.getMethods()) { md.accept(this); } return false; }
From source file:edu.cmu.cs.crystal.cfg.eclipse.EclipseCFG.java
License:Open Source License
@Override public boolean visit(MethodDeclaration node) { EclipseCFGNode method = nodeMap.get(node); EclipseCFGNode implicitCatch;/* w w w . j a v a2 s .com*/ excpReturns = new HashMap<ITypeBinding, EclipseCFGNode>(); undeclExit = new EclipseCFGNode(null); createEdge(undeclExit, method); undeclExit.setName("(error)"); exceptionMap.pushCatch(undeclExit, node.getAST().resolveWellKnownType("java.lang.Throwable")); for (Name name : (List<Name>) node.thrownExceptions()) { implicitCatch = new EclipseCFGNode(null); createEdge(implicitCatch, method); implicitCatch.setName("(throws)"); exceptionMap.pushCatch(implicitCatch, (ITypeBinding) name.resolveBinding()); excpReturns.put(name.resolveTypeBinding(), implicitCatch); } uberReturn = new EclipseCFGNode(null); uberReturn.setName("(uber-return)"); createEdge(uberReturn, method); if (node.isConstructor()) { TypeDeclaration type = (TypeDeclaration) node.getParent(); for (FieldDeclaration field : type.getFields()) { if (!Modifier.isStatic(field.getModifiers())) field.accept(this); } } // visit the statements individually. // we'll need to put them together by hand later so we can insert the // field decls // into constructors. for (ASTNode param : (List<ASTNode>) node.parameters()) param.accept(this); if (node.getBody() != null) for (ASTNode stmt : (List<ASTNode>) node.getBody().statements()) stmt.accept(this); return false; }
From source file:egovframework.mgt.fit.library.parser.visitor.ClassParsingVisitor.java
License:Apache License
/** * ./*from w ww .j a v a 2 s . co m*/ * @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); }
From source file:org.eclipse.recommenders.codesearch.rcp.index.indexer.FullTextIndexer2.java
License:Open Source License
@Override public void indexField(final Document document, final FieldDeclaration field) { field.accept(new LiteralsCollector(document)); }
From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils.java
License:Open Source License
/** * Visits static or instance {@link FieldDeclaration}'s. *///from w w w.j a va2 s . c om private static void visitFields(ExecutionFlowFrameVisitor visitor, TypeDeclaration typeDeclaration, boolean onlyStatic) { FieldDeclaration[] fields = typeDeclaration.getFields(); for (FieldDeclaration fieldDeclaration : fields) { boolean isStatic = isStatic(fieldDeclaration); if (onlyStatic && isStatic) { fieldDeclaration.accept(visitor); } if (!onlyStatic && !isStatic) { fieldDeclaration.accept(visitor); } } }
From source file:org.eclipse.wb.tests.designer.core.util.ast.AstNodeUtilsTest.java
License:Open Source License
public void test_moveNode() throws Exception { TypeDeclaration typeDeclaration = createTypeDeclaration_TestC("int m_value;"); FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0]; // remember ranges final LinkedList<Integer> ranges = Lists.newLinkedList(); fieldDeclaration.accept(new ASTVisitor() { @Override/*from w ww . j a v a 2s . c om*/ public void preVisit(ASTNode node) { ranges.add(node.getStartPosition()); ranges.add(node.getLength()); } }); // do move int targetPosition = 1; final int delta = targetPosition - fieldDeclaration.getStartPosition(); AstNodeUtils.moveNode(fieldDeclaration, targetPosition); // compare ranges fieldDeclaration.accept(new ASTVisitor() { @Override public void preVisit(ASTNode node) { assertEquals(ranges.removeFirst(), Integer.valueOf(node.getStartPosition() - delta)); assertEquals(ranges.removeFirst(), Integer.valueOf(node.getLength())); } }); }
From source file:org.eclipse.wst.xml.ui.internal.contentassist.tapestry.TapestryComponentCompletionProposalComputer.java
License:Open Source License
private void goThroughClass(String ClassContent) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(ClassContent.toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor() { private String elNodeName; private boolean intoEL; private boolean definedId; public void endVisit(FieldDeclaration node) { elNodeName = ""; intoEL = false;/*w w w . j a v a 2 s . co m*/ definedId = false; node.accept(new ASTVisitor() { public void endVisit(MarkerAnnotation node) { intoEL = node.getTypeName().toString().equals(TapestryContants.COMPONENT_PROPERTY); super.endVisit(node); } public void endVisit(NormalAnnotation node) { intoEL = node.getTypeName().toString().equals(TapestryContants.COMPONENT_PROPERTY); List values = node.values(); for (int i = 0; i < values.size(); i++) { MemberValuePair pair = (MemberValuePair) values.get(i); if (pair.getName().toString().equals("id") && !pair.getValue().toString().trim().isEmpty()) { definedId = true; elNodeName = pair.getValue().toString().trim(); if (elNodeName.startsWith("\"")) elNodeName = elNodeName.substring(1); if (elNodeName.endsWith("\"")) elNodeName = elNodeName.substring(0, elNodeName.length() - 1); } } super.endVisit(node); } public void endVisit(VariableDeclarationFragment node) { if (!definedId) elNodeName = node.getName().toString(); super.endVisit(node); } }); super.endVisit(node); if (intoEL) componentList.add(elNodeName); } }); }
From source file:org.eclipse.wst.xml.ui.internal.contentassist.tapestry.TapestryELCompletionProposalComputer.java
License:Open Source License
private void goThroughClass(String ClassContent) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(ClassContent.toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor() { private String elNodeName; private boolean intoEL; public void endVisit(FieldDeclaration node) { elNodeName = ""; intoEL = false;/* w w w .j av a 2 s. com*/ node.accept(new ASTVisitor() { public void endVisit(MarkerAnnotation node) { intoEL = node.getTypeName().toString().equals(TapestryContants.ANNOTATION_PROPERTY); super.endVisit(node); } public void endVisit(NormalAnnotation node) { intoEL = node.getTypeName().toString().equals(TapestryContants.ANNOTATION_PROPERTY); List values = node.values(); for (int i = 0; i < values.size(); i++) { MemberValuePair pair = (MemberValuePair) values.get(i); if (pair.getName().toString().equals("read") && pair.getValue().toString().equals("false")) intoEL = false; } super.endVisit(node); } public void endVisit(VariableDeclarationFragment node) { elNodeName = node.getName().toString(); super.endVisit(node); } }); super.endVisit(node); if (intoEL) addIfNotExist(elNodeName, propList); } public boolean visit(MethodDeclaration node) { SimpleName name = node.getName(); String methodName = name.toString(); if (node.getReturnType2() != null && node.getModifiers() == Modifier.PUBLIC && !(node .getReturnType2().isPrimitiveType() && ((PrimitiveType) node.getReturnType2()).getPrimitiveTypeCode() == PrimitiveType.VOID)) { if (methodName.startsWith("is") && methodName.length() > 2) { String propName = getPropertyName(methodName.substring(2)); addIfNotExist(propName, propList); //methodList.add(methodName + "()"); } else if (methodName.startsWith("get") && methodName.length() > 3) { String propName = getPropertyName(methodName.substring(3)); addIfNotExist(propName, propList); //methodList.add(methodName + "()"); } else { methodList.add(methodName + "()"); } } return false; } private String getPropertyName(String name) { if (name.length() > 1) return name.substring(0, 1).toLowerCase() + name.substring(1); else return name.toLowerCase(); } }); }
From source file:org.eclipse.wst.xml.ui.internal.contentassist.tapestry.TapestryRootComponentsProposalComputer.java
License:Open Source License
private void goThroughClass(ICompilationUnit ClassContent, final String contextTypeId) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(ClassContent);/* w ww. j a v a 2s. c om*/ parser.setKind(ASTParser.K_COMPILATION_UNIT); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor() { private boolean parameter = false; private String paramName = ""; public void endVisit(FieldDeclaration node) { paramName = ""; parameter = false; node.accept(new ASTVisitor() { public void endVisit(MarkerAnnotation node) { parameter = node.getTypeName().toString().equals(TapestryContants.ANNOTATION_PARAMETER); super.endVisit(node); } public void endVisit(NormalAnnotation node) { parameter = node.getTypeName().toString().equals(TapestryContants.ANNOTATION_PARAMETER); List values = node.values(); for (int i = 0; i < values.size(); i++) { MemberValuePair pair = (MemberValuePair) values.get(i); if (pair.getName().toString().equals("read") && pair.getValue().toString().equals("false")) parameter = false; } super.endVisit(node); } public void endVisit(VariableDeclarationFragment node) { paramName = node.getName().toString(); super.endVisit(node); } }); super.endVisit(node); if (parameter) { Template template = new Template(paramName, "add attribute " + paramName, contextTypeId, buildAttributeInsertCode(paramName), true); components.add(template); } } }); }
From source file:org.modeshape.sequencer.java.AbstractJavaMetadata.java
License:Open Source License
protected String getFieldName(FieldDeclaration fieldDeclaration) { FieldVisitor visitor = new FieldVisitor(); fieldDeclaration.accept(visitor); return visitor.name; }