Java Code Examples for org.eclipse.emf.common.util.EList#get()

The following examples show how to use org.eclipse.emf.common.util.EList#get() . 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 Project: birt   File: LineSeriesImpl.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private SampleData getConvertedSampleData( SampleData currentSampleData,
		int iSeriesDefinitionIndex )
{
	// Do NOT convert the base sample data since the base axis is not being
	// changed

	// Convert orthogonal sample data
	EList<OrthogonalSampleData> osdList = currentSampleData.getOrthogonalSampleData( );
	for ( int i = 0; i < osdList.size( ); i++ )
	{
		if ( i == iSeriesDefinitionIndex )
		{
			OrthogonalSampleData osd = osdList.get( i );
			osd.setDataSetRepresentation( getConvertedOrthogonalSampleDataRepresentation( osd.getDataSetRepresentation( ) ) );
			currentSampleData.getOrthogonalSampleData( ).set( i, osd );
		}
	}
	return currentSampleData;
}
 
Example 2
Source Project: birt   File: ChartWithAxesImpl.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public IValueSeries[][] getValueSeries( )
{
	Axis bAxis = (Axis) getChartWithAxes( ).getAxes( ).get( 0 );
	EList oAxes = bAxis.getAssociatedAxes( );
	IValueSeries[][] valueSeries = new IValueSeries[oAxes.size( )][];
	for ( int i = 0; i < oAxes.size( ); i++ )
	{
		Axis oAxis = (Axis) oAxes.get( i );
		EList oSeries = oAxis.getSeriesDefinitions( );
		valueSeries[i] = new IValueSeries[oSeries.size( )];
		for ( int j = 0; j < oSeries.size( ); j++ )
		{
			SeriesDefinition sd = (SeriesDefinition) oSeries.get( j );
			valueSeries[i][j] = ValueSeriesImpl.createValueSeries( sd, cm );
		}
	}
	return valueSeries;
}
 
Example 3
@Test
public void should_migrateAfter_update_version_in_connector_configuration() throws Exception {
    //Given
    doCallRealMethod().when(updateConnectorVersionMigration).migrateAfter(model, metamodel);
    final EList<Instance> connectorConfigInstanceList = connectorConfiguratiobInstanceList("id1", "id2");
    final Instance oldConnectorConfInstance = aConnectorConfigurationInstance("id1", "0.9");
    connectorConfigInstanceList.add(oldConnectorConfInstance);
    when(model.getAllInstances("connectorconfiguration.ConnectorConfiguration")).thenReturn(connectorConfigInstanceList);
    when(model.getAllInstances("process.Connector")).thenReturn(new BasicEList<Instance>());
    when(updateConnectorVersionMigration.shouldUpdateVersion("id1")).thenReturn(true);
    when(updateConnectorVersionMigration.getOldDefinitionVersion()).thenReturn("1.0");
    when(updateConnectorVersionMigration.getNewDefinitionVersion()).thenReturn("2.0");

    //When
    updateConnectorVersionMigration.migrateAfter(model, metamodel);

    //Then
    final Instance id1ConnectorConf = connectorConfigInstanceList.get(0);
    final Instance id2ConnectorConf = connectorConfigInstanceList.get(1);
    verify(id1ConnectorConf).set(UpdateConnectorDefinitionMigration.VERSION_FEATURE_NAME, "2.0");
    verify(id2ConnectorConf, never()).set(UpdateConnectorDefinitionMigration.VERSION_FEATURE_NAME, "2.0");
    verify(oldConnectorConfInstance, never()).set(UpdateConnectorDefinitionMigration.VERSION_FEATURE_NAME, "2.0");
}
 
Example 4
Source Project: birt   File: ChartWithAxesImpl.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This method returns all (primary and overlay) orthogonal axes for a given
 * base axis If the primary orthogonal is requested for, it would be
 * returned as the first element in the array
 * 
 * NOTE: Manually written
 * 
 * @param axBase
 * @return Axis array
 */
public final Axis[] getOrthogonalAxes( Axis axBase, boolean bIncludePrimary )
{
	final EList<Axis> elAxes = axBase.getAssociatedAxes( );
	final int iAxisCount = elAxes.size( );
	final int iDecrease = bIncludePrimary ? 0 : 1;
	final Axis[] axa = new Axis[iAxisCount - iDecrease];

	for ( int i = 0, j = 1 - iDecrease; i < iAxisCount; i++ )
	{
		Axis ax = elAxes.get( i );
		if ( !ax.isPrimaryAxis( ) )
		{
			axa[j++] = ax;
		}
		else if ( bIncludePrimary )
		{
			axa[0] = ax;
		}
	}
	return axa;
}
 
