Example usage for org.eclipse.jdt.core IType getHandleIdentifier

List of usage examples for org.eclipse.jdt.core IType getHandleIdentifier

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IType getHandleIdentifier.

Prototype

String getHandleIdentifier();

Source Link

Document

Returns a string representation of this element handle.

Usage

From source file:com.google.gwt.eclipse.core.uibinder.model.UiBinderSubtypeToUiXmlIndex.java

License:Open Source License

private void persistEntry(IMemento memento, IType uiBinderSubtype, IPath uiXmlPath) {
    memento.putString(KEY_UIBINDER_SUBTYPE, uiBinderSubtype.getHandleIdentifier());
    memento.putString(KEY_UI_XML_PATH, uiXmlPath.toString());
}

From source file:edu.buffalo.cse.green.test.GreenTest.java

License:Open Source License

public void testJML_CompilationUnitMove() throws Exception {
    // create the target package and move the CU there
    IPackageFragment toPack = createPackage(TARGET_PACKAGE_NAME);
    _sourceClass.getType().getCompilationUnit().move(toPack, null, null, false, PM);

    // find the type after it was moved
    List<IType> types = (ArrayList<IType>) (List) ROOT.getElementsOfKind(IJavaElement.TYPE);

    for (IType type : types) {
        String handle = type.getHandleIdentifier();

        if ((handle.indexOf("<" + TARGET_PACKAGE_NAME + "{") != -1)
                && (handle.endsWith("[" + SOURCE_CLASS_NAME))) {
            return;
        }/*from  w ww  . j  a v a  2 s. c o  m*/
    }

    fail(FAIL_TYPE_DOES_NOT_EXIST);
}

From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java

License:Open Source License

/**
 * Initialise the created types and populated them with operation properties and inner types.
 * /*from   www.  jav  a 2 s .c om*/
 * This code modifies Java2UMLConverter.initializeTypes() to handle AspectJ elements.
 */
@Override
protected void initializeTypes(Package packageObject, IPackageFragment fragment) throws JavaModelException

