List of usage examples for org.eclipse.jdt.core.jdom IDOMNode getNodeType
public int getNodeType();
From source file:com.iw.plugins.spindle.wizards.project.ApplicationWizardPage.java
License:Mozilla Public License
protected void populateMethodSource(IType servletType, IProgressMonitor monitor) throws JavaModelException { String methodName = MessageUtil.getString("Tapestry.servlet.getAppMethodName"); ICompilationUnit parentCU = servletType.getCompilationUnit(); String gensource = parentCU.getSource(); DOMFactory domFactory = new DOMFactory(); IDOMCompilationUnit unit = domFactory.createCompilationUnit(gensource, servletType.getElementName()); IDOMNode current = unit.getFirstChild(); while (current.getNodeType() != IDOMNode.TYPE) { current = current.getNextNode(); }//from w ww. j a v a2 s .c om IDOMNode theType = current; IDOMMethod method = findMethod(theType, methodName); if (method == null) { method = domFactory.createMethod("protected String getApplicationSpecificationPath() {}"); theType.addChild(method); } method.setBody(getAppMethodBody()); String newContents = Utils.formatJavaCode(unit.getContents(), 0, StubUtility.getLineDelimiterUsed(parentCU)); parentCU.getBuffer().setContents(newContents); parentCU.save(monitor, true); }
From source file:com.iw.plugins.spindle.wizards.project.ApplicationWizardPage.java
License:Mozilla Public License
private IDOMMethod findMethod(IDOMNode type, String desiredMethod) { IDOMNode current = type.getFirstChild(); if (current != null) { while (true) { if (current.getNodeType() == IDOMNode.METHOD && desiredMethod.equals(current.getName())) { return (IDOMMethod) current; }//w ww . jav a 2s.c om current = current.getNextNode(); } } return null; }
From source file:org.eclipse.emf.codegen.jmerge.JMerger.java
License:Open Source License
protected IDOMNode insertClone(IDOMNode sourceNode) { IDOMNode targetNode = null;/*from w w w . j a v a2s . co m*/ switch (sourceNode.getNodeType()) { case IDOMNode.COMPILATION_UNIT: { targetNode = jdomFactory.createCompilationUnit(applyFormatRules(sourceNode.getContents()), ((IDOMCompilationUnit) sourceNode).getName()); break; } case IDOMNode.PACKAGE: { targetNode = jdomFactory.createPackage(applyFormatRules(sourceNode.getContents())); break; } case IDOMNode.IMPORT: { targetNode = jdomFactory.createImport(applyFormatRules(sourceNode.getContents())); break; } case IDOMNode.TYPE: { targetNode = jdomFactory.createType(applyFormatRules(sourceNode.getContents())); break; } case IDOMNode.INITIALIZER: { targetNode = jdomFactory.createInitializer(applyFormatRules(sourceNode.getContents())); break; } case IDOMNode.FIELD: { targetNode = jdomFactory.createField(applyFormatRules(sourceNode.getContents())); break; } case IDOMNode.METHOD: { targetNode = jdomFactory.createMethod(applyFormatRules(sourceNode.getContents())); break; } default: { targetNode = (IDOMNode) sourceNode.clone(); break; } } if (targetNode != null) { map(sourceNode, targetNode); mapChildren(sourceNode, targetNode); } else { // System.err.println("Warning: Cannot clone '" + sourceNode.getContents() + "'"); } for (IDOMNode previousNode = sourceNode.getPreviousNode(); previousNode != null; previousNode = previousNode .getPreviousNode()) { IDOMNode targetSibling = (IDOMNode) sourceToTargetMap.get(previousNode); if (targetSibling != null) { IDOMNode targetNextSibling = targetSibling.getNextNode(); if (targetNextSibling == null) { targetSibling.getParent().addChild(targetNode); } else { targetNextSibling.insertSibling(targetNode); } return targetNode; } } if (sourceNode.getParent() != null) { IDOMNode targetParent = (IDOMNode) sourceToTargetMap.get(sourceNode.getParent()); IDOMNode targetSibling = targetParent.getFirstChild(); if (targetSibling == null) { targetParent.addChild(targetNode); } else { targetSibling.insertSibling(targetNode); } } return targetNode; }
From source file:org.eclipse.emf.codegen.jmerge.JPatternDictionary.java
License:Open Source License
public String getQualifiedName(IDOMNode jdomNode) { switch (jdomNode.getNodeType()) { case IDOMNode.COMPILATION_UNIT: { return jdomNode.getName(); }//from www .jav a 2 s.c o m case IDOMNode.PACKAGE: { return jdomNode.getName(); } case IDOMNode.IMPORT: { return jdomNode.getName(); } case IDOMNode.TYPE: { return jPackage != null ? jPackage.getName() + "." + jdomNode.getName() : jdomNode.getName(); } case IDOMNode.FIELD: { return getQualifiedName(jdomNode.getParent()) + "." + jdomNode.getName(); } case IDOMNode.INITIALIZER: { String name = getQualifiedName(jdomNode.getParent()); int index = 0; for (jdomNode = jdomNode.getNextNode(); jdomNode != null; jdomNode = jdomNode.getNextNode()) { if (jdomNode.getNodeType() == IDOMNode.INITIALIZER) { ++index; } } return name + "." + index; } case IDOMNode.METHOD: { IDOMMethod jdomMethod = (IDOMMethod) jdomNode; StringBuffer result = new StringBuffer(getQualifiedName(jdomNode.getParent())); result.append("."); if (jdomMethod.isConstructor()) { result.append(jdomMethod.getParent().getName()); } else { result.append(jdomMethod.getName()); } result.append("("); //) String[] parameters = jdomMethod.getParameterTypes(); if (parameters != null) { for (int i = 0; i < parameters.length; ++i) { if (i != 0) { result.append(", "); } result.append(parameters[i]); } } // ( result.append(")"); return result.toString(); } default: { return ""; } } }