Example usage for org.eclipse.jdt.internal.core SourceField getTypeSignature

List of usage examples for org.eclipse.jdt.internal.core SourceField getTypeSignature

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core SourceField getTypeSignature.

Prototype

@Override
public String getTypeSignature() throws JavaModelException 

Source Link

Usage

From source file:org.eclipse.gemoc.execution.concurrent.ccsljavaxdsml.ui.builder.GemocLanguageDesignerBuilder.java

License:Open Source License

@SuppressWarnings("restriction")
protected void createLanguageSpecificDSAHelper(String allAspects, IProject project, String fullLanguageName,
        ManifestChanger manifestChanger)
        throws CoreException, BundleException, IOException, ClassNotFoundException {
    // create the java class
    int lastDot = fullLanguageName.lastIndexOf(".");
    if (lastDot == -1)
        lastDot = 0;//from w  w w. ja  v  a 2 s  .  co m
    String languageName = fullLanguageName.substring(lastDot + 1);
    String languageToUpperFirst = getLanguageNameWithFirstUpper(languageName);
    String packageName = getPackageName(languageName);
    String folderName = getFolderName(languageName);

    String fileContent = BuilderTemplates.RTD_ACCESSOR_CLASS_TEMPLATE;
    fileContent = fileContent.replaceAll(Pattern.quote("${package.name}"), packageName);
    fileContent = fileContent.replaceAll(Pattern.quote("${language.name.toupperfirst}"), languageToUpperFirst);

    StringBuilder sbContent = new StringBuilder();
    StringBuilder sbExtraImport = new StringBuilder();
    setAspectsWithRTDs = new HashSet<String>();
    mapAspectProperties = ArrayListMultimap.create();

    for (String a : allAspects.trim().split(",")) {
        String originalAspectClassName = a;
        int dot = a.lastIndexOf('.');
        a = a + a.substring(dot + 1) + "Properties";
        char[][] qualifications;
        String simpleName;
        if (dot != -1) {
            qualifications = new char[][] { a.substring(0, dot).toCharArray() };
            simpleName = a.substring(dot + 1);
        } else {
            qualifications = null;
            simpleName = a;
        }
        char[][] typeNames = new char[][] { simpleName.toCharArray() };

        IType aspectClass = findAnyTypeInWorkspace(qualifications, typeNames);
        IJavaElement[] allChildren = aspectClass.getChildren();
        for (int i = 0; i < allChildren.length; i++) {
            IJavaElement javaElem = allChildren[i];
            if (javaElem instanceof SourceField) {
                setAspectsWithRTDs.add(originalAspectClassName);
                SourceField f = (SourceField) javaElem;
                mapAspectProperties.put(originalAspectClassName, f.getElementName());
                //            if(f.isAccessible()) {

                String fieldTypeName = f.getTypeSignature().substring(1, f.getTypeSignature().length() - 1);
                int dotType = fieldTypeName.lastIndexOf('.');
                char[][] qualificationsType;
                String simpleNameType;
                if (dotType != -1) {
                    qualificationsType = new char[][] { fieldTypeName.substring(0, dotType).toCharArray() };
                    simpleNameType = fieldTypeName.substring(dotType + 1);
                } else {
                    qualificationsType = null;
                    simpleNameType = fieldTypeName;
                }
                //remove template param
                if (simpleNameType.contains("<")) {
                    simpleNameType = simpleNameType.replaceAll("<(.*)>", "");
                }

                char[][] typeNamesType = new char[][] { simpleNameType.toCharArray() };
                IType fieldType = findAnyTypeInWorkspace(qualificationsType, typeNamesType);
                if (fieldType != null) {
                    String fieldName = fieldType.getElementName();
                    if (!fieldName.equals("Object") && !fieldName.equals("String")) {
                        sbExtraImport.append("import " + fieldType.getFullyQualifiedName() + ";\n");
                    }
                    sbContent.append("  public static " + simpleNameType + " get" + f.getElementName()
                            + "(EObject eObject) {\n" + "      return (" + simpleNameType
                            + ")  getAspectProperty(eObject, \"" + fullLanguageName + "\", \""
                            + originalAspectClassName + "\", \"" + f.getElementName() + "\");\n" + "   }\n");

                    sbContent.append("   public static boolean set" + f.getElementName() + "(EObject eObject, "
                            + simpleNameType + " newValue) {\n" + "      return setAspectProperty(eObject, \""
                            + fullLanguageName + "\", \"" + originalAspectClassName + "\", \""
                            + f.getElementName() + "\", newValue);\n" + "   }\n");
                } else {
                    System.out.println(typeNamesType);
                }
            }
        }
    }

    fileContent = fileContent.replaceAll(Pattern.quote("${allGettersAndSetters}"), sbContent.toString());

    fileContent = fileContent.replaceAll(Pattern.quote("${extraImports}"), sbExtraImport.toString());

    IFile file = project.getFile(Activator.EXTENSION_GENERATED_CLASS_FOLDER_NAME + folderName + "/"
            + languageToUpperFirst + Activator.RTD_ACCESSOR_CLASS_NAMEPART + ".java");
    writeFile(file, fileContent);

    IFile AspectsFile = project.getFile(Activator.EXTENSION_GENERATED_CLASS_FOLDER_NAME + folderName + "/"
            + languageToUpperFirst + Activator.RTD_ASPECTS_CLASS_NAMEPART + ".list");

    StringBuilder sbAspects = new StringBuilder();
    setAspectsWithRTDs.stream().forEachOrdered(s -> sbAspects.append(s + "\n"));
    writeFile(AspectsFile, sbAspects.toString());

    // add the rtd accessor package to exported packages
    manifestChanger.addExportPackage(packageName);
}