{
    ajModel = AJProjectModelFactory.getInstance().getModelForJavaElement(fragment);
    for (IJavaElement javaElement : fragment.getChildren()) {
        if (javaElement instanceof ICompilationUnit) {
            ICompilationUnit unit = (ICompilationUnit) javaElement;
            //            AJParseTree tree = new AJParseTree(unit);
            for (IType type : unit.getAllTypes()) {
                String typeName = type.getElementName();
                NamedElement element = packageObject.getOwnedMember(typeName);
                if (element == null && type.getParent() != null) {
                    element = findInnerType(packageObject, type, typeName);
                }

                if (element instanceof Interface) {
                    Interface interfaceObject = (Interface) element;

                    // Super interfaces
                    for (String interfaceName : type.getSuperInterfaceNames()) {
                        Type interfaceType = findType(packageObject, interfaceName);
                        if (interfaceType == null && type.getParent() != null) {
                            interfaceType = findInnerType(packageObject, type, typeName);
                        }

                        if (interfaceType != null && interfaceType instanceof Classifier) {
                            interfaceObject.createGeneralization((Classifier) interfaceType);
                        }
                    }

                    // Inner objects
                    createProperties(type, interfaceObject);
                    createOperations(type, interfaceObject);
                } else if (element instanceof Enumeration) {
                    Enumeration enumeration = (Enumeration) element;

                    for (String interfaceName : type.getSuperInterfaceNames()) {
                        Type interfaceType = findType(packageObject, interfaceName);
                        if (interfaceType == null) {
                            interfaceType = findGenericType(packageObject, interfaceName);
                        }

                        if (interfaceType == null && type.getParent() != null) {
                            interfaceType = findInnerType(packageObject, type, typeName);
                        }

                        if (interfaceType != null && interfaceType instanceof Interface) {
                            Classifier classifier = (Classifier) interfaceType;
                            if (enumeration.getGeneralization(classifier) == null) {
                                enumeration.createGeneralization(classifier);
                            }
                        }
                    }
                    // Inner objects
                    createProperties(type, enumeration);
                    createOperations(type, enumeration);

                } else if (element instanceof Class) {
                    Class classObject = (Class) element;
                    // Super Interfaces
                    for (String interfaceName : type.getSuperInterfaceNames()) {
                        Type interfaceType = findType(packageObject, interfaceName);
                        if (interfaceType == null) {
                            interfaceType = findGenericType(packageObject, interfaceName);
                        }

                        if (interfaceType == null && type.getParent() != null) {
                            interfaceType = findInnerType(packageObject, type, typeName);
                        }

                        if (interfaceType != null && interfaceType instanceof Interface) {
                            Interface interf = (Interface) interfaceType;

                            if (classObject.getInterfaceRealization(interfaceName, interf) == null) {
                                classObject.createInterfaceRealization(interfaceName, interf);
                            }
                        }
                    }

                    // Generalization
                    String superClassName = type.getSuperclassName();
                    Type classType = findType(packageObject, superClassName);
                    if (classType == null && type.getParent() != null) {
                        classType = findInnerType(packageObject, type, typeName);
                    }

                    if (classType == null) {
                        classType = findOrCreateType(packageObject, superClassName);
                    }

                    if (classType != null && classType instanceof Classifier) {
                        Classifier classifier = (Classifier) classType;
                        // Create generalization only if it is needed
                        if (classObject.getGeneralization(classifier) == null) {
                            classObject.createGeneralization(classifier);
                        }
                    }
                    /*
                     * Eventually, here's what I need to do.  I need to find the 
                     * ProgramElement that corresponds to the class; if it's an
                     * Aspect, then plug in the Aspect stereotype. (For now, I'll
                     * hand-wave it by sticking in a comment to syserr.)
                     * 
                     * Don't know if I'll try to handle the intertype stuff here,
                     * or if I'll push that down into createProperties/createOperations.
                     * Probably the former, which means I wouldn't call createProperties
                     * or createOperations at all for Aspects.
                     */
                    IProgramElement ajElement = javaElementToProgramElement(type);
                    if (ajElement.getKind().toString().equals("aspect")) {
                        System.err.println("aspect found:  javaElement " + typeName + " (handle "
                                + type.getHandleIdentifier() + "), programElement " + ajElement.getName()
                                + ", UML object = " + classObject.getQualifiedName());
                        Stereotype aspectST = profile.getStereotype("Aspect");
                        try {
                            classObject.applyStereotype(aspectST);
                        } catch (Exception e) {
                            System.err.println(
                                    "Exception attempting to apply Aspect stereotype to " + typeName + ":");
                            e.printStackTrace();
                        }
                        //Extract elements from the Program Element
                        createAjFeatures(type, ajElement, classObject);

                    } else {

                        // Inner objects
                        createProperties(type, classObject);
                        createOperations(type, classObject);
                    }
                }
            }
        }
    }
    addAspectRelationships(ajModel, packageObject, fragment);
}

From source file:fr.imag.adele.cadse.cadseg.managers.dataModel.EnumTypeManager.java

License:Apache License

