Java Code Examples for org.eclipse.xtext.util.Strings#equal()

The following examples show how to use org.eclipse.xtext.util.Strings#equal() . 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: SarlFieldBuilderImpl.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Initialize the Ecore element.
 * @param container the container of the SarlField.
 * @param name the name of the SarlField.
 */
public void eInit(XtendTypeDeclaration container, String name, String modifier, IJvmTypeProvider context) {
	setTypeResolutionContext(context);
	if (this.sarlField == null) {
		this.container = container;
		this.sarlField = SarlFactory.eINSTANCE.createSarlField();
		this.sarlField.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendMember());
		this.sarlField.setName(name);
		if (Strings.equal(modifier, "var")
			|| Strings.equal(modifier, "val")) {
			this.sarlField.getModifiers().add(modifier);
		} else {
			throw new IllegalStateException("Invalid modifier");
		}
		container.getMembers().add(this.sarlField);
	}
}
 
Example 2
Source File: AbstractDocumentationMojo.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Convert a file to a package name.
 *
 * @param rootPackage an additional root package.
 * @param packageName the file.
 * @return the package name.
 */
protected static String toPackageName(String rootPackage,  File packageName) {
	final StringBuilder name = new StringBuilder();
	File tmp = packageName;
	while (tmp != null) {
		final String elementName = tmp.getName();
		if (!Strings.equal(FileSystem.CURRENT_DIRECTORY, elementName)
				&& !Strings.equal(FileSystem.PARENT_DIRECTORY, elementName)) {
			if (name.length() > 0) {
				name.insert(0, "."); //$NON-NLS-1$
			}
			name.insert(0, elementName);
		}
		tmp = tmp.getParentFile();
	}
	if (!Strings.isEmpty(rootPackage)) {
		if (name.length() > 0) {
			name.insert(0, "."); //$NON-NLS-1$
		}
		name.insert(0, rootPackage);
	}
	return name.toString();
}
 
Example 3
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public JvmOperation getDispatcherOperation(JvmOperation dispatchCase) {
	EObject sourceElement = associations.getPrimarySourceElement(dispatchCase);
	if (sourceElement instanceof XtendFunction) {
		XtendFunction function = (XtendFunction) sourceElement;
		if (function.isDispatch()) {
			Iterable<JvmOperation> operations = filter(associations.getJvmElements(sourceElement), JvmOperation.class);
			for(JvmOperation operation: operations) {
				if (Strings.equal(operation.getSimpleName(), function.getName())) {
					return operation;
				}
			}
		}
	} else {
		DispatchSignature signature = new DispatchSignature(dispatchCase.getSimpleName().substring(1), dispatchCase.getParameters().size());
		JvmOperation result = getDispatcherOperation(dispatchCase.getDeclaringType(), signature);
		return result;
	}
	return null;
}
 
Example 4
Source File: AbstractDocumentationMojo.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static boolean isParentFile(File file, File root) {
	if (file.isAbsolute() && root.isAbsolute()) {
		try {
			final String[] components1 = FileSystem.split(file.getCanonicalFile());
			final String[] components2 = FileSystem.split(root.getCanonicalFile());
			for (int i = 0; i < components2.length; ++i) {
				if (i >= components1.length || !Strings.equal(components2[i], components1[i])) {
					return false;
				}
			}
			return true;
		} catch (IOException exception) {
			//
		}
	}
	return false;
}
 
Example 5
Source File: IssueDatabaseExtensions.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static String formatIndex(int major, int minor, IssueDescription prevIssue, IssueDescription currentIssue,
		IssueDescription nextIssue) {
	String pcode = prevIssue == null ? null : prevIssue.getCode();
	String ccode = currentIssue == null ? null : currentIssue.getCode();
	String ncode = nextIssue == null ? null : nextIssue.getCode();
	if (Strings.equal(pcode, ccode) || Strings.equal(ccode, ncode)) {
		// Long numbering
		final char c = (char) ((int) 'a' + (minor - 1));
		return major + Character.toString(c);
	}
	// Short numbering
	return Integer.toString(major);
}
 
