Sourcecompatibility Assignment Is Not Used

Xtend 2.11.0 Release Notes  Feb 1, 2017

Xtend version 2.11 comes with a new source repository and plenty of improvements and bug fixes.

New Source Repository

The Xtend code base has been moved to a dedicated repository xtext-xtend in the course of the restructuring of Xtext (see the Xtext 2.11.0 Release Notes).

The Xtend Language and Library

String Concatenation Performance Improvements

The performance of string concatenation, e.g. as used for rich strings, has been improved. This change has important consequences for working with Xtend: you should make sure that you use consistent versions of Xtend in your host IDE and your target platform in order to avoid compatibility problems.

Improved Compiler

The Java code produced by the Xtend compiler is now less verbose and more readable. For many situations Xtend does not produce synthetic variables anymore.

For switch statements on Strings an additional null guard is produced. This lead to NPEs when a null argument was passed to the switch statement.

A for-loop over an array resulted in uncompilable Java code. This has been fixed.

Comparison with null

For comparison expressions with as argument it is more efficient to use the triple (not) equals operator and instead of and . While the “normal” operators will result in a call of , the triple equals operator can perform a direct comparison.

For these situations a warning is produced and a quickfix is offered.

New Class Wizard

The New Xtend Class wizard has an option to create a main method.

Xtend 2.9.0 Release Notes  Dec 1, 2015

Version 2.9 adds support for IntelliJ and includes many bug fixes. (full bugzilla list).

IntelliJ IDEA support

There is now an Xtend plug-in for IntelliJ IDEA. The plug-in provides a smart code editor for Xtend files, including syntax highlighting, code completion, on-the-fly validation, automatic compilation in the background, and more. The plug-in uses the same parser and compiler as Eclipse, but we had to re-implement large parts of the UI integration code.

Create a new Xtend type (class, interface, or enum) inside Java packages.

Enjoy the smart code editor with syntax highlighting and code completion. The latter also proposes Xtend’s extension methods. The example from this screenshot is a small JUnit test, which - obviously - can also be launched as such.

Android Studio Support

Xtend now supports Android Studio, which uses IntelliJ IDEA as a foundation. This is not to be confused with the Android Developer Tools, which are based on Eclipse and which have been supported by Xtend since the very beginning.

This is exciting news as it allows you to use lambda expressions and Active Annotations for Android development - something neither Android Studio nor ADT support out of the box.

Xtend 2.8.0 Release Notes  Mar 11, 2015

Version 2.8 got many new features, bug fixes, and performance improvements (full bugzilla list).

The most noteworthy changes are the following.

Target Java Version

The new version of the Xbase compiler allows to configure the Java version of the generated code. The default is to use the same version as set for the source compatibility of the Java compiler (Java → Compiler → Source compatibility), which is in turn usually set to the same version as the compiler compliance level. The Xbase compiler settings can be configured in the Compiler preference page or project properties page of your Xbase language.

By unchecking Use source compatibility level from Java settings, you can choose to generate Java code with a different version than is set for the Java compiler. The actual changes in the generated code are described in the following.

Java 5

Java 5 has been the version level of the Xtend compiler from the beginning, so the generated code is the same as with earlier Xtend versions if you choose this target version.

Java 6

When the Xtend compiler is set to at least Java 6, it generates an annotation to each method that overrides a method from a superclass or implements an interface method.

Java 7

Xtend expressions like where is of type String are translated to Java statements (see Strings in switch Statements).

In Xtend you can write number literals in the form to enhance their readability. This is also supported by Java 7. When the Xtend compiler is set to at least Java 7, underscores in number literals are retained in the generated code.

Java 8

Xtend lambda expressions like are translated to Java 8 lambda expressions, e.g. . More details on this translation are discussed in this blog post.

Note that independent of which Java version is chosen for the generated code, Xtend works perfectly with the lambda-optimized Java 8 API because Xtend lambdas are fully compatible with Java 8 lambdas.

