Java 类org.eclipse.xtext.xbase.compiler.output.ITreeAppendable 实例源码

项目:xtext-extras    文件:JvmTypesBuilder.java   
/**
 * Creates a <code>toString()</code> method accumulating the values of all fields.
 *
 * @return a result representing a Java toString() method, <code>null</code> if sourceElement or declaredType are <code>null</code>.
 */
/* @Nullable */ 
public JvmOperation toToStringMethod(/* @Nullable */ final EObject sourceElement, /* @Nullable */ final JvmDeclaredType declaredType) {
    if(sourceElement == null || declaredType == null)
        return null;
    JvmOperation result = toMethod(sourceElement, "toString", newTypeRef(sourceElement, String.class), null);
    if (result == null)
        return null;
    JvmType overrideType = references.findDeclaredType(Override.class, sourceElement);
    if (overrideType != null)
        result.getAnnotations().add(toAnnotation(sourceElement, Override.class));
    setBody(result, new Procedure1<ITreeAppendable>() {
        @Override
        public void apply(/* @Nullable */ ITreeAppendable p) {
            if (p == null)
                return;
            p.append("String result = new ");
            p.append(ToStringBuilder.class);
            p.append("(this).addAllFields().toString();");
            p.newLine().append("return result;");
        }
    });
    return result;
}
项目:xtext-extras    文件:LoopExtensions.java   
/**
 * Uses curly braces and comma as delimiters. Doesn't use them for single valued iterables.
 */
