Java Code Examples for org.eclipse.xtext.resource.IEObjectDescription#getEClass()

The following examples show how to use org.eclipse.xtext.resource.IEObjectDescription#getEClass() . 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: HelpIntegrationTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private List<String> getFeaturesWithoutDocumentation(String generatorId) {
	Iterable<IEObjectDescription> allElements = getAllElements(generatorId);
	List<String> missingDocumentation = Lists.newArrayList();
	for (IEObjectDescription desc : allElements) {
		if (desc.getEClass() != SGenPackage.Literals.FEATURE_TYPE)
			continue;
		EObject eObjectOrProxy = desc.getEObjectOrProxy();
		String documentation = documentationProvider
				.getDocumentation(eObjectOrProxy);
		if (documentation == null
				|| SGenUserHelpDocumentationProvider.EMPTY_DOCUMENTATION
						.equals(documentation)) {
			missingDocumentation.add(desc.getName().toString());
		}
	}
	return missingDocumentation;
}
 
Example 2
Source File: ContextAwareTypeScope.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IEObjectDescriptionWithError wrapFilteredDescription(IEObjectDescription originalDescr) {
	final EClass eClass = originalDescr.getEClass();
	if (!isValidLocationForNull && eClass == TypesPackage.Literals.NULL_TYPE) {
		return null; // 'null' will filter out this element completely (i.e. not custom error message)
	}
	if (!isValidLocationForVoid && eClass == TypesPackage.Literals.VOID_TYPE) {
		return new DisallowedTypeDescription(originalDescr,
				IssueCodes.getMessageForTYS_VOID_AT_WRONG_LOCATION(),
				IssueCodes.TYS_VOID_AT_WRONG_LOCATION);
	}
	if (!isValidLocationForFunctionType && TypesPackage.Literals.TFUNCTION.isSuperTypeOf(eClass)) {
		return new DisallowedTypeDescription(originalDescr,
				IssueCodes.getMessageForTYS_FUNCTION_DISALLOWED_AS_TYPE(),
				IssueCodes.TYS_FUNCTION_DISALLOWED_AS_TYPE);
	}
	return null; // should never happen, because #isAccepted() has returned true
}
 
Example 3
Source File: XtendDescriptionLabelProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object image(IEObjectDescription element) {
	EClass eClass = element.getEClass();
	int adornments = (descriptionFlags.isStatic(element)) ? JavaElementImageDescriptor.STATIC : 0;
	if (eClass == XTEND_FILE)
		return images.forFile();
	else if (eClass == XIMPORT_DECLARATION)
		return images.forImport();
	else if (eClass == XTEND_CLASS || eClass == TypesPackage.Literals.JVM_GENERIC_TYPE)
		return images.forClass(JvmVisibility.PUBLIC, adornments);
	else if (eClass == XTEND_FUNCTION)
		return images.forOperation(JvmVisibility.PUBLIC, adornments);
	else if (eClass == XTEND_FIELD)
		return images.forField(JvmVisibility.PUBLIC, adornments);
	else if (eClass == TypesPackage.Literals.JVM_OPERATION)
		return (descriptionFlags.isDispatcherOperation(element)) 
			? images.forDispatcherFunction(JvmVisibility.PUBLIC, adornments) 
			: images.forOperation(JvmVisibility.PUBLIC, adornments);
	else
		return super.image(element);
}
 
Example 4
Source File: IteratorJob.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
	long startTime = System.currentTimeMillis();
	while (iterator.hasNext()) {
		IEObjectDescription next = iterator.next();
		if (next.getQualifiedName() != null && next.getEObjectURI() != null && next.getEClass() != null) {
			matches.add(next);
			long endTime = System.currentTimeMillis();
			if (matches.size() == dialog.getHeightInChars() || endTime - startTime > TIME_THRESHOLD) {
				if (monitor.isCanceled()) {
					return Status.CANCEL_STATUS;
				}
				dialog.updateMatches(sortedCopy(matches), false);
				startTime = System.currentTimeMillis();
			}
		}
	}
	dialog.updateMatches(sortedCopy(matches), true);
	return Status.OK_STATUS;
}
 