Example 5
Source Project: sarl   File: SARLLabelProviderTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception
 */
@Test
public void getTextJvmParametizedTypeReference_1() throws Exception {
	SarlEvent event = helper().sarlTypeDeclaration(
			SarlEvent.class,
			PACKAGE_STATEMENT
			+ "event E1 {\n" //$NON-NLS-1$
			+ "var attr : org.eclipse.xtext.xbase.lib.Pair<java.lang.Integer,java.lang.Double>\n" //$NON-NLS-1$
			+ "}"); //$NON-NLS-1$
	validate(event.eResource()).assertNoErrors();
	EList<XtendMember> features = event.getMembers();
	assertNotNull(features);
	assertEquals(1, features.size());
	EObject eObject = features.get(0);
	assertTrue(eObject instanceof SarlField);
	SarlField attr = (SarlField)eObject;
	JvmTypeReference typeReference = attr.getType();
	assertTrue(typeReference instanceof JvmParameterizedTypeReference);
	JvmParameterizedTypeReference parametizedTypeReference = (JvmParameterizedTypeReference)typeReference;
	Object text = this.provider.getText(parametizedTypeReference);
	assertNotNull(text);
	assertEquals("Pair<Integer, Double>", text); //$NON-NLS-1$
}
 
Example 6
@SuppressWarnings("javadoc")
@Test
public void test_fullRef_simpleName() {
	String in = "/** foo."
			+ "\n * @testee n4/model/collections/DataSet.DataSet.each"
			+ "\n */";
	AbstractLineTagDefinition tagDef = new LineTagWithFullMemberReference("testee");
	DocletParser docletParser = new DocletParser(new TagDictionary<>(Arrays.asList(tagDef)),
			new TagDictionary<AbstractInlineTagDefinition>());
	Doclet doclet = docletParser.parse(in);

	LineTag lineTag = doclet.getLineTags().get(0);

	EList<ContentNode> contents = lineTag.getValueByKey(LineTagWithFullElementReference.REF)
			.getContents();
	FullMemberReference ref = (FullMemberReference) contents.get(0);

	assertEquals("n4/model/collections/DataSet", ref.getModuleName());
	assertEquals("DataSet", ref.getTypeName());
	assertEquals("each", ref.getMemberName());
}
 