public static IType getSelectedEnumQualifiedClass(Item enumType, boolean attemptToResolve) {
    String typeStr = enumType.getAttribute(CadseGCST.ENUM_TYPE_at_JAVA_CLASS_);
    IType ret = null;//from w  ww .  ja  v a  2  s  .c o m
    if (typeStr != null && typeStr.length() != 0) {
        ret = (IType) JavaCore.create(typeStr);
    }
    if (ret != null && attemptToResolve) {
        IJavaProject jp = ret.getJavaProject();
        try {
            // bug le type peut etre dans un type et avoir ete mis  jour et
            // donc pointer sur un ancien jar...
            // il faut le rechercher
            IType ret2 = jp.findType(ret.getFullyQualifiedName());
            if (ret2 != null) {
                ret = ret2;
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    if (ret == null && typeStr != null && typeStr.length() > 0) {
        Item cadseDef = enumType.getPartParent(CadseGCST.CADSE_DEFINITION);
        IJavaProject jp = cadseDef.getMainMappingContent(IJavaProject.class);
        try {
            final IType findType = jp.findType(typeStr);
            if (findType != null) {
                enumType.setAttribute(CadseGCST.ENUM_TYPE_at_JAVA_CLASS_, findType.getHandleIdentifier());
            }
            return findType;
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (CadseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return ret;
}

From source file:navclus.userinterface.classdiagram.java.analyzer.RelationAnalyzer.java

License:Open Source License

public boolean doesDeclare(TypeNode node1, TypeNode node2) throws JavaModelException {

    if ((node1 == null) || (node2 == null))
        return false;

    IType[] types = node1.getType().getTypes();
    for (IType tp : types) {
        if (tp.getHandleIdentifier().equals(node2.getType().getHandleIdentifier())) {
            return true;
        }//  w  ww.  j ava 2s  .c o  m
    }

    return false;
}

From source file:navclus.userinterface.classdiagram.java.analyzer.RelationAnalyzer.java

License:Open Source License

public boolean isDeclared(TypeNode node1, TypeNode node2) throws JavaModelException {

    IType[] types = node1.getType().getTypes();

    if (types.length == 0)
        return false;
    else {/* ww  w. j  a  v a 2 s . c om*/
        for (IType tp : types) {
            if (tp.getHandleIdentifier().equals(node2.getType().getHandleIdentifier())) {
                return true;
            }
        }

        for (IType tp : types) {
            if (isDeclared(tp, node2.getType()))
                return true;
        }
    }
    return false;
}

From source file:navclus.userinterface.classdiagram.java.analyzer.RelationAnalyzer.java

License:Open Source License

public boolean isDeclared(IType type1, IType type2) throws JavaModelException {

    IType[] types = type1.getTypes();/*from   w  w w.j  a v a 2  s  . c  o m*/

    if (types.length == 0)
        return false;
    else {
        for (IType tp : types) {
            if (tp.getHandleIdentifier().equals(type2.getHandleIdentifier())) {
                return true;
            }
        }

        for (IType tp : types) {
            if (isDeclared(tp, type2))
                return true;
        }
    }
    return false;
}

From source file:navclus.userinterface.classdiagram.java.analyzer.RelationModel.java

License:Open Source License

public void removeSuperPart(IType type) { // doing
    List<ConnectionNode> dummyconnectionparts = new ArrayList<ConnectionNode>();

    for (ConnectionNode preConnection : rootNode.getStructuralRelations()) {
        if (preConnection.getDestinationNode().getType().getHandleIdentifier()
                .equals(type.getHandleIdentifier())) {
            if (preConnection.getTag().equals("extends") || preConnection.getTag().equals("implements"))
                dummyconnectionparts.add(preConnection);
        }/*w  w w  . j  ava 2  s .c om*/
    }
    rootNode.removeStructuralRelations(dummyconnectionparts);
}

From source file:navclus.userinterface.classdiagram.java.analyzer.RelationModel.java

License:Open Source License

public void removeConnectionPart(IType type, String tag) { // doing
    List<ConnectionNode> dummyconnectionparts = new ArrayList<ConnectionNode>();

    for (ConnectionNode preConnection : rootNode.getStructuralRelations()) {
        if (preConnection.getSourceNode().getType().getHandleIdentifier().equals(type.getHandleIdentifier())) {
            if (preConnection.getTag().equals(tag))
                dummyconnectionparts.add(preConnection);
        }//from   ww w. j av  a2 s .c  o m
    }
    rootNode.removeStructuralRelations(dummyconnectionparts);
}

From source file:navclus.userinterface.classdiagram.java.analyzer.RootModel.java

License:Open Source License

public boolean addElement(IType topType, IJavaElement locElement) {

    boolean bExist = false;

    if (topType == null)
        return false;
    if (locElement == null)
        return false;
    if (topType.getHandleIdentifier().equals(locElement.getHandleIdentifier()))
        return false;

    // finding the node having itypeTop
    // if finding the node, add the javaelement methods
    IType locType = (IType) locElement.getAncestor(IJavaElement.TYPE);
    TypeNode topNode = rootNode.findNode(topType);
    TypeNode locNode = rootNode.findNode(locType);
    if (topNode == null)
        return false;

    boolean bCreateType = false;
    if (locNode == null) {
        locNode = createType(locType);//  w  ww  . j a va 2  s  . co m
        //         rootNode.synchronizeNodesinView();
        bCreateType = true;
    }

    if (locNode != null) {
        if (!topType.getHandleIdentifier().equals(locType.getHandleIdentifier())) {
            topNode.embeddedTypes.add(locType);
            TypeHistory.setPreType(locType);
        }

        if (locElement instanceof IMethod) {
            bExist = locNode.addMethod((IMethod) locElement);
        } else if (locElement instanceof IField) {
            bExist = locNode.addField((IField) locElement);
        } else if (bCreateType)
            return true;
        else
            return false;
    }

    if (bExist) {
        return true;
    } else
        return false;
}