Example 6
Source File: DynamicValidationContext.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static boolean hasExtension(File file, Iterable<String> extensions) {
	final String extension = FileSystem.extension(file);
	for (final String ext : extensions) {
		if (Strings.equal(ext, extension)) {
			return true;
		}
	}
	return false;
}
 
Example 7
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean doCheckGrammarRecursiveReference(Grammar grammarToCheck, Grammar currentGrammar, int idx, Set<Grammar> visitedGrammars) {
	if (Strings.equal(grammarToCheck.getName(), currentGrammar.getName())) {
		error("Invalid recursive reference of grammar.", XtextPackage.Literals.GRAMMAR__USED_GRAMMARS, idx);
		return false;
	}
	if (!visitedGrammars.add(currentGrammar))
		return true;
	for(Grammar usedGrammar: currentGrammar.getUsedGrammars()) {
		if (!doCheckGrammarRecursiveReference(grammarToCheck, usedGrammar, idx, visitedGrammars))
			return false;
	}
	return true;
}
 
Example 8
Source File: MarkdownParser.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies if the given extension is for Markdown file.
 *
 * @param extension the extension to test.
 * @return {@code true} if the extension is for a Markdown file.
 */
public static boolean isMarkdownFileExtension(String extension) {
	for (final String ext : MARKDOWN_FILE_EXTENSIONS) {
		if (Strings.equal(ext, extension)) {
			return true;
		}
	}
	return false;
}
 
Example 9
Source File: DocumentationFormatterTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert formatting
 *
 * @param input the input.
 * @param expected the expected input.
 */
protected void assertSLFormatted(String input, final String expected) {
	String actual = this.formatter.formatSinglelineComment(input);
	if (!Strings.equal(expected, actual)) {
		throw new AssertionFailedError("not same formatting", expected, actual);
	}
}
 
Example 10
Source File: DerivedSourceView.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private Color getColorFromStore(IPreferenceStore store, String isDefaultKey, int systemDefault, String key) {
	String isDefault = store.getString(isDefaultKey);
	if(Strings.isEmpty(isDefault) || Strings.equal("true", isDefault)) {
		return getDisplay().getSystemColor(systemDefault);
	} else {
		RGB rgb = PreferenceConverter.getColor(store, key);
		return EditorsPlugin.getDefault().getSharedTextColors().getColor(rgb);
	}
}
 
Example 11
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies if the given annotation is a forbidden active annotation.
 *
 * @param annotation the annotation.
 * @return {@code true} if the annotation is forbidden.
 */
@SuppressWarnings("static-method")
protected boolean isForbiddenActiveAnnotation(XAnnotation annotation) {
	final String name = annotation.getAnnotationType().getQualifiedName();
	return Strings.equal(EqualsHashCode.class.getName(), name)
			|| Strings.equal(FinalFieldsConstructor.class.getName(), name);
}
 
Example 12
Source File: DocumentationFormatterTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert formatting
 *
 * @param input the input.
 * @param expected the expected input.
 */
protected void assertMLFormatted(String input, final String expected) {
	String actual = this.formatter.formatMultilineComment(input);
	if (!Strings.equal(expected, actual)) {
		throw new AssertionFailedError("not same formatting", expected, actual);
	}
}
 
