Example usage for org.eclipse.jdt.core.jdom IDOMNode METHOD

List of usage examples for org.eclipse.jdt.core.jdom IDOMNode METHOD

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.jdom IDOMNode METHOD.

Prototype

int METHOD

To view the source code for org.eclipse.jdt.core.jdom IDOMNode METHOD.

Click Source Link

Document

Node type constant indicating a method (or constructor) declaration.

Usage

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  .  ja  va 2  s. c om*/
            current = current.getNextNode();
        }
    }
    return null;
}

From source file:org.eclipse.emf.codegen.jet.JETSkeleton.java

License:Open Source License

protected IDOMMethod getLastMethod() {
    IDOMMethod method = null;/*from  w  w w.  java  2s  .c  o  m*/
    for (IDOMNode node = compilationUnit.getFirstChild(); node != null; node = node.getNextNode()) {
        if (node.getNodeType() == IDOMNode.TYPE) {
            for (IDOMNode child = node.getFirstChild(); child != null; child = child.getNextNode()) {
                if (child.getNodeType() == IDOMNode.METHOD) {
                    method = (IDOMMethod) child;
                }
            }
        }
    }
    return method;
}

From source file:org.eclipse.emf.codegen.jmerge.JMerger.java

License:Open Source License

protected void pullTargetType(IDOMType targetType) {
    IDOMType sourceType = (IDOMType) sourcePatternDictionary.getTypeMap()
            .get(targetPatternDictionary.getQualifiedName(targetType));

    map(sourceType, targetType);/*from  w w  w .jav  a2s .c o  m*/
    if (sourceType != null) {
        applyPullRules(sourceType, targetType);

        /*
              // PULL: Comment
              //
              String sourceComment = sourceType.getComment();
              if (sourceComment != null)
              {
                targetType.setComment(sourceComment);
              }
        */
        /*
              // PULL: Flags
              //
              int sourceFlags = sourceType.getFlags();
              targetType.setFlags(sourceFlags);
                
              // PULL: Superclass
              //
              targetType.setSuperclass(sourceType.getSuperclass());
                
              // PULL: SuperInterfaces
              //
              ArrayList additionalSuperInterfaces = new ArrayList();
              String [] sourceSuperInterfaces = sourceType.getSuperInterfaces();
              if (sourceSuperInterfaces != null)
              {
                additionalSuperInterfaces.addAll(Arrays.asList(sourceSuperInterfaces));
                String [] targetTypeSuperInterfaces = targetType.getSuperInterfaces();
                if (targetTypeSuperInterfaces != null)
                {
                  additionalSuperInterfaces.removeAll(Arrays.asList(targetType.getSuperInterfaces()));
                }
              }
              for (Iterator i = additionalSuperInterfaces.iterator(); i.hasNext(); )
              {
                String superInterface = (String)i.next();
                targetType.addSuperInterface(superInterface);
              }
        */
    }

    for (IDOMNode child = targetType.getFirstChild(); child != null; child = child.getNextNode()) {
        switch (child.getNodeType()) {
        case IDOMNode.INITIALIZER: {
            pullTargetInitializer((IDOMInitializer) child);
            break;
        }
        case IDOMNode.FIELD: {
            pullTargetField((IDOMField) child);
            break;
        }
        case IDOMNode.METHOD: {
            pullTargetMethod((IDOMMethod) child);
            break;
        }
        case IDOMNode.TYPE: {
            pullTargetType((IDOMType) child);
            break;
        }
        }
    }
}

From source file:org.eclipse.emf.codegen.jmerge.JMerger.java

License:Open Source License

protected void pushSourceType(IDOMType sourceType) {
    if (!sourceToTargetMap.containsKey(sourceType)) {
        insertClone(sourceType);/*w  w  w .  j a v  a2s  .  c  o  m*/
    } else {
        for (IDOMNode child = sourceType.getFirstChild(); child != null; child = child.getNextNode()) {
            switch (child.getNodeType()) {
            case IDOMNode.INITIALIZER: {
                pushSourceInitializer((IDOMInitializer) child);
                break;
            }
            case IDOMNode.FIELD: {
                pushSourceField((IDOMField) child);
                break;
            }
            case IDOMNode.METHOD: {
                pushSourceMethod((IDOMMethod) child);
                break;
            }
            case IDOMNode.TYPE: {
                pushSourceType((IDOMType) child);
                break;
            }
            }
        }
    }
}

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 ava 2  s  . 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

protected void analyzeType(IDOMType type) {
    typeMap.put(getQualifiedName(type), type);
    match(type);/*from  ww  w .java2s  . c o  m*/
    for (IDOMNode child = type.getFirstChild(); child != null; child = child.getNextNode()) {
        switch (child.getNodeType()) {
        case IDOMNode.INITIALIZER: {
            analyzeInitializer((IDOMInitializer) child);
            break;
        }
        case IDOMNode.FIELD: {
            analyzeField((IDOMField) child);
            break;
        }
        case IDOMNode.METHOD: {
            analyzeMethod((IDOMMethod) child);
            break;
        }
        case IDOMNode.TYPE: {
            analyzeType((IDOMType) child);
            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 av 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 "";
    }
    }
}