Java Code Examples for org.eclipse.emf.ecore.EReference#getName()

The following examples show how to use org.eclipse.emf.ecore.EReference#getName() . 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: ASTGraphProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void getConnectedEdgesForEObjectManyCase(Node node, final List<Node> allNodes, final List<Edge> result,
		EReference currRef, final Object targets) {

	final List<Node> targetNodes = new ArrayList<>();
	final List<String> targetNodesExternal = new ArrayList<>();
	for (Object currTarget : (Collection<?>) targets) {
		final Node currTargetNode = GraphUtils.getNodeForElement(currTarget, allNodes);

		if (currTargetNode != null)
			targetNodes.add(currTargetNode);
		else if (currTarget instanceof EObject && ((EObject) currTarget).eIsProxy())
			targetNodesExternal.add(EcoreUtil.getURI((EObject) currTarget).toString());
	}
	if (!targetNodes.isEmpty() || !targetNodesExternal.isEmpty()) {
		Edge edge = new Edge(
				currRef.getName(),
				!currRef.isContainment(),
				node,
				targetNodes,
				targetNodesExternal);

		result.add(edge);
	}
}
 
Example 2
Source File: ASTGraphProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void getConnectedEdgesForEObjectSingleCase(Node node, final List<Node> allNodes, final List<Edge> result,
		EReference currRef, final Object target) {

	final Node targetNode = GraphUtils.getNodeForElement(target, allNodes);
	final String targetNodeExternal;

	if (targetNode == null && ((EObject) target).eIsProxy())
		targetNodeExternal = EcoreUtil.getURI((EObject) target).toString();
	else
		targetNodeExternal = null;

	if (targetNode != null || targetNodeExternal != null) {
		Edge edge = new Edge(
				currRef.getName(),
				!currRef.isContainment(),
				node,
				asCollection(targetNode),
				asCollection(targetNodeExternal));

		result.add(edge);
	}
}
 
Example 3
Source File: JvmFormalParameterImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String toString() {
	if (name != null) {
		return "param " + name;
	}
	String result = "param [name not computed]";
	EObject executable = eContainer();
	if (executable != null) {
		EReference containmentFeature = eContainmentFeature();
		result = result + "@" + containmentFeature.getName();
		if (containmentFeature.isMany()) {
			List<?> siblings = (List<?>) executable.eGet(eContainmentFeature());
			int idx = siblings.indexOf(this);
			result = result + "[" + idx + "]";
		}
	}
	return result; 
}
 
Example 4
Source File: ByteBufferVirtualObject.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void setReference(EReference eReference, long referenceOid, int bufferPosition) throws BimserverDatabaseException {
	EClass definedType = (EClass)eReference.getEType();
	EClass referencedEClass = getDatabaseInterface().getEClassForOid(referenceOid);
	if (!definedType.isSuperTypeOf(referencedEClass)) {
		throw new CannotStoreReferenceInFieldException(DeserializerErrorCode.REFERENCED_OBJECT_CANNOT_BE_STORED_IN_THIS_FIELD, "Cannot store a " + referencedEClass.getName() + " in " + eClass().getName() + "." + eReference.getName() + " of type " + definedType.getName());
	}

	if (bufferPosition == -1) {
		incrementFeatureCounter(eReference);
	}
	int pos = bufferPosition == -1 ? buffer.position() : bufferPosition;
	ensureCapacity(pos, 8);
	if (referenceOid < 0) {
		throw new BimserverDatabaseException("Writing a reference with oid " + referenceOid + ", this is not supposed to happen, referenced: " + referenceOid + " " + referenceOid + " from " + getOid() + " " + this);
	}
	buffer.order(ByteOrder.LITTLE_ENDIAN);
	buffer.putLong(pos, referenceOid);
	buffer.order(ByteOrder.BIG_ENDIAN);
	if (bufferPosition == -1) {
		buffer.position(buffer.position() + 8);
	}
}
 
