List of usage examples for org.eclipse.jdt.internal.core SourceField getElementName
@Override
public String getElementName()
From source file:org.eclipse.che.jdt.internal.compiler.parser.SourceTypeConverter.java
License:Open Source License
private FieldDeclaration convert(SourceField fieldHandle, TypeDeclaration type, CompilationResult compilationResult) throws JavaModelException { SourceFieldElementInfo fieldInfo = (SourceFieldElementInfo) fieldHandle.getElementInfo(); FieldDeclaration field = new FieldDeclaration(); int start = fieldInfo.getNameSourceStart(); int end = fieldInfo.getNameSourceEnd(); field.name = fieldHandle.getElementName().toCharArray(); field.sourceStart = start;// www . j a va2s .co m field.sourceEnd = end; field.declarationSourceStart = fieldInfo.getDeclarationSourceStart(); field.declarationSourceEnd = fieldInfo.getDeclarationSourceEnd(); int modifiers = fieldInfo.getModifiers(); boolean isEnumConstant = (modifiers & ClassFileConstants.AccEnum) != 0; if (isEnumConstant) { field.modifiers = modifiers & ~ClassFileConstants.AccEnum; // clear AccEnum bit onto AST (binding will add it) } else { field.modifiers = modifiers; field.type = createTypeReference(fieldInfo.getTypeName(), start, end); } // convert 1.5 specific constructs only if compliance is 1.5 or above if (this.has1_5Compliance) { /* convert annotations */ field.annotations = convertAnnotations(fieldHandle); } /* conversion of field constant */ if ((this.flags & FIELD_INITIALIZATION) != 0) { char[] initializationSource = fieldInfo.getInitializationSource(); if (initializationSource != null) { if (this.parser == null) { this.parser = new Parser(this.problemReporter, true); } this.parser.parse(field, type, this.unit, initializationSource); } } /* conversion of local and anonymous types */ if ((this.flags & LOCAL_TYPE) != 0) { IJavaElement[] children = fieldInfo.getChildren(); int childrenLength = children.length; if (childrenLength == 1) { field.initialization = convert(children[0], isEnumConstant ? field : null, compilationResult); } else if (childrenLength > 1) { ArrayInitializer initializer = new ArrayInitializer(); field.initialization = initializer; Expression[] expressions = new Expression[childrenLength]; initializer.expressions = expressions; for (int i = 0; i < childrenLength; i++) { expressions[i] = convert(children[i], isEnumConstant ? field : null, compilationResult); } } } return field; }
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;//w w w. java2 s.com 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); }