Xtend allows to define non-abstract methods (static or non-static) in interfaces when Java 8 is chosen as target language level. If such a method is non-static, it is translated to a Java 8 default method.

More Compiler Options

You can now disable the automatic generation of annotations for generated classes. Furthermore, you can enable the generation of annotations for all generated types, which can be useful for automatic processing of the source code, e.g. when you want to exclude generated types in code analysis tools. The annotation also allows to attach more information, which can be enabled in the preferences.

Enhancements of the Xtend Editor

Open Generated File

You can open the Java file that was generated from Xtend by right-clicking the Xtend editor and selecting Open Generated File.

Open Inferred Type

You can open the declaration of the inferred type of a local variable by Ctrl-clicking (Cmd on Mac) the variable name.

Improved Hover for Annotations

Hovers of annotated members have been improved and allow to navigate to annotation values.

Unique Class Name Validation

If your Xtend type’s qualified name collides with another Java or Xtend type in the same project you now get an error.

Convert Java to Xtend

The new version features a Java-to-Xtend converter. Right-click a Java file, package or source folder in the Package Explorer and select Convert to Xtend. You can choose to keep the original Java files (though that will lead to errors due to duplicate types), and you are warned if the Java code contains parts that cannot be translated automatically. These are marked with comments in the Xtend code. However, the converter is able to convert the majority of Java classes without problems.

Active Annotations

Constant Field Initializer

MutableFieldDeclaration now features a set of methods like for creating static final fields with constant initializers. All primitive values as well as String are supported.

Default Methods

If the Xtend compiler is set to Java 8, you can create a method with default implementation in a Java interface by defining a method body and setting the abstract flag on the MutableMethodDeclaration.

Faster Builds and More Responsive UI

Compiling an Xtend resource involves a lot of computation. With 2.8 we store the computed resource state and reload it if no changes have happened. This leads to a significantly faster build.

Into the bargain, user actions like saving an editor now cancel the auto-build and are no longer blocked by it.

Xtend 2.7.0 Release Notes  Sep 2, 2014

Version 2.7 got many new features, bug fixes and performance improvements (full bugzilla list). The most noteworthy changes are the following.


Sugared Lambdas With Zero And More Than Two Arguments

It is now allowed to leave out parameter declarations for all lambda expressions using a positional syntax, similar to Apple's Swift:

#[1, 2, 3].reduce[$0 + $1]

Unqualified Enum Usage

Enum constants in annotations and switch expressions can be referenced without their type name. @Retention(RUNTIME)

Inner Type of Parameterized Types

Type inference for parameterized inner classes was improved and supports types like OuterType<T>.InnerType

Deprecated and Dead Code Analysis

The validator will now detect use of deprecated API and is much better at finding dead code. Would you have spotted the following?


New Extension Methods on Iterables

The standard library has new extension methods for , including /, and .

#["Xtend", "Java", "Eclipse"].maxBy[length]

New Active Annotations

New Active Annotations have been added to free you of some repetitive tasks. The new generates getters and setters, with fine grained control and even for all fields of a class if you want. The annotation automatically implements the delegation pattern for you, so you only need to concentrate on methods that you actually want to implement differently than just delegating. Here is an example:

