Introduce Variable feature (in pre-alpha quality).
Problems: 1. Still problems with containers, due to new for me JetContainerNode. 2. Needs name suggester 3. Needs name validator 4. Needs type annotation adding 5. Needs changing to var and checking write access of usages 6. Needs final modifier adding 7. Some problems on class and file level. Should be fixed. Problems with inplace rename on this positions. Additionally possibly should be added proper work with expressions on class body level and namespace/file level. It parsed as error now. 8. Needs much more tests than just 6.
This commit is contained in:
@@ -25,8 +25,10 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
public class JetParserDefinition implements ParserDefinition {
|
||||
|
||||
public JetParserDefinition() {
|
||||
if (!ApplicationManager.getApplication().isCommandLine()) {
|
||||
}
|
||||
//todo: ApplicationManager.getApplication() is null during JetParsingTest setting up
|
||||
|
||||
/*if (!ApplicationManager.getApplication().isCommandLine()) {
|
||||
}*/
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetBlockExpression extends JetExpression {
|
||||
public class JetBlockExpression extends JetExpression implements JetStatementExpression {
|
||||
public JetBlockExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetBreakExpression extends JetLabelQualifiedExpression {
|
||||
public class JetBreakExpression extends JetLabelQualifiedExpression implements JetStatementExpression {
|
||||
public JetBreakExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetClassInitializer extends JetDeclaration {
|
||||
public class JetClassInitializer extends JetDeclaration implements JetStatementExpression {
|
||||
public JetClassInitializer(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.jet.JetNodeTypes;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetClassObject extends JetDeclaration {
|
||||
public class JetClassObject extends JetDeclaration implements JetStatementExpression {
|
||||
public JetClassObject(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetContinueExpression extends JetLabelQualifiedExpression {
|
||||
public class JetContinueExpression extends JetLabelQualifiedExpression implements JetStatementExpression {
|
||||
public JetContinueExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -81,4 +81,9 @@ abstract public class JetFunction extends JetTypeParameterListOwner
|
||||
public JetElement asElement() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
PsiElement parent = getParent();
|
||||
return !(parent instanceof JetFile || parent instanceof JetClassBody || parent instanceof JetNamespaceBody);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -7,7 +7,8 @@ import org.jetbrains.jet.JetNodeTypes;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class JetLabelQualifiedInstanceExpression extends JetLabelQualifiedExpression {
|
||||
public abstract class JetLabelQualifiedInstanceExpression extends JetLabelQualifiedExpression
|
||||
implements JetStatementExpression {
|
||||
|
||||
public JetLabelQualifiedInstanceExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.jet.JetNodeTypes;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class JetLoopExpression extends JetExpression {
|
||||
public abstract class JetLoopExpression extends JetExpression implements JetStatementExpression {
|
||||
public JetLoopExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public abstract class JetNamedDeclaration extends JetDeclaration implements PsiNameIdentifierOwner {
|
||||
public abstract class JetNamedDeclaration extends JetDeclaration implements PsiNameIdentifierOwner, JetStatementExpression {
|
||||
public JetNamedDeclaration(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -39,6 +41,21 @@ public class JetProperty extends JetTypeParameterListOwner implements JetModifie
|
||||
return getNode().findChildByType(JetTokens.VAR_KEYWORD) != null;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
PsiElement parent = getParent();
|
||||
return !(parent instanceof JetFile || parent instanceof JetClassBody || parent instanceof JetNamespaceBody);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SearchScope getUseScope() {
|
||||
if (isLocal()) {
|
||||
PsiElement block = PsiTreeUtil.getParentOfType(this, JetBlockExpression.class, JetClassInitializer.class);
|
||||
if (block == null) return super.getUseScope();
|
||||
else return new LocalSearchScope(block);
|
||||
} else return super.getUseScope();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetTypeReference getReceiverTypeRef() {
|
||||
ASTNode node = getNode().getFirstChildNode();
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetReturnExpression extends JetLabelQualifiedExpression {
|
||||
public class JetReturnExpression extends JetLabelQualifiedExpression implements JetStatementExpression {
|
||||
public JetReturnExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetSecondaryConstructor extends JetDeclaration implements JetDeclarationWithBody {
|
||||
public class JetSecondaryConstructor extends JetDeclaration implements JetDeclarationWithBody, JetStatementExpression {
|
||||
public JetSecondaryConstructor(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,14 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
||||
return ReferenceProvidersRegistry.getReferencesFromProviders(this, PsiReferenceService.Hints.NO_HINTS);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiReference getReference() {
|
||||
PsiReference[] references = getReferences();
|
||||
if (references.length == 1) return references[0];
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull JetVisitorVoid visitor) {
|
||||
visitor.visitSimpleNameExpression(this);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
/**
|
||||
* User: Alefas
|
||||
* Date: 31.01.12
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is an interface to show that {@link JetExpression} is not
|
||||
* actually an expression (in meaning that this expression can be placed after "val x = ").
|
||||
* This is possibly redundant interface, all inheritors of this interface should be refactored that they are not
|
||||
* {@link JetExpression}, after such refactoring, this interface can be removed.
|
||||
*/
|
||||
public interface JetStatementExpression {
|
||||
}
|
||||
Reference in New Issue
Block a user