Example 5
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void completeVariable_Parameters(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if ((mode & NORMAL) != 0) {
		VariableData data = new VariableData(model);
		if (data.doCreateProposals()) {
			String variableType = data.variable.getType();
			if ("CrossReference".equals(variableType)) {
				List<CrossReference> crossReferences = GrammarUtil.containedCrossReferences(data.rule);
				for(CrossReference crossReference: crossReferences) {
					EReference reference = GrammarUtil.getReference(crossReference);
					String fqn = reference.getEContainingClass().getName() + "." + reference.getName();
					acceptor.accept(createCompletionProposal(fqn, context));
					acceptor.accept(createCompletionProposal("'" + fqn + "'", context));
				}
			} else if ("Enum".equals(variableType)) {
				
			}
			super.completeVariable_Parameters(model, assignment, context, acceptor);	
		}
	}
}
 
Example 6
Source File: HashMapVirtualObject.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void setReference(EReference eReference, WrappedVirtualObject wrappedVirtualObject) throws BimserverDatabaseException {
	EClass definedType = (EClass)eReference.getEType();
	EClass referencedEClass = wrappedVirtualObject.eClass();
	if (!definedType.isSuperTypeOf(referencedEClass)) {
		throw new CannotStoreReferenceInFieldException(DeserializerErrorCode.REFERENCED_OBJECT_CANNOT_BE_STORED_IN_THIS_FIELD, "Cannot store a " + referencedEClass.getName() + " in " + eClass().getName() + "." + eReference.getName() + " of type " + definedType.getName());
	}
	map.put(eReference, wrappedVirtualObject);
}
 
Example 7
Source File: HashMapVirtualObject.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void setReference(EReference eReference, long referenceOid, int bufferPosition) throws BimserverDatabaseException {
	EClass definedType = (EClass)eReference.getEType();
	EClass referencedEClass = getDatabaseInterface().getEClassForOid(referenceOid);
	if (!definedType.isSuperTypeOf(referencedEClass)) {
		throw new CannotStoreReferenceInFieldException(DeserializerErrorCode.REFERENCED_OBJECT_CANNOT_BE_STORED_IN_THIS_FIELD, "Cannot store a " + referencedEClass.getName() + " in " + eClass().getName() + "." + eReference.getName() + " of type " + definedType.getName());
	}
	map.put(eReference, referenceOid);
}
 
Example 8
Source File: EObjectSnapshotProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String toString() {
	List<String> result = Lists.newArrayList();
	for (IEObjectDescription desc : descriptions) {
		result.add(desc.toString());
	}
	for (IReferenceSnapshot ref : incomingReferences) {
		EReference eRef = ref.getEReference();
		String cls = eRef.getEContainingClass().getName();
		String refString = cls + "." + eRef.getName() + ":" + eRef.getEReferenceType().getName();
		result.add("<- " + refString + " @ " + ref.getSourceEObjectUri());
	}
	Collections.sort(result);
	return Joiner.on("\n").join(result);
}
 
Example 9
Source File: EmfAssert.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private static void assertObjectResource(EObject parent, EReference ref,
		EObject model, Set<Resource> allowedResources) {
	String id = parent.eClass().getName() + "("
			+ ref.getEContainingClass().getName() + ")." + ref.getName();
	assertNotNull("Has no Resource " + id + ": " + model, model.eResource());
	assertTrue("Resource not Allowed: " + model.eResource().getURI() + "\n"
			+ id + " -> " + model.eClass().getName() + " "
			+ model.eResource().getURIFragment(model), allowedResources
			.contains(model.eResource()));
}
 
Example 10
Source File: TokenDiagnosticProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getFullReferenceName(EObject semanticObject, CrossReference reference) {
	EReference ref = GrammarUtil.getReference(reference);
	String clazz = semanticObject.eClass().getName();
	if (ref.getEContainingClass() != semanticObject.eClass())
		clazz = ref.getEContainingClass().getName() + "(" + clazz + ")";
	return clazz + "." + ref.getName();
}
 