Example 5
Source File: AssociationHierarchyBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected IEObjectDescription findDeclaration(URI objectURI) {
	IEObjectDescription description = getDescription(objectURI);
	if (description != null) {
		EClass eClass = description.getEClass();
		if (isJvmType(eClass)) {
			return readOnly(description.getEObjectURI(), (EObject targetElement) -> {
				EObject sourceElement = jvmModelAssociations.getPrimarySourceElement(targetElement);
				if (sourceElement != null) {
					if (isEntity(sourceElement.eClass())) {
						return getDescription(sourceElement);
					}
				}
				return null;
			});
		}
		if (isEntity(eClass)) {
			return description;
		}
	}
	return readOnly(objectURI, (EObject object) -> {
		return getDescription(EcoreUtil2.getContainerOfType(object, Entity.class));
	});
}
 
Example 6
Source File: STextGlobalScopeProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected IScope filterPropertiesOfLibrary(Resource context, EReference reference,
		Predicate<IEObjectDescription> filter) {
	return new FilteringScope(libraryScope.getScope(context, reference, filter),
			new Predicate<IEObjectDescription>() {
				@Override
				public boolean apply(IEObjectDescription input) {
					return input.getEClass() != TypesPackage.Literals.PROPERTY;
				}
			});
}
 
Example 7
Source File: StateNamesAreUniqueValidationHelper.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void duplicateLastElement(IEObjectDescription description, IEObjectDescription doublet,
		ValidationMessageAcceptor acceptor) {
	if (inSameResource(doublet, description) && description.getEClass() == SGraphPackage.Literals.STATE
			&& doublet.getEClass() == SGraphPackage.Literals.STATE && shouldValidate(description)) {
		createDuplicateStateNameError(description, acceptor);
		createDuplicateStateNameError(doublet, acceptor);
	}
}
 
Example 8
Source File: DefaultResourceDescriptionDelta.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean equals(IEObjectDescription oldObj, IEObjectDescription newObj) {
	if (oldObj == newObj)
		return true;
	if (oldObj.getEClass() != newObj.getEClass())
		return false;
	if (oldObj.getName() != null && !oldObj.getName().equals(newObj.getName()))
		return false;
	if (!oldObj.getEObjectURI().equals(newObj.getEObjectURI()))
		return false;
	String[] oldKeys = oldObj.getUserDataKeys();
	String[] newKeys = newObj.getUserDataKeys();
	if (oldKeys.length != newKeys.length)
		return false;
	for (String key : oldKeys) {
		if (!Arrays.contains(newKeys, key))
			return false;
		String oldValue = oldObj.getUserData(key);
		String newValue = newObj.getUserData(key);
		if (oldValue == null) {
			if (newValue != null)
				return false;
		} else if (!oldValue.equals(newValue)) {
			return false;
		}
	}
	return true;
}
 
Example 9
Source File: PortableURIs.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected PortableURIs.PortableFragmentDescription createPortableFragmentDescription(IEObjectDescription desc,
		EObject target) {
	EObject possibleContainer = EcoreUtil.resolve(desc.getEObjectOrProxy(), target);
	String fragmentToTarget = getFragment(target, possibleContainer);
	return new PortableURIs.PortableFragmentDescription(desc.getEClass(), desc.getQualifiedName(),
			fragmentToTarget);
}
 
Example 10
Source File: XtendSearchFilter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean reject(IEObjectDescription element) {
	if (fileExtensionProvider.isValid(element.getEObjectURI().fileExtension())) {
		return element.getEClass() == TypesPackage.Literals.JVM_GENERIC_TYPE
			|| (TypesPackage.Literals.JVM_MEMBER.isSuperTypeOf(element.getEClass()));
	}
	return false;
}
 
