Java Code Examples for org.eclipse.xtext.util.Strings#toFirstUpper()
The following examples show how to use
org.eclipse.xtext.util.Strings#toFirstUpper() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TerminalsProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private void createStringProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor, String feature, RuleCall ruleCall) { String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase()); proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName()); String displayText = proposalText; if (feature != null) displayText = displayText + " - " + ruleCall.getRule().getName(); ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal; configurable.setSelectionStart(configurable.getReplacementOffset() + 1); configurable.setSelectionLength(proposalText.length() - 2); configurable.setAutoInsertable(false); configurable.setSimpleLinkedMode(context.getViewer(), proposalText.charAt(0), '\t'); } acceptor.accept(proposal); }
Example 2
Source File: CodetemplatesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private void createStringProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor, String feature, RuleCall ruleCall) { String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase()); proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName()); String displayText = proposalText; if (feature != null) displayText = displayText + " - " + ruleCall.getRule().getName(); ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal; configurable.setSelectionStart(configurable.getReplacementOffset() + 1); configurable.setSelectionLength(proposalText.length() - 2); configurable.setAutoInsertable(false); configurable.setSimpleLinkedMode(context.getViewer(), proposalText.charAt(0), '\t'); } acceptor.accept(proposal); }
Example 3
Source File: FormalParameterBuilderFragment.java From sarl with Apache License 2.0 | 5 votes |
/** Generate the formal parameter appender. */ protected void generateFormalParameterAppender() { final CodeElementExtractor.ElementDescription parameter = getCodeElementExtractor().getFormalParameter(); final String accessor = "get" //$NON-NLS-1$ + Strings.toFirstUpper(parameter.getElementType().getSimpleName()) + "()"; //$NON-NLS-1$ final TypeReference builderInterface = getFormalParameterBuilderInterface(); final TypeReference appender = getCodeElementExtractor().getElementAppenderImpl("FormalParameter"); //$NON-NLS-1$ final StringConcatenationClient content = new StringConcatenationClient() { @Override protected void appendTo(TargetStringConcatenation it) { it.append("/** Appender of a " + getLanguageName() //$NON-NLS-1$ + " formal parameter."); //$NON-NLS-1$ it.newLine(); it.append(" */"); //$NON-NLS-1$ it.newLine(); it.append("@SuppressWarnings(\"all\")"); //$NON-NLS-1$ it.newLine(); it.append("public class "); //$NON-NLS-1$ it.append(appender.getSimpleName()); it.append(" extends "); //$NON-NLS-1$ it.append(getCodeElementExtractor().getAbstractAppenderImpl()); it.append(" implements "); //$NON-NLS-1$ it.append(builderInterface); it.append(" {"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); it.append(generateAppenderMembers(appender.getSimpleName(), builderInterface, accessor)); it.append(generateMembers(false, true)); it.append("}"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); } }; final JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(appender, content); javaFile.writeTo(getSrcGen()); }
Example 4
Source File: CheckProposalProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Get the name assigned feature in an Assignment rule call. * * @param call * a rule call * @return the assigned feature */ private String getAssignedFeature(final RuleCall call) { Assignment ass = GrammarUtil.containingAssignment(call); if (ass != null) { String result = ass.getFeature(); if (result.equals(result.toLowerCase())) { // NOPMD result = Strings.toFirstUpper(result); } return result; } return null; }
Example 5
Source File: TypeParameterBuilderFragment.java From sarl with Apache License 2.0 | 5 votes |
/** Generate the formal parameter appender. */ protected void generateTypeParameterAppender() { final CodeElementExtractor.ElementDescription parameter = getCodeElementExtractor().getTypeParameter(); final String accessor = "get" //$NON-NLS-1$ + Strings.toFirstUpper(parameter.getElementType().getSimpleName()) + "()"; //$NON-NLS-1$ final TypeReference builderInterface = getTypeParameterBuilderInterface(); final TypeReference appender = getCodeElementExtractor().getElementAppenderImpl("TypeParameter"); //$NON-NLS-1$ final StringConcatenationClient content = new StringConcatenationClient() { @Override protected void appendTo(TargetStringConcatenation it) { it.append("/** Appender of a " + getLanguageName() //$NON-NLS-1$ + " type parameter."); //$NON-NLS-1$ it.newLine(); it.append(" */"); //$NON-NLS-1$ it.newLine(); it.append("@SuppressWarnings(\"all\")"); //$NON-NLS-1$ it.newLine(); it.append("public class "); //$NON-NLS-1$ it.append(appender.getSimpleName()); it.append(" extends "); //$NON-NLS-1$ it.append(getCodeElementExtractor().getAbstractAppenderImpl()); it.append(" implements "); //$NON-NLS-1$ it.append(builderInterface); it.append(" {"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); it.append(generateAppenderMembers(appender.getSimpleName(), builderInterface, accessor)); it.append(generateMembers(false, true)); it.append("}"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); } }; final JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(appender, content); javaFile.writeTo(getSrcGen()); }
Example 6
Source File: XtextValidator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Check public void checkGeneratedPackageForNameClashes(GeneratedMetamodel metamodel) { EPackage pack = metamodel.getEPackage(); Multimap<String, ENamedElement> constantNameToElement = HashMultimap.create(); Multimap<String, ENamedElement> accessorNameToElement = HashMultimap.create(); if (pack != null) { for(EClassifier classifier: pack.getEClassifiers()) { String accessorName = classifier.getName(); if ("Class".equals(accessorName) || "Name".equals(accessorName)) accessorName += "_"; accessorNameToElement.put("get" + accessorName, classifier); String classifierConstantName = CodeGenUtil2.format(classifier.getName(), '_', null, true, true).toUpperCase(); constantNameToElement.put(classifierConstantName, classifier); if (classifier instanceof EClass) { for(EStructuralFeature feature: ((EClass) classifier).getEAllStructuralFeatures()) { String featureConstantPart = CodeGenUtil2.format(feature.getName(), '_', null, false, false).toUpperCase(); String featureConstantName = classifierConstantName + "__" + featureConstantPart; constantNameToElement.put(featureConstantName, feature); String featureAccessorName = "get" + classifier.getName() + "_" + Strings.toFirstUpper(feature.getName()); accessorNameToElement.put(featureAccessorName, feature); } } } } createMessageForNameClashes(constantNameToElement); createMessageForNameClashes(accessorNameToElement); }
Example 7
Source File: AbstractSubCodeBuilderFragment.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the getter function for accessing to the top element collection of the script. * * @return the name of the getter function. */ @Pure protected String getLanguageScriptMemberGetter() { final Grammar grammar = getGrammar(); final AbstractRule scriptRule = GrammarUtil.findRuleForName(grammar, getCodeBuilderConfig().getScriptRuleName()); for (final Assignment assignment : GrammarUtil.containedAssignments(scriptRule)) { if ((assignment.getTerminal() instanceof RuleCall) && Objects.equals(((RuleCall) assignment.getTerminal()).getRule().getName(), getCodeBuilderConfig().getTopElementRuleName())) { return "get" + Strings.toFirstUpper(assignment.getFeature()); //$NON-NLS-1$ } } throw new IllegalStateException("member not found"); //$NON-NLS-1$ }
Example 8
Source File: ObjectAndPrimitiveBasedCastOperationCandidateSelector.java From sarl with Apache License 2.0 | 5 votes |
/** Validate the simple name for class type. * * @param name the simple name to validate. * @return the type name part of the name, with the first letter upper case. or {@code null} if the name is invalid. */ @SuppressWarnings("static-method") protected String getValidClassSimpleName(String name) { if (name.startsWith(CLASS_PREFIX)) { final String nm = Strings.toFirstUpper(name.substring(CLASS_PREFIX.length())); if (!Strings.isEmpty(nm)) { return nm; } } return null; }
Example 9
Source File: AbstractCodeElementExtractor.java From sarl with Apache License 2.0 | 4 votes |
@Pure @Override public TypeReference getElementAppenderImpl(String elementName) { return new TypeReference(getAppenderPackage() + "." //$NON-NLS-1$ + Strings.toFirstUpper(elementName) + "SourceAppender"); //$NON-NLS-1$ }
Example 10
Source File: AbstractCodeElementExtractor.java From sarl with Apache License 2.0 | 4 votes |
@Pure @Override public TypeReference getElementBuilderImpl(String elementName) { return new TypeReference(getBuilderPackage() + "." //$NON-NLS-1$ + Strings.toFirstUpper(elementName) + "BuilderImpl"); //$NON-NLS-1$ }
Example 11
Source File: GrammarKeywordAccessFragment2.java From sarl with Apache License 2.0 | 4 votes |
/** Generate a basic keyword. * * @param keyword the keyword to add. * @param comment a comment for the javadoc. * @param getters filled by this function with the getters' names. * @return the content. */ protected StringConcatenationClient generateKeyword(final String keyword, final String comment, Map<String, String> getters) { final String fieldName = keyword.toUpperCase().replaceAll("[^a-zA-Z0-9_]+", "_"); //$NON-NLS-1$ //$NON-NLS-2$ final String methodName = Strings.toFirstUpper(keyword.replaceAll("[^a-zA-Z0-9_]+", "_")) //$NON-NLS-1$ //$NON-NLS-2$ + "Keyword"; //$NON-NLS-1$ if (getters != null) { getters.put(methodName, keyword); } return new StringConcatenationClient() { @Override protected void appendTo(TargetStringConcatenation it) { it.append("\tprivate static final String "); //$NON-NLS-1$ it.append(fieldName); it.append(" = \""); //$NON-NLS-1$ it.append(Strings.convertToJavaString(keyword)); it.append("\";"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); it.append("\t/** Keyword: {@code "); //$NON-NLS-1$ it.append(protectCommentKeyword(keyword)); it.append("}."); //$NON-NLS-1$ it.newLine(); if (!Strings.isEmpty(comment)) { it.append("\t * Source: "); //$NON-NLS-1$ it.append(comment); it.newLine(); } it.append("\t */"); //$NON-NLS-1$ it.newLine(); it.append("\tpublic String get"); //$NON-NLS-1$ it.append(methodName); it.append("() {"); //$NON-NLS-1$ it.newLine(); it.append("\t\treturn "); //$NON-NLS-1$ it.append(fieldName); it.append(";"); //$NON-NLS-1$ it.newLine(); it.append("\t}"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); } }; }
Example 12
Source File: AbstractCodeElementExtractor.java From sarl with Apache License 2.0 | 4 votes |
@Pure @Override public TypeReference getElementAppenderImplCustom(String elementName) { return new TypeReference(getAppenderPackage() + "." //$NON-NLS-1$ + Strings.toFirstUpper(elementName) + "SourceAppenderCustom"); //$NON-NLS-1$ }
Example 13
Source File: AbstractCodeElementExtractor.java From sarl with Apache License 2.0 | 4 votes |
@Pure @Override public TypeReference getElementBuilderInterface(String elementName) { return new TypeReference(getBuilderPackage() + ".I" //$NON-NLS-1$ + Strings.toFirstUpper(elementName) + "Builder"); //$NON-NLS-1$ }
Example 14
Source File: EmfModelsTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public void dumpFeatures(final EClass eClassifier, final EObject obj) { EList<EStructuralFeature> _eAllStructuralFeatures = eClassifier.getEAllStructuralFeatures(); for (final EStructuralFeature eStructuralFeature : _eAllStructuralFeatures) { try { String prefix = "get"; if ((Objects.equal(eStructuralFeature.getEType(), EcorePackage.Literals.EBOOLEAN) && (eStructuralFeature.getUpperBound() == 1))) { prefix = "is"; } String _firstUpper = Strings.toFirstUpper(eStructuralFeature.getName()); final String getterName = (prefix + _firstUpper); final Method getter = obj.getClass().getMethod(getterName); boolean _isCustom = this.isCustom(getter); if (_isCustom) { String _name = eClassifier.getName(); String _plus = (_name + ": Overridden getter "); String _plus_1 = (_plus + getterName); EmfModelsTest.LOGGER.debug(_plus_1); } boolean _isMany = eStructuralFeature.isMany(); boolean _not = (!_isMany); if (_not) { boolean _isChangeable = eStructuralFeature.isChangeable(); if (_isChangeable) { String _firstUpper_1 = Strings.toFirstUpper(eStructuralFeature.getName()); final String setterName = ("set" + _firstUpper_1); final Method setter = obj.getClass().getMethod(setterName, this.toJavaClass(eStructuralFeature.getEType())); boolean _isCustom_1 = this.isCustom(setter); if (_isCustom_1) { String _name_1 = eClassifier.getName(); String _plus_2 = (_name_1 + ": Overridden setter "); String _name_2 = setter.getName(); String _plus_3 = (_plus_2 + _name_2); EmfModelsTest.LOGGER.debug(_plus_3); } } if ((((eStructuralFeature instanceof EReference) && (!((EReference) eStructuralFeature).isContainment())) && (((EReference) eStructuralFeature).getEOpposite() == null))) { String _firstUpper_2 = Strings.toFirstUpper(getterName); final String basicGetterName = ("basic" + _firstUpper_2); final Method basicGetter = obj.getClass().getMethod(basicGetterName); boolean _isCustom_2 = this.isCustom(basicGetter); if (_isCustom_2) { String _name_3 = eClassifier.getName(); String _plus_4 = (_name_3 + ": Overridden basicGetter "); String _name_4 = basicGetter.getName(); String _plus_5 = (_plus_4 + _name_4); EmfModelsTest.LOGGER.debug(_plus_5); } } } } catch (final Throwable _t) { if (_t instanceof Exception) { final Exception e = (Exception)_t; e.printStackTrace(); } else { throw Exceptions.sneakyThrow(_t); } } } }
Example 15
Source File: JavaValidatorFragment.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public String getGeneratedEPackageName(Grammar g, Naming n, EPackage pack) { return getBasePackage(g, n) + "." + pack.getName() + "." + Strings.toFirstUpper(pack.getName()) + "Package"; }
Example 16
Source File: GrammarKeywordAccessFragment2.java From sarl with Apache License 2.0 | 4 votes |
/** Replies the language name. * * @return the language name. */ @Pure public String getLanguageName() { return Strings.toFirstUpper(GrammarUtil.getSimpleName(getGrammar()).toLowerCase()); }
Example 17
Source File: AntlrGrammarGenUtil.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public static String getContentAssistRuleName(AbstractRule rule) { String ruleName = getRuleName(rule); if (ruleName.startsWith("rule")) return "rule__" + Strings.toFirstUpper(ruleName.substring(4, ruleName.length())); return ruleName; }
Example 18
Source File: PreferenceRule.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** {@inheritDoc} */ @Override public String toString() { return Strings.toFirstUpper(super.toString().toLowerCase()); }
Example 19
Source File: PreferenceRule.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** {@inheritDoc} */ @Override public String toString() { return Strings.toFirstUpper(super.toString().toLowerCase()); }
Example 20
Source File: ExternalLibraryBuilder.java From n4js with Eclipse Public License 1.0 | 4 votes |
private List<IProject> doPerformOperation(N4JSExternalProject[] projects, BuildOperation operation, IProgressMonitor monitor) { if (projects == null || projects.length == 0) { return Collections.emptyList(); } Measurement allProjectsMeasurement = N4JSDataCollectors.dcExtLibBuilder .getMeasurement(operation.name().toLowerCase() + "ing all projects"); ISchedulingRule rule = getRule(); try { Job.getJobManager().beginRule(rule, monitor); validatorExtension.clearAllMarkersOfExternalProjects(projects); VertexOrder<IN4JSProject> buildOrder = builtOrderComputer.getBuildOrder(projects); // wrap as Arrays.asList returns immutable list List<IN4JSProject> buildOrderList = new ArrayList<>(Arrays.asList(buildOrder.vertexes)); if (BuildOperation.CLEAN.equals(operation)) { // use wipe to remove the resource descriptions of the given projects from index wipeProjectFromIndex(SubMonitor.convert(monitor, 1), Arrays.asList(projects)); projectsStateHelper.clearProjectCache(); // clean in reverse order Collections.reverse(buildOrderList); } // Remove external projects that have the workspace counterpart if it is a build operation. if (BuildOperation.BUILD.equals(operation)) { for (Iterator<IN4JSProject> itr = buildOrderList.iterator(); itr.hasNext();) { if (hasWorkspaceCounterpart(itr.next())) { itr.remove(); } } } ensureDynamicDependenciesSetForWorkspaceProjects(); String prefix = Strings.toFirstUpper(operation.toString().toLowerCase()); String projectNames = getProjectNames(buildOrderList); LOGGER.info(prefix + "ing external libraries: " + projectNames); SubMonitor subMonitor = SubMonitor.convert(monitor, buildOrderList.size()); List<IProject> actualBuildOrderList = new LinkedList<>(); for (IN4JSProject project : buildOrderList) { LOGGER.info(prefix + "ing external library: " + project.getProjectName()); N4JSEclipseProject n4EclPrj = (N4JSEclipseProject) project; // bold cast operation.run(this, n4EclPrj, subMonitor.split(1)); IProject iProject = n4EclPrj.getProject(); actualBuildOrderList.add(iProject); } return actualBuildOrderList; } finally { allProjectsMeasurement.close(); Job.getJobManager().endRule(rule); } }