Example 7
@Test public void testInferredFunction_06() throws Exception {
	XtendFile xtendFile = file("class Foo { def Iterable<? super CharSequence> create result: newArrayList(s) newList(String s) {} }");
	JvmGenericType inferredType = getInferredType(xtendFile);
	XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
	EList<JvmMember> jvmMembers = inferredType.getMembers();
	assertEquals(4, jvmMembers.size());
	JvmMember jvmMember = jvmMembers.get(1);
	assertTrue(jvmMember instanceof JvmOperation);
	XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
	assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
	assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
	assertEquals("java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
	
	JvmField cacheVar = (JvmField) jvmMembers.get(2);
	assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
	assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
	assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
	
	JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
	assertEquals("_init_"+xtendFunction.getName(), privateInitializer.getSimpleName());
	assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
	assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
	assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
 
Example 8
@Test public void testCommentAssociationAtEndOfFile() throws Exception {
	String textModel = "element x // comment post x";
	Model model = (Model) getModel(textModel);
	Multimap<EObject, String> multimap = createModel2CommentMap(model);
	EList<Element> elements = model.getElements();
	Element x = elements.get(0);

	checkComments(multimap, x, "// comment post x");
}
 
Example 9
public void cleanAssociationState(Resource resource) {
	checkLanguageResource(resource);
	List<EObject> derived = Lists.newArrayList();
	EList<EObject> resourcesContentsList = resource.getContents();
	for (int i = 1; i < resourcesContentsList.size(); i++) {
		EObject eObject = resourcesContentsList.get(i);
		unloader.unloadRoot(eObject);
		derived.add(eObject);
	}
	resourcesContentsList.removeAll(derived);
	sourceToTargetMap(resource).clear();
	targetToSourceMap(resource).clear();
	getLogicalContainerMapping(resource).clear();
}
 
Example 10
Source Project: birt   File: ChartValueUpdater.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected void rotateAxesTitle( ChartWithAxes cwa )
{
	boolean isHorizontal = (cwa.getOrientation( ) == Orientation.HORIZONTAL_LITERAL );
	Axis aX = cwa.getAxes( ).get( 0 );
	if ( aX.getTitle( ).isSetVisible( )
			&& aX.getTitle( ).isVisible( )
			&& !aX.getTitle( ).getCaption( ).getFont( ).isSetRotation( ) )
	{
		if ( isHorizontal )
		{
			aX.getTitle( ).getCaption( ).getFont( ).setRotation( 90 );
		}
		else
		{
			aX.getTitle( ).getCaption( ).getFont( ).setRotation( 0 );
		}
	}

	EList<Axis> aYs = aX.getAssociatedAxes( );
	for ( int i = 0; i < aYs.size( ); i++ )
	{

		Axis aY = aYs.get( i );
		if ( aY.getTitle( ).isSetVisible( )
				&& aY.getTitle( ).isVisible( )
				&& !aY.getTitle( ).getCaption( ).getFont( ).isSetRotation( ) )
		{
			if ( isHorizontal )
			{
				aY.getTitle( ).getCaption( ).getFont( ).setRotation( 0 );
			}
			else
			{
				aY.getTitle( ).getCaption( ).getFont( ).setRotation( 90 );
			}
		}
	}
}
 
Example 11
private boolean isExpressionReferenceABusinessData(final Expression value) {
    if (value != null) {
        final EList<EObject> referencedElements = value.getReferencedElements();
        return !referencedElements.isEmpty()
                && referencedElements.get(0) instanceof BusinessObjectData;
    } else {
        return false;
    }
}
 
Example 12
Source Project: n4js   File: N4JSDReader.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private FullMemberReference getFullMemberRef(LineTag tag) {
	EList<ContentNode> contents = tag.getValueByKey(LineTagWithFullElementReference.REF).getContents();
	if (!contents.isEmpty()) {
		return (FullMemberReference) contents.get(0);
	}
	return null;
}
 
Example 13
Source Project: birt   File: ChartWithAxesImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public Axis getAncillaryBaseAxis( Axis axBase )
{
	final EList<Axis> elAxes = axBase.getAncillaryAxes( );
	final int iAxisCount = elAxes.size( );

	if ( iAxisCount > 0 )
	{
		return elAxes.get( 0 );
	}

	return null;
}
 
Example 14
@Test public void testInferredFunction_01() throws Exception {
	XtendFile xtendFile = file("class Foo { def bar() { true } }");
	JvmGenericType inferredType = getInferredType(xtendFile);
	XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
	EList<JvmMember> jvmMembers = inferredType.getMembers();
	assertEquals(2, jvmMembers.size());
	JvmMember jvmMember = jvmMembers.get(1);
	assertTrue(jvmMember instanceof JvmOperation);
	XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
	assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
	assertEquals(jvmMember, associations.getDirectlyInferredOperation(xtendFunction));
	assertEquals(xtendFunction, associations.getXtendFunction((JvmOperation) inferredType.getMembers().get(1)));
}
 
Example 15
private void initRowExpressions( ChartWithAxes cwa, IActionEvaluator iae )
		throws ChartException
{
	final Axis axPrimaryBase = cwa.getPrimaryBaseAxes( )[0];
	EList<SeriesDefinition> elSD = axPrimaryBase.getSeriesDefinitions( );
	if ( elSD.size( ) != 1 )
	{
		throw new ChartException( ChartEnginePlugin.ID,
				ChartException.GENERATION,
				"dataprocessor.exception.CannotDecipher2", //$NON-NLS-1$
				Messages.getResourceBundle( this.locale ) );
	}

	// PROJECT THE EXPRESSION ASSOCIATED WITH THE BASE SERIES DEFINITION
	SeriesDefinition baseSD = elSD.get( 0 );
	this.strBaseAggExp = getBaseAggregationExpression( baseSD );
	addLookupForBaseSeries( baseSD );

	// PROJECT ALL DATA DEFINITIONS ASSOCIATED WITH THE ORTHOGONAL SERIES
	final Axis[] axaOrthogonal = cwa.getOrthogonalAxes( axPrimaryBase, true );
	for ( int j = 0; j < axaOrthogonal.length; j++ )
	{
		addLookupForOrthogonalSeries( baseSD, axaOrthogonal[j].getSeriesDefinitions( ),
				iae );
	}

	// If base sort expression is not base series or value series, directly
	// add the expression.
	addCommonSortKey( baseSD );
}
 
Example 16
Source Project: birt   File: ChartWithAxesImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method needs to be called after the chart has been populated with
 * runtime datasets and runtime series have been associated with each of the
 * series definitions.
 * 
 * @param iBaseOrOrthogonal
 * @return All series associated with the specified axis types
 */
public final Series[] getSeries( int iBaseOrOrthogonal )
{
	final ArrayList<Series> al = new ArrayList<Series>( 8 );
	final Axis[] axaBase = getBaseAxes( );
	Axis[] axaOrthogonal;
	SeriesDefinition sd;
	EList<SeriesDefinition> el;

	for ( int i = 0; i < axaBase.length; i++ )
	{
		if ( ( iBaseOrOrthogonal | IConstants.BASE ) == IConstants.BASE )
		{
			el = axaBase[i].getSeriesDefinitions( );
			for ( int j = 0; j < el.size( ); j++ )
			{
				sd = el.get( j );
				al.addAll( sd.getRunTimeSeries( ) );
			}
		}
		axaOrthogonal = getOrthogonalAxes( axaBase[i], true );
		for ( int j = 0; j < axaOrthogonal.length; j++ )
		{
			if ( ( iBaseOrOrthogonal | IConstants.ORTHOGONAL ) == IConstants.ORTHOGONAL )
			{
				el = axaOrthogonal[j].getSeriesDefinitions( );
				for ( int k = 0; k < el.size( ); k++ )
				{
					sd = el.get( k );
					al.addAll( sd.getRunTimeSeries( ) );
				}
			}
		}
	}

	return al.toArray( new Series[al.size( )] );
}
 
Example 17
private static ProxyCompositeNode uninstallProxyNode(final EObject eObject) {
  EList<Adapter> adapters = eObject.eAdapters();
  int size = adapters.size();
  for (int i = 0; i < size; ++i) {
    Adapter adapter = adapters.get(i);
    if (adapter.isAdapterForType(ProxyCompositeNode.class)) {
      if (adapter instanceof ProxyCompositeNode) {
        return (ProxyCompositeNode) adapters.remove(i);
      }
      break;
    }
  }
  return null;
}
 
Example 18
protected void toJavaWhileStatement(XBasicForLoopExpression expr, ITreeAppendable b, boolean isReferenced) {
	ITreeAppendable loopAppendable = b.trace(expr);
	
	boolean needBraces = !bracesAreAddedByOuterStructure(expr);
	if (needBraces) {
		loopAppendable.newLine().increaseIndentation().append("{");
		loopAppendable.openPseudoScope();
	}
	
	EList<XExpression> initExpressions = expr.getInitExpressions();
	for (int i = 0; i < initExpressions.size(); i++) {
		XExpression initExpression = initExpressions.get(i);
		if (i < initExpressions.size() - 1) {
			internalToJavaStatement(initExpression, loopAppendable, false);
		} else {
			internalToJavaStatement(initExpression, loopAppendable, isReferenced);
			if (isReferenced) {
				loopAppendable.newLine().append(getVarName(expr, loopAppendable)).append(" = (");
				internalToConvertedExpression(initExpression, loopAppendable, getLightweightType(expr));
				loopAppendable.append(");");
			}
		}
	}

	final String varName = loopAppendable.declareSyntheticVariable(expr, "_while");
	
	XExpression expression = expr.getExpression();
	if (expression != null) {
		internalToJavaStatement(expression, loopAppendable, true);
		loopAppendable.newLine().append("boolean ").append(varName).append(" = ");
		internalToJavaExpression(expression, loopAppendable);
		loopAppendable.append(";");
	} else {
		loopAppendable.newLine().append("boolean ").append(varName).append(" = true;");
	}
	loopAppendable.newLine();
	loopAppendable.append("while (");
	loopAppendable.append(varName);
	loopAppendable.append(") {").increaseIndentation();
	loopAppendable.openPseudoScope();
	
	XExpression eachExpression = expr.getEachExpression();
	internalToJavaStatement(eachExpression, loopAppendable, false);
	
	EList<XExpression> updateExpressions = expr.getUpdateExpressions();
	if (!updateExpressions.isEmpty()) {
		for (XExpression updateExpression : updateExpressions) {
			internalToJavaStatement(updateExpression, loopAppendable, false);
		}
	}
	
	if (!isEarlyExit(eachExpression)) {
		if (expression != null) {
			internalToJavaStatement(expression, loopAppendable, true);
			loopAppendable.newLine().append(varName).append(" = ");
			internalToJavaExpression(expression, loopAppendable);
			loopAppendable.append(";");
		} else {
			loopAppendable.newLine().append(varName).append(" = true;");
		}
	}
	
	loopAppendable.closeScope();
	loopAppendable.decreaseIndentation().newLine().append("}");
	
	if (needBraces) {
		loopAppendable.closeScope();
		loopAppendable.decreaseIndentation().newLine().append("}");
	}
}
 
Example 19
/** {@inheritDoc} */
@Override
@SuppressWarnings({"unchecked", "PMD.NPathComplexity"})
public EObject getEObjectFromSegment(final EObject container, final String segment) {
  final int selectorEndOffset = segment.lastIndexOf(SELECTOR_END);
  if (selectorEndOffset != -1) {
    final int selectorOffset = segment.indexOf(SELECTOR_START);
    final int containmentFeatureId = Integer.parseUnsignedInt(segment.substring(0, selectorOffset));
    final EStructuralFeature containmentFeature = container.eClass().getEStructuralFeature(containmentFeatureId);
    if (containmentFeature == null) {
      return null;
    }
    if (!containmentFeature.isMany()) {
      return (EObject) container.eGet(containmentFeature);
    }
    final int eqOffset = segment.indexOf(EQ_OP, selectorOffset);
    final int selectorFeatureId = Integer.parseUnsignedInt(segment.substring(selectorOffset + 1, eqOffset));
    boolean uniqueMatch = segment.charAt(selectorEndOffset - 1) == UNIQUE;
    int matchedIndex = uniqueMatch ? 0 : Integer.parseUnsignedInt(segment.substring(selectorEndOffset + 2));
    boolean isNull = segment.startsWith(NULL_VALUE, eqOffset + EQ_OP_LENGTH);
    String matchedValue = isNull ? null
        : unescape(segment.substring(eqOffset + EQ_OP_LENGTH + 1, uniqueMatch ? selectorEndOffset - 2 : selectorEndOffset - 1));
    int index = 0;
    EList<? extends EObject> containmentList = (EList<? extends EObject>) container.eGet(containmentFeature);
    int containmentListSize = containmentList.size();
    for (int i = 0; i < containmentListSize; i++) {
      EObject object = containmentList.get(i);
      Object value = object.eGet(object.eClass().getEStructuralFeature(selectorFeatureId));
      if (value == null) {
        if (matchedValue == null && index++ == matchedIndex) {
          return object;
        }
      } else {
        if ((isCaseSensitive(object.eClass()) ? value.toString().equals(matchedValue) : value.toString().equalsIgnoreCase(matchedValue))
            && index++ == matchedIndex) {
          return object;
        }
      }
    }
    return null;
  } else {
    return shortFragmentProvider.getEObjectFromSegment(container, segment);
  }
}
 
Example 20
Source Project: birt   File: FillUtil.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the fill from palette. If the index is less than the palette
 * colors size, simply return the fill. If else, first return brighter fill,
 * then darker fill. The color fetching logic is like this: In the first
 * round, use the color from palette directly. In the second round, use the
 * brighter color of respective one in the first round. In the third round,
 * use the darker color of respective one in the first round. In the forth
 * round, use the brighter color of respective one in the second round. In
 * the fifth round, use the darker color of respective one in the third
 * round. ...
 * 
 * @param elPalette
 * @param index
 * @since 2.5
 * @return fill from palette
 */
public static Fill getPaletteFill( EList<Fill> elPalette, int index )
{
	final int iPaletteSize = elPalette.size( );
	if ( iPaletteSize == 0 )
	{
		return null;
	}
	
	Fill fill = elPalette.get( index % iPaletteSize );
	if ( index < iPaletteSize )
	{
		return goFactory.copyOf( fill );
	}

	if ( fill instanceof ColorDefinition )
	{
		return tunePaletteColor( (ColorDefinition) fill,
				iPaletteSize,
				index );
	}

	int d = index / iPaletteSize;
	if ( d % 2 != 0 )
	{
		Fill brighterFill = getBrighterFill( fill );
		while ( d / 2 > 0 )
		{
			d -= 2;
			brighterFill = getBrighterFill( brighterFill );
		}
		return brighterFill;
	}
	Fill darkerFill = getDarkerFill( fill );
	while ( ( d - 1 ) / 2 > 0 )
	{
		d -= 2;
		darkerFill = getDarkerFill( darkerFill );
	}
	return darkerFill;
}