Example 11
Source File: ArithmeticsCallHierarchyBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IEObjectDescription findDeclaration(URI objectURI) {
	IEObjectDescription description = this.getDescription(objectURI);
	EClass eClass = null;
	if (description != null) {
		eClass = description.getEClass();
	}
	if (this.isDefinition(eClass)) {
		return description;
	}
	return readOnly(objectURI, (EObject object) -> {
		AbstractDefinition abstractDefinition = EcoreUtil2.getContainerOfType(object, AbstractDefinition.class);
		return getDescription(abstractDefinition);
	});
}
 
Example 12
Source File: XtextCallHierarchyBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IEObjectDescription findDeclaration(URI objectURI) {
	IEObjectDescription description = getDescription(objectURI);
	if (description != null && description.getEClass() != null && isRule(description.getEClass())) {
		return description;
	}

	return readOnly(objectURI, (object) -> getDescription(getContainerOfType(object, AbstractRule.class)));
}
 
Example 13
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected StyledString getStyledDisplayString(IEObjectDescription description) {
	if (EcorePackage.Literals.EPACKAGE == description.getEClass()) {
		if ("true".equals(description.getUserData("nsURI"))) {
			String name = description.getUserData("name");
			if (name == null) {
				return new StyledString(description.getName().toString());
			}
			String string = name + " - " + description.getName();
			return new StyledString(string);
		}
	} else if(XtextPackage.Literals.GRAMMAR == description.getEClass()){
		QualifiedName qualifiedName = description.getQualifiedName();
		if(qualifiedName.getSegmentCount() >1) {
			return new StyledString(qualifiedName.getLastSegment() + " - " + qualifiedName.toString());
		}
		return new StyledString(qualifiedName.toString());
	} else if (XtextPackage.Literals.ABSTRACT_RULE.isSuperTypeOf(description.getEClass())) {
		EObject object = description.getEObjectOrProxy();
		if (!object.eIsProxy()) {
			AbstractRule rule = (AbstractRule) object;
			Grammar grammar = GrammarUtil.getGrammar(rule);
			if (description instanceof EnclosingGrammarAwareDescription) {
				if (grammar == ((EnclosingGrammarAwareDescription) description).getGrammar()) {
					return getStyledDisplayString(rule, null, rule.getName());
				}
			}
			return getStyledDisplayString(rule,
					grammar.getName() + "." + rule.getName(),
					description.getName().toString().replace(".", "::"));	
		}
		
	}
	return super.getStyledDisplayString(description);
}
 
Example 14
Source File: EObjectDescriptionBasedStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void appendType(final IEObjectDescription description, Multimap<QualifiedName, IEObjectDescription> owner2nested,
		StringBuilder classSignatureBuilder) {
	classSignatureBuilder.append("\npublic ");
	if(isNestedType(description))
		classSignatureBuilder.append("static ");
	if (description.getEClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
		if (description.getUserData(JvmTypesResourceDescriptionStrategy.IS_INTERFACE) != null) {
			classSignatureBuilder.append("interface ");
		} else {
			classSignatureBuilder.append("class ");
		}
	} else if (description.getEClass() == TypesPackage.Literals.JVM_ENUMERATION_TYPE) {
		classSignatureBuilder.append("enum ");
	} else if (description.getEClass() == TypesPackage.Literals.JVM_ANNOTATION_TYPE) {
		classSignatureBuilder.append("@interface ");
	}
	String lastSegment = description.getQualifiedName().getLastSegment();
	int trimIndex = lastSegment.lastIndexOf('$');
	String simpleName = lastSegment.substring(trimIndex + 1);
	classSignatureBuilder.append(simpleName);
	String typeParameters = description.getUserData(JvmTypesResourceDescriptionStrategy.TYPE_PARAMETERS);
	if (typeParameters != null) {
		classSignatureBuilder.append(typeParameters);
	}
	classSignatureBuilder.append("{");
	for(IEObjectDescription nested: owner2nested.get(description.getQualifiedName())) {
		appendType(nested, owner2nested, classSignatureBuilder);
	}
	classSignatureBuilder.append("\n}");
}
 