Example 11
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void completeNestedCrossReference(CrossReference crossReference, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor, TemplateData data) {
	if (data.doCreateProposals()) {
		ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language);
		if (helper != null) {
			String contextTypeId = helper.getId(data.rule);
			ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language);
			TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
			TemplateVariableResolver crossRefResolver = getResolver(contextType, "CrossReference");
			if (crossRefResolver != null) {
				Assignment assignment = (Assignment) crossReference.eContainer();
				EReference reference = GrammarUtil.getReference(crossReference);
				if (reference != null) {
					String proposalText = "${" + assignment.getFeature() + ":CrossReference("
							+ reference.getEContainingClass().getName() + "." + reference.getName() + ")}";
					StyledString displayText = new StyledString("${", StyledString.DECORATIONS_STYLER)
							.append(assignment.getFeature())
							.append(":CrossReference(", StyledString.DECORATIONS_STYLER)
							.append(reference.getEContainingClass().getName() + "." + reference.getName(),
									StyledString.COUNTER_STYLER)
							.append(")}", StyledString.DECORATIONS_STYLER)
							.append(" - Create a new template variable", StyledString.QUALIFIER_STYLER);
					ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
					if (proposal instanceof ConfigurableCompletionProposal) {
						ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
						configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
						configurable.setSelectionLength(assignment.getFeature().length());
						configurable.setAutoInsertable(false);
						configurable.setSimpleLinkedMode(context.getViewer(), '\t');
						configurable.setPriority(configurable.getPriority() * 2);
					}
					acceptor.accept(proposal);
				}
			}
		}
	}
}
 
Example 12
Source File: EmfAssert.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private static void assertObjectResource(EObject parent, EReference ref,
		EObject model, Set<Resource> allowedResources) {
	String id = parent.eClass().getName() + "("
			+ ref.getEContainingClass().getName() + ")." + ref.getName();
	assertNotNull("Has no Resource " + id + ": " + model, model.eResource());
	assertTrue("Resource not Allowed: " + model.eResource().getURI() + "\n"
			+ id + " -> " + model.eClass().getName() + " "
			+ model.eResource().getURIFragment(model), allowedResources
			.contains(model.eResource()));
}
 
Example 13
Source File: AbstractDeclarativeScopeProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected Predicate<Method> getPredicate(EObject context, EReference reference) {
	String methodName = "scope_" + reference.getEContainingClass().getName() + "_" + reference.getName();
	return PolymorphicDispatcher.Predicates.forName(methodName, 2);
}
 
Example 14
Source File: LazyLinkingResource.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private String getQualifiedName(EReference eReference) {
	return eReference.getEContainingClass().getName() + "." + eReference.getName();
}
 
Example 15
Source File: StructureAnalyzer.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private int printClassifier(String name, EClassifier classifier, ArrayList<EClassifier> referrers, int indention) {
	out2.println(StringUtils.fill("", indention, "\t") + name + ": " + classifier.getName());
	if (count > limit) {
		return -1;
	}
	count++;
	if (classifier instanceof EClass) {
		EClass eClass = (EClass)classifier;
		int references = 0;
		for (EReference reference : eClass.getEAllReferences()) {
			String name2 = reference.getName();
			if (name2.equals("ProvidesBoundaries") || name2.equals("ContainedInStructure") || 
					name2.equals("FillsVoids") || name2.equals("IsDecomposedBy") || name2.equals("Decomposes") ||
					name2.equals("RelatedObjects") || name2.equals("IsDefinedBy") || name2.equals("ReferencedBy") ||
					name2.equals("HasAssociations") || name2.equals("HasAssignments") || name2.equals("ReferencedByPlacements") || 
					name2.equals("ConnectedTo") || name2.equals("HasCoverings") || name2.equals("HasProjections") || 
					name2.equals("HasStructuralMember") || name2.equals("ReferencedInStructures") || name2.equals("VoidsElements") ||
					name2.equals("ConnectedFrom")) {
			} else {
				boolean go = true;
				for (EClassifier referrer : referrers) {
					if (referrer == reference.getEType()) {
						go = false;
					}
				}
				if (go) {
					if (((EClass)reference.getEType()).getEStructuralFeature("wrappedValue") == null) {
						references++;
						ArrayList<EClassifier> newList = (ArrayList<EClassifier>)referrers.clone();
						newList.add(classifier);
						int newReferences = printClassifier(name2, reference.getEType(), newList, indention+1);
						if (newReferences != -1) {
							references += newReferences;
						} else {
							return -1;
						}
					}
				}
			}
		}
		return references;
	}
	return 0;
}
 