interface I { def void m1() def void m2() def void m3() } class A implements I { override m1() {} override m2() {} override m3() {} } class B implements I { //all methods automatically implemented @Delegate A delegate = new A }

Other additions include , , and a new (the old one is now deprecated as well as ).

Active Annotations API Improvements

The active annotation API integrates even deeper with the IDE. Every generated element can (and should) now declare its source element. This tracing information is used in places like the outline view. A separate validation phase has been added, so the end result after running all transformations can be validated. Also, changes to classes and even arbitrary resources that the annotation processor requested are detected and lead to automatic rebuilds.

IDE Features


Xtend breakpoints can now have conditions. Conditions are written in Java, so you get full access even to synthetic variables inserted by the Xtend compiler. Of course you also get content assist in the condition editor.

Breakpoints can now be toggled, enabled/disabled and inspected via the ruler context menu.

Content Assist

Content Assist has become a lot faster and more accurate at the same time. It will now also retain the "is"-prefix of boolean properties.

Performance Improvements

Performance has reached a new level with big improvements to Content Assist, parallel code generation and lots of fine tuning. Also, Xtend will now cancel jobs (like outline refreshing) when you start typing again, making the editor much more responsive.

Outline with Java-Mode

The outline view now supports two modes: One shows the original Xtend AST, the other one shows the resulting Java AST. This is very useful in the presence of Active Annotations that add a lot of new members to a class.

Organize imports on packages

You can now use "Organize Xtend Imports" on whole packages via the "Source" context menu.

Template proposals support import

A new type of template variable was added. It adds an import to an Xtend file when the template is inserted. This greatly reduces the need for qualified type names in templates.

Open return type

Ever wondered what you can do with the type of a variable or the return type of a method? You can now CTRL-Click on feature calls and open the declaration of the return type of that call.

Show errors from derived Java files

By using black box Java code within active annotations the generated Java source could sometimes have errors while the Xtend code is fine. In those cases, the errors are now shown at the appropriate locations in Xtend as well.

Maven and Java 8

The Xtend Maven plugin is now toolchain-aware. Using this, you can for instance run Maven on Java 8, but compile against a JDK 6.

Xtend 2.6.0 Release Notes  May 21, 2014

Version 2.6 got many bug fixes and performance improvements (full bugzilla list). The new features are the following.

Anonymous Classes

Xtend supports using lambdas to implement anonymous classes with just one abstract method since its inception. For interfaces and abstract classes with more than one method you can now also use the an anonymous class using the following syntax:

val tabListener = new ActionBar.TabListener() { override onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { // show the given tab } override onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { // hide the given tab } override onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { // probably ignore this event } };

Static Nested Classes

Xtend now supports static nested classes.

class A { static class NestedClass { } }

Operator Declarations

In addition to overloading operators by adhering to the name mappings, listed in the documentation, one can now use the actual operator in the declaration as well.

class Money { def + (Money other) { ... } def - (Money other) { ... } def * (BigDecimal times) { ... } ... }

Synchronized Expression

The synchronized expression works basically like Java's synchronized statement.

synchronized(lock) { // do stuff }

But of course it is an expression, as everything in Xtend/Xbase. So you can write the following as well:

someMethodCall(synchronized(lock) { ... })

Qualified Static Imports

It is now possible to import features in a fully qualified way. This works for regular static imports as well as for extension imports.

// static import import static java.util.Collections.singleton // extension import import static extension java.util.Collections.min import static extension java.util.Collections.max

Switch Fall Through

The switch expression now supports a kind of fall through. Here's an example

switch myOperator { case '+', case '-' : handlePlusMinus() case '*', case '/' : handleDivMultiply() default : throw new IllegalStateException }

Compound Assignments

Xtend now supports compound assignment operators.

var i = 0 i += 42

Compound operators work on overloaded operators as well. That is you don't need to declare '+=' if you have '+' defined. Example:

var distance = distance +=

Postfix Operators

Postfix operators for incrementing and decrementing numbers have been added.

var i = 0 while (condition()) { i++ }

Traditional For-Loop

The traditional for-loop from Java is now available in Xtend, too.

for (var i = 0; i < 99; i++) { println(''+i+' bottles of beer on the wall.') }

Multivalued Annotations Sugar

Instead of writing

@SurpressWarnings(#["unused", "unchecked"])

you can write

@SurpressWarnings("unused", "unchecked")

Active Annotations - Flag fields as read resp. initialized

When initializing a final field within a synthetic constructor, the control flow analysis couldn't detect it was in fact initialized and would raise an error. Another typical solution was a warning when a private field was only accessed through methods added by an active annotation (e.g. a setter or getter). You can now mark a field as read resp. initialized.

Style Checks

2.6 adds the following optional compiler checks (inactive by default):

Force return expression

Force declare return types

Force empty parenthesis on method invocation

Task Tags

TODO, FIXME, and XXX markers in comments are now recognized by the IDE as task markers. The Xtend editor picks up the preference of JDT for adding new kind of markers or removing existing ones.

Open Implementation

In addition to the "Go to declaration"-action, you can now navigate to existing implementations of a method. It works just like in JDT

Debug Hover Shows Inspect Dialog

In a debug session, when hovering over a local variable or a visible field, the popo up shows the inspection tree of the hovered value.

Hover Shows Annotations

The declaration hover now includes the annotations.

Gradle Plug-in

A gradle plug-in for easy integration of the Xtend compiler in any gradle based Java projects is now available. The gradle plug-in even also works with the new Android buildsystem developed by Google.
The gradle plug-in is hosted at github.

buildscript { repositories { mavenCentral() } dependencies { classpath 'org.xtend:xtend-gradle-plugin:0.0.8' } } apply plugin: 'xtend' repositories { mavenCentral() } dependencies { //or testCompile if you only want to use Xtend for some tests compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.6.0' }

Treeshaken Lib for Android

For large Android projects there is a need to have as little code packaged as possible. Usually this is achieved by proguarding cour code and the dependencies during the build. For people who find that tedious and want to work with a reduced lib from the get go, we offer a treeshaken version of the library, which is only 300k small.

The library can be downloaded from maven central.

The C and C++programming languages are closely related but also different as well in many regards. C++ began as a fork of an early, pre-standardized C, and was designed to be mostly source-and-link compatible with C compilers of the time.[1] Due to this, development tools for the two languages (such as IDEs and compilers) are often integrated into a single product, with the programmer able to specify C or C++ as their source language.

However, C is not a subset of C++,[2] and most non-trivial C programs will not compile as C++ code without modification. Likewise, C++ introduces many features that are not available in C and in practice almost all code written in C++ is not conforming C code. This article, however, focuses on differences that cause conforming C code to be ill-formed C++ code, or to be conforming/well-formed in both languages, but to behave differently in C and C++.

Bjarne Stroustrup, the creator of C++, has suggested[3] that the incompatibilities between C and C++ should be reduced as much as possible in order to maximize inter-operability between the two languages. Others have argued that since C and C++ are two different languages, compatibility between them is useful but not vital; according to this camp, efforts to reduce incompatibility should not hinder attempts to improve each language in isolation. The official rationale for the 1999 C standard (C99) "endorse[d] the principle of maintaining the largest common subset" between C and C++ "while maintaining a distinction between them and allowing them to evolve separately", and stated that the authors were "content to let C++ be the big and ambitious language."[4]

Several additions of C99 are not supported in the current C++ standard or conflicted with C++ features, such as variable-length arrays, native complex number types, compound literals, and designated initializers. The initializer list syntax of C++11 generalizes the functionality of C99 compound literals, although with some semantic differences. Designated initializers are planned for C++20. The type qualifier defined in C99 was not included in the C++03 standard, but most mainstream compilers such as the GNU Compiler Collection,[5]Microsoft Visual C++, and Intel C++ Compiler provide similar functionality as an extension. On the other hand, C99 reduced some other incompatibilities compared with C89 by incorporating C++ features such as comments and mixed declarations and code.[6]

Constructs valid in C but not in C++[edit]

C++ enforces stricter typing rules (no implicit violations of the static type system [1]), enforcement of the one definition rule (ODR), and initialization requirements than C, and so some valid C code is disallowed in C++. A rationale for these is provided in the ISO C++ standard.[7]

  • One commonly encountered difference is C being more weakly-typed regarding pointers. For example, C allows a pointer to be assigned to any pointer type without a cast, while C++ does not; this idiom appears often in C code using memory allocation,[8] or in the passing of context pointers to the pthreads API and other frameworks involving callbacks. For example, the following is valid in C but not C++:
void*ptr;/* Implicit conversion from void* to int* */int*i=ptr;
or similarly:
int*j=malloc(sizeof(int)*5);/* Implicit conversion from void* to int* */
In order to make the code compile as both C and C++, one must use an explicit cast, as follows (with some potentially unpleasant side effects in both languages[9][10]):
  • C++ is also more strict than C about pointer assignments that discard a qualifier (e.g. assigning a value to an variable): in C++ this is invalid and generates a compiler error (unless an explicit typecast is used),[11] whereas in C this is allowed (although many compilers emit a warning).
  • C++ changes some C standard library functions to add additional polymorphic functions with type qualifiers, e.g. returns in C, while C++ acts as if there were two polymorphic functions and a .
  • C++ is also more strict in conversions to enums: ints cannot be implicitly converted to enums as in C. Also, Enumeration constants ( values) are always of type in C, whereas they are distinct types in C++ and may have a size different from that of . C++11 allows the programmer to use custom integer types for the values of an enum.
  • In C++ a variable must be initialized; in C this is not necessary.
  • C++ compilers prohibit goto or switch from crossing an initialization, as in the following C99 code:
  • While syntactically valid, a results in undefined behaviour in C++ if the jumped-over stack frames include objects with nontrivial destructors[12]. The C++ implementation is free to define the behaviour such that destructors would be called. However, this would preclude some uses of longjmp() which would otherwise be valid, such as implementation of threads or coroutines by longjmping between separate call stacks - when jumping from the lower to the upper call stack in global address space, destructors would be called for every object in the lower call stack. No such issue exists in C.
  • C allows for multiple tentative definitions of a single global variable in a single translation unit, which is disallowed as an ODR violation in C++.
  • C allows declaring a new type with the same name as an existing , or which is not allowed in C++, as in C , , and types must be indicated as such whenever the type is referenced whereas in C++ all declarations of such types carry the typedef implicitly.
  • Non-prototype ("K&R"-style) function declarations are not allowed in C++, although they have also been deprecated in C since 1990. Similarly, implicit function declarations (using functions that have not been declared) are not allowed in C++, and have been disallowed in C since 1999.
  • In C, a function prototype without parameters, e.g. , implies that the parameters are unspecified. Therefore, it is legal to call such a function with one or more arguments, e.g. . In contrast, in C++ a function prototype without arguments means that the function takes no arguments, and calling such a function with arguments is ill-formed. In C, the correct way to declare a function that takes no arguments is by using 'void', as in , which is also valid in C++. Empty function prototypes are a deprecated feature in C99 (as they were in C89).
  • In both C and C++, one can define nested types, but the scope is interpreted differently: in C++, a nested is defined only within the scope/namespace of the outer and so access requires use of the :: scope resolution operator.

C99 and C11 added several additional features to C that have not been incorporated into standard C++, such as complex numbers, variable length arrays (note that complex numbers and variable length arrays are designated as optional extensions in C11), flexible array members, the restrict keyword, array parameter qualifiers, designated initializers.

  • Complex arithmetic using the and primitive data types was added in the C99 standard, via the keyword and convenience macro. In C++, complex arithmetic can be performed using the complex number class, but the two methods are not code-compatible. (The standards since C++11 require binary compatibility, however.)[13]
  • Variable length arrays. This feature leads to possibly non-compile time sizeof operator.[14]
voidfoo(size_tx,inta[*]);// VLA declarationvoidfoo(size_tx,inta[x]){printf("%zu\n",sizeofa);// same as sizeof(int*)chars[x*2];printf("%zu\n",sizeofs);// will print x*2}
  • The last member of a C99 structure type with more than one member may be a "flexible array member", which takes the syntactic form of an array with unspecified length. This serves a purpose similar to variable-length arrays, but VLAs cannot appear in type definitions, and unlike VLAs, flexible array members have no defined size. ISO C++ has no such feature. Example:
  • Array parameter qualifiers in functions.
intfoo(inta[const]);// equivalent to int *const a intbar(chars[static5]);// annotates that s is at least 5 chars long
  • Designated initializers for structs and arrays are valid only in C, although they are planned for addition in C++2x:
  • C allows , , and types to be declared in function prototypes, whereas C++ does not.

C++ adds numerous additional keywords to support its new features. This renders C code using those keywords for identifiers invalid in C++. For example:

is valid C code, but is rejected by a C++ compiler, since the keywords "template", "new" and "class" are reserved.

Constructs that behave differently in C and C++[edit]

There are a few syntactical constructs that are valid in both C and C++ but produce different results in the two languages.

  • Character literals such as are of type in C and of type in C++, which means that will generally give different results in the two languages: in C++, it will be , while in C it will be . As another consequence of this type difference, in C, will always be a signed expression, regardless of whether or not is a signed or unsigned type, whereas for C++ this is compiler implementation specific.
  • C++ assigns internal linkage to namespace-scoped variables unless they are explicitly declared , unlike C in which is the default for all file-scoped entities.
  • C distinguishes two kinds of definitions of functions: ordinary external definitions (where extern is explicitly used) and inline definitions. C++, on the other hand, provides only inline definitions for inline functions. In C, an inline definition is similar to an internal (i.e. static) one, in that it can coexist in the same program with one external definition and any number of internal and inline definitions of the same function in other translation units, all of which can differ. This is a separate consideration from the linkage of the function, but not an independent one. C compilers are afforded the discretion to choose between using inline and external definitions of the same function when both are visible. C++, however, requires that if a function with external linkage is declared inline in any translation unit then it must be so declared (and therefore also defined) in every translation unit where it is used, and that all the definitions of that function be identical, following the ODR.
  • Both C99 and C++ have a boolean type with constants and , but they are defined differently. In C++, is a built-in type and a reserved keyword. In C99, a new keyword, , is introduced as the new boolean type. The header provides macros , and that are defined as , and , respectively.

Several of the other differences from the previous section can also be exploited to create code that compiles in both languages but behaves differently. For example, the following function will return different values in C and C++:

externintT;intsize(void){structT{inti;intj;};returnsizeof(T);/* C: return sizeof(int) * C++: return sizeof(struct T) */}

This is due to C requiring in front of structure tags (and so refers to the variable), but C++ allowing it to be omitted (and so refers to the implicit ). Beware that the outcome is different when the declaration is placed inside the function: then the presence of an identifier with same name in the function scope inhibits the implicit to take effect for C++, and the outcome for C and C++ would be the same. Observe also that the ambiguity in the example above is due to the use of the parenthesis with the operator. Using would expect to be an expression and not a type, and thus the example would not compile with C++.

Linking C and C++ code[edit]

While C and C++ maintain a large degree of source compatibility, the object files their respective compilers produce can have important differences that manifest themselves when intermixing C and C++ code. Notably:

  • C compilers do not name mangle symbols in the way that C++ compilers do.[15]
  • Depending on the compiler and architecture, it also may be the case that calling conventions differ between the two languages.

For these reasons, for C++ code to call a C function , the C++ code must prototype with . Likewise, for C code to call a C++ function , the C++ code for must be declared with .

A common practice for header files to maintain both C and C++ compatibility is to make its declaration be for the scope of the header:[16]

/* Header file foo.h */#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */extern"C"{#endif/* These functions get C linkage */voidfoo();structbar{/* ... */};#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */}#endif

Differences between C and C++ linkage and calling conventions can also have subtle implications for code that uses function pointers. Some compilers will produce non-working code if a function pointer declared points to a C++ function that is not declared .[17]

For example, the following code:

1 voidmy_function();2 extern"C"voidfoo(void(*fn_ptr)(void));3 4 voidbar()5 {6 foo(my_function);7 }

Using Sun Microsystems' C++ compiler, this produces the following warning:


This is because is not declared with C linkage and calling conventions, but is being passed to the C function .


External links[edit]

0 thoughts on “Sourcecompatibility Assignment Is Not Used”


Leave a Comment

Your email address will not be published. Required fields are marked *