Java Code Examples for org.eclipse.xtext.util.Strings#isEmpty()
The following examples show how to use
org.eclipse.xtext.util.Strings#isEmpty() .
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: JavaInlineExpressionCompiler.java From sarl with Apache License 2.0 | 6 votes |
@Override public void appendInlineAnnotation(JvmAnnotationTarget target, XtendExecutable source) { final ImportManager imports = new ImportManager(); final InlineAnnotationTreeAppendable result = newAppendable(imports); generate(source.getExpression(), null, source, result); final String content = result.getContent(); if (!Strings.isEmpty(content)) { final List<String> importedTypes = imports.getImports(); final JvmTypeReference[] importArray = new JvmTypeReference[importedTypes.size()]; for (int i = 0; i < importArray.length; ++i) { importArray[i] = this.typeReferences.getTypeForName(importedTypes.get(i), source); } appendInlineAnnotation(target, source.eResource().getResourceSet(), content, result.isConstant(), result.isStatement(), importArray); } }
Example 2
Source File: XImportSectionNamespaceScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Create a new {@link ImportNormalizer} for the given namespace. * @param namespace the namespace. * @param ignoreCase <code>true</code> if the resolver should be case insensitive. * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be converted to a valid * qualified name. */ protected ImportNormalizer createImportedNamespaceResolver(final String namespace, boolean ignoreCase) { if (Strings.isEmpty(namespace)) return null; QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace); if (importedNamespace == null || importedNamespace.isEmpty()) { return null; } boolean hasWildcard = ignoreCase ? importedNamespace.getLastSegment().equalsIgnoreCase(getWildcard()) : importedNamespace.getLastSegment().equals(getWildcard()); if (hasWildcard) { if (importedNamespace.getSegmentCount() <= 1) return null; return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase); } else { return doCreateImportNormalizer(importedNamespace, false, ignoreCase); } }
Example 3
Source File: AbstractMarkerLanguageParser.java From sarl with Apache License 2.0 | 6 votes |
/** Validate the given anchor and reply the one that is validated. * * @param anchor the anchor to validate. * @return the validated anchor text. * @throws InvalidAnchorLabelException a runtime exception */ public String validateAnchor(String anchor) { if (!this.anchorToTitle.containsKey(anchor)) { String anc = this.simpleAnchorToAnchor.get(anchor); if (!Strings.isEmpty(anc) && anc != MANY) { return anc; } anc = this.titleToAnchor.get(anchor); if (!Strings.isEmpty(anc) && anc != MANY) { return anc; } final String[] anchors = new String[this.anchorToTitle.size()]; int i = 0; for (final String eanchor : this.anchorToTitle.keySet()) { anchors[i] = eanchor; ++i; } Arrays.sort(anchors); throw new InvalidAnchorLabelException(anchor, anchors); } return anchor; }
Example 4
Source File: SolidityContentProposalPriorities.java From solidity-ide with Eclipse Public License 1.0 | 6 votes |
@Override protected void adjustPriority(ICompletionProposal proposal, String prefix, int priority) { if (proposal == null || !(proposal instanceof ConfigurableCompletionProposal)) return; ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal; if (castedProposal.getPriority() != getDefaultPriority()) return; int adjustedPriority = priority; if (!Strings.isEmpty(prefix)) { if (castedProposal.getReplacementString().equals(prefix)) adjustedPriority = (int) (adjustedPriority * sameTextMultiplier); else if (castedProposal.getReplacementString().startsWith(prefix)) adjustedPriority = adjustedPriority * proposalWithPrefixMultiplier; } castedProposal.setPriority(adjustedPriority); }
Example 5
Source File: ElementTypeCalculator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public EClassifier caseTypeRef(TypeRef object) { if (object.getClassifier() == null) { if (object.getMetamodel() == null || object.getMetamodel().getEPackage() == null) return null; String name = GrammarUtil.getTypeRefName(object); if (Strings.isEmpty(name)) return null; EClassifierInfo info = classifierInfos.getInfo(object.getMetamodel(), name); if (info != null) object.setClassifier(info.getEClassifier()); } return object.getClassifier(); }
Example 6
Source File: BuiltInTypeModelAccess.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Load the concrete meta model instance from modelLocation. */ private synchronized void load() { if (model == null) { URI modelURI = getBuiltInElementsResourceURI(); try { ResourceSet rs = new ResourceSetImpl(); Resource resource = rs.createResource(modelURI); // Stand-alone builder cannot handle platform:/plugin/ URIs... final InputStream is = BuiltInTypeModelAccess.class.getClassLoader().getResourceAsStream(MODEL_LOCATION); resource.load(is, null); EcoreUtil.resolveAll(resource); model = (BuiltInTypeModel) resource.getContents().get(0); // CHECKSTYLE:CHECK-OFF IllegalCatch // We *do* want to catch any exception here because we are in construction and need to initialize with something } catch (Exception ex) { // CHECKSTYLE:CHECK-ON IllegalCatch LOGGER.error("Error loading metamodel from " + modelURI, ex); //$NON-NLS-1$ // Create an empty model... model = BuiltInTypeModelPackage.eINSTANCE.getBuiltInTypeModelFactory().createBuiltInTypeModel(); } } GlobalResources.INSTANCE.addResource(model.eResource()); for (InternalType type : model.getInternalTypes()) { String typeName = type.getName(); if (!Strings.isEmpty(typeName)) { internalTypesByName.put(typeName, type); } else { LOGGER.error("incomplete internal type in " + MODEL_LOCATION); //$NON-NLS-1$ } } }
Example 7
Source File: SarlEventBuilderImpl.java From sarl with Apache License 2.0 | 5 votes |
/** Change the super type. * @param superType the qualified name of the super type, * or {@code null} if the default type. */ public void setExtends(String superType) { if (!Strings.isEmpty(superType) && !Event.class.getName().equals(superType)) { JvmParameterizedTypeReference superTypeRef = newTypeRef(this.sarlEvent, superType); JvmTypeReference baseTypeRef = findType(this.sarlEvent, Event.class.getCanonicalName()); if (isSubTypeOf(this.sarlEvent, superTypeRef, baseTypeRef)) { this.sarlEvent.setExtends(superTypeRef); return; } } this.sarlEvent.setExtends(null); }
Example 8
Source File: ExternalHighlightingConfig.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the color of the strings. * * @return the name of the color to use. */ public String getStringColor() { if (Strings.isEmpty(this.stringColor)) { return DEFAULT_COLOR; } return this.stringColor; }
Example 9
Source File: RenameRefactoringController.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void startRefactoringWithDialog(final boolean previewOnly) throws InterruptedException { if (Strings.isEmpty(newName)) newName = getOriginalName(getXtextEditor()); if (Strings.isEmpty(newName)) restoreOriginalSelection(); else { IRenameSupport renameSupport = createRenameSupport(renameElementContext, newName); if(renameSupport != null) { renameSupport.startRefactoringWithDialog(previewOnly); } } }
Example 10
Source File: AbstractExternalHighlightingFragment2.java From sarl with Apache License 2.0 | 5 votes |
/** Explore the grammar for extracting the key elements. * * @param grammar the grammar to explore. * @param expressionKeywords the SARL keywords, usually within expressions. * @param modifiers the modifier keywords. * @param primitiveTypes the primitive types. * @param punctuation the set of detected punctuation symbols. * @param literals the set of detected literals. * @param excludedKeywords the set of given excluded keywords. * @param ignored the set of ignored tokens that is filled by this function. */ @SuppressWarnings("checkstyle:nestedifdepth") private static void exploreGrammar(Grammar grammar, Set<String> expressionKeywords, Set<String> modifiers, Set<String> primitiveTypes, Set<String> punctuation, Set<String> literals, Set<String> excludedKeywords, Set<String> ignored) { for (final AbstractRule rule : grammar.getRules()) { final boolean isModifierRule = MODIFIER_RULE_PATTERN.matcher(rule.getName()).matches(); final TreeIterator<EObject> iterator = rule.eAllContents(); while (iterator.hasNext()) { final EObject object = iterator.next(); if (object instanceof Keyword) { final Keyword xkeyword = (Keyword) object; final String value = xkeyword.getValue(); if (!Strings.isEmpty(value)) { if (KEYWORD_PATTERN.matcher(value).matches()) { if (!literals.contains(value) && !primitiveTypes.contains(value)) { if (excludedKeywords.contains(value)) { ignored.add(value); } else { if (isModifierRule) { modifiers.add(value); } else { expressionKeywords.add(value); } } } } else if (PUNCTUATION_PATTERN.matcher(value).matches()) { punctuation.add(value); } } } } } }
Example 11
Source File: INTValueConverter.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Integer toValue(String string, INode node) { if (Strings.isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to an int value.", node, null); try { int intValue = Integer.parseInt(string, 10); return Integer.valueOf(intValue); } catch (NumberFormatException e) { throw new ValueConverterException("Couldn't convert '" + string + "' to an int value.", node, e); } }
Example 12
Source File: XbaseValueConverterService.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Integer toValue(String string, INode node) { if (Strings.isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to an int value.", node, null); String withoutUnderscore = string.replace("_", ""); if (Strings.isEmpty(withoutUnderscore)) throw new ValueConverterException("Couldn't convert input '" + string + "' to an int value.", node, null); return super.toValue(withoutUnderscore, node); }
Example 13
Source File: ExpressionConfig.java From sarl with Apache License 2.0 | 4 votes |
/** Set the pattern that is matching a block expression in the grammar. * * @param pattern the pattern for a block expression. */ public void setBlockExpressionGrammarPattern(String pattern) { if (!Strings.isEmpty(pattern)) { this.blockExpressionGrammarPattern = pattern; } }
Example 14
Source File: ExpressionConfig.java From sarl with Apache License 2.0 | 4 votes |
/** Set the keyword for declaring a field. * * @param keyword the keyword. */ public void setFieldDeclarationKeyword(String keyword) { if (!Strings.isEmpty(keyword)) { this.fieldDeclarationKeyword = keyword; } }
Example 15
Source File: CodeBuilderConfig.java From sarl with Apache License 2.0 | 4 votes |
/** Set the name that is used for representing the type of a formal parameter in the grammar's assignments. * * @param name the name of the assignment for the type of a formal parameter. */ public void setParameterTypeGrammarName(String name) { if (!Strings.isEmpty(name)) { this.parameterTypeGrammarName = name; } }
Example 16
Source File: CodeBuilderConfig.java From sarl with Apache License 2.0 | 4 votes |
/** Set the name that is used for representing the name of a member in the grammar's assignments. * * @param name the name of the assignment for the name of a member. */ public void addUnnamedMemberExtensionGrammarName(String name) { if (!Strings.isEmpty(name)) { this.unnamedMemberGrammarNames.add(name); } }
Example 17
Source File: PasteJavaCodeHandler.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
private void doPasteJavaCode(final XtextEditor activeXtextEditor, final String javaCode, final JavaImportData javaImports) throws ExecutionException { ISourceViewer sourceViewer = activeXtextEditor.getInternalSourceViewer(); final IXtextDocument xtextDocument = activeXtextEditor.getDocument(); IJavaProject project = null; IProject iProject = null; IEditorInput editorInput = activeXtextEditor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { iProject = ((IFileEditorInput) editorInput).getFile().getProject(); project = JavaCore.create(iProject); } final int selectionOffset = Math.max(0, sourceViewer.getSelectedRange().x - 1); EObject targetElement = xtextDocument.readOnly(new IUnitOfWork<EObject, XtextResource>() { @Override public EObject exec(XtextResource state) throws Exception { IParseResult parseResult = state.getParseResult(); if (parseResult == null) { return null; } ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), selectionOffset); if (leafNode == null) { return parseResult.getRootASTElement(); } return leafNode.getSemanticElement(); } }); JavaConverter javaConverter = javaConverterProvider.get(); final String xtendCode = javaConverter.toXtend(javaCode, javaImports != null ? javaImports.getImports() : null, targetElement, project, conditionalExpressionsAllowed(iProject)); if (!Strings.isEmpty(xtendCode)) { if (javaImports != null) { importsUtil.addImports(javaImports.getImports(), javaImports.getStaticImports(), new String[] {}, xtextDocument); } Point selection = sourceViewer.getSelectedRange(); try { xtextDocument.replace(selection.x, selection.y, xtendCode); } catch (BadLocationException e) { throw new ExecutionException("Failed to replace content.", e); } //TODO enable formatting, when performance became better // https://bugs.eclipse.org/bugs/show_bug.cgi?id=457814 // doFormat(sourceViewer, xtendCode, selection); } }
Example 18
Source File: CodeBuilderConfig.java From sarl with Apache License 2.0 | 4 votes |
/** Change the name of the grammar rule that defines the type parameters. * * @param name the name of the rule. */ public void setTypeParameterRuleName(String name) { if (!Strings.isEmpty(name)) { this.typeParameterRuleName = name; } }
Example 19
Source File: SarlInterfaceBuilderImpl.java From sarl with Apache License 2.0 | 4 votes |
/** Add a modifier. * @param modifier the modifier to add. */ public void addModifier(String modifier) { if (!Strings.isEmpty(modifier)) { this.sarlInterface.getModifiers().add(modifier); } }
Example 20
Source File: BuiltInTypeModelAccess.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Gets an internal type's instance by its name. * <p> * The implementation guarantees that there is exactly one instance of each validly named, internal type, that is two invocations with the same {@code name} * return the same instance. More specifically<br> * for all x, x != {@code null} and x != "" implies getInternalType(x) == getInternalType(x). * </p> * * @param name * The internal type's name * @return The instance of the type with {@code name} or {@code null} if {@code name} == {@code null}, {@code name} == "", or there is no type with * {@code name} */ public INamedType getInternalType(final String name) { if (!Strings.isEmpty(name)) { return internalTypesByName.get(name); } else { return null; } }