List of usage examples for org.eclipse.jdt.core.jdom IDOMNode getName
public String getName();
From source file:ac.at.tuwien.dsg.uml.stereotype.export.transformation.util.JavaClassOutputter.java
License:Open Source License
public static void outputFile(ITransformContext context, IDOMNode content) { //generate CLass output file IResource res = (IResource) context.getTargetContainer(); IPath targetPath = res.getLocation(); String filename = targetPath.toOSString() + File.separatorChar + content.getName() + ".java"; //format Code String code = content.getContents(); CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(null); TextEdit textEdit = codeFormatter.format(CodeFormatter.K_UNKNOWN, code, 0, code.length(), 0, null); IDocument doc = new Document(code); try {//from www . j av a 2 s .c om //unsure why but sometimes formatted is nu if (textEdit != null) { textEdit.apply(doc); } else { //usually errors appear due to spaces or illegal characters in property names IOException exception = new IOException("Generated document has formatting errors: \n" + code); throw new UncheckedIOException("Generated document has formatting errors: \n" + code, exception); } File myFile = new File(filename); PrintWriter fw; try { fw = new PrintWriter(myFile); for (String importString : defaultImports) { fw.write("import " + importString + ";"); fw.write("\n"); } fw.write(doc.get()); fw.flush(); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (MalformedTreeException e) { e.printStackTrace(); } catch (BadLocationException e) { e.printStackTrace(); } }
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 w w . j a v a 2s . c o m*/ current = current.getNextNode(); } } return null; }
From source file:org.eclipse.emf.codegen.jmerge.JMerger.java
License:Open Source License
protected void applySweepRules(IDOMNode targetNode) { for (Iterator sweepRules = jControlModel.getSweepRules().iterator(); sweepRules.hasNext();) { JControlModel.SweepRule sweepRule = (JControlModel.SweepRule) sweepRules.next(); if (sweepRule.getSelector() == IDOMImport.class && targetNode instanceof IDOMImport) { if (sweepRule.getMarkup().matcher(targetNode.getName()).find()) { targetNode.remove();//from ww w.ja va 2 s. co m break; } } else if (targetPatternDictionary.isMarkedUp(sweepRule.getMarkup(), targetNode) && sweepRule.getSelector().isInstance(targetNode)) { targetNode.remove(); break; } } }
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(); }/* w w w . j a v a 2s .com*/ 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 ""; } } }