mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Lambda expressions support: first round
This commit is contained in:
@@ -375,4 +375,8 @@ public abstract class JavaElementVisitor extends PsiElementVisitor {
|
||||
public void visitPolyadicExpression(PsiPolyadicExpression expression) {
|
||||
visitExpression(expression);
|
||||
}
|
||||
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {
|
||||
visitExpression(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a Java lambda expression.
|
||||
*/
|
||||
public interface PsiLambdaExpression extends PsiExpression {
|
||||
/**
|
||||
* Returns this lambda expression's parameter list.
|
||||
*
|
||||
* @return parameter list.
|
||||
*/
|
||||
@NotNull
|
||||
PsiParameterList getParameterList();
|
||||
|
||||
/**
|
||||
* Returns PSI element representing lambda expression body: {@link PsiCodeBlock}, {@link PsiExpression}, or null if none.
|
||||
*
|
||||
* @return lambda expression body.
|
||||
*/
|
||||
@Nullable
|
||||
PsiElement getBody();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A type which represents a function denoted by a lambda expression.
|
||||
*/
|
||||
public class PsiLambdaExpressionType extends PsiType {
|
||||
private final PsiLambdaExpression myExpression;
|
||||
|
||||
public PsiLambdaExpressionType(PsiLambdaExpression expression) {
|
||||
super(PsiAnnotation.EMPTY_ARRAY);
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "<lambda expression>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCanonicalText() {
|
||||
return getPresentableText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalCanonicalText() {
|
||||
return getCanonicalText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return myExpression.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsToText(@NonNls final String text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A> A accept(@NotNull final PsiTypeVisitor<A> visitor) {
|
||||
return visitor.visitType(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalSearchScope getResolveScope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType[] getSuperTypes() {
|
||||
return PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A type which represents an omitted type for parameter of lambda expression.
|
||||
*/
|
||||
public class PsiLambdaParameterType extends PsiType {
|
||||
private final PsiParameter myParameter;
|
||||
|
||||
public PsiLambdaParameterType(PsiParameter parameter) {
|
||||
super(PsiAnnotation.EMPTY_ARRAY);
|
||||
myParameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "<lambda parameter>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCanonicalText() {
|
||||
return getPresentableText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalCanonicalText() {
|
||||
return getCanonicalText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return myParameter.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsToText(@NonNls final String text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A> A accept(@NotNull final PsiTypeVisitor<A> visitor) {
|
||||
return visitor.visitType(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalSearchScope getResolveScope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType[] getSuperTypes() {
|
||||
return PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class PsiMethodReferenceType extends PsiType {
|
||||
|
||||
@Override
|
||||
public <A> A accept(@NotNull final PsiTypeVisitor<A> visitor) {
|
||||
return visitor.visitMethodReferenceType(this);
|
||||
return visitor.visitType(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,8 +56,4 @@ public class PsiTypeVisitor<A> {
|
||||
public A visitDiamondType(PsiDiamondType diamondType) {
|
||||
return visitType(diamondType);
|
||||
}
|
||||
|
||||
public A visitMethodReferenceType(PsiMethodReferenceType methodReferenceType) {
|
||||
return visitType(methodReferenceType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,6 +644,7 @@ public class TypeConversionUtil {
|
||||
|
||||
// todo[r.sh] implement
|
||||
if (right instanceof PsiMethodReferenceType && left instanceof PsiClassType) return true;
|
||||
if (right instanceof PsiLambdaExpressionType && left instanceof PsiClassType) return true;
|
||||
|
||||
if (left instanceof PsiIntersectionType) {
|
||||
PsiType[] conjuncts = ((PsiIntersectionType)left).getConjuncts();
|
||||
|
||||
Reference in New Issue
Block a user