Example 16
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean isInverse(EReference eReference) {
	if (isInverseCache.containsKey(eReference)) {
		return isInverseCache.get(eReference);
	}
	throw new RuntimeException("Inverse cache not initialized for " + eReference.getName());
}
 
Example 17
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean hasInverse(EReference eReference) {
	if (hasInverseCache.containsKey(eReference)) {
		return hasInverseCache.get(eReference);
	}
	throw new RuntimeException("Has inverse cache not initialized for " + eReference.getName());
}
 
Example 18
Source File: FormatterStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected CharSequence generateFormatMethod(final EClass clazz, @Extension final JavaEMFFile file, final Collection<EReference> containmentRefs, final boolean isOverriding) {
  StringConcatenation _builder = new StringConcatenation();
  {
    if (isOverriding) {
      _builder.append("override");
    } else {
      _builder.append("def");
    }
  }
  _builder.append(" dispatch void format(");
  String _importedGenTypeName = file.importedGenTypeName(clazz);
  _builder.append(_importedGenTypeName);
  _builder.append(" ");
  String _name = this.toName(clazz);
  _builder.append(_name);
  _builder.append(", extension IFormattableDocument document) {");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("// TODO: format HiddenRegions around keywords, attributes, cross references, etc. ");
  _builder.newLine();
  {
    for(final EReference ref : containmentRefs) {
      {
        boolean _isMany = ref.isMany();
        if (_isMany) {
          _builder.append("\t");
          _builder.append("for (");
          String _importedGenTypeName_1 = file.importedGenTypeName(ref.getEReferenceType());
          _builder.append(_importedGenTypeName_1, "\t");
          _builder.append(" ");
          String _name_1 = ref.getName();
          _builder.append(_name_1, "\t");
          _builder.append(" : ");
          String _name_2 = this.toName(clazz);
          _builder.append(_name_2, "\t");
          _builder.append(".");
          String _getAccessor = file.getGetAccessor(ref);
          _builder.append(_getAccessor, "\t");
          _builder.append("()) {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("\t");
          _builder.append("format(");
          String _name_3 = ref.getName();
          _builder.append(_name_3, "\t\t");
          _builder.append(", document);");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("}");
          _builder.newLine();
        } else {
          _builder.append("\t");
          _builder.append("format(");
          String _name_4 = this.toName(clazz);
          _builder.append(_name_4, "\t");
          _builder.append(".");
          String _getAccessor_1 = file.getGetAccessor(ref);
          _builder.append(_getAccessor_1, "\t");
          _builder.append("(), document);");
          _builder.newLineIfNotEmpty();
        }
      }
    }
  }
  _builder.append("}");
  _builder.newLine();
  return _builder;
}
 
Example 19
Source File: N4JSValidationTestHelper.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private static final String getErrorInfoForDanglingEObject(EObject base, EReference ref) {
	return "in " + base.eClass().getName() + " at " + EcoreUtil.getURI(base) + " via reference " + ref.getName();
}