mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] 'new' expressions in Groovy cannot be qualified like in Java
This commit is contained in:
@@ -231,7 +231,6 @@ dynamic.properties.table.no.arguments=Arguments list is empty.
|
||||
assignment.expected='=' expected
|
||||
tuple.cant.be.placed.in.class=Multiple assignments are not allowed for fields
|
||||
singleton.class.should.have.private.constructor=Class with '@Singleton' annotation should have private constructor
|
||||
qualified.new.of.static.class=Qualified new of static class
|
||||
unknown.class=unknown class ''{0}''
|
||||
is.not.enclosing.class=''{0}'' is not an enclosing class
|
||||
package.definition.cannot.have.modifiers=Package definition cannot have modifiers
|
||||
|
||||
-6
@@ -1236,12 +1236,6 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
: GroovyBundle.message("cannot.instantiate.abstract.class", clazz.getName());
|
||||
myHolder.createErrorAnnotation(refElement, message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (newExpression.getQualifier() != null) {
|
||||
if (clazz.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
myHolder.createErrorAnnotation(newExpression, GroovyBundle.message("qualified.new.of.static.class"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -159,17 +159,15 @@ public class GrUnresolvedAccessChecker {
|
||||
GrNewExpression newExpression = (GrNewExpression)refElement.getParent();
|
||||
if (resolved instanceof PsiClass) {
|
||||
PsiClass clazz = (PsiClass)resolved;
|
||||
if (newExpression.getQualifier() == null) {
|
||||
final PsiClass outerClass = clazz.getContainingClass();
|
||||
if (com.intellij.psi.util.PsiUtil.isInnerClass(clazz) &&
|
||||
outerClass != null &&
|
||||
newExpression.getArgumentList() != null &&
|
||||
!PsiUtil.hasEnclosingInstanceInScope(outerClass, newExpression, true) &&
|
||||
!hasEnclosingInstanceInArgList(newExpression.getArgumentList(), outerClass)) {
|
||||
String qname = clazz.getQualifiedName();
|
||||
LOG.assertTrue(qname != null, clazz.getText());
|
||||
return createAnnotationForRef(refElement, inStaticContext, GroovyBundle.message("cannot.reference.non.static", qname));
|
||||
}
|
||||
final PsiClass outerClass = clazz.getContainingClass();
|
||||
if (com.intellij.psi.util.PsiUtil.isInnerClass(clazz) &&
|
||||
outerClass != null &&
|
||||
newExpression.getArgumentList() != null &&
|
||||
!PsiUtil.hasEnclosingInstanceInScope(outerClass, newExpression, true) &&
|
||||
!hasEnclosingInstanceInArgList(newExpression.getArgumentList(), outerClass)) {
|
||||
String qname = clazz.getQualifiedName();
|
||||
LOG.assertTrue(qname != null, clazz.getText());
|
||||
return createAnnotationForRef(refElement, inStaticContext, GroovyBundle.message("cannot.reference.non.static", qname));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,8 +27,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
* @author ilyas
|
||||
*/
|
||||
public interface GrNewExpression extends GrCallExpression, GrConstructorCall {
|
||||
@Nullable
|
||||
GrExpression getQualifier();
|
||||
|
||||
@Nullable
|
||||
GrCodeReferenceElement getReferenceElement();
|
||||
|
||||
-11
@@ -141,17 +141,6 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx
|
||||
return super.getArgumentList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public GrExpression getQualifier() {
|
||||
final PsiElement[] children = getChildren();
|
||||
for (PsiElement child : children) {
|
||||
if (child instanceof GrExpression) return (GrExpression)child;
|
||||
if (PsiKeyword.NEW.equals(child.getText())) return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrCodeReferenceElement getReferenceElement() {
|
||||
final GrAnonymousClassDefinition anonymous = getAnonymousClassDefinition();
|
||||
|
||||
+2
-18
@@ -27,7 +27,6 @@ import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause;
|
||||
@@ -83,13 +82,7 @@ public class GrAnonymousClassDefinitionImpl extends GrTypeDefinitionImpl impleme
|
||||
|
||||
@Override
|
||||
public boolean isInQualifiedNew() {
|
||||
final GrTypeDefinitionStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isAnonymousInQualifiedNew();
|
||||
}
|
||||
|
||||
final PsiElement parent = getParent();
|
||||
return parent instanceof GrNewExpression && ((GrNewExpression)parent).getQualifier() != null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,14 +94,10 @@ public class GrAnonymousClassDefinitionImpl extends GrTypeDefinitionImpl impleme
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClassType getBaseClassType() {
|
||||
if (isInQualifiedNew()) {
|
||||
return createClassType();
|
||||
}
|
||||
|
||||
PsiClassType type = SoftReference.dereference(myCachedBaseType);
|
||||
if (type != null && type.isValid()) return type;
|
||||
|
||||
type = createClassType();
|
||||
type = new GrClassReferenceType(getBaseClassReferenceGroovy());
|
||||
myCachedBaseType = new SoftReference<PsiClassType>(type);
|
||||
return type;
|
||||
}
|
||||
@@ -119,11 +108,6 @@ public class GrAnonymousClassDefinitionImpl extends GrTypeDefinitionImpl impleme
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiClassType createClassType() {
|
||||
return new GrClassReferenceType(getBaseClassReferenceGroovy());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiClass getBaseClass() {
|
||||
return getBaseClassType().resolve();
|
||||
|
||||
+1
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,11 +50,6 @@ public class GrEnumConstantInitializerImpl extends GrAnonymousClassDefinitionImp
|
||||
return (GrEnumConstant)getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInQualifiedNew() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GrCodeReferenceElement getBaseClassReferenceGroovy() {
|
||||
|
||||
-31
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.ResolveCache;
|
||||
import com.intellij.psi.scope.ElementClassHint;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,7 +34,6 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement;
|
||||
@@ -115,7 +113,6 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
CLASS_FQ,
|
||||
CLASS_OR_PACKAGE_FQ,
|
||||
STATIC_MEMBER_FQ,
|
||||
CLASS_IN_QUALIFIED_NEW
|
||||
}
|
||||
|
||||
public ReferenceKind getKind(boolean forCompletion) {
|
||||
@@ -153,7 +150,6 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
else if (parent instanceof GrNewExpression || parent instanceof GrAnonymousClassDefinition) {
|
||||
PsiElement newExpr = parent instanceof GrAnonymousClassDefinition ? parent.getParent() : parent;
|
||||
assert newExpr instanceof GrNewExpression;
|
||||
if (((GrNewExpression)newExpr).getQualifier() != null) return ReferenceKind.CLASS_IN_QUALIFIED_NEW;
|
||||
}
|
||||
|
||||
return ReferenceKind.CLASS;
|
||||
@@ -165,7 +161,6 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
final ReferenceKind kind = getKind(false);
|
||||
switch (kind) {
|
||||
case CLASS:
|
||||
case CLASS_IN_QUALIFIED_NEW:
|
||||
case CLASS_OR_PACKAGE:
|
||||
final PsiElement target = resolve();
|
||||
if (target instanceof PsiClass) {
|
||||
@@ -233,7 +228,6 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
case CLASS_OR_PACKAGE:
|
||||
if (resolve() instanceof PsiPackage) return true;
|
||||
case CLASS:
|
||||
case CLASS_IN_QUALIFIED_NEW:
|
||||
}
|
||||
final GrCodeReferenceElement qualifier = getQualifier();
|
||||
return qualifier != null && ((GrCodeReferenceElementImpl)qualifier).isFullyQualified();
|
||||
@@ -386,31 +380,6 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CLASS_IN_QUALIFIED_NEW: {
|
||||
if (ref.getParent() instanceof GrCodeReferenceElement) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
final GrNewExpression newExpression = PsiTreeUtil.getParentOfType(ref, GrNewExpression.class);
|
||||
assert newExpression != null;
|
||||
final GrExpression qualifier = newExpression.getQualifier();
|
||||
assert qualifier != null;
|
||||
|
||||
final PsiType type = qualifier.getType();
|
||||
if (!(type instanceof PsiClassType)) break;
|
||||
|
||||
final PsiClassType classType = (PsiClassType)type;
|
||||
final PsiClass psiClass = classType.resolve();
|
||||
if (psiClass == null) break;
|
||||
|
||||
final PsiClass[] allInnerClasses = psiClass.getAllInnerClasses();
|
||||
ArrayList<GroovyResolveResult> result = new ArrayList<GroovyResolveResult>();
|
||||
PsiResolveHelper helper = JavaPsiFacade.getInstance(ref.getProject()).getResolveHelper();
|
||||
|
||||
for (final PsiClass innerClass : allInnerClasses) {
|
||||
if (refName.equals(innerClass.getName())) {
|
||||
result.add(new GroovyResolveResultImpl(innerClass, helper.isAccessible(innerClass, ref, null)));
|
||||
}
|
||||
}
|
||||
return result.toArray(new GroovyResolveResult[result.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
return GroovyResolveResult.EMPTY_ARRAY;
|
||||
|
||||
-8
@@ -34,7 +34,6 @@ public class GrTypeDefinitionStub extends StubBase<GrTypeDefinition> implements
|
||||
private static final int INTERFACE = 0x02;
|
||||
private static final int ENUM = 0x04;
|
||||
private static final int ANNOTATION = 0x08;
|
||||
private static final int IS_IN_QUALIFIED_NEW = 0x10;
|
||||
private static final int DEPRECATED_BY_DOC = 0x20;
|
||||
private static final int TRAIT = 0x40;
|
||||
|
||||
@@ -85,10 +84,6 @@ public class GrTypeDefinitionStub extends StubBase<GrTypeDefinition> implements
|
||||
return (myFlags & ANONYMOUS) != 0;
|
||||
}
|
||||
|
||||
public boolean isAnonymousInQualifiedNew() {
|
||||
return (myFlags & IS_IN_QUALIFIED_NEW) != 0;
|
||||
}
|
||||
|
||||
public boolean isInterface() {
|
||||
return (myFlags & INTERFACE) != 0;
|
||||
}
|
||||
@@ -114,9 +109,6 @@ public class GrTypeDefinitionStub extends StubBase<GrTypeDefinition> implements
|
||||
if (typeDefinition.isAnonymous()) {
|
||||
flags |= ANONYMOUS;
|
||||
assert typeDefinition instanceof GrAnonymousClassDefinition;
|
||||
if (((GrAnonymousClassDefinition)typeDefinition).isInQualifiedNew()) {
|
||||
flags |= IS_IN_QUALIFIED_NEW;
|
||||
}
|
||||
}
|
||||
if (typeDefinition.isAnnotationType()) flags |= ANNOTATION;
|
||||
if (typeDefinition.isInterface()) flags |= INTERFACE;
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public class GrStubFileElementType extends IStubFileElementType<GrFileStub> {
|
||||
|
||||
@Override
|
||||
public int getStubVersion() {
|
||||
return super.getStubVersion() + 26;
|
||||
return super.getStubVersion() + 27;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-4
@@ -71,10 +71,7 @@ public class GrStubIndexer {
|
||||
@Nullable
|
||||
private static Decl processMember(StubElement<?> el, Set<String> namesCache) {
|
||||
if (el instanceof GrTypeDefinitionStub) {
|
||||
GrTypeDefinitionStub classStub = (GrTypeDefinitionStub)el;
|
||||
if (!classStub.isAnonymousInQualifiedNew()) {
|
||||
return processClassDecl(classStub, namesCache);
|
||||
}
|
||||
return processClassDecl((GrTypeDefinitionStub)el, namesCache);
|
||||
}
|
||||
ArrayList<Decl> innerList = new ArrayList<Decl>();
|
||||
for (StubElement childElement : el.getChildrenStubs()) {
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -168,8 +168,7 @@ public class ReplaceAbstractClassInstanceByMapIntention extends Intention {
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
if (element instanceof GrCodeReferenceElement && element.getParent() instanceof GrAnonymousClassDefinition) {
|
||||
final GrAnonymousClassDefinition anonymous = ((GrAnonymousClassDefinition)element.getParent());
|
||||
GrNewExpression newExpression = (GrNewExpression)anonymous.getParent();
|
||||
if (newExpression.getQualifier() == null && anonymous.getFields().length == 0) {
|
||||
if (anonymous.getFields().length == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -138,7 +138,6 @@ public class CompleteCodeReferenceElement {
|
||||
}
|
||||
|
||||
case CLASS_OR_PACKAGE:
|
||||
case CLASS_IN_QUALIFIED_NEW:
|
||||
case CLASS: {
|
||||
GrCodeReferenceElement qualifier = myRef.getQualifier();
|
||||
if (qualifier != null) {
|
||||
|
||||
-6
@@ -215,12 +215,6 @@ public class ExpressionGenerator extends Generator {
|
||||
builder = this.builder;
|
||||
}
|
||||
|
||||
final GrExpression qualifier = newExpression.getQualifier();
|
||||
if (qualifier != null) {
|
||||
qualifier.accept(this);
|
||||
builder.append('.');
|
||||
}
|
||||
|
||||
final GrTypeElement typeElement = newExpression.getTypeElement();
|
||||
final GrArrayDeclaration arrayDeclaration = newExpression.getArrayDeclaration();
|
||||
final GrCodeReferenceElement referenceElement = newExpression.getReferenceElement();
|
||||
|
||||
Reference in New Issue
Block a user