use of org.jetbrains.plugins.groovy.config.GroovyConfigUtils in project intellij-community by JetBrains.
the class GroovyAnnotator method checkDiamonds.
private static boolean checkDiamonds(GrCodeReferenceElement refElement, AnnotationHolder holder) {
GrTypeArgumentList typeArgumentList = refElement.getTypeArgumentList();
if (typeArgumentList == null)
return true;
if (!typeArgumentList.isDiamond())
return true;
final GroovyConfigUtils configUtils = GroovyConfigUtils.getInstance();
if (!configUtils.isVersionAtLeast(refElement, GroovyConfigUtils.GROOVY1_8)) {
final String message = GroovyBundle.message("diamonds.are.not.allowed.in.groovy.0", configUtils.getSDKVersion(refElement));
holder.createErrorAnnotation(typeArgumentList, message);
}
return false;
}
use of org.jetbrains.plugins.groovy.config.GroovyConfigUtils in project intellij-community by JetBrains.
the class GroovyAnnotator method checkRegexLiteral.
private void checkRegexLiteral(PsiElement regex) {
String text = regex.getText();
String quote = GrStringUtil.getStartQuote(text);
final GroovyConfigUtils config = GroovyConfigUtils.getInstance();
if ("$/".equals(quote)) {
if (!config.isVersionAtLeast(regex, GroovyConfigUtils.GROOVY1_8)) {
myHolder.createErrorAnnotation(regex, GroovyBundle.message("dollar.slash.strings.are.not.allowed.in.0", config.getSDKVersion(regex)));
}
}
String[] parts;
if (regex instanceof GrRegex) {
parts = ((GrRegex) regex).getTextParts();
} else {
//noinspection ConstantConditions
parts = new String[] { regex.getFirstChild().getNextSibling().getText() };
}
for (String part : parts) {
if (!GrStringUtil.parseRegexCharacters(part, new StringBuilder(part.length()), null, regex.getText().startsWith("/"))) {
myHolder.createErrorAnnotation(regex, GroovyBundle.message("illegal.escape.character.in.string.literal"));
return;
}
}
if ("/".equals(quote)) {
if (!config.isVersionAtLeast(regex, GroovyConfigUtils.GROOVY1_8)) {
if (text.contains("\n") || text.contains("\r")) {
myHolder.createErrorAnnotation(regex, GroovyBundle.message("multiline.slashy.strings.are.not.allowed.in.groovy.0", config.getSDKVersion(regex)));
return;
}
}
}
}
use of org.jetbrains.plugins.groovy.config.GroovyConfigUtils in project intellij-community by JetBrains.
the class GroovyAnnotator method checkTypeDefinition.
private static void checkTypeDefinition(AnnotationHolder holder, GrTypeDefinition typeDefinition) {
final GroovyConfigUtils configUtils = GroovyConfigUtils.getInstance();
if (typeDefinition.isAnonymous()) {
if (!configUtils.isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_7)) {
holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("anonymous.classes.are.not.supported", configUtils.getSDKVersion(typeDefinition)));
}
PsiClass superClass = ((PsiAnonymousClass) typeDefinition).getBaseClassType().resolve();
if (superClass instanceof GrTypeDefinition && ((GrTypeDefinition) superClass).isTrait()) {
holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("anonymous.classes.cannot.be.created.from.traits"));
}
} else if (typeDefinition.isTrait()) {
if (!configUtils.isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY2_3)) {
ASTNode keyword = typeDefinition.getNode().findChildByType(GroovyTokenTypes.kTRAIT);
assert keyword != null;
holder.createErrorAnnotation(keyword, GroovyBundle.message("traits.are.not.supported.in.groovy.0", configUtils.getSDKVersion(typeDefinition)));
}
} else if (typeDefinition.getContainingClass() != null && !(typeDefinition instanceof GrEnumTypeDefinition)) {
if (!configUtils.isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_7)) {
holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("inner.classes.are.not.supported", configUtils.getSDKVersion(typeDefinition)));
}
}
if (typeDefinition.isAnnotationType() && typeDefinition.getContainingClass() != null) {
holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("annotation.type.cannot.be.inner"));
}
if (!typeDefinition.hasModifierProperty(PsiModifier.STATIC) && (typeDefinition.getContainingClass() != null || typeDefinition instanceof GrAnonymousClassDefinition)) {
GrTypeDefinition owner = PsiTreeUtil.getParentOfType(typeDefinition, GrTypeDefinition.class);
if (owner instanceof GrTraitTypeDefinition) {
holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("non.static.classes.not.allowed"));
}
}
checkDuplicateClass(typeDefinition, holder);
checkCyclicInheritance(holder, typeDefinition);
}
use of org.jetbrains.plugins.groovy.config.GroovyConfigUtils in project intellij-community by JetBrains.
the class GroovyAntCustomCompilerProvider method generateCustomCompilerTaskRegistration.
/**
* {@inheritDoc}
*/
@Override
public void generateCustomCompilerTaskRegistration(Project project, GenerationOptions genOptions, CompositeGenerator generator) {
final GroovyConfigUtils utils = GroovyConfigUtils.getInstance();
// find SDK library with maximum version number in order to use for compiler
final Library[] libraries = utils.getAllUsedSDKLibraries(project);
if (libraries.length == 0) {
// no SDKs in the project, the task registration is not generated
return;
}
final Collection<String> versions = utils.getSDKVersions(libraries);
String maxVersion = versions.isEmpty() ? null : Collections.max(versions);
Library sdkLib = null;
for (Library lib : libraries) {
if (maxVersion == null || maxVersion.equals(utils.getSDKVersion(LibrariesUtil.getGroovyLibraryHome(lib)))) {
sdkLib = lib;
}
}
assert sdkLib != null;
String groovySdkPathRef = BuildProperties.getLibraryPathId(sdkLib.getName());
generator.add(new Property(GROOVYC_TASK_SDK_PROPERTY, groovySdkPathRef));
//noinspection HardCodedStringLiteral
Tag taskdef = new Tag("taskdef", Couple.of("name", "groovyc"), Couple.of("classname", "org.codehaus.groovy.ant.Groovyc"), Couple.of("classpathref", "${" + GROOVYC_TASK_SDK_PROPERTY + "}"));
generator.add(taskdef);
}
Aggregations