Example usage for org.eclipse.jdt.core.jdom IDOMType getSuperInterfaces

List of usage examples for org.eclipse.jdt.core.jdom IDOMType getSuperInterfaces

Introduction

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

Prototype

public String[] getSuperInterfaces();

Source Link

Document

Returns the names of interfaces that this type implements or extends, in the order in which they are listed in the source, or an empty array if no superinterfaces are present.

Usage

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

License:Open Source License

protected void applyPullRules(IDOMNode sourceNode, IDOMNode targetNode) {
    try {//from   w  w  w  . j a  va2s .c o 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();
    }
}