use of org.eclipse.xtext.common.types.JvmFeature in project xtext-xtend by eclipse.
the class DispatchHelper method getAllDispatchMethods.
protected List<JvmOperation> getAllDispatchMethods(DispatchSignature signature, JvmDeclaredType type, ContextualVisibilityHelper contextualVisibilityHelper) {
List<JvmOperation> allOperations = Lists.newArrayListWithExpectedSize(5);
Iterable<JvmFeature> allFeatures = type.findAllFeaturesByName(signature.getDispatchCaseName());
for (JvmFeature feature : allFeatures) {
if (feature instanceof JvmOperation) {
JvmOperation operationByName = (JvmOperation) feature;
if (signature.isDispatchCase(operationByName) && contextualVisibilityHelper.isVisible(operationByName)) {
allOperations.add(operationByName);
}
}
}
sort(allOperations);
return allOperations;
}
use of org.eclipse.xtext.common.types.JvmFeature in project xtext-xtend by eclipse.
the class AbstractXtendOutlineTreeBuilder method buildMembers.
protected void buildMembers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, @Extension final IXtendOutlineContext context) {
EList<JvmMember> _members = inferredType.getMembers();
for (final JvmMember member : _members) {
boolean _isProcessed = context.isProcessed(member);
boolean _not = (!_isProcessed);
if (_not) {
if ((member instanceof JvmDeclaredType)) {
boolean _isShowInherited = context.isShowInherited();
if (_isShowInherited) {
final IXtendOutlineContext typeContext = context.newContext();
final EObject sourceElement = this._iXtendJvmAssociations.getPrimarySourceElement(member);
if ((sourceElement instanceof XtendTypeDeclaration)) {
this.buildType(sourceElement, typeContext);
} else {
this.buildJvmType(((JvmDeclaredType) member), typeContext);
}
} else {
this.buildJvmType(((JvmDeclaredType) member), context);
}
} else {
if ((member instanceof JvmFeature)) {
boolean _skipFeature = this.skipFeature(((JvmFeature) member));
boolean _not_1 = (!_skipFeature);
if (_not_1) {
final IXtendOutlineContext featureContext = this.buildFeature(baseType, ((JvmFeature) member), member, context);
final Consumer<JvmGenericType> _function = (JvmGenericType it) -> {
this.buildJvmType(it, featureContext.newContext());
};
((JvmFeature) member).getLocalClasses().forEach(_function);
}
}
}
context.markAsProcessed(member);
}
}
boolean _isShowInherited_1 = context.isShowInherited();
if (_isShowInherited_1) {
this.buildInheritedMembers(inferredType, context);
}
}
use of org.eclipse.xtext.common.types.JvmFeature in project xtext-eclipse by eclipse.
the class XbaseReferenceUpdater method resolveNameConflict.
@Override
protected String resolveNameConflict(EObject referringElement, EReference reference, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_IDENTIFIABLE_ELEMENT, reference.getEReferenceType())) {
if (newTargetElement instanceof JvmType) {
JvmType type = (JvmType) newTargetElement;
if (canLinkJvmType(referringElement, type)) {
return toString(qualifiedNameProvider.getFullyQualifiedName(type));
}
}
if (newTargetElement instanceof JvmFeature) {
JvmFeature feature = (JvmFeature) newTargetElement;
if (feature.isStatic() && !isStaticExtensionFeatureCall(referringElement, reference, newTargetElement)) {
JvmDeclaredType declaringType = feature.getDeclaringType();
if (canLinkJvmType(referringElement, declaringType)) {
JvmDeclaredType parentType = declaringType;
List<String> segments = new LinkedList<String>();
segments.add(feature.getSimpleName());
segments.add(0, parentType.getSimpleName());
while (!hasImportedType(updateAcceptor, parentType)) {
parentType = parentType.getDeclaringType();
if (parentType == null) {
return toString(qualifiedNameProvider.getFullyQualifiedName(feature));
}
segments.add(0, parentType.getSimpleName());
}
return toString(QualifiedName.create(segments));
}
}
}
}
return super.resolveNameConflict(referringElement, reference, newTargetElement, updateAcceptor);
}
use of org.eclipse.xtext.common.types.JvmFeature in project xtext-eclipse by eclipse.
the class XbaseHoverDocumentationProvider method handleLink.
protected void handleLink(List<?> fragments) {
if (fragments == null || fragments.isEmpty()) {
return;
}
URI elementURI = null;
String firstFragment = fragments.get(0).toString();
int hashIndex = firstFragment.indexOf("#");
if (hashIndex != -1) {
JvmDeclaredType resolvedDeclarator = getResolvedDeclarator(firstFragment.substring(0, hashIndex));
if (resolvedDeclarator != null && !resolvedDeclarator.eIsProxy()) {
String signature = firstFragment.substring(hashIndex + 1);
int indexOfOpenBracket = signature.indexOf("(");
int indexOfClosingBracket = signature.indexOf(")");
String simpleNameOfFeature = indexOfOpenBracket != -1 ? signature.substring(0, indexOfOpenBracket) : signature;
Iterable<JvmFeature> possibleCandidates = resolvedDeclarator.findAllFeaturesByName(simpleNameOfFeature);
List<String> parameterNames = null;
if (indexOfOpenBracket != -1 && indexOfClosingBracket != -1) {
parameterNames = Strings.split(signature.substring(indexOfOpenBracket + 1, indexOfClosingBracket), ",");
}
Iterator<JvmFeature> featureIterator = possibleCandidates.iterator();
while (elementURI == null && featureIterator.hasNext()) {
JvmFeature feature = featureIterator.next();
boolean valid = false;
if (feature instanceof JvmField) {
valid = true;
} else if (feature instanceof JvmExecutable) {
JvmExecutable executable = (JvmExecutable) feature;
EList<JvmFormalParameter> parameters = executable.getParameters();
if (parameterNames == null) {
valid = true;
} else if (parameters.size() == parameterNames.size()) {
valid = true;
for (int i = 0; (i < parameterNames.size() && valid); i++) {
URI parameterTypeURI = EcoreUtil.getURI(parameters.get(i).getParameterType().getType());
IEObjectDescription expectedParameter = scopeProvider.getScope(context, new HoverReference(TypesPackage.Literals.JVM_TYPE)).getSingleElement(qualifiedNameConverter.toQualifiedName(parameterNames.get(i)));
if (expectedParameter == null || !expectedParameter.getEObjectURI().equals(parameterTypeURI)) {
valid = false;
}
}
}
}
if (valid)
elementURI = EcoreUtil.getURI(feature);
}
}
} else {
IScope scope = scopeProvider.getScope(context, new HoverReference(TypesPackage.Literals.JVM_TYPE));
IEObjectDescription singleElement = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(firstFragment));
if (singleElement != null)
elementURI = singleElement.getEObjectURI();
}
String label = "";
if (fragments.size() > 1) {
for (int i = 1; i < fragments.size(); i++) {
String portentialLabel = fragments.get(i).toString();
if (portentialLabel.trim().length() > 0)
label += portentialLabel;
}
}
if (label.length() == 0)
label = firstFragment;
if (elementURI == null)
buffer.append(label);
else {
buffer.append(createLinkWithLabel(XtextElementLinks.XTEXTDOC_SCHEME, elementURI, label));
}
}
use of org.eclipse.xtext.common.types.JvmFeature in project xtext-eclipse by eclipse.
the class XbaseHyperLinkHelper method createHyperlinksByOffset.
@Override
public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
final EObject element = getEObjectAtOffsetHelper().resolveElementAt(resource, offset);
if (element instanceof XImportDeclaration) {
XImportDeclaration importDeclaration = (XImportDeclaration) element;
if (importDeclaration.isStatic() && !importDeclaration.isWildcard()) {
final ITextRegion textRegion = getTextRegion(importDeclaration, offset);
if (textRegion != null) {
final Region region = new Region(textRegion.getOffset(), textRegion.getLength());
Iterable<JvmFeature> _allFeatures = staticImpMemberProvider.getAllFeatures(importDeclaration);
for (final JvmFeature feature : _allFeatures) {
this.createHyperlinksTo(resource, region, feature, acceptor);
}
}
}
}
super.createHyperlinksByOffset(resource, offset, acceptor);
if (canShowMany(acceptor)) {
if (element instanceof XVariableDeclaration) {
XVariableDeclaration variableDeclaration = (XVariableDeclaration) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(element, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, node) && variableDeclaration.getType() == null) {
addOpenInferredTypeHyperlink(resource, variableDeclaration, node, acceptor);
}
}
if (element instanceof JvmFormalParameter) {
JvmFormalParameter param = (JvmFormalParameter) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(element, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME, node) && param.getParameterType() == null) {
addOpenInferredTypeHyperlink(resource, param, node, acceptor);
}
}
}
}
Aggregations