Example 15
Source File: ContextAwareTypeScope.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean isAccepted(IEObjectDescription originalDescr) {
	final EClass eClass = originalDescr.getEClass();
	if (!isValidLocationForNull && eClass == TypesPackage.Literals.NULL_TYPE) {
		return false;
	}
	if (!isValidLocationForVoid && eClass == TypesPackage.Literals.VOID_TYPE) {
		return false; // Requirements 13, Void type.
	}
	if (!isValidLocationForFunctionType && TypesPackage.Literals.TFUNCTION.isSuperTypeOf(eClass)) {
		return false;
	}
	return true;
}
 
Example 16
Source File: N4JSResourceDescriptionDelta.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean equals(IEObjectDescription oldObj, IEObjectDescription newObj) {
	if (oldObj == newObj)
		return true;
	if (oldObj.getEClass() != newObj.getEClass())
		return false;
	if (oldObj.getName() != null && !oldObj.getName().equals(newObj.getName()))
		return false;
	if (!oldObj.getEObjectURI().equals(newObj.getEObjectURI()))
		return false;
	String[] oldKeys = oldObj.getUserDataKeys();
	String[] newKeys = newObj.getUserDataKeys();
	if (oldKeys.length != newKeys.length)
		return false;
	for (String key : oldKeys) {
		// ------------------------------------------------ START of changes w.r.t. super class
		if (isIgnoredUserDataKey(key)) {
			continue;
		}
		// ------------------------------------------------ END of changes w.r.t. super class
		if (!Arrays.contains(newKeys, key))
			return false;
		String oldValue = oldObj.getUserData(key);
		String newValue = newObj.getUserData(key);
		if (oldValue == null) {
			if (newValue != null)
				return false;
		} else if (!oldValue.equals(newValue)) {
			return false;
		}
	}
	return true;
}
 
Example 17
Source File: N4JSDirtyStateEditorSupport.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private boolean equalDescriptions(IEObjectDescription newDescription,
		IEObjectDescription oldDescription, URI uri) {
	if (!newDescription.getQualifiedName().equals(oldDescription.getQualifiedName())) {
		return false;
	}
	if (!newDescription.getEClass().equals(oldDescription.getEClass())) {
		return false;
	}
	if (!newDescription.getEObjectURI().equals(oldDescription.getEObjectURI())) {
		return false;
	}
	if (TypesPackage.Literals.TMODULE == newDescription.getEClass()) {
		String newModule = newDescription.getUserData(UserDataMapper.USER_DATA_KEY_SERIALIZED_SCRIPT);
		String oldModule = oldDescription.getUserData(UserDataMapper.USER_DATA_KEY_SERIALIZED_SCRIPT);
		if (newModule == null || oldModule == null) {
			return true;
		}
		if (!newModule.equals(oldModule)) {
			TModule newModuleObj = UserDataMapper.getDeserializedModuleFromDescription(newDescription, uri);
			TModule oldModuleObj = UserDataMapper.getDeserializedModuleFromDescription(oldDescription, uri);
			// we deserialize the TModules and ignore the MD5 Hash
			newModuleObj.setAstMD5("");
			oldModuleObj.setAstMD5("");
			if (!EcoreUtilN4.equalsNonResolving(newModuleObj, oldModuleObj)) {
				return false;
			}
		}
	}
	// todo compare user data if module
	return true;
}
 
Example 18
Source File: EObjectDescriptionBasedStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isJvmDeclaredType(IEObjectDescription description) {
	EClass eClass = description.getEClass();
	return (eClass == TypesPackage.Literals.JVM_GENERIC_TYPE
			|| eClass == TypesPackage.Literals.JVM_ENUMERATION_TYPE 
			|| eClass == TypesPackage.Literals.JVM_ANNOTATION_TYPE);
}
 
Example 19
Source File: ResourceDescriptionWithoutModuleUserData.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private IEObjectDescription wrapIfModule(IEObjectDescription desc) {
	if (desc.getEClass() == TypesPackage.eINSTANCE.getTModule())
		return new EObjectDescriptionWithoutModuleUserData(desc);
	return desc;
}