Example usage for org.eclipse.jdt.core.jdom IDOMMethod getParameterTypes

List of usage examples for org.eclipse.jdt.core.jdom IDOMMethod getParameterTypes

Introduction

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

Prototype

public String[] getParameterTypes();

Source Link

Document

Returns the type names for the parameters of this method in the order they are declared, or null if no parameters are declared.

Usage

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

License:Open Source License

protected void applyPullRules(IDOMNode sourceNode, IDOMNode targetNode) {
    try {/*w  w w.  j  a  va  2s .co m*/
        for (Iterator pullRules = jControlModel.getPullRules().iterator(); pullRules.hasNext();) {
            JControlModel.PullRule pullRule = (JControlModel.PullRule) pullRules.next();
            if (sourcePatternDictionary.isMarkedUp(pullRule.getSourceMarkup(), sourceNode)
                    && targetPatternDictionary.isMarkedUp(pullRule.getTargetMarkup(), targetNode)
                    && pullRule.getSourceGetFeature().getFeatureMethod() != null
                    && pullRule.getSourceGetFeature().getFeatureClass().isInstance(sourceNode)
                    && pullRule.getTargetPutFeature().getFeatureMethod() != null
                    && pullRule.getTargetPutFeature().getFeatureClass().isInstance(targetNode)) {
                Method sourceGetMethod = pullRule.getSourceGetFeature().getFeatureMethod();
                Object value = sourceGetMethod.invoke(sourceNode, noArguments);
                Method targetPutMethod = pullRule.getTargetPutFeature().getFeatureMethod();
                if (!sourceGetMethod.getReturnType().isArray() || targetPutMethod.getParameterTypes()[0]
                        .isAssignableFrom(sourceGetMethod.getReturnType())) {
                    if (value instanceof String) {
                        String stringValue = (String) value;
                        stringValue = applyFormatRules(stringValue);
                        Pattern sourceTransfer = pullRule.getSourceTransfer();
                        if (sourceTransfer != null) {
                            String oldStringValue = (String) sourceGetMethod.invoke(targetNode, noArguments);
                            Matcher sourceMatcher = sourceTransfer.matcher(stringValue);
                            Matcher targetMatcher = sourceTransfer.matcher(oldStringValue);
                            if (sourceMatcher.groupCount() >= 1 && targetMatcher.groupCount() >= 1) {
                                StringBuffer result = new StringBuffer();
                                int index = 0;
                                while (sourceMatcher.find() && targetMatcher.find()) {
                                    result.append(stringValue.substring(index, sourceMatcher.start(1)));
                                    result.append(targetMatcher.group(1));
                                    index = sourceMatcher.end(1);
                                }
                                // There must be at least one match.
                                //
                                if (result.length() == 0) {
                                    stringValue = null;
                                } else {
                                    result.append(stringValue.substring(index));
                                    stringValue = result.toString();
                                }
                            } else {
                                stringValue = null;
                            }
                        }
                        value = stringValue;
                    }
                    if (value != null || targetPutMethod.getName().equals("setInitializer")
                            || targetPutMethod.getName().equals("setSuperclass")
                            || targetPutMethod.getName().equals("setExceptions")) {
                        // Ignore if there is not substantial change.
                        //
                        Object oldValue = sourceGetMethod.invoke(targetNode, noArguments);
                        if (value == null ? oldValue == null : value.equals(oldValue)) {
                            continue;
                        } else if (targetPutMethod.getName().equals("setSuperclass")) {
                            if (oldValue != null && value != null
                                    && ((String) oldValue).trim().equals(((String) value).trim())) {
                                continue;
                            }
                        }

                        // The block pattern needs to prevent merging of the return type, to allow changing from the modeled data
                        // type (Bugzilla 102209). 
                        //
                        if (sourceGetMethod.getName().equals("getReturnType")
                                && jControlModel.getBlockPattern() != null
                                && ((IDOMMethod) targetNode).getComment() != null
                                && jControlModel.getBlockPattern()
                                        .matcher(((IDOMMethod) targetNode).getComment()).find()) {
                            continue;
                        }

                        targetPutMethod.invoke(targetNode, new Object[] { value });
                        if (targetPutMethod.getName().equals("setBody") && sourceNode instanceof IDOMMethod) {
                            IDOMMethod sourceMethod = (IDOMMethod) sourceNode;
                            IDOMMethod targetMethod = (IDOMMethod) targetNode;
                            String[] sourceParameterNames = sourceMethod.getParameterNames();
                            String[] targetParameterTypes = targetMethod.getParameterTypes();
                            targetMethod.setParameters(targetParameterTypes, sourceParameterNames);
                        }
                    }
                } else {
                    ArrayList additionalStrings = new ArrayList();
                    String[] sourceStrings = (String[]) value;
                    if (sourceStrings != null) {
                        additionalStrings.addAll(Arrays.asList(sourceStrings));
                    }

                    if (targetPutMethod.getName().equals("addSuperInterface")) {
                        Pattern sourceTransfer = pullRule.getSourceTransfer();
                        if (sourceTransfer != null) {
                            String comment = ((IDOMMember) targetNode).getComment();
                            Matcher matcher = sourceTransfer.matcher(comment);
                            while (matcher.find() && matcher.groupCount() >= 1) {
                                String clientStrings = comment.substring(matcher.start(matcher.groupCount()),
                                        matcher.end(matcher.groupCount()));

                                for (StringTokenizer stringTokenizer = new StringTokenizer(clientStrings,
                                        ", \t\n\r\f"); stringTokenizer.hasMoreTokens();) {
                                    String token = stringTokenizer.nextToken();
                                    if (!additionalStrings.contains(token)) {
                                        additionalStrings.add(token);
                                    }
                                }
                            }
                        }

                        IDOMType type = (IDOMType) targetNode;
                        String[] superInterfaces = (String[]) additionalStrings
                                .toArray(new String[additionalStrings.size()]);
                        if (type.getSuperInterfaces() == null ? superInterfaces.length != 0
                                : !Arrays.equals(type.getSuperInterfaces(), superInterfaces)) {
                            type.setSuperInterfaces(
                                    (String[]) additionalStrings.toArray(new String[additionalStrings.size()]));
                        }
                    } else {
                        String[] oldStringValues = (String[]) sourceGetMethod.invoke(targetNode, noArguments);
                        List old = oldStringValues == null ? Collections.EMPTY_LIST
                                : Arrays.asList(oldStringValues);
                        for (Iterator i = additionalStrings.iterator(); i.hasNext();) {
                            String string = (String) i.next();
                            if (!old.contains(string)) {
                                targetPutMethod.invoke(targetNode, new Object[] { string });
                            }
                        }
                    }
                }
            }
        }

    } catch (InvocationTargetException exception) {
        // exception.printStackTrace();
    } catch (IllegalAccessException exception) {
        // exception.printStackTrace();
    }
}

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  ww w  .  j  ava2s. 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 "";
    }
    }
}