Example 13
Source File: AbstractTypeReferencePairWalker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void doVisitMatchingTypeParameters(ParameterizedTypeReference reference,
		ParameterizedTypeReference declaration) {
	Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> actualMapping = getTypeParameterMapping(reference);
	TypeParameterSubstitutor<?> actualSubstitutor = createTypeParameterSubstitutor(actualMapping);
	Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> declaredMapping = getTypeParameterMapping(declaration);
	TypeParameterSubstitutor<?> declaredSubstitutor = createTypeParameterSubstitutor(declaredMapping);
	Set<JvmTypeParameter> actualBoundParameters = actualMapping.keySet();
	Set<JvmTypeParameter> visited = Sets.newHashSet();
	outer: for (JvmTypeParameter actualBoundParameter : actualBoundParameters) {
		if (visited.add(actualBoundParameter)) {
			LightweightMergedBoundTypeArgument declaredBoundArgument = declaredMapping.get(actualBoundParameter);
			while(declaredBoundArgument == null && actualBoundParameter != null) {
				actualBoundParameter = findMappedParameter(actualBoundParameter, actualMapping, visited);
				if (actualBoundParameter == null)
					continue outer;
				declaredBoundArgument = declaredMapping.get(actualBoundParameter);
			}
			if (declaredBoundArgument != null) {
				LightweightTypeReference declaredTypeReference = declaredBoundArgument.getTypeReference();
				JvmType declaredType = declaredTypeReference.getType();
				if (declaredType instanceof JvmTypeParameter) {
					JvmTypeParameter declaredTypeParameter = (JvmTypeParameter) declaredType;
					if (!shouldProcessInContextOf(declaredTypeParameter, actualBoundParameters, visited))
						continue;
					declaredTypeReference = declaredSubstitutor.substitute(declaredTypeReference);
				}
				LightweightTypeReference actual = actualSubstitutor.substitute(actualMapping.get(actualBoundParameter).getTypeReference());
				if (!actual.isResolved() || !declaredTypeReference.isResolved() || !Strings.equal(actual.getIdentifier(), declaredTypeReference.getIdentifier())) {
					if (reference.getType() != actual.getType() 
							|| declaredTypeReference.getType() != declaration.getType() 
							|| !reference.getIdentifier().equals(actual.getIdentifier())
							|| !declaredTypeReference.getIdentifier().equals(declaration.getIdentifier())) {
						outerVisit(declaredTypeReference, actual, declaration, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
					}
				}
			}
		}
	}
}
 
Example 14
Source File: MemberVisibilityChecker.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isProjectVisible(TModule contextModule, TMember member) {
	TModule memberModule = EcoreUtil2.getContainerOfType(member, TModule.class);
	// receiverModule == null indicates either a follow-up problem or a builtin type
	return memberModule == null || memberModule == contextModule
			|| Strings.equal(memberModule.getProjectName(), contextModule.getProjectName())
					&& Strings.equal(contextModule.getVendorID(), memberModule.getVendorID())
			|| typeVisibilityChecker.isTestedProjectOf(contextModule, memberModule);
}
 
Example 15
Source File: CheckCfgTemplateProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Image getImage(final Template template) {
  if (Strings.equal("CheckConfiguration", template.getName())) { // see templates.xml //$NON-NLS-1$
    return images.forCheckConfiguration();
  } else if (Strings.equal("Add a catalog", template.getName())) { // see templates.xml //$NON-NLS-1$
    return images.forConfiguredCatalog();
  }
  return super.getImage(template);
}
 
Example 16
Source File: FeatureScopeSessionWithContext.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean isVisible(JvmMember member, /* @Nullable */ LightweightTypeReference receiverType, /* @Nullable */ JvmIdentifiableElement receiverFeature) {
	boolean result = isVisible(member);
	if (result && JvmVisibility.PROTECTED == member.getVisibility()) {
		if (receiverFeature != null) {
			// We bypass this check for qualified.this and qualified.super in the scope provider
			// they are considered to be always visible
			/*
			 * class A {
			 *   class B {
			 *     {
			 *       A.super.toString
			 *     }
			 *   }
			 * }
			 */
			if (isThisSuperOrTypeLiteral(receiverFeature)) {
				if (receiverType == null || !receiverType.isType(Class.class)) {
					return true;
				}
			}
		}
		JvmType contextType = visibilityHelper.getRawContextType();
		if (contextType instanceof JvmDeclaredType) {
			String packageName = visibilityHelper.getPackageName();
			JvmDeclaredType declaringType = member.getDeclaringType();
			String memberPackageName = declaringType.getPackageName();
			if (Strings.equal(packageName, memberPackageName)) {
				return true;
			}
		}
		if (receiverType != null) {
			if (receiverType.isSubtypeOf(contextType)) {
				return true;
			}
			EObject container = contextType.eContainer();
			while (container instanceof JvmType) {
				if (receiverType.isSubtypeOf((JvmType)container)) {
					return true;
				}
				container = container.eContainer();
			}
		}
		return false;
	}
	return result;
}
 
Example 17
Source File: IssueDatabaseExtensions.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Replies a table description for the list of issues.
 *
 * <p>The result is a table with 3 columns:<ul>
 * <li>Column 1: index of the issue</li>
 * <li>Column 2: the code of the issue</li>
 * <li>Column 3: the message and description of the issue</li>
 * <li>Column 4: the importance level of the issue</li>
 * </ul>
 *
 * @param descriptions the list of issue descriptions to render.
 * @param sort indicates if the table rows should be sorted on simples codes.
 * @return the table content.
 */
@Pure
public static List<List<String>> asTable(List<IssueDescription> descriptions) {
	final List<List<String>> content = new ArrayList<>();
	int major = 0;
	int minor = 1;
	IssueDescription prevIssue = null;
	for (int i = 0; i < descriptions.size(); ++i) {
		final IssueDescription description = descriptions.get(i);
		if (description.level != IssueLevel.IGNORE) {
			final List<String> columns = new ArrayList<>();

			// Column "N."
			if (Strings.equal(prevIssue == null ? null : prevIssue.getCode(), description.getCode())) {
				++minor;
			} else {
				++major;
				minor = 1;
			}

			final IssueDescription nextIssue;
			if (i < descriptions.size() - 1) {
				nextIssue = descriptions.get(i + 1);
			} else {
				nextIssue = null;
			}

			columns.add(formatIndex(major, minor, prevIssue, description, nextIssue));

			// Column "Message and Description"
			final StringBuilder msg = new StringBuilder();
			msg.append(head(Messages.IssueDatabaseExtensions_8)).append(description.message).append(nl());
			msg.append(head(Messages.IssueDatabaseExtensions_9)).append(description.cause);
			if (!Strings.isEmpty(description.solution)) {
				msg.append(nl()).append(head(Messages.IssueDatabaseExtensions_10)).append(description.solution);
			}
			if (!Strings.isEmpty(description.delegate)) {
				msg.append(nl()).append(head(Messages.IssueDatabaseExtensions_11)).append(description.delegate);
			}
			columns.add(msg.toString());

			// Column "Level"
			columns.add(description.level.getLabel(description.delegate, description.defaultLevel));

			// Column "Code"
			final StringBuilder code = new StringBuilder();
			code.append("[");
			code.append(description.getShortDisplayCode());
			code.append("](: \"");
			code.append(description.getLongDisplayCode());
			code.append("\")");
			columns.add(code.toString());

			
			content.add(columns);

			prevIssue = description;
		}
	}
	DocumentationLogger.getLogger().info(MessageFormat.format(Messages.IssueDatabaseExtensions_12, descriptions.size(), major));
	return content;
}
 
Example 18
Source File: MemberVisibilityChecker.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private boolean checkVendorEquality(TModule contextModule, TMember member) {
	TModule memberModule = EcoreUtil2.getContainerOfType(member, TModule.class);
	// receiverModule == null indicates either a follow-up problem or a builtin type
	return memberModule == null || memberModule == contextModule
			|| Strings.equal(contextModule.getVendorID(), memberModule.getVendorID());
}
 
Example 19
Source File: CheckPreferencesExtensionHelper.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Checks if the name of given plugin extension matches with that calculated using given check catalog.
 *
 * @param extension
 *          the plugin extension
 * @param catalog
 *          the check catalog
 * @return {@code true}, if given plugin extension element is up to date
 */
@Override
protected boolean extensionNameMatches(final IPluginExtension extension, final CheckCatalog catalog) {
  return Strings.equal(extension.getName(), EXTENSION_NAME_PREFIX + catalog.getName());
}
 
Example 20
Source File: AbstractCheckExtensionHelper.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Checks if the language name defined in given plugin extension element matches with given language.
 *
 * @param element
 *          the plugin extension element
 * @param expectedLanguageName
 *          the expected language name
 * @return {@code true} if the language name as defined in the plugin extension element is up to date
 */
protected boolean languageNameMatches(final IPluginElement element, final String expectedLanguageName) {
  return element.getAttribute(LANGUAGE_ELEMENT_TAG) != null && Strings.equal(element.getAttribute(LANGUAGE_ELEMENT_TAG).getValue(), expectedLanguageName);
}