public <T extends Object> void forEachWithShortcut(final ITreeAppendable appendable, final Iterable<T> elements, final Procedure1<? super T> procedure) {
  int _size = IterableExtensions.size(elements);
  boolean _equals = (_size == 1);
  if (_equals) {
    T _head = IterableExtensions.<T>head(elements);
    ObjectExtensions.<T>operator_doubleArrow(_head, procedure);
  } else {
    appendable.append("{");
    final Procedure1<LoopParams> _function = (LoopParams it) -> {
      it.setPrefix(" ");
      it.setSeparator(", ");
      it.setSuffix(" ");
    };
    this.<T>forEach(appendable, elements, _function, procedure);
    appendable.append("}");
  }
}
项目:dsl-devkit    文件:CheckCompiler.java   
@Override
// CHECKSTYLE:OFF
protected void _toJavaExpression(final XAbstractFeatureCall expr, final ITreeAppendable b) {
  // CHECKSTYLE:ON
  FormalParameter parameter = getFormalParameter(expr);
  if (parameter != null) {
    // No Java entities are generated for this. Replace by a call to the getter function.
    b.append(generatorNaming.catalogInstanceName(parameter)).append(".").append(generatorNaming.formalParameterGetterName(parameter));
    b.append("(").append(getContextImplicitVariableName(expr)).append(")");
  } else {
    Member member = getMember(expr);
    if (member != null) {
      // Something isn't quite right in the Jvm model yet... or in the xbase compiler. Don't know what it is, but even if in an inner
      // class, it generates "this.foo" instead of either just "foo" or "OuterClass.this.foo". Force it to produce the latter.
      CheckCatalog catalog = EcoreUtil2.getContainerOfType(member, CheckCatalog.class);
      String catalogName = generatorNaming.validatorClassName(catalog);
      b.append(catalogName + ".this.").append(member.getName());
      return;
    }
    super._toJavaExpression(expr, b);
  }
}
项目:dsl-devkit    文件:CheckCompiler.java   
@Override
protected void appendImmutableCollectionExpression(final XCollectionLiteral literal, final ITreeAppendable b, final String collectionsMethod, final Class<?> guavaHelper, final String guavaHelperMethod) {
  // This is a work-around for a bug in the xbase compiler, which always constructs empty list literals #[] as List<Object>,
  // which then cannot be assigned (without cast) to any typed list. Note that this is not a problem in check; it also occurs
  // in plain xtend.
  if (literal.getElements().isEmpty()) {
    JvmType collectionsClass = findKnownTopLevelType(Collections.class, literal);
    if (collectionsClass != null) {
      if (literal instanceof XListLiteral) {
        b.append(collectionsClass).append(".emptyList()");
        return;
      } else if (literal instanceof XSetLiteral) {
        b.append(collectionsClass).append(".emptySet()");
        return;
      }
    }
  }
  super.appendImmutableCollectionExpression(literal, b, collectionsMethod, guavaHelper, guavaHelperMethod);
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
private void convertMultiType(LightweightTypeReference expectation, CompoundTypeReference multiType, XExpression context,
        ITreeAppendable b, Later expression) {
    LightweightTypeReference castTo = null;
    List<LightweightTypeReference> components = multiType.getMultiTypeComponents();
    ITypeReferenceOwner owner = multiType.getOwner();
    LightweightTypeReference commonType = owner.getServices().getTypeConformanceComputer().getCommonSuperType(components, owner);
    if (!isJavaConformant(expectation, commonType)) {
        for(LightweightTypeReference candidate: multiType.getMultiTypeComponents()) {
            if (isJavaConformant(expectation, candidate)) {
                castTo = candidate;
                break;
            }
        }
    }
    if (castTo != null && mustInsertTypeCast(context, castTo)) {
        b.append("((");
        b.append(castTo);
        b.append(")");
        expression.exec(b);
        b.append(")");
    } else {
        expression.exec(b);
    }
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected void _toJavaStatement(final XSynchronizedExpression synchronizedExpression, final ITreeAppendable b, boolean isReferenced) {
    if (isReferenced) {
        declareSyntheticVariable(synchronizedExpression, b);
    }
    ITreeAppendable synchronizedAppendable = b.trace(synchronizedExpression, true);
    XExpression param = synchronizedExpression.getParam();
    if (!canCompileToJavaExpression(param, b))
        internalToJavaStatement(param, synchronizedAppendable, isReferenced);

    synchronizedAppendable.newLine().append("synchronized (");
    internalToJavaExpression(param, synchronizedAppendable);
    synchronizedAppendable.append(") {").increaseIndentation();
    synchronizedAppendable.openPseudoScope();

    XExpression expression = synchronizedExpression.getExpression();
    internalToJavaStatement(expression, b, isReferenced);
    if (isReferenced) {
        b.newLine().append(getVarName(synchronizedExpression, synchronizedAppendable)).append(" = ");
        internalToConvertedExpression(expression, b, getLightweightType(synchronizedExpression));
        b.append(";");
    }

    synchronizedAppendable.closeScope();
    synchronizedAppendable.decreaseIndentation().newLine().append("}");
}
项目:xtext-extras    文件:EvaluationCompilerTest.java   
protected String compileToJavaCode(String xtendCode) {
    XExpression model = null;
    ITreeAppendable appendable = new FakeTreeAppendable();
    try {
        model = expression(xtendCode, true);
        XbaseCompiler compiler = compilerProvider.get();
        LightweightTypeReference objectRef = new StandardTypeReferenceOwner(services, model).newReferenceToObject();
        compiler.compile(model, appendable, objectRef);
    } catch (Exception e) {
        throw new RuntimeException("Xtend compilation failed", e);
    } finally {
        if (model != null)
            cache.clear(model.eResource());
    }
    return appendable.getContent();
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
protected void featureCalltoJavaExpression(final XAbstractFeatureCall call, ITreeAppendable b, boolean isExpressionContext) {
    if (call instanceof XAssignment) {
        assignmentToJavaExpression((XAssignment) call, b, isExpressionContext);
    } else {
        if (needMultiAssignment(call)) {
            appendLeftOperand(call, b, isExpressionContext).append(" = ");
        }
        final JvmAnnotationReference annotationRef = this.expressionHelper.findInlineAnnotation(call);
        if (annotationRef == null || !isConstantExpression(annotationRef)) {
            boolean hasReceiver = appendReceiver(call, b, isExpressionContext);
            if (hasReceiver) {
                b.append(".");
                b = appendTypeArguments(call, b);
            }
        }
        appendFeatureCall(call, b);
    }
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public void generateParameters(final JvmExecutable it, final ITreeAppendable appendable, final GeneratorConfig config) {
  boolean _isEmpty = it.getParameters().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    int _size = it.getParameters().size();
    int _minus = (_size - 1);
    IntegerRange _upTo = new IntegerRange(0, _minus);
    for (final Integer i : _upTo) {
      {
        int _size_1 = it.getParameters().size();
        final boolean last = (((i).intValue() + 1) == _size_1);
        final JvmFormalParameter p = it.getParameters().get((i).intValue());
        this.generateParameter(p, appendable, (last && it.isVarArgs()), config);
        if ((!last)) {
          appendable.append(", ");
        }
      }
    }
  }
}
项目:xtext-extras    文件:JvmModelGenerator.java   
protected ITreeAppendable _generateMember(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    appendable.newLine();
    appendable.openScope();
    this.assignThisAndSuper(appendable, it, config);
    ITreeAppendable _xtrycatchfinallyexpression = null;
    try {
      _xtrycatchfinallyexpression = this.generateBody(it, appendable, config);
    } finally {
      appendable.closeScope();
    }
    _xblockexpression = _xtrycatchfinallyexpression;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public ITreeAppendable generateModifier(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (it instanceof JvmConstructor) {
    return _generateModifier((JvmConstructor)it, appendable, config);
  } else if (it instanceof JvmOperation) {
    return _generateModifier((JvmOperation)it, appendable, config);
  } else if (it instanceof JvmField) {
    return _generateModifier((JvmField)it, appendable, config);
  } else if (it instanceof JvmGenericType) {
    return _generateModifier((JvmGenericType)it, appendable, config);
  } else if (it instanceof JvmDeclaredType) {
    return _generateModifier((JvmDeclaredType)it, appendable, config);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, appendable, config).toString());
  }
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected void _toJavaExpression(XSetLiteral literal, ITreeAppendable b) {
    LightweightTypeReference literalType = batchTypeResolver.resolveTypes(literal).getActualType(literal);
    if (literalType == null) {
        b.append("error - couldn't compute type for literal : "+literal);
        return;
    } 
    if (literalType.isType(Map.class)) {
        LightweightTypeReference keyType = literalType.getTypeArguments().get(0);
        LightweightTypeReference valueType = literalType.getTypeArguments().get(1);
        b.append(Collections.class)
            .append(".<").append(keyType).append(", ").append(valueType)
            .append(">unmodifiableMap(");
        b.append(CollectionLiterals.class).append(".<").append(keyType).append(", ").append(valueType).append(">newHashMap(");
        Iterator<XExpression> elements = literal.getElements().iterator();
        while(elements.hasNext())  {
            XExpression element = elements.next();
            internalToJavaExpression(element, b);
            if (elements.hasNext()) {
                b.append(", ");
            }
        }
        b.append("))");
    } else {
        appendImmutableCollectionExpression(literal, b, "unmodifiableSet", CollectionLiterals.class, "newHashSet");
    }
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected void appendImmutableCollectionExpression(XCollectionLiteral literal,
        ITreeAppendable b, String collectionsMethod, Class<?> guavaHelper, String guavaHelperMethod) {
    LightweightTypeReference collectionElementType = getCollectionElementType(literal);
    b.append(Collections.class);
    b.append(".<").append(collectionElementType).append(">").append(collectionsMethod).append("(");
    b.append(guavaHelper).append(".<").append(collectionElementType).append(">").append(guavaHelperMethod).append("(");
    boolean isFirst = true;
    for(XExpression element: literal.getElements())  {
        if(!isFirst)
            b.append(", ");
        isFirst = false;
        if(element instanceof XNullLiteral) {
            b.append("(").append(collectionElementType).append(")");
        }
        internalToJavaExpression(element, b);
    }
    b.append("))");
    return;
}
项目:xtext-extras    文件:TreeAppendableUtil.java   
public ITreeAppendable traceSignificant(final ITreeAppendable appendable, final EObject source, final boolean useForDebugging) {
  ITreeAppendable _xifexpression = null;
  if ((appendable instanceof TreeAppendable)) {
    _xifexpression = ((TreeAppendable)appendable).trace(source, ILocationInFileProviderExtension.RegionDescription.SIGNIFICANT, useForDebugging);
  } else {
    ITreeAppendable _xblockexpression = null;
    {
      ITextRegion _significantTextRegion = this.locationProvider.getSignificantTextRegion(source);
      final ITextRegionWithLineInformation it = ((ITextRegionWithLineInformation) _significantTextRegion);
      ITreeAppendable _xifexpression_1 = null;
      if (((it != null) && (it != ITextRegion.EMPTY_REGION))) {
        int _offset = it.getOffset();
        int _length = it.getLength();
        int _lineNumber = it.getLineNumber();
        int _endLineNumber = it.getEndLineNumber();
        LocationData _locationData = new LocationData(_offset, _length, _lineNumber, _endLineNumber, null);
        _xifexpression_1 = appendable.trace(_locationData, useForDebugging);
      } else {
        _xifexpression_1 = appendable;
      }
      _xblockexpression = _xifexpression_1;
    }
    _xifexpression = _xblockexpression;
  }
  return _xifexpression;
}
项目:xtext-extras    文件:ErrorSafeExtensions.java   
public void serializeSafely(final JvmAnnotationReference annotationRef, final ITreeAppendable appendable, final Procedure1<? super ITreeAppendable> onSuccess) {
  if (((annotationRef == null) || (annotationRef.getAnnotation() == null))) {
    final ITreeAppendable errorChild = this.openErrorAppendable(appendable, appendable);
    errorChild.append("annotation is \'null\'");
    this.closeErrorAppendable(appendable, errorChild);
  } else {
    boolean _eIsProxy = annotationRef.getAnnotation().eIsProxy();
    if (_eIsProxy) {
      final ITreeAppendable errorChild_1 = this.openErrorAppendable(appendable, appendable);
      appendable.append("@");
      appendable.append(annotationRef.getAnnotation());
      this.closeErrorAppendable(appendable, errorChild_1);
    } else {
      appendable.append("@");
      appendable.append(annotationRef.getAnnotation());
      onSuccess.apply(appendable);
    }
  }
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected void appendCatchClause(XCatchClause catchClause, boolean parentIsReferenced, String parentVariable,
        ITreeAppendable appendable) {
    JvmTypeReference type = catchClause.getDeclaredParam().getParameterType();
    final String declaredParamName = makeJavaIdentifier(catchClause.getDeclaredParam().getName());
    final String name = appendable.declareVariable(catchClause.getDeclaredParam(), declaredParamName);
    appendable.append("if (").append(parentVariable).append(" instanceof ");
    serialize(type, catchClause, appendable);
    appendable.append(") ").append("{");
    appendable.increaseIndentation();
    ITreeAppendable withDebugging = appendable.trace(catchClause, true);
    if (!XbaseUsageCrossReferencer.find(catchClause.getDeclaredParam(), catchClause.getExpression()).isEmpty()) {
        ITreeAppendable parameterAppendable = withDebugging.trace(catchClause.getDeclaredParam());
        appendCatchClauseParameter(catchClause, type, name, parameterAppendable.newLine());
        withDebugging.append(" = (");
        serialize(type, catchClause, withDebugging);
        withDebugging.append(")").append(parentVariable).append(";");
    }
    final boolean canBeReferenced = parentIsReferenced && ! isPrimitiveVoid(catchClause.getExpression());
    internalToJavaStatement(catchClause.getExpression(), withDebugging, canBeReferenced);
    if (canBeReferenced) {
        appendable.newLine().append(getVarName(catchClause.eContainer(), appendable)).append(" = ");
        internalToConvertedExpression(catchClause.getExpression(), appendable, getLightweightType((XExpression) catchClause.eContainer()));
        appendable.append(";");
    }
    closeBlock(appendable);
}
项目:xtext-extras    文件:JvmModelGenerator.java   
private void appendCompilationTemplate(final ITreeAppendable appendable, final JvmIdentifiableElement it) {
  boolean _matched = false;
  if (appendable instanceof TreeAppendable) {
    _matched=true;
    SharedAppendableState _state = ((TreeAppendable)appendable).getState();
    StandardTypeReferenceOwner _standardTypeReferenceOwner = new StandardTypeReferenceOwner(this.commonServices, it);
    final ImportingStringConcatenation target = this.createImportingStringConcatenation(_state, _standardTypeReferenceOwner);
    target.append(this._jvmTypeExtensions.getCompilationTemplate(it));
    ((TreeAppendable)appendable).append(target);
  }
  if (!_matched) {
    String _name = appendable.getClass().getName();
    String _plus = ("unexpected appendable: " + _name);
    throw new IllegalStateException(_plus);
  }
}
项目:xtext-extras    文件:JvmModelGenerator.java   
protected ITreeAppendable _generateModifier(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateVisibilityModifier(it, appendable);
    boolean _isFinal = it.isFinal();
    if (_isFinal) {
      appendable.append("final ");
    }
    boolean _isStatic = it.isStatic();
    if (_isStatic) {
      appendable.append("static ");
    }
    boolean _isTransient = it.isTransient();
    if (_isTransient) {
      appendable.append("transient ");
    }
    ITreeAppendable _xifexpression = null;
    boolean _isVolatile = it.isVolatile();
    if (_isVolatile) {
      _xifexpression = appendable.append("volatile ");
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public void toJava(final JvmAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  JvmOperation _operation = it.getOperation();
  boolean _tripleNotEquals = (_operation != null);
  if (_tripleNotEquals) {
    String _simpleName = it.getOperation().getSimpleName();
    boolean _tripleEquals = (_simpleName == null);
    if (_tripleEquals) {
      return;
    }
    appendable.append(it.getOperation().getSimpleName());
    appendable.append(" = ");
  } else {
    EObject _eContainer = it.eContainer();
    int _size = ((JvmAnnotationReference) _eContainer).getExplicitValues().size();
    boolean _greaterThan = (_size > 1);
    if (_greaterThan) {
      appendable.append("value = ");
    }
  }
  this.toJavaLiteral(it, appendable, config);
}
项目:xtext-extras    文件:ConstantInlineExpansionTest.java   
protected String compileToJavaCode(String xtendCode) {
    XExpression model = null;
    ITreeAppendable appendable = new FakeTreeAppendable();
    try {
        model = expression(xtendCode, true);
        XbaseCompiler compiler = this.compilerProvider.get();
        LightweightTypeReference objectRef = new StandardTypeReferenceOwner(this.services, model).newReferenceToObject();
        compiler.compile(model, appendable, objectRef);
    } catch (Exception e) {
        throw new RuntimeException("Xtend compilation failed", e);
    } finally {
        if (model != null)
            this.cache.clear(model.eResource());
    }
    return appendable.getContent();
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected String getSwitchLocalVariableName(XSwitchExpression expr, ITreeAppendable b) {
    JvmFormalParameter declaredParam = expr.getDeclaredParam();
    if (declaredParam != null) {
        if (b.hasName(declaredParam)) {
            return b.getName(declaredParam);
        }
        return null;
    }
    XExpression switchExpression = expr.getSwitch();
    if (b.hasName(switchExpression)) {
        return b.getName(switchExpression);
    } 
    if (switchExpression instanceof XFeatureCall) {
        XFeatureCall featureCall = (XFeatureCall) switchExpression;
        JvmIdentifiableElement feature = featureCall.getFeature();
        if (b.hasName(feature)) {
            return b.getName(feature);
        }
    }
    return null;
}
项目:xtext-extras    文件:LoopExtensions.java   
/**
 * Iterates elements and execute the procedure.
 * A prefix, a separator and a suffix can be initialized with the loopInitializer lambda.
 */
public <T extends Object> void forEach(final ITreeAppendable appendable, final Iterable<T> elements, final Procedure1<? super LoopParams> loopInitializer, final Procedure1<? super T> procedure) {
  boolean _isEmpty = IterableExtensions.isEmpty(elements);
  if (_isEmpty) {
    return;
  }
  LoopParams _loopParams = new LoopParams();
  final LoopParams params = ObjectExtensions.<LoopParams>operator_doubleArrow(_loopParams, loopInitializer);
  params.appendPrefix(appendable);
  T _head = IterableExtensions.<T>head(elements);
  ObjectExtensions.<T>operator_doubleArrow(_head, procedure);
  final Consumer<T> _function = (T it) -> {
    params.appendSeparator(appendable);
    ObjectExtensions.<T>operator_doubleArrow(it, procedure);
  };
  IterableExtensions.<T>tail(elements).forEach(_function);
  params.appendSuffix(appendable);
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public void generateFileHeader(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final FileHeaderAdapter fileHeaderAdapter = IterableExtensions.<FileHeaderAdapter>head(Iterables.<FileHeaderAdapter>filter(it.eAdapters(), FileHeaderAdapter.class));
  String _headerText = null;
  if (fileHeaderAdapter!=null) {
    _headerText=fileHeaderAdapter.getHeaderText();
  }
  boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_headerText);
  boolean _not = (!_isNullOrEmpty);
  if (_not) {
    this.generateDocumentation(fileHeaderAdapter.getHeaderText(), this.fileHeaderProvider.getFileHeaderNodes(it.eResource()), appendable, config);
  }
}
项目:xtext-extras    文件:XbaseCompiler.java   
@Override
/* @Nullable */
protected String getReferenceName(XExpression expr, ITreeAppendable b) {
    if (expr instanceof XSwitchExpression) {
        Object key = getSwitchExpressionKey((XSwitchExpression) expr);
        if (b.hasName(key))
            return b.getName(key);
    }
    return super.getReferenceName(expr, b);
}
项目:dsl-devkit    文件:CheckCompiler.java   
@Override
protected ITreeAppendable appendTypeArguments(final XAbstractFeatureCall call, final ITreeAppendable original) {
  if (call.eResource() == null) {
    // That can happen four our hand-crafted CheckType.FAST annotations. Since these don't have
    // type arguments, there's nothing to do.
    return original;
  }
  return super.appendTypeArguments(call, original);
}
项目:xtext-extras    文件:JvmTypesBuilder.java   
protected void setCompilationStrategy(/* @Nullable */ JvmMember member, /* @Nullable */ Procedures.Procedure1<ITreeAppendable> strategy) {
    if(member == null || strategy == null)
        return;
    CompilationStrategyAdapter adapter = new CompilationStrategyAdapter();
    adapter.setCompilationStrategy(strategy);
    member.eAdapters().add(adapter);
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
private void doCastConversion(final LightweightTypeReference castTo, final ITreeAppendable b, final Later expression) {
    b.append("((");
    b.append(castTo);
    b.append(")");
    expression.exec(b);
    b.append(")");
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
private void convertListToArray(
        final LightweightTypeReference arrayTypeReference, 
        final ITreeAppendable appendable,
        final Later expression) {
    appendable.append("((");
    appendable.append(arrayTypeReference);
    appendable.append(")");
    appendable.append(Conversions.class);
    appendable.append(".unwrapArray(");
    expression.exec(appendable);
    LightweightTypeReference rawTypeArrayReference = arrayTypeReference.getRawTypeReference();
    appendable.append(", ");
    appendable.append(rawTypeArrayReference.getComponentType());
    appendable.append(".class))");
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
/**
 * @param wrapper unused in this context but useful for inheritors 
 */
private void convertWrapperToPrimitive(
        final LightweightTypeReference wrapper, 
        final LightweightTypeReference primitive, 
        XExpression context, 
        final ITreeAppendable appendable,
        final Later expression) {
    XExpression normalized = normalizeBlockExpression(context);
    if (normalized instanceof XAbstractFeatureCall && !(context.eContainer() instanceof XAbstractFeatureCall)) {
        // Avoid javac bug
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=410797
        // TODO make that dependent on the compiler version (javac 1.7 fixed that bug)
        XAbstractFeatureCall featureCall = (XAbstractFeatureCall) normalized;
        if (featureCall.isStatic()) {
            JvmIdentifiableElement feature = featureCall.getFeature();
            if (feature instanceof JvmOperation) {
                if (!((JvmOperation) feature).getTypeParameters().isEmpty()) {
                    appendable.append("(");
                    appendable.append(primitive);
                    appendable.append(") ");
                    expression.exec(appendable);
                    return;
                }
            }
        }
    }
    appendable.append("(");
    if (mustInsertTypeCast(context, wrapper)) {
        appendable.append("(");
        appendable.append(wrapper);
        appendable.append(") ");
    } 
    expression.exec(appendable);
    appendable.append(")");
    appendable.append(".");
    appendable.append(primitive);
    appendable.append("Value()");
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
@Override
protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) {
    if (obj instanceof XFeatureCall) {
        _toJavaStatement((XFeatureCall) obj, appendable, isReferenced);
    } else if (obj instanceof XAbstractFeatureCall) {
        _toJavaStatement((XAbstractFeatureCall) obj, appendable, isReferenced);
    } else {
        super.doInternalToJavaStatement(obj, appendable, isReferenced);
    }
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
protected boolean nullSafeMemberFeatureCallExpressionNeedsPreparation(XExpression argument, ITreeAppendable b) {
    if (b.hasName(argument))
        return false;
    if (argument instanceof JvmField || argument instanceof JvmFormalParameter)
        return false;
    return true;
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
protected ITreeAppendable appendLeftOperand(final XAbstractFeatureCall expr, ITreeAppendable appendable, boolean isExpressionContext) {
    XBinaryOperation binaryOperation = (XBinaryOperation) expr;
    XAbstractFeatureCall leftOperand = (XAbstractFeatureCall) binaryOperation.getLeftOperand();
    JvmIdentifiableElement feature = leftOperand.getFeature();
    if (appendable.hasName(feature)) {
        return appendable.append(appendable.getName(feature));
    }
    boolean hasReceiver = appendReceiver(leftOperand, appendable, isExpressionContext);
    if (hasReceiver) {
        appendable.append(".");
    }
    return appendable.append(feature.getSimpleName());
}
项目:xtext-extras    文件:JvmModelGenerator.java   
protected void _toJavaLiteral(final JvmDoubleAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<Double> _function = (Double it_1) -> {
    String _switchResult = null;
    boolean _matched = false;
    boolean _isNaN = Double.isNaN((it_1).doubleValue());
    if (_isNaN) {
      _matched=true;
      _switchResult = "Double.NaN";
    }
    if (!_matched) {
      if (Objects.equal(it_1, Double.POSITIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Double.POSITIVE_INFINITY";
      }
    }
    if (!_matched) {
      if (Objects.equal(it_1, Double.NEGATIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Double.NEGATIVE_INFINITY";
      }
    }
    if (!_matched) {
      String _string = it_1.toString();
      _switchResult = (_string + "d");
    }
    appendable.append(_switchResult);
  };
  this._loopExtensions.<Double>forEachWithShortcut(appendable, it.getValues(), _function);
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public void addJavaDocImports(final EObject it, final ITreeAppendable appendable, final List<INode> documentationNodes) {
  for (final INode node : documentationNodes) {
    List<ReplaceRegion> _computeTypeRefRegions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(node);
    for (final ReplaceRegion region : _computeTypeRefRegions) {
      {
        final String text = region.getText();
        if (((text != null) && (text.length() > 0))) {
          final QualifiedName fqn = this.qualifiedNameConverter.toQualifiedName(text);
          final EObject context = NodeModelUtils.findActualSemanticObjectFor(node);
          if (((fqn.getSegmentCount() == 1) && (context != null))) {
            final IScope scope = this.scopeProvider.getScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
            final IEObjectDescription candidate = scope.getSingleElement(fqn);
            if ((candidate != null)) {
              EObject _xifexpression = null;
              boolean _eIsProxy = candidate.getEObjectOrProxy().eIsProxy();
              if (_eIsProxy) {
                _xifexpression = EcoreUtil.resolve(candidate.getEObjectOrProxy(), context);
              } else {
                _xifexpression = candidate.getEObjectOrProxy();
              }
              final JvmType jvmType = ((JvmType) _xifexpression);
              if (((jvmType instanceof JvmDeclaredType) && (!jvmType.eIsProxy()))) {
                final JvmDeclaredType referencedType = ((JvmDeclaredType) jvmType);
                final JvmDeclaredType contextDeclarator = EcoreUtil2.<JvmDeclaredType>getContainerOfType(it, JvmDeclaredType.class);
                String _packageName = referencedType.getPackageName();
                String _packageName_1 = contextDeclarator.getPackageName();
                boolean _notEquals = (!Objects.equal(_packageName, _packageName_1));
                if (_notEquals) {
                  final ImportManager importManager = this.getImportManager(appendable);
                  importManager.addImportFor(jvmType);
                }
              }
            }
          }
        }
      }
    }
  }
}
项目:dsl-devkit    文件:CheckCompiler.java   
@Override
protected void doInternalToJavaStatement(final XExpression obj, final ITreeAppendable appendable, final boolean isReferenced) {
  if (obj instanceof XGuardExpression) {
    _toJavaStatement((XGuardExpression) obj, appendable, isReferenced);
  } else if (obj instanceof XIssueExpression) {
    _toJavaStatement((XIssueExpression) obj, appendable, isReferenced);
  } else {
    super.doInternalToJavaStatement(obj, appendable, isReferenced);
  }
}
项目:xtext-extras    文件:JvmModelGenerator.java   
protected void _toJavaLiteral(final JvmEnumAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<JvmEnumerationLiteral> _function = (JvmEnumerationLiteral it_1) -> {
    appendable.append(it_1.getDeclaringType());
    appendable.append(".");
    appendable.append(this.makeJavaIdentifier(it_1.getSimpleName()));
  };
  this._loopExtensions.<JvmEnumerationLiteral>forEachWithShortcut(appendable, it.getValues(), _function);
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
protected void appendArguments(List<? extends XExpression> arguments, ITreeAppendable b, boolean shouldWrapLine) {
    for (int i = 0; i < arguments.size(); i++) {
        XExpression argument = arguments.get(i);
        appendArgument(argument, b, shouldWrapLine || i > 0);
        if (i + 1 < arguments.size())
            b.append(", ");
    }
}
项目:xtext-extras    文件:AbstractXbaseCompiler.java   
public ITreeAppendable compile(XExpression obj, ITreeAppendable parentAppendable, /* @Nullable */ LightweightTypeReference expectedReturnType, /* @Nullable */ Set<JvmTypeReference> declaredExceptions) {
    if (declaredExceptions == null) {
        declaredExceptions = newHashSet();
        assert declaredExceptions != null;
    }
    ITreeAppendable appendable = parentAppendable.trace(obj, true);
    final boolean isPrimitiveVoidExpected = expectedReturnType.isPrimitiveVoid(); 
    final boolean isPrimitiveVoid = isPrimitiveVoid(obj);
    final boolean earlyExit = isEarlyExit(obj);
    boolean needsSneakyThrow = needsSneakyThrow(obj, declaredExceptions);
    if (needsSneakyThrow && isPrimitiveVoidExpected && hasJvmConstructorCall(obj)) {
        compileWithJvmConstructorCall((XBlockExpression) obj, appendable);
        return parentAppendable;
    }
    if (needsSneakyThrow) {
        appendable.newLine().append("try {").increaseIndentation();
    }
    internalToJavaStatement(obj, appendable, !isPrimitiveVoidExpected && !isPrimitiveVoid && !earlyExit);
    if (!isPrimitiveVoidExpected && !earlyExit) {
        appendable.newLine().append("return ");
        if (isPrimitiveVoid && !isPrimitiveVoidExpected) {
            appendDefaultLiteral(appendable, expectedReturnType);
        } else {
            internalToConvertedExpression(obj, appendable, expectedReturnType);
        }
        appendable.append(";");
    }
    if (needsSneakyThrow) {
        generateCheckedExceptionHandling(appendable);
    }
    return parentAppendable;
}
项目:xtext-extras    文件:AbstractXbaseCompiler.java   
/**
 * @return the variable name under which the result of the expression is stored. Returns <code>null</code> if the
 *          expression hasn't been assigned to a local variable before.
 */
/* @Nullable */
protected String getReferenceName(XExpression expr, ITreeAppendable b) {
    if (b.hasName(expr))
        return b.getName(expr);
    if (expr instanceof XFeatureCall) {
        XFeatureCall featureCall = (XFeatureCall) expr;
        if (b.hasName(featureCall.getFeature()))
            return b.getName(featureCall.getFeature());
    }
    return null;
}
项目:xtext-extras    文件:LiteralsCompiler.java   
/**
 * @since 2.4
 */
protected void toJavaStatement(final XStringLiteral expr, ITreeAppendable b, boolean isReferenced, final boolean useUnicodeEscapes) {
    generateComment(new Later() {
        @Override
        public void exec(ITreeAppendable appendable) {
            // we have to escape closing comments in string literals
            String escapedClosingComments = expr.getValue().replace("*/", "* /");
            String javaString = Strings.convertToJavaString(escapedClosingComments, useUnicodeEscapes);
            appendable.append("\"").append(javaString).append("\"");
        }
    }, b, isReferenced);
}