file_name stringlengths 6 86 | file_path stringlengths 45 249 | content stringlengths 47 6.26M | file_size int64 47 6.26M | language stringclasses 1 value | extension stringclasses 1 value | repo_name stringclasses 767 values | repo_stars int64 8 14.4k | repo_forks int64 0 1.17k | repo_open_issues int64 0 788 | repo_created_at stringclasses 767 values | repo_pushed_at stringclasses 767 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
ImportFlow.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/dataflow/ImportFlow.java | package ksp.kos.ideaplugin.dataflow;
import ksp.kos.ideaplugin.psi.KerboScriptNamedElement;
import ksp.kos.ideaplugin.reference.ReferableType;
import ksp.kos.ideaplugin.reference.context.Duality;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
/**
* Created on 05/04/16.
*
* @author ptasha
*/
public class ImportFlow extends BaseFlow<ImportFlow>
implements NamedFlow<ImportFlow>, Comparable<ImportFlow>,
ReferenceFlow<ImportFlow>, Duality {
private final String name;
public ImportFlow(String name) {
this.name = name;
}
@Override
public LocalContext getKingdom() {
return null; // TODO implement
}
@Override
public ReferableType getReferableType() {
return ReferableType.FILE;
}
@Override
public String getName() {
return name;
}
@Override
public ImportFlow differentiate(LocalContext context) {
if (name.endsWith("_")) {
return this;
}
return new ImportFlow(name+"_");
}
@Override
public String getText() {
return "run once "+getName()+".";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ImportFlow that = (ImportFlow) o;
return Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
@Override
public int compareTo(@NotNull ImportFlow o) {
return getName().compareTo(o.getName());
}
@Override
public @Nullable KerboScriptNamedElement getSyntax() {
return null; // TODO implement
}
@Override
public ImportFlow getSemantics() {
return this;
}
}
| 1,901 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ContextBuilder.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/dataflow/ContextBuilder.java | package ksp.kos.ideaplugin.dataflow;
import ksp.kos.ideaplugin.expressions.ExpressionVisitor;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import java.util.*;
/**
* Created on 14/08/16.
*
* @author ptasha
*/
public class ContextBuilder { // TODO combine into diff context?
private ContextBuilder parent;
private final List<Flow<?>> list = new LinkedList<>();
private final HashMap<String, Dependency> map = new HashMap<>();
private final MixedDependency returnFlow = new MixedDependency();
public ContextBuilder() {
this(null);
}
public ContextBuilder(ContextBuilder parent) {
this.parent = parent;
}
public void visit(ExpressionVisitor visitor) {
for (Flow<?> flow : getList()) {
flow.accept(visitor);
}
}
public String getText() {
String text = "";
for (Flow<?> flow : getList()) {
if (!text.isEmpty()) text += "\n";
text += flow.getText();
}
return text;
}
public void differentiate(LocalContext context, ContextBuilder contextBuilder) {
for (Flow<?> flow : list) {
flow.differentiate(context, contextBuilder);
}
}
public void simplify() {
for (ListIterator<Flow<?>> iterator = list.listIterator(list.size()); iterator.hasPrevious(); ) {
Flow<?> variable = iterator.previous();
// TODO simplify
if (!variable.hasDependees()) {
iterator.remove();
}
}
}
public void add(Flow<?> flow) {
list.add(flow);
}
public boolean buildMap() {
for (Flow<?> flow : list) {
if (!flow.addContext(this)) {
return false;
}
}
return true;
}
public Dependency getFlow(String name) {
Dependency flow = map.get(name);
if (flow==null && parent!=null) {
return parent.getFlow(name);
}
return flow;
}
public HashMap<String, Dependency> getMap() {
return map;
}
public MixedDependency getReturn() {
return returnFlow;
}
public void addReturnFlow(Dependency returnFlow) {
this.returnFlow.addDependency(returnFlow); // TODO optimize?
}
public List<Flow<?>> getList() {
return list;
}
public void setParent(ContextBuilder parent) {
this.parent = parent;
}
public void sort() {
TreeSet<Flow<?>> sorted = new TreeSet<>((o1, o2) -> {
if (o1 instanceof ReturnFlow) {
return 1;
} else if (o2 instanceof ReferenceFlow) {
return -1;
} else if (o1.isDependee(o2)) {
return -1;
} else if (o2.isDependee(o1)) {
return 1;
}
if (o1 instanceof VariableFlow && o2 instanceof VariableFlow) {
String n1 = ((VariableFlow) o1).getName();
String n2 = ((VariableFlow) o2).getName();
while (n1.endsWith("_")) {
if (!n2.endsWith("_")) {
return 1;
}
n1 = n1.substring(0, n1.length()-1);
n2 = n2.substring(0, n2.length()-1);
}
if (n2.endsWith("_")) {
return -1;
}
}
return list.indexOf(o1) - list.indexOf(o2);
});
sorted.addAll(list);
list.clear();
list.addAll(sorted);
}
}
| 3,578 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptSyntaxHighlighterFactory.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/highlighting/KerboScriptSyntaxHighlighterFactory.java | package ksp.kos.ideaplugin.highlighting;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 27/12/15.
*
* @author ptasha
*/
public class KerboScriptSyntaxHighlighterFactory extends SyntaxHighlighterFactory {
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) {
return new KerboScriptSyntaxHighlighter();
}
}
| 676 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptSyntaxHighlighter.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/highlighting/KerboScriptSyntaxHighlighter.java | package ksp.kos.ideaplugin.highlighting;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import ksp.kos.ideaplugin.parser.KerboScriptLexerAdapter;
import ksp.kos.ideaplugin.psi.KerboScriptTypes;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* Created on 27/12/15.
*
* @author ptasha
*/
public class KerboScriptSyntaxHighlighter extends SyntaxHighlighterBase {
public static final TextAttributesKey KEYWORD = TextAttributesKey.createTextAttributesKey("KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);
public static final TextAttributesKey IDENTIFIER = TextAttributesKey.createTextAttributesKey("IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER);
public static final TextAttributesKey COMMENT = TextAttributesKey.createTextAttributesKey("COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
public static final TextAttributesKey STRING = TextAttributesKey.createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING);
public static final TextAttributesKey NUMBER = TextAttributesKey.createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER);
public static final Set<IElementType> KEYWORDS = new HashSet<>(
Arrays.asList(
KerboScriptTypes.NOT,
KerboScriptTypes.AND,
KerboScriptTypes.OR,
KerboScriptTypes.TRUEFALSE,
KerboScriptTypes.SET,
KerboScriptTypes.TO,
KerboScriptTypes.IS,
KerboScriptTypes.IF,
KerboScriptTypes.ELSE,
KerboScriptTypes.UNTIL,
KerboScriptTypes.STEP,
KerboScriptTypes.DO,
KerboScriptTypes.LOCK,
KerboScriptTypes.UNLOCK,
KerboScriptTypes.PRINT,
KerboScriptTypes.AT,
KerboScriptTypes.ON,
KerboScriptTypes.TOGGLE,
KerboScriptTypes.WAIT,
KerboScriptTypes.WHEN,
KerboScriptTypes.THEN,
KerboScriptTypes.OFF,
KerboScriptTypes.STAGE,
KerboScriptTypes.CLEARSCREEN,
KerboScriptTypes.ADD,
KerboScriptTypes.REMOVE,
KerboScriptTypes.LOG,
KerboScriptTypes.BREAK,
KerboScriptTypes.PRESERVE,
KerboScriptTypes.DECLARE,
KerboScriptTypes.DEFINED,
KerboScriptTypes.LOCAL,
KerboScriptTypes.GLOBAL,
KerboScriptTypes.PARAMETER,
KerboScriptTypes.FUNCTION,
KerboScriptTypes.RETURN,
KerboScriptTypes.SWITCH,
KerboScriptTypes.COPY,
KerboScriptTypes.FROM,
KerboScriptTypes.RENAME,
KerboScriptTypes.VOLUME,
KerboScriptTypes.FILE,
KerboScriptTypes.DELETE,
KerboScriptTypes.EDIT,
KerboScriptTypes.RUN,
KerboScriptTypes.ONCE,
KerboScriptTypes.COMPILE,
KerboScriptTypes.LIST,
KerboScriptTypes.REBOOT,
KerboScriptTypes.SHUTDOWN,
KerboScriptTypes.FOR,
KerboScriptTypes.UNSET,
KerboScriptTypes.CHOOSE,
KerboScriptTypes.ATSIGN,
KerboScriptTypes.LAZYGLOBAL
)
);
@NotNull
@Override
public Lexer getHighlightingLexer() {
return new KerboScriptLexerAdapter();
}
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
// TODO - Ideally syntax highlight based off of parser, not lexer, to handle keywords used as variables.
if (tokenType.equals(KerboScriptTypes.IDENTIFIER)) {
return createKeys(IDENTIFIER);
} else if (tokenType.equals(KerboScriptTypes.COMMENTLINE)) {
return createKeys(COMMENT);
} else if (tokenType.equals(KerboScriptTypes.STRING)) {
return createKeys(STRING);
} else if (KEYWORDS.contains(tokenType)) {
return createKeys(KEYWORD);
} else if (tokenType.equals(KerboScriptTypes.E) || tokenType.equals(KerboScriptTypes.INTEGER) || tokenType.equals(KerboScriptTypes.DOUBLE)) {
return createKeys(NUMBER);
}
return new TextAttributesKey[0];
}
@NotNull
private TextAttributesKey[] createKeys(TextAttributesKey identifier) {
return new TextAttributesKey[]{identifier};
}
}
| 5,081 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptHighlightFilter.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/highlighting/KerboScriptHighlightFilter.java | package ksp.kos.ideaplugin.highlighting;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;
import ksp.kos.ideaplugin.KerboScriptFileType;
/**
* Created on 09/01/16.
*
* @author ptasha
*/
public class KerboScriptHighlightFilter implements Condition<VirtualFile> {
private final Project project;
public KerboScriptHighlightFilter(Project project) {
this.project = project;
}
@Override
public boolean value(final VirtualFile file) {
return file.getFileType() == KerboScriptFileType.INSTANCE
&& !CompilerManager.getInstance(project).isExcludedFromCompilation(file);
}
}
| 768 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptLexerAdapter.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/parser/KerboScriptLexerAdapter.java | package ksp.kos.ideaplugin.parser;
import com.intellij.lexer.FlexAdapter;
/**
* Created on 26/12/15.
*
* @author ptasha
*/
public class KerboScriptLexerAdapter extends FlexAdapter {
public KerboScriptLexerAdapter() {
super(new KerboScriptLexer(null));
}
}
| 278 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptParserDefinition.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/parser/KerboScriptParserDefinition.java | package ksp.kos.ideaplugin.parser;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.project.Project;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.KerboScriptLanguage;
import ksp.kos.ideaplugin.psi.KerboScriptTypes;
import org.jetbrains.annotations.NotNull;
/**
* Created on 26/12/15.
*
* @author ptasha
*/
public class KerboScriptParserDefinition implements ParserDefinition {
public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
public static final TokenSet COMMENTS = TokenSet.create(KerboScriptTypes.COMMENTLINE);
public static final IFileElementType FILE = new IFileElementType(Language.findInstance(KerboScriptLanguage.class));
@NotNull
@Override
public Lexer createLexer(Project project) {
return new KerboScriptLexerAdapter();
}
@Override
@NotNull
public TokenSet getWhitespaceTokens() {
return WHITE_SPACES;
}
@Override
@NotNull
public TokenSet getCommentTokens() {
return COMMENTS;
}
@Override
@NotNull
public TokenSet getStringLiteralElements() {
return TokenSet.EMPTY;
}
@Override
@NotNull
public PsiParser createParser(final Project project) {
return new KerboScriptParser();
}
@Override
public IFileElementType getFileNodeType() {
return FILE;
}
@Override
public PsiFile createFile(FileViewProvider viewProvider) {
return new KerboScriptFile(viewProvider);
}
@Override
public SpaceRequirements spaceExistenceTypeBetweenTokens(ASTNode left, ASTNode right) {
return SpaceRequirements.MAY;
}
@Override
@NotNull
public PsiElement createElement(ASTNode node) {
return KerboScriptTypes.Factory.createElement(node);
}
}
| 2,205 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptParserUtil.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/parser/KerboScriptParserUtil.java | package ksp.kos.ideaplugin.parser;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiParser;
import com.intellij.lang.parser.GeneratedParserUtilBase;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
/**
* Created on 06/01/16.
*
* @author ptasha
*/
public class KerboScriptParserUtil extends GeneratedParserUtilBase {
public static PsiBuilder adapt_builder_(IElementType root, PsiBuilder builder, PsiParser parser, TokenSet[] extendsSets) {
ErrorState state = new ErrorState();
ErrorState.initState(state, builder, root, extendsSets);
// TODO - Look into remapping ident node tokens post-parsing, if possible.
return new GeneratedParserUtilBase.Builder(builder, state, parser);
}
}
| 775 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ExpressionVisitor.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/ExpressionVisitor.java | package ksp.kos.ideaplugin.expressions;
/**
* Created on 08/04/16.
*
* @author ptasha
*/
public class ExpressionVisitor {
public void visitFunction(Function function) {visit(function);}
public void visitVariable(Variable variable) {visit(variable);}
public void visit(Expression expression) {
expression.acceptChildren(this);
}
}
| 361 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Function.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Function.java | package ksp.kos.ideaplugin.expressions;
import ksp.kos.ideaplugin.dataflow.FunctionFlow;
import ksp.kos.ideaplugin.dataflow.ParameterFlow;
import ksp.kos.ideaplugin.expressions.inline.InlineFunction;
import ksp.kos.ideaplugin.expressions.inline.InlineFunctions;
import ksp.kos.ideaplugin.psi.KerboScriptExpr;
import ksp.kos.ideaplugin.reference.FlowSelfResolvable;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
/**
* Created on 30/01/16.
*
* @author ptasha
*/
public class Function extends Atom {
private final String name;
private final Expression[] args;
public Function(String name, Expression... args) {
this.name = name;
this.args = args;
}
public Function(String name, List<KerboScriptExpr> exprList) throws SyntaxException {
this.name = name;
this.args = new Expression[exprList.size()];
for (int i = 0; i < exprList.size(); i++) {
KerboScriptExpr expr = exprList.get(i);
args[i] = Expression.parse(expr);
}
}
public String getName() {
return name;
}
public Expression[] getArgs() {
return args;
}
@Override
public String getText() {
String text = this.name + "(";
boolean first = true;
for (Expression arg : args) {
if (first) {
first = false;
} else {
text+=", ";
}
text += arg.getText();
}
return text+")";
}
@Override
public Expression differentiate(LocalContext context) {
if (args.length==0) {
return Number.ZERO;
}
String name = this.name + "_";
// TODO diff function here
FunctionFlow diff = (FunctionFlow) FlowSelfResolvable.function(context, name).resolve();
if (args.length==1) {
return new Function(name, args).inline(context).multiply(args[0].differentiate(context));
}
FunctionFlow original = (FunctionFlow) FlowSelfResolvable.function(context, this.name).resolve();
if (original!=null && diff!=null) {
int j = 0;
List<ParameterFlow> origParams = original.getParameters();
List<ParameterFlow> diffParams = diff.getParameters();
Expression[] diffArgs = new Expression[diffParams.size()];
for (ParameterFlow diffParam : diffParams) {
int i = origParams.indexOf(diffParam);
if (i>=0) {
diffArgs[j] = args[i];
} else if (diffParam.getName().endsWith("_")) {
String paramName = diffParam.getName();
paramName = paramName.substring(0, paramName.length() - 1);
i = origParams.indexOf(new ParameterFlow(paramName));
if (i < 0) {
break;
}
diffArgs[j] = args[i].differentiate(context);
} else {
break;
}
j++;
}
if (j==diffArgs.length) {
return new Function(name, diffArgs).inline(context);
}
}
Expression[] diffArgs = new Expression[args.length*2];
for (int i = 0; i < args.length; i++) {
diffArgs[2*i] = args[i];
diffArgs[2*i + 1] = args[i].differentiate(context);
}
return new Function(name, diffArgs).inline(context);
}
@Override
public Expression inline(HashMap<String, Expression> parameters) {
Expression[] args = new Expression[this.args.length];
for (int i = 0; i < this.args.length; i++) {
args[i] = this.args[i].inline(parameters);
}
return new Function(name, args);
}
@Override
public Expression simplify() {
Expression[] args = new Expression[this.args.length];
for (int i = 0; i < this.args.length; i++) {
args[i] = this.args[i].simplify();
}
return new Function(name, args).inline();
}
private Expression inline() {
return inline((LocalContext)null);
}
private Expression inline(LocalContext context) {
Expression inlined = InlineFunctions.getInstance().inline(this);
if (inlined == null) {
if (context != null) { // TODO pass context to simplify
// TODO shouldn't parse all functions here for speed sake
FunctionFlow flow = (FunctionFlow) FlowSelfResolvable.function(context, name).resolve();
if (flow!=null) {
InlineFunction inlineFunction = flow.getInlineFunction();
if (inlineFunction!=null) {
return inlineFunction.inline(args);
}
}
}
return this;
}
return inlined;
}
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visitFunction(this);
}
@Override
public void acceptChildren(ExpressionVisitor visitor) {
for (Expression arg : args) {
arg.accept(visitor);
}
}
public static Expression log(Expression arg) {
return new Function("log", arg);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Function function = (Function) o;
return Objects.equals(name, function.name) &&
Arrays.equals(args, function.args);
}
@Override
public int hashCode() {
return Objects.hash(name, args);
}
}
| 5,777 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Constant.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Constant.java | package ksp.kos.ideaplugin.expressions;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import ksp.kos.ideaplugin.psi.*;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Objects;
/**
* Created on 30/01/16.
*
* @author ptasha
*/
public class Constant extends Atom {
private final String key;
private final Collection<Expression> expressions = new ArrayList<>();
private final PsiElement psi;
public Constant(KerboScriptSuffix psi) throws SyntaxException {
this.psi = psi;
this.key = getKey(psi);
expressions.add(Expression.parse(psi.getSuffixterm()));
for (KerboScriptSuffixTrailer trailer : psi.getSuffixTrailerList()) {
parseSuffixtermTrailer(trailer.getSuffixterm());
}
}
public Constant(KerboScriptSuffixterm psi) throws SyntaxException {
this.psi = psi;
this.key = getKey(psi);
expressions.add(Atom.parse(psi.getAtom()));
parseSuffixtermTrailer(psi);
}
private void parseSuffixtermTrailer(KerboScriptSuffixterm psi) throws SyntaxException {
for (KerboScriptSuffixtermTrailer trailer : psi.getSuffixtermTrailerList()) {
if (trailer instanceof KerboScriptFunctionTrailer) {
KerboScriptArglist arglist = ((KerboScriptFunctionTrailer) trailer).getArglist();
if (arglist!=null) {
for (KerboScriptExpr expr : arglist.getExprList()) {
expressions.add(Expression.parse(expr));
}
}
} else if (trailer instanceof KerboScriptArrayTrailer) {
expressions.add(Expression.parse(((KerboScriptArrayTrailer) trailer).getExpr()));
}
}
}
private static String getKey(PsiElement psi) {
String key = "";
Collection<LeafPsiElement> children = PsiTreeUtil.findChildrenOfType(psi, LeafPsiElement.class);
for (LeafPsiElement child : children) {
if (!(child instanceof PsiWhiteSpace)) {
key += child.getText();
}
}
return key;
}
@Override
public String getText() {
return psi.getText();
}
@Override
public Expression differentiate(LocalContext context) {
return Number.ZERO;
}
@Override
public Expression inline(HashMap<String, Expression> args) {
return this;
}
@Override
public void acceptChildren(ExpressionVisitor visitor) {
for (Expression expression : expressions) {
expression.accept(visitor);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Constant constant = (Constant) o;
return Objects.equals(key, constant.key);
}
@Override
public int hashCode() {
return Objects.hash(key);
}
}
| 3,159 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
SyntaxException.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/SyntaxException.java | package ksp.kos.ideaplugin.expressions;
/**
* Created on 30/01/16.
*
* @author ptasha
*/
public class SyntaxException extends Exception {
public SyntaxException(String message) {
super(message);
}
}
| 220 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
MultiExpression.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/MultiExpression.java | package ksp.kos.ideaplugin.expressions;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import ksp.kos.ideaplugin.psi.KerboScriptExpr;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.function.BiFunction;
/**
* Created on 31/01/16.
*
* @author ptasha
*/
public abstract class MultiExpression<O extends Enum<O> & MultiExpression.Op, E extends Expression> extends Expression {
protected final List<Item<O, E>> items;
protected MultiExpression(List<Item<O, E>> items) {
this.items = items;
}
protected MultiExpression(Expression... expressions) {
items = createBuilder().addExpressions(expressions).createItems();
}
protected MultiExpression(KerboScriptExpr expr) throws SyntaxException {
items = createBuilder().parse(expr).createItems();
}
public List<Item<O, E>> getItems() {
return items;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MultiExpression<?, ?> that = (MultiExpression<?, ?>) o;
return Objects.equals(items, that.items);
}
@Override
public int hashCode() {
return Objects.hash(items);
}
@Override
public String getText() {
String text = "";
boolean first = true;
for (Item<O, E> item : items) {
if (!first) {
text += item.operation;
} else {
first = false;
}
text += item.expression.getText();
}
return text;
}
public static class Item<O extends Enum<O>, E extends Expression> {
private final O operation;
private final E expression;
protected Item(O operation, E expression) {
this.operation = operation;
this.expression = expression;
}
public O getOperation() {
return operation;
}
public E getExpression() {
return expression;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Item<?, ?> item = (Item<?, ?>) o;
return Objects.equals(operation, item.operation) &&
Objects.equals(expression, item.expression);
}
@Override
public int hashCode() {
return Objects.hash(operation, expression);
}
}
public interface Op extends Operation {
String getText();
}
public interface Operation
extends BiFunction<Expression, Expression, Expression> {
}
public abstract static class MultiExpressionBuilder<O extends Enum<O> & MultiExpression.Op, E extends Expression> {
private final Class<? extends MultiExpression<O, E>> expressionClass;
private final E zero = toElement(zero());
private final E one = toElement(one());
protected final LinkedList<Item<O, E>> items = new LinkedList<>();
public MultiExpressionBuilder(Class<? extends MultiExpression<O, E>> expressionClass) {
this.expressionClass = expressionClass;
}
public Item<O, E> createItem(O operation, Expression expression) {
return new Item<>(operation, toElement(expression));
}
public MultiExpressionBuilder<O, E> addExpressions(Expression... expressions) {
for (Expression expression : expressions) {
addExpression(defaultOperator(), expression);
}
return this;
}
protected MultiExpressionBuilder<O, E> addExpression(Expression expression) {
addExpression(defaultOperator(), expression);
return this;
}
protected MultiExpressionBuilder<O, E> addExpression(O operator, Expression expression) {
expression = expression.simplify();
MultiExpression<O, E> associate = associate(expression);
if (associate == null) {
addItem(createItem(operator, toElement(expression)));
} else {
addExpression(operator, associate);
}
return this;
}
private void addExpression(O operator, MultiExpression<O, E> associate) {
for (Item<O, E> item : associate.items) {
addItem(createItem(merge(operator, item.getOperation()), item.getExpression()));
}
}
protected void addItem(Item<O, E> newItem) {
if (items.size()==1 && nullifyEverything(items.get(0))) {
return;
}
if (nullifyEverything(newItem)) {
items.clear();
items.add(newItem);
return;
}
if (omit(newItem)) {
return;
}
if (this instanceof ConsumeSupported) {
Item<O, E> consumed = this.consume(newItem);
if (consumed!=null) {
addExpression(consumed.getOperation(), consumed.getExpression());
return;
}
}
items.add(newItem);
}
public MultiExpressionBuilder<O, E> addItems(Collection<Item<O, E>> items) {
for (Item<O, E> item : items) {
this.addItem(item);
}
return this;
}
protected Expression zero() {
return null;
}
protected Expression one() {
return null;
}
protected boolean nullifyEverything(Item<O, E> item) {
return item.operation == defaultOperator() && item.expression.equals(zero);
}
protected boolean omit(Item<O, E> item) {
return item.expression.equals(one);
}
protected Item<O, E> consume(Item<O, E> newItem) {
for (Iterator<Item<O, E>> iterator = items.iterator(); iterator.hasNext(); ) {
Item<O, E> item = iterator.next();
item = consumeItem(item, newItem);
if (item != null) {
iterator.remove();
return item;
}
}
return null;
}
@SuppressWarnings("unchecked")
protected Item<O, E> consumeItem(Item<O, E> item, Item<O, E> newItem) {
Item<O, E> consumed = ((ConsumeSupported<O, E>) this).consume(item, newItem);
if (consumed==null) {
return ((ConsumeSupported<O, E>) this).consume(newItem, item); // TODO get rid of me once symmetry is supported
}
return consumed;
}
@SuppressWarnings("unchecked")
protected MultiExpression<O, E> associate(Expression expression) {
if (expression.getClass() == expressionClass) {
return (MultiExpression<O, E>) expression;
} else if (expression instanceof Escaped) {
return associate(((Escaped) expression).getExpression());
} else if (expression instanceof Element && ((Element) expression).isSimple()) {
return associate(((Element) expression).getAtom());
}
return null;
}
protected Expression singleItemExpression(Item<O, E> item) {
return item.getExpression();
}
@NotNull
protected abstract O[] operators();
protected O defaultOperator() {
return operators()[0];
}
protected O merge(O operation1, O operation2) {
if (operation1 == operation2) {
return defaultOperator();
} else if (operation1 == defaultOperator()) {
return operation2;
} else {
return operation1;
}
}
@SuppressWarnings("unchecked")
protected E toElement(Expression expression) {
return (E) expression;
}
public MultiExpressionBuilder<O, E> parse(KerboScriptExpr expr) throws SyntaxException {
int state = 0;
O operation = defaultOperator();
for (ASTNode node : expr.getNode().getChildren(null)) {
PsiElement element = node.getPsi();
if (element instanceof PsiWhiteSpace) {
continue;
}
switch (state) {
case 0:
if (element instanceof KerboScriptExpr) {
addItem(createItem(operation, parseElement((KerboScriptExpr) element)));
} else {
throw new SyntaxException("Expression is required: found " + element + ": " + element.getText());
}
state = 1;
break;
case 1:
operation = parseOperation(element);
state = 0;
break;
}
}
return this;
}
protected O parseOperation(PsiElement element) throws SyntaxException {
String text = element.getText();
for (O o : operators()) {
if (o.getText().equals(text)) {
return o;
}
}
throw new SyntaxException("One of " + Arrays.toString(operators()) + " is required: found " + element + ": " + text);
}
@SuppressWarnings("unchecked")
protected E parseElement(KerboScriptExpr element) throws SyntaxException {
return toElement(Expression.parse(element));
}
public Expression createExpression() {
List<Item<O, E>> items = createItems();
if (items.isEmpty()) {
return one();
}
if (items.size() == 1) {
return singleItemExpression(items.get(0));
}
return createExpression(items);
}
protected abstract MultiExpression<O, E> createExpression(List<Item<O, E>> items);
public List<Item<O, E>> createItems() {
normalize();
return Collections.unmodifiableList(items);
}
protected void normalize() {
}
}
public abstract MultiExpressionBuilder<O, E> createBuilder();
protected MultiExpressionBuilder<O, E> createBuilder(MultiExpression<O, E> expression) {
return createBuilder().addItems(expression.items);
}
@SuppressWarnings("unchecked")
@Override
public Expression simplify() {
MultiExpressionBuilder<O, E> builder = createBuilder();
for (Item<O, E> item : items) {
builder.addExpression(item.getOperation(), item.getExpression().simplify());
}
return builder.createExpression();
}
protected Expression addExpression(Expression expression) {
return createBuilder(this).addExpression(expression).createExpression();
}
protected Expression addExpression(O operator, Expression expression) {
return createBuilder(this).addExpression(operator, expression).createExpression();
}
protected Expression addExpressionLeft(Expression expression) {
return createBuilder().addExpression(expression).addItems(items).createExpression();
}
@Override
public Expression inline(HashMap<String, Expression> args) {
MultiExpressionBuilder<O, E> builder = createBuilder();
for (Item<O, E> item : items) {
builder.addExpression(item.getOperation(), item.getExpression().inline(args));
}
return builder.createExpression();
}
@Override
public void acceptChildren(ExpressionVisitor visitor) {
for (Item<O, E> item : items) {
item.getExpression().accept(visitor);
}
}
}
| 12,017 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Variable.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Variable.java | package ksp.kos.ideaplugin.expressions;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import java.util.HashMap;
import java.util.Objects;
/**
* Created on 29/01/16.
*
* @author ptasha
*/
public class Variable extends Atom {
private final String name;
public Variable(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String getText() {
return name;
}
@Override
public Expression differentiate(LocalContext context) {
return new Variable(name+"_");
}
@Override
public Expression inline(HashMap<String, Expression> args) {
Expression expression = args.get(name);
if (expression!=null) {
return expression;
}
return this;
}
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visitVariable(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Variable variable = (Variable) o;
return Objects.equals(name, variable.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
}
| 1,272 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Addition.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Addition.java | package ksp.kos.ideaplugin.expressions;
import ksp.kos.ideaplugin.psi.KerboScriptArithExpr;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Created on 31/01/16.
*
* @author ptasha
*/
public class Addition extends MultiExpression<Addition.Op,Expression> {
@SuppressWarnings("unused")
public Addition() {
super();
}
protected Addition(List<Item<Op, Expression>> items) {
super(items);
}
public Addition(Expression... expressions) {
super(expressions);
}
public Addition(KerboScriptArithExpr arith) throws SyntaxException {
super(arith);
}
@Override
public MultiExpressionBuilder<Op, Expression> createBuilder() {
return new AdditionBuilder();
}
@Override
public Expression differentiate(LocalContext context) {
MultiExpressionBuilder<Op, Expression> builder = createBuilder();
for (Item<Op, Expression> item : items) {
builder.addExpression(item.getOperation(), item.getExpression().differentiate(context));
}
return builder.createExpression();
}
@Override
public Expression plus(Expression expression) {
return addExpression(expression);
}
@Override
public Expression minus(Expression expression) {
return addExpression(Op.MINUS, expression);
}
@Override
public boolean canMultiply(Expression expression) {
return false;
}
public Expression multiplyItems(Expression expression) {
MultiExpressionBuilder<Op, Expression> builder = createBuilder();
for (Item<Op, Expression> item : items) {
builder.addExpression(item.getOperation(), item.getExpression().multiply(expression));
}
return builder.createExpression();
}
@Override
public Expression normalize() {
Expression expression = this.distribute();
if (expression instanceof Addition) {
return ((Addition) expression).extractRoot();
}
return expression;
}
public Expression extractRoot() {
Expression root = null;
AdditionBuilder builder = new AdditionBuilder();
for (Item<Op, Expression> item : items) {
Expression expression = item.getExpression();
if (root==null) {
root = item.getExpression();
} else {
root = root.root(item.getExpression());
}
builder.addExpression(item.getOperation(), expression);
}
Expression expression = builder.createExpression();
if (root.isNegative()) {
root = root.minus();
}
if (!root.equals(Number.ONE)) {
return expression.distribute(Multiplication.Op.DIV, root).multiply(root);
} else {
return expression;
}
}
@Override
public Expression distribute() {
AdditionBuilder builder = new AdditionBuilder();
for (Item<Op, Expression> item : items) {
builder.addExpression(item.getOperation(), item.getExpression().distribute());
}
return builder.createExpression();
}
@Override
public Expression distribute(Expression expression) {
return distribute(Multiplication.Op.MUL, expression);
}
@Override
public Expression distribute(Multiplication.Op operation, Expression expression) {
AdditionBuilder builder = new AdditionBuilder();
for (Item<Op, Expression> item : items) {
builder.addExpression(item.getOperation(), operation.apply(item.getExpression(), expression).distribute());
}
return builder.createExpression();
}
public enum Op implements MultiExpression.Op {
PLUS("+", Expression::plus),
MINUS("-", Expression::minus);
private final String text;
private final MultiExpression.Operation operation;
Op(String text, MultiExpression.Operation operation) {
this.text = text;
this.operation = operation;
}
@Override
public String getText() {
return text;
}
public String toString() {
return " "+text+" ";
}
@Override
public Expression apply(Expression exp1, Expression exp2) {
return operation.apply(exp1, exp2);
}
}
private static class AdditionBuilder extends MultiExpressionBuilder<Op, Expression> implements ConsumeSupported<Op, Expression>{
public AdditionBuilder() {
super(Addition.class);
}
@Override
protected Expression one() {
return Number.ZERO;
}
@Override
protected Expression singleItemExpression(Item<Op, Expression> item) {
if (item.getOperation()== Op.PLUS) {
return item.getExpression();
} else {
return item.getExpression().minus();
}
}
@Override
protected void addItem(Item<Op, Expression> newItem) {
if (items.isEmpty()) {
if (newItem.getOperation()== Op.MINUS) {
newItem = createItem(Op.PLUS, newItem.getExpression().minus());
}
} else if (newItem.getExpression().isNegative()) {
newItem = createItem(merge(newItem.getOperation(), Op.MINUS), newItem.getExpression().minus());
}
super.addItem(newItem);
}
@NotNull
@Override
protected Op[] operators() {
return Op.values();
}
@Override
protected MultiExpression<Op, Expression> createExpression(List<Item<Op, Expression>> items) {
return new Addition(items);
}
@Override
protected Item<Op, Expression> consumeItem(Item<Op, Expression> item, Item<Op, Expression> newItem) {
return this.consume(item, newItem); // TODO multiply must be the same
}
@Override
public Item<Op, Expression> consume(Item<Op, Expression> item, Item<Op, Expression> newItem) {
Expression e1 = singleItemExpression(item);
Expression e2 = singleItemExpression(newItem);
Expression result = e1.simplePlus(e2);
if (result!=null) {
return createItem(Op.PLUS, result);
}
result = e2.simplePlus(e1);
if (result!=null) {
return createItem(Op.PLUS, result);
}
return null;
}
}
}
| 6,632 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Escaped.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Escaped.java | package ksp.kos.ideaplugin.expressions;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import java.util.HashMap;
import java.util.Objects;
/**
* Created on 29/01/16.
*
* @author ptasha
*/
public class Escaped extends Atom {
private final Expression expression;
public Escaped(Expression expression) {
this.expression = expression;
}
@Override
public String getText() {
return "(" + expression.getText() + ")";
}
@Override
public Expression differentiate(LocalContext context) {
return expression.differentiate(context);
}
@Override
public Expression inline(HashMap<String, Expression> args) {
return expression.inline(args);
}
public Expression getExpression() {
return expression;
}
@Override
public Expression simplify() {
return expression.simplify();
}
@Override
public Expression minus() {
return expression.minus();
}
@Override
public boolean isNegative() {
return expression.isNegative();
}
@Override
public boolean isAddition() {
if (expression instanceof Addition) {
return true;
}
return super.isAddition();
}
@Override
public void acceptChildren(ExpressionVisitor visitor) {
expression.accept(visitor);
}
public static Expression unescape(Expression expression) {
if (expression instanceof Escaped) {
return unescape(((Escaped) expression).getExpression());
}
return expression;
}
@Override
public Expression normalize() {
return expression.normalize();
}
@Override
public Expression distribute() {
return expression.distribute();
}
@Override
public Expression distribute(Expression expression) {
return this.expression.distribute(expression);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Escaped escaped = (Escaped) o;
return Objects.equals(expression, escaped.expression);
}
@Override
public int hashCode() {
return Objects.hash(expression);
}
}
| 2,274 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Multiplication.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Multiplication.java | package ksp.kos.ideaplugin.expressions;
import ksp.kos.ideaplugin.psi.KerboScriptMultdivExpr;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* Created on 30/01/16.
*
* @author ptasha
*/
public class Multiplication extends MultiExpression<Multiplication.Op, Element> {
@SuppressWarnings("unused")
public Multiplication() {
super();
}
protected Multiplication(List<Item<Op, Element>> items) {
super(items);
}
public Multiplication(Expression... expressions) {
super(expressions);
}
public Multiplication(KerboScriptMultdivExpr muldiv) throws SyntaxException {
super(muldiv);
}
@Override
public MultiExpressionBuilder<Op, Element> createBuilder() {
return new MultiplicationBuilder();
}
@Override
public Expression differentiate(LocalContext context) {
Expression diff = Number.ZERO;
for (Item<Op, Element> item : items) {
Expression id = Number.ONE;
for (Item<Op, Element> ditem : items) {
if (item!=ditem) {
if (ditem.getOperation()==Op.MUL) {
id = id.multiply(ditem.getExpression());
} else {
id = id.divide(ditem.getExpression());
}
} else {
if (ditem.getOperation()==Op.MUL) {
id = id.multiply(ditem.getExpression().differentiate(context));
} else {
id = id.multiply(ditem.getExpression().power(Number.create(-1)).differentiate(context));
}
}
}
diff = diff.plus(id);
}
return diff;
}
@Override
public Expression multiply(Expression expression) {
return addExpression(expression);
}
@Override
public Expression multiplyLeft(Expression expression) {
return addExpressionLeft(expression);
}
@Override
public Expression divide(Expression expression) {
return addExpression(Op.DIV, expression);
}
@Override
public Expression minus() {
boolean first = true;
MultiExpressionBuilder<Op, Element> builder = createBuilder();
for (Item<Op, Element> item : items) {
if (first) {
item = builder.createItem(item.getOperation(), item.getExpression().minus());
first = false;
}
builder.addItem(item);
}
return builder.createExpression();
}
private static class NormalForm {
private final Expression mulNumber;
private final Expression divNumber;
private final Set<Item<Op, Element>> items;
public NormalForm(Expression mulNumber, Expression divNumber, Set<Item<Op, Element>> items) {
this.mulNumber = mulNumber;
this.divNumber = divNumber;
this.items = items;
}
public static NormalForm toNormal(Multiplication multiplication) {
Expression mulNumber = Number.ONE;
Expression divNumber = Number.ONE;
HashSet<Item<Op, Element>> items = new HashSet<>();
for (Item<Op, Element> item : multiplication.getItems()) {
if (item.getExpression().isNumber()) {
if (item.getOperation()==Op.MUL) {
mulNumber = mulNumber.multiply(item.getExpression());
} else {
divNumber = divNumber.multiply(item.getExpression());
}
} else if (item.getExpression().isNegative()) {
mulNumber = mulNumber.minus();
items.add(new Item<>(item.getOperation(), Element.toElement(item.getExpression().minus())));
} else {
items.add(item);
}
}
return new NormalForm(mulNumber, divNumber, items);
}
public Expression plus(NormalForm normalForm) {
if (!this.items.equals(normalForm.items)) {
return null;
}
MultiplicationBuilder builder = new MultiplicationBuilder();
builder.addExpression(
this.mulNumber.multiply(normalForm.divNumber)
.plus(normalForm.mulNumber.multiply(this.divNumber))
.divide(this.divNumber).divide(normalForm.divNumber));
builder.addItems(items);
return builder.createExpression();
}
}
@Override
@Nullable
public Expression simplePlus(Expression expression) {
if (expression instanceof Multiplication) {
return NormalForm.toNormal(this).plus(NormalForm.toNormal((Multiplication) expression));
} else {
ArrayList<Item<Op, Element>> items = new ArrayList<>();
items.add(new Item<>(Op.MUL, Element.toElement(expression)));
return simplePlus(new Multiplication(items));
}
}
@Override
public Expression normalize() {
MultiplicationBuilder builder = new MultiplicationBuilder();
for (Item<Op, Element> item : items) {
builder.addExpression(item.getOperation(), item.getExpression().normalize().simplify());
}
return builder.createExpression();
}
@Override
public Expression divisor() {
MultiplicationBuilder builder = new MultiplicationBuilder();
for (Item<Op, Element> item : items) {
if (item.getOperation()==Op.DIV) {
builder.addExpression(Op.MUL, item.getExpression());
}
}
return builder.createExpression();
}
@Override
public Expression distribute() {
Expression addition = Number.ONE.distribute();
MultiplicationBuilder divisor = new MultiplicationBuilder();
for (Item<Op, Element> item : items) {
if (item.getOperation()==Op.MUL) {
addition = addition.distribute(item.getExpression().distribute());
} else {
divisor.addExpression(Op.MUL, item.getExpression());
}
}
return addition.divide(divisor.createExpression());
}
@Override
public boolean isNegative() {
return items.get(0).getExpression().isNegative();
}
public enum Op implements MultiExpression.Op {
MUL("*", Expression::multiply),
DIV("/", Expression::divide);
private final String text;
private final MultiExpression.Operation operation;
Op(String text, Operation operation) {
this.text = text;
this.operation = operation;
}
@Override
public String getText() {
return text;
}
public String toString() {
return text;
}
@Override
public Expression apply(Expression exp1, Expression exp2) {
return operation.apply(exp1, exp2);
}
}
public static class MultiplicationBuilder extends MultiExpressionBuilder<Op, Element> implements ConsumeSupported<Op, Element> {
public MultiplicationBuilder() {
super(Multiplication.class);
}
@Override
protected Expression zero() {
return Number.ZERO;
}
@Override
protected Expression one() {
return Number.ONE;
}
@Override
protected Expression singleItemExpression(Item<Op, Element> item) {
if (item.getOperation()== Op.MUL) {
Element expression = item.getExpression();
if (expression.isSimple()) {
return expression.getAtom().simplify();
}
return expression;
} else {
items.add(0, createItem(Op.MUL, toElement(Number.ONE)));
return createExpression();
}
}
@NotNull
@Override
protected Op[] operators() {
return Op.values();
}
@Override
protected Element toElement(Expression expression) {
return Element.toElement(expression);
}
@Override
protected void normalize() {
int sign = 1;
LinkedList<Item<Op, Element>> mult = new LinkedList<>();
LinkedList<Item<Op, Element>> div = new LinkedList<>();
for (Item<Op, Element> item : this.items) {
if (item.getExpression().isNegative()) {
item = createItem(item.getOperation(), item.getExpression().minus());
sign*=-1;
}
if (item.getOperation() == Op.MUL) {
mult.add(item);
} else {
div.add(item);
}
}
Expression muln = normalize(mult);
Expression divn = normalize(div);
Number root = Number.root(muln, divn);
if (!root.equals(Number.ONE)) {
muln= muln.divide(root);
divn= divn.divide(root);
}
if (!muln.equals(Number.ONE)) {
mult.addFirst(createItem(Op.MUL, toElement(muln)));
} else if (mult.isEmpty()) {
mult.add(createItem(Op.MUL, toElement(Number.ONE)));
}
if (!divn.equals(Number.ONE)) {
div.addFirst(createItem(Op.DIV, toElement(divn)));
}
if (sign<0) {
mult.set(0, createItem(Op.MUL, mult.get(0).getExpression().minus()));
}
this.items.clear();
this.items.addAll(mult);
this.items.addAll(div);
}
private Expression normalize(LinkedList<Item<Op, Element>> items) {
Expression number = Number.ONE;
int index = -1;
float score = 0;
int i = 0;
for (Iterator<Item<Op, Element>> iterator = items.iterator(); iterator.hasNext(); i++) {
Item<Op, Element> item = iterator.next();
Element expression = item.getExpression();
if (expression.isNumber()) {
number = number.multiply(expression).simplify();
iterator.remove();
i--;
} else if (expression.isAddition()) {
float newScore = getNumbersScore(getAddition(expression));
if (newScore>score) {
index = i;
score = newScore;
}
}
}
if (!number.equals(Number.ONE)) {
if (score>0.99) {
Item<Op, Element> addition = items.get(index);
Expression expression = getAddition(addition.getExpression()).multiplyItems(number);
items.set(index, createItem(addition.getOperation(), toElement(expression)));
number = Number.ONE;
}
}
return number;
}
private float getNumbersScore(Addition addition) {
float numbers = 0;
for (Item<Addition.Op, Expression> item : addition.items) {
Expression expression = item.getExpression();
if (expression instanceof Number) {
numbers++;
} else if (expression instanceof Multiplication) {
for (Item<Op, Element> mulItem : ((Multiplication) expression).items) {
if (mulItem.getExpression().isNumber()) {
numbers++;
break;
}
}
}
}
return numbers/addition.items.size();
}
private Addition getAddition(Element expression) {
return (Addition)((Escaped)expression.getAtom()).getExpression();
}
@Override
protected MultiExpression<Op, Element> createExpression(List<Item<Op, Element>> items) {
return new Multiplication(items);
}
@Override
public Item<Op, Element> consume(Item<Op, Element> item, Item<Op, Element> newItem) {
if (item.getExpression().canMultiply(newItem.getExpression())) {
Expression merged = merge(item.getOperation(), newItem.getOperation()).apply(item.getExpression(), newItem.getExpression());
return createItem(item.getOperation(), toElement(merged));
}
return null;
}
}
}
| 12,793 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Element.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Element.java | package ksp.kos.ideaplugin.expressions;
import com.intellij.lang.ASTNode;
import ksp.kos.ideaplugin.psi.KerboScriptExpr;
import ksp.kos.ideaplugin.psi.KerboScriptFactor;
import ksp.kos.ideaplugin.psi.KerboScriptTypes;
import ksp.kos.ideaplugin.psi.KerboScriptUnaryExpr;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
/**
* Created on 30/01/16.
*
* @author ptasha
*/
public class Element extends Expression {
private final int sign;
private final Atom atom;
private final Atom power;
public static Expression create(int sign, Expression atom) {
return create(sign, atom, Number.ONE);
}
public static Expression create(int sign, Expression atom, Expression power) {
if (atom.equals(Number.ZERO)) {
power = Number.ONE;
sign = 1;
} else if (atom.equals(Number.ONE)) {
power = Number.ONE;
}
if (power.equals(Number.ONE)) {
if (sign == 1) {
return atom;
}
} else if (power.equals(Number.ZERO)) {
return create(sign, Number.ONE);
}
return new Element(sign, atom, power);
}
public Element(int sign, Expression atom, Expression power) {
this.sign = sign;
this.atom = Atom.toAtom(atom);
this.power = Atom.toAtom(power);
}
public int getSign() {
return sign;
}
public Atom getAtom() {
return atom;
}
public Expression getPower() {
return power;
}
public static Element parseUnary(KerboScriptUnaryExpr element) throws SyntaxException {
int sign = parseSign(element);
KerboScriptExpr expr = element.getExpr();
if (expr instanceof KerboScriptFactor) {
return parseFactor(sign, (KerboScriptFactor) expr);
} else {
return new Element(sign, Atom.parse(expr), Number.ONE);
}
}
@NotNull
public static Element parseFactor(KerboScriptFactor element) throws SyntaxException {
return parseFactor(1, element);
}
@NotNull
private static Element parseFactor(int sign, KerboScriptFactor expr) throws SyntaxException {
List<KerboScriptExpr> list = expr.getExprList();
Expression power = Number.create(1);
for (int i = 1; i < list.size(); i++) {
KerboScriptExpr fexp = list.get(i);
power = power.multiply(Expression.parse(fexp));
}
return new Element(sign, Atom.parse(list.get(0)), power);
}
private static int parseSign(KerboScriptUnaryExpr element) throws SyntaxException {
int sign;
ASTNode plusMinus = element.getNode().findChildByType(KerboScriptTypes.PLUSMINUS);
if (plusMinus == null) {
sign = 1;
} else {
String text = plusMinus.getText();
switch (text) {
case "+":
sign = 1;
break;
case "-":
sign = -1;
break;
default:
throw new SyntaxException("+ or - is required: found " + plusMinus + ": " + text);
}
}
return sign;
}
public static Element parse(KerboScriptExpr element) throws SyntaxException {
if (element instanceof KerboScriptUnaryExpr) {
return parseUnary((KerboScriptUnaryExpr) element);
} else if (element instanceof KerboScriptFactor) {
return parseFactor((KerboScriptFactor) element);
} else {
return new Element(1, Atom.parse(element), Number.ONE);
}
}
@Override
public String getText() {
String text = "";
if (sign == -1) {
text += "-";
}
text += atom.getText();
if (!power.equals(Number.ONE)) {
text += "^" + power.getText();
}
return text;
}
@Override
public Expression differentiate(LocalContext context) {
if (power.equals(Number.ONE)) {
Expression diff = atom.differentiate(context);
if (sign == -1) {
diff = diff.minus();
}
return diff;
}
return Function.log(atom).multiply(power).differentiate(context).multiply(this);
}
public static Element toElement(Expression expression) {
expression = Escaped.unescape(expression);
if (expression instanceof Element) {
return (Element) expression;
} else {
return new Element(1, Atom.toAtom(expression), Number.ONE);
}
}
public boolean isSimple() {
return sign == 1 && power.equals(Number.ONE);
}
@Override
public Expression simplify() {
if (power.isNegative()) {
return Number.ONE.divide(create(sign, atom, power.minus()));
}
return create(sign, atom.simplify(), power.simplify());
}
@Override
public Expression power(Expression expression) {
Expression power = this.power.multiply(expression);
return create(sign, atom, power);
}
@Override
public Expression inline(HashMap<String, Expression> args) {
return create(sign, atom.inline(args), power.inline(args));
}
@Override
public Expression simplePlus(Expression expression) {
if (expression instanceof Element) {
Element element = (Element) expression;
if (power.equals(element.power) && atom.equals(element.atom)) {
if (sign==element.sign) {
return Number.create(2).multiply(this);
} else {
return Number.ZERO;
}
}
}
if (power.equals(Number.ONE)) {
if (sign<0) {
if (Atom.toAtom(expression).equals(atom)) {
return Number.ZERO;
}
Expression simplePlus = atom.simplePlus(expression.minus());
if (simplePlus!=null) {
return simplePlus.minus();
}
} else {
return atom.simplePlus(expression);
}
}
return null;
}
@Override
public Expression simpleMultiply(Expression expression) {
if (expression instanceof Element) {
Element element = (Element) expression;
if (this.isNumber() && element.isNumber()) {
return create(sign * element.sign, atom.multiply(element.getAtom()));
} else if (atom.equals(((Element) expression).atom)) {
return create(sign * element.sign, atom, power.plus(element.power));
}
} else if (isNumber() && expression instanceof Number) {
return create(sign, atom.multiply(expression));
}
return null;
}
@Nullable
@Override
public Expression simpleDivide(Expression expression) {
if (expression instanceof Element) {
if (atom.equals(((Element) expression).atom)) {
Element element = (Element) expression;
return create(sign * element.sign, atom, power.minus(element.power));
}
} else if (atom.equals(expression)) {
return create(sign, atom, power.minus(Number.ONE));
} else if (power.equals(Number.ONE)) {
Expression div = atom.simpleDivide(expression);
if (div!=null) {
return create(sign, div, Number.ONE);
}
}
return null;
}
@Override
protected Expression simpleDivideBackward(Expression expression) {
if (atom.equals(expression)) {
return create(sign, atom, Number.ONE.minus(power));
} else if (power.equals(Number.ONE)) {
Expression div = expression.simpleDivide(atom);
if (div!=null) {
return create(sign, div, Number.ONE);
}
}
return null;
}
@Override
public boolean canMultiply(Expression expression) {
return expression instanceof Element && atom.equals(((Element) expression).atom);
}
@Override
public Expression minus() {
return create(-sign, atom, power);
}
@Override
public boolean isNegative() {
return sign < 0;
}
@Override
public boolean isNumber() {
return atom.isNumber() && power.equals(Number.ONE);
}
public boolean isAddition() {
return atom.isAddition() && power.equals(Number.ONE);
}
@Override
public Expression normalize() {
if (power.equals(Number.ONE)) {
Expression expression = atom.normalize();
if (sign <= 0) {
expression = expression.distribute(Element.create(-1, Number.ONE));
}
return expression;
}
return super.normalize();
}
@Override
public Expression distribute() {
if (power instanceof Number) {
Number number = (Number) power;
if (number.getE()==0 && number.getPoint()==0 && number.getNumber()>0) {
return distribute(sign, atom, number.getNumber());
}
}
return super.distribute();
}
private Expression distribute(int sign, Atom atom, int power) {
if (power==1) {
Expression expression = atom.distribute();
if (sign <= 0) {
expression = expression.distribute(Element.create(-1, Number.ONE));
}
return expression;
} else {
return distribute(sign, atom, power-1).distribute(atom.distribute());
}
}
@Override
public void acceptChildren(ExpressionVisitor visitor) {
atom.accept(visitor);
power.accept(visitor);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Element element = (Element) o;
if (!atom.equals(element.atom)) return false;
if (sign != element.sign) return false;
return power.equals(element.power);
}
@Override
public int hashCode() {
int result = sign;
result = 31 * result + atom.hashCode();
result = 31 * result + power.hashCode();
return result;
}
}
| 10,494 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Number.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Number.java | package ksp.kos.ideaplugin.expressions;
import com.intellij.lang.ASTNode;
import ksp.kos.ideaplugin.psi.KerboScriptNumber;
import ksp.kos.ideaplugin.psi.KerboScriptSciNumber;
import ksp.kos.ideaplugin.psi.KerboScriptTypes;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.function.BiFunction;
/**
* Created on 28/01/16.
*
* @author ptasha
*/
public class Number extends Atom {
public static final Number ZERO = new Number(0);
public static final Number ONE = new Number(1);
private final int number;
private final int point;
private final int e;
public static Expression create(int number) {
if (number < 0) {
return Element.create(-1, new Number(-number));
}
return new Number(number);
}
public static Expression create(int number, int point, int e) {
if (number < 0) {
return Element.create(-1, new Number(-number, point, e));
}
return new Number(number, point, e);
}
public Number(int number) {
this(number, 0, 0);
}
private Number(int number, int point, int e) {
if (number < 0) {
throw new IllegalArgumentException("Negative numbers are not allowed");
}
this.number = number;
this.point = point;
this.e = e;
}
public Number(KerboScriptNumber psiNumber) {
this(psiNumber, 0);
}
public Number(KerboScriptNumber psiNumber, int e) {
String text = psiNumber.getText();
int p = text.indexOf('.');
if (p >= 0) {
point = text.length() - p - 1;
text = text.replace(".", "");
} else {
point = 0;
}
this.number = Integer.parseInt(text);
this.e = e;
}
public Number(KerboScriptSciNumber psiNumber) {
this(psiNumber.getNumber(), parseE(psiNumber));
}
private static int parseE(KerboScriptSciNumber psiNumber) {
ASTNode plusMinus = psiNumber.getNode().findChildByType(KerboScriptTypes.PLUSMINUS);
int sign = 1;
if (plusMinus != null && plusMinus.getText().equals("-")) {
sign = -1;
}
ASTNode psiE = psiNumber.getNode().findChildByType(KerboScriptTypes.INTEGER);
return psiE == null ? 0 : sign * Integer.parseInt(psiE.getText());
}
public int getNumber() {
return number;
}
public int getPoint() {
return point;
}
public int getE() {
return e;
}
@Override
public String getText() {
String text = "";
int point = this.point;
int number = this.number;
while (point-- > 0) {
int c = number % 10;
if (c > 0 || !text.isEmpty()) {
text = c + text;
}
number /= 10;
}
if (!text.isEmpty()) {
text = "." + text;
}
text = number + text;
if (e != 0) {
text += "e" + e;
}
return text;
}
@Override
@Nullable
public Expression simplePlus(Expression expression) {
if (number == 0) {
return expression;
} else if (expression instanceof Number) {
return addition((Number) expression, (x, y) -> x + y);
} else if (expression instanceof Element) {
Element element = (Element) expression;
if (element.getPower().equals(Number.ONE) && element.getAtom() instanceof Number) {
return addition((Number) element.getAtom(), (x, y) -> x + element.getSign()*y);
}
}
return null;
}
private Expression addition(Number number, BiFunction<Integer, Integer, Integer> function) {
int pow = e - point - number.e + number.point;
int e = Math.min(this.e, number.e);
int point = e - pow;
if (pow == 0) {
return create(function.apply(this.number, number.number), point, e);
} else if (pow > 0) {
int n = this.number;
double p = Math.pow(10, pow);
if (n < Integer.MAX_VALUE / p) {
n = (int) (n * p);
return create(function.apply(n, number.number), point, e);
}
} else if (pow < 0) {
int n = number.number;
double p = Math.pow(10, -pow);
if (n < Integer.MAX_VALUE / p) {
n = (int) (n * p);
return create(function.apply(this.number, n), point, e);
}
}
return null;
}
@Override
public Expression multiply(Expression expression) {
if (number == 0) {
return ZERO;
} else if (this.equals(ONE)) {
return expression;
} else if (expression instanceof Number) {
Number number = (Number) expression;
return create(this.number*number.number, this.point + number.point, this.e + number.e);
}
return super.multiply(expression);
}
@Override
@Nullable
public Expression simpleDivide(Expression expression) {
if (number == 0) {
return ZERO;
} else if (expression instanceof Number) {
if (expression.equals(ONE)) {
return this;
}
Number number = (Number) expression;
if (this.number%number.number==0) {
return create(this.number/number.number, this.point - number.point, this.e - number.e);
} else {
Number root = root(this, expression);
if (!root.equals(Number.ONE)) {
return this.divide(root).divide(expression.divide(root));
}
}
}
return super.simpleDivide(expression);
}
@Override
public Expression inline(HashMap<String, Expression> args) {
return this;
}
@Override
public Expression differentiate(LocalContext context) {
return Number.ZERO;
}
@Override
public boolean isNumber() {
return true;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Number number = (Number) o;
return Double.compare(number.doubleValue(), doubleValue()) == 0;
}
@Override
public int hashCode() {
long temp = Double.doubleToLongBits(doubleValue());
return (int) (temp ^ (temp >>> 32));
}
public double doubleValue() {
return number * Math.pow(10, e - point);
}
public static Number root(Expression n1, Expression n2) {
return root(getNumber(n1), getNumber(n2));
}
private static Number getNumber(Expression expression) {
if (expression instanceof Number) {
return (Number) expression;
} else if (expression instanceof Element) {
Element element = (Element) expression;
if (element.isNumber()) {
return (Number) element.getAtom();
}
}
return Number.ONE;
}
private static final int[] SIMPLE_NUMBERS = new int[]{2, 3, 5, 7};
public static Number root(Number n1, Number n2) {
if (n1.number%n2.number==0) {
return n2;
} else if (n2.number%n1.number==0) {
return n1;
} else {
int root = 1;
int nn1 = n1.number;
int nn2 = n2.number;
for (int simple : SIMPLE_NUMBERS) {
while (nn1%simple==0 && nn2%simple==0) {
root*=simple;
nn1/=simple;
nn2/=simple;
}
}
return new Number(root);
}
}
}
| 7,833 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ConsumeSupported.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/ConsumeSupported.java | package ksp.kos.ideaplugin.expressions;
/**
* Created on 31/01/16.
*
* @author ptasha
*/
public interface ConsumeSupported<O extends Enum<O> & MultiExpression.Op, E extends Expression> {
/**
* Merge two items together, if it's possible.
* Returns null if it's not.
*
* E.g. 2 * 3 -> 6, x^2 * x -> x^3, x * y -> null
*
* @param item item which is already in the expression
* @param newItem new item to add
* @return merge of two items, null - if not possible
*/
MultiExpression.Item<O, E> consume(MultiExpression.Item<O, E> item, MultiExpression.Item<O, E> newItem);
}
| 626 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Compare.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Compare.java | package ksp.kos.ideaplugin.expressions;
import ksp.kos.ideaplugin.psi.KerboScriptCompareExpr;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Created on 18/09/16.
*
* @author ptasha
*/
public class Compare extends MultiExpression<Compare.Op,Expression> {
public Compare(KerboScriptCompareExpr expr) throws SyntaxException {
super(expr);
}
public Compare(List<Item<Op,Expression>> items) {
super(items);
}
@Override
public Expression differentiate(LocalContext context) {
return null;
}
@Override
public MultiExpressionBuilder<Op, Expression> createBuilder() {
return new MultiExpressionBuilder<Op, Expression>(Compare.class) {
@NotNull
@Override
protected Op[] operators() {
return Op.values();
}
@Override
protected MultiExpression<Op, Expression> createExpression(List<Item<Op, Expression>> items) {
return new Compare(items);
}
};
}
public enum Op implements MultiExpression.Op {
EQ("=", null),
NEQ("<>", null),
GT(">", null),
LT("<", null),
GET(">=", null),
LET("<=", null);
private final String text;
private final MultiExpression.Operation operation;
Op(String text, MultiExpression.Operation operation) {
this.text = text;
this.operation = operation;
}
@Override
public String getText() {
return text;
}
public String toString() {
return " "+text+" ";
}
@Override
public Expression apply(Expression exp1, Expression exp2) {
return operation.apply(exp1, exp2);
}
}
}
| 1,880 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Expression.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/Expression.java | package ksp.kos.ideaplugin.expressions;
import com.intellij.lang.ASTNode;
import ksp.kos.ideaplugin.psi.*;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/**
* Created on 28/01/16.
*
* @author ptasha
*/
public abstract class Expression {
public static Expression parse(KerboScriptExpr psiExpression) throws SyntaxException {
if (psiExpression instanceof KerboScriptFactor) {
return Element.parse(psiExpression);
} else if (psiExpression instanceof KerboScriptUnaryExpr) {
return Element.parse(psiExpression);
} else if (psiExpression instanceof KerboScriptArithExpr) {
return new Addition((KerboScriptArithExpr) psiExpression);
} else if (psiExpression instanceof KerboScriptMultdivExpr) {
return new Multiplication((KerboScriptMultdivExpr) psiExpression);
} else if (psiExpression instanceof KerboScriptCompareExpr) {
return new Compare((KerboScriptCompareExpr) psiExpression);
} else if (psiExpression instanceof KerboScriptNumber) {
return new Number((KerboScriptNumber) psiExpression);
} else if (psiExpression instanceof KerboScriptSciNumber) {
return new Number((KerboScriptSciNumber) psiExpression);
} else if (psiExpression instanceof KerboScriptSuffix) {
return new Constant((KerboScriptSuffix) psiExpression);
} else if (psiExpression instanceof KerboScriptSuffixterm) {
KerboScriptSuffixterm suffixterm = (KerboScriptSuffixterm) psiExpression;
int tailSize = suffixterm.getSuffixtermTrailerList().size();
if (tailSize == 0) {
return Atom.parse(suffixterm.getAtom());
} else if (tailSize == 1) {
KerboScriptAtom atom = suffixterm.getAtom();
String identifierName = atom.getName();
if (identifierName !=null) {
KerboScriptSuffixtermTrailer trailer = suffixterm.getSuffixtermTrailerList().get(0);
if (trailer instanceof KerboScriptFunctionTrailer) {
KerboScriptArglist arglist = ((KerboScriptFunctionTrailer) trailer).getArglist();
if (arglist==null) {
return new Function(identifierName);
}
return new Function(identifierName, arglist.getExprList());
}
}
}
return new Constant(suffixterm);
} else {
throw new SyntaxException("Unexpected element "+psiExpression+": "+psiExpression.getText());
}
}
public Expression simplify() {
return this;
}
public abstract String getText();
public abstract Expression differentiate(LocalContext context);
public Expression minus() {
return Element.create(-1, Atom.toAtom(this));
}
public Expression simplePlus(Expression expression) {
if (this.equals(expression)) {
return this.multiply(Number.create(2));
}
return null;
}
public Expression plus(Expression expression) {
Expression result = simplePlus(expression);
if (result!=null) {
return result;
}
return new Addition(this).plus(expression);
}
public Expression minus(Expression expression) {
if (this.equals(expression)) {
return Number.ZERO;
}
return new Addition(this).minus(expression);
}
public boolean isNegative() {
return false;
}
public Expression simpleMultiply(Expression expression) {
if (this.equals(expression)) {
return Element.create(1, this, new Number(2));
}
return null;
}
public Expression multiply(Expression expression) {
Expression result = simpleMultiply(expression);
if (result!=null) {
return result;
}
result = expression.simpleMultiply(this);
if (result!=null) {
return result;
}
return new Multiplication(this).multiply(expression);
}
public Expression multiplyLeft(Expression expression) {
return expression.multiply(this);
}
public Expression divide(Expression expression) {
Expression result = simpleDivide(expression);
if (result != null) return result;
return new Multiplication(this).divide(expression);
}
public boolean canMultiply(Expression expression) { // TODO symmetry for this and multiply and plus
return this.equals(expression);
}
public Expression power(Expression expression) {
return Element.create(1, Atom.toAtom(this), Atom.toAtom(expression));
}
@Nullable
public Expression simpleDivide(Expression expression) {
if (this.equals(expression)) {
return Number.ONE;
}
return expression.simpleDivideBackward(this);
}
protected Expression simpleDivideBackward(Expression expression) {
return null;
}
public abstract Expression inline(HashMap<String, Expression> args);
public final Set<String> getVariableNames() {
HashSet<String> variables = new HashSet<>();
accept(new ExpressionVisitor() {
@Override
public void visitVariable(Variable variable) {
variables.add(variable.getName());
super.visitVariable(variable);
}
});
return variables;
}
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
}
public void acceptChildren(ExpressionVisitor visitor) {
}
public boolean isNumber() {
return false;
}
public Expression normalize() {
return this;
}
public Expression distribute() {
return this;
}
public Expression root(Expression expression) {
return this.divide(expression.divide(this).divisor());
}
public Expression divisor() {
return Number.ONE;
}
public Expression distribute(Expression expression) {
if (expression instanceof Addition) {
return expression.distribute(this);
}
return this.multiply(expression);
}
public Expression distribute(Multiplication.Op operation, Expression expression) {
if (operation==Multiplication.Op.MUL) {
return distribute(expression);
}
return operation.apply(this, expression);
}
public String toString() {
return getClass().getSimpleName()+"="+getText();
}
}
| 6,749 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
InlineFunctions.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/inline/InlineFunctions.java | package ksp.kos.ideaplugin.expressions.inline;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiElement;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.expressions.Expression;
import ksp.kos.ideaplugin.expressions.Function;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.*;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created on 07/03/16.
*
* @author ptasha
*/
public class InlineFunctions {
private static final Logger LOG = Logger.getInstance(InlineFunctions.class);
private static InlineFunctions instance;
public static InlineFunctions getInstance() {
if (instance == null) {
instance = new InlineFunctions();
}
return instance;
}
private final HashMap<String, InlineFunction> functions = new HashMap<>();
private InlineFunctions() {
try {
InputStream stream = this.getClass().getResourceAsStream("/inline.ks");
if (stream != null) {
String inline = new String(FileUtil.loadBytes(stream));
KerboScriptFile file = KerboScriptElementFactory.file(inline);
for (PsiElement child : file.getChildren()) {
if (child instanceof KerboScriptDeclareStmt) {
KerboScriptDeclareFunctionClause functionClause = ((KerboScriptDeclareStmt) child).getDeclareFunctionClause();
if (functionClause != null) {
InlineFunction function = parseFunction(functionClause);
if (function != null) {
functions.put(function.getName(), function);
}
}
}
}
} else {
LOG.warn("inline.ks is not found");
}
} catch (Exception e) {
LOG.warn("Failed to load inline.ks file", e);
}
}
private InlineFunction parseFunction(KerboScriptDeclareFunctionClause function) {
String name = function.getName();
Expression expression = null;
ArrayList<String> names = new ArrayList<>();
List<KerboScriptInstruction> instructions = function.getInstructionBlock().getInstructionList();
for (KerboScriptInstruction instruction : instructions) {
if (instruction instanceof KerboScriptDeclareStmt) {
KerboScriptDeclareStmt declareStmt = (KerboScriptDeclareStmt) instruction;
KerboScriptDeclareParameterClause declareParameter = declareStmt.getDeclareParameterClause();
if (declareParameter == null) {
LOG.warn("Failed to parse inline function " + name + ": unsupported declare statement " + declareStmt);
return null;
}
names.add(declareParameter.getName());
} else if (instruction instanceof KerboScriptReturnStmt) {
try {
expression = Expression.parse(((KerboScriptReturnStmt) instruction).getExpr());
} catch (SyntaxException e) {
LOG.warn("Failed to parse inline function " + name, e);
}
} else {
LOG.warn("Failed to parse inline function " + name + ": unsupported instruction " + instruction);
return null;
}
}
if (expression == null) {
LOG.warn("Failed to parse inline function " + name + ": return statement is not found");
return null;
}
return new InlineFunction(name, names.toArray(new String[0]), expression);
}
public Expression inline(Function function) {
InlineFunction inlineFunction = functions.get(function.getName());
if (inlineFunction == null) {
return null;
}
return inlineFunction.inline(function.getArgs());
}
}
| 4,091 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
InlineFunction.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/expressions/inline/InlineFunction.java | package ksp.kos.ideaplugin.expressions.inline;
import ksp.kos.ideaplugin.expressions.Expression;
import java.util.HashMap;
/**
* Created on 07/03/16.
*
* @author ptasha
*/
public class InlineFunction {
private final String name;
private final String[] argNames;
private final Expression expression;
public InlineFunction(String name, String[] argNames, Expression expression) {
this.name = name;
this.argNames = argNames;
this.expression = expression;
}
public String getName() {
return name;
}
public Expression inline(Expression... args) {
HashMap<String, Expression> inlineArgs = new HashMap<>();
for (int i = 0; i < Math.min(args.length, argNames.length); i++) {
inlineArgs.put(argNames[i], args[i]);
}
return expression.inline(inlineArgs);
}
}
| 871 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptReference.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/KerboScriptReference.java | package ksp.kos.ideaplugin.reference;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import ksp.kos.ideaplugin.psi.impl.KerboScriptNamedElementImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 02/01/16.
*
* @author ptasha
*/
public class KerboScriptReference extends PsiReferenceBase<KerboScriptNamedElementImpl> {
public KerboScriptReference(@NotNull KerboScriptNamedElementImpl element) {
super(element);
if (element.getNameIdentifier()==null) {
throw new NullPointerException();
}
}
@Override
protected TextRange calculateDefaultRangeInElement() {
PsiElement nameIdentifier = myElement.getNameIdentifier();
if (nameIdentifier==null) {
return myElement.getTextRange().shiftRight(-myElement.getTextOffset());
}
return nameIdentifier.getTextRange().shiftRight(-myElement.getTextOffset());
}
@Nullable
@Override
public PsiElement resolve() {
return myElement.resolve();
}
@NotNull
@Override
public Object[] getVariants() {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
return myElement.setName(newElementName);
}
}
| 1,516 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
PsiSelfResolvable.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/PsiSelfResolvable.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.psi.KerboScriptNamedElement;
import ksp.kos.ideaplugin.psi.KerboScriptScope;
import ksp.kos.ideaplugin.reference.context.Duality;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
/**
* Created on 10/04/16.
*
* @author ptasha
*/
public interface PsiSelfResolvable extends Reference {
static PsiSelfResolvable variable(KerboScriptScope kingdom, String name) {
return reference(kingdom.getCachedScope(), ReferableType.VARIABLE, name);
}
static PsiSelfResolvable function(KerboScriptScope kingdom, String name) {
return function(kingdom.getCachedScope(), name);
}
static PsiSelfResolvable function(LocalContext kingdom, String name) {
return reference(kingdom, ReferableType.FUNCTION, name);
}
@NotNull
static PsiSelfResolvable reference(LocalContext kingdom, ReferableType type, String name) {
return new PsiReferenceImpl(kingdom, type, name);
}
static PsiSelfResolvable copy(Reference reference) {
return reference(reference.getKingdom(), reference.getReferableType(), reference.getName());
}
default KerboScriptNamedElement resolve() {
return Duality.getSyntax(getKingdom().resolve(this));
}
default KerboScriptNamedElement findDeclaration() {
return Duality.getSyntax(getKingdom().findDeclaration(this));
}
}
| 1,453 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
DualitySelfResolvable.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/DualitySelfResolvable.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.reference.context.Duality;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
/**
* Created on 23/10/16.
*
* @author ptasha
*/
public interface DualitySelfResolvable extends Reference {
static DualitySelfResolvable variable(LocalContext kingdom, String name) {
return reference(kingdom, ReferableType.VARIABLE, name);
}
static DualitySelfResolvable function(LocalContext kingdom, String name) {
return reference(kingdom, ReferableType.FUNCTION, name);
}
static DualitySelfResolvable file(LocalContext kingdom, String name) {
return reference(kingdom, ReferableType.FILE, name);
}
@NotNull
static DualitySelfResolvable reference(LocalContext kingdom, ReferableType type, String name) {
return new DualityReferenceImpl(kingdom, type, name);
}
default Duality resolve() {
return getKingdom().resolve(this);
}
default Duality findDeclaration() {
return getKingdom().findDeclaration(this);
}
}
| 1,113 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Cache.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/Cache.java | package ksp.kos.ideaplugin.reference;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import ksp.kos.ideaplugin.KerboScriptFile;
/**
* Created on 08/01/16.
*
* @author ptasha
*/
public class Cache<T> {
private final PsiElement element;
private final T scope;
public Cache(PsiElement element, T scope) {
this.element = element;
this.scope = scope;
}
public T getScope() {
PsiFile file = element.getContainingFile();
if (file instanceof KerboScriptFile) {
((KerboScriptFile) file).checkVersion();
}
return scope;
}
}
| 628 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
PsiReferenceImpl.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/PsiReferenceImpl.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.reference.context.LocalContext;
/**
* Created on 10/04/16.
*
* @author ptasha
*/
public class PsiReferenceImpl extends ReferenceImpl implements PsiSelfResolvable {
public PsiReferenceImpl(LocalContext kingdom, ReferableType referableType, String name) {
super(kingdom, referableType, name);
}
}
| 381 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ReferableType.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/ReferableType.java | package ksp.kos.ideaplugin.reference;
import java.util.EnumSet;
import java.util.Set;
/**
* Created on 03/01/16.
*
* @author ptasha
*/
public enum ReferableType {
VARIABLE,
FUNCTION,
FIELD,
METHOD,
FILE,
OTHER;
private static final Set<ReferableType> REFERABLE = EnumSet.of(VARIABLE, FILE, FUNCTION);
public boolean isReferable() {
return REFERABLE.contains(this);
}
}
| 421 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ReferenceImpl.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/ReferenceImpl.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import java.util.Objects;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public class ReferenceImpl {
protected final LocalContext kingdom;
protected final ReferableType referableType;
protected final String name;
public ReferenceImpl(LocalContext kingdom, ReferableType referableType, String name) {
this.name = name;
this.kingdom = kingdom;
this.referableType = referableType;
}
public LocalContext getKingdom() {
return kingdom;
}
public ReferableType getReferableType() {
return referableType;
}
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof Reference)) return false;
Reference reference = (Reference) o;
return referableType == reference.getReferableType() &&
Objects.equals(name, reference.getName());
}
@Override
public int hashCode() {
return Objects.hash(referableType, name);
}
}
| 1,172 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
OccurrenceType.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/OccurrenceType.java | package ksp.kos.ideaplugin.reference;
/**
* Created on 03/01/16.
*
* @author ptasha
*/
public enum OccurrenceType {
LOCAL(true),
GLOBAL(true),
REFERENCE(false),
NONE(false);
private final boolean declaration;
OccurrenceType(boolean declaration) {
this.declaration = declaration;
}
public boolean isDeclaration() {
return declaration;
}
}
| 398 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptFileReference.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/KerboScriptFileReference.java | package ksp.kos.ideaplugin.reference;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.psi.impl.KerboScriptNamedElementImpl;
import org.jetbrains.annotations.NotNull;
/**
* Created on 01/04/16.
*
* @author ptasha
*/
public class KerboScriptFileReference extends KerboScriptReference {
public KerboScriptFileReference(@NotNull KerboScriptNamedElementImpl element) {
super(element);
}
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
newElementName = KerboScriptFile.stripExtension(newElementName.substring(0, newElementName.length() - 3));
newElementName += KerboScriptFile.getExtension(myElement.getName());
return super.handleElementRename(newElementName);
}
}
| 890 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
FlowSelfResolvable.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/FlowSelfResolvable.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.dataflow.ReferenceFlow;
import ksp.kos.ideaplugin.reference.context.Duality;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import org.jetbrains.annotations.NotNull;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public interface FlowSelfResolvable extends Reference {
static FlowSelfResolvable function(LocalContext kingdom, String name) {
return reference(kingdom, ReferableType.FUNCTION, name);
}
@NotNull
static FlowSelfResolvable reference(LocalContext kingdom, ReferableType type, String name) {
return new FlowReferenceImpl(kingdom, type, name);
}
default ReferenceFlow<?> resolve() {
return getSemantics(getKingdom().resolve(this));
}
default ReferenceFlow<?> findDeclaration() {
return getSemantics(getKingdom().findDeclaration(this));
}
static ReferenceFlow<?> getSemantics(Duality duality) {
if (duality==null) {
return null;
}
return duality.getSemantics();
}
}
| 1,073 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
FlowReferenceImpl.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/FlowReferenceImpl.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.reference.context.LocalContext;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public class FlowReferenceImpl extends ReferenceImpl implements FlowSelfResolvable {
public FlowReferenceImpl(LocalContext kingdom, ReferableType referableType, String name) {
super(kingdom, referableType, name);
}
}
| 384 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
PsiFileResolver.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/PsiFileResolver.java | package ksp.kos.ideaplugin.reference;
import com.intellij.psi.PsiFileFactory;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.KerboScriptLanguage;
import ksp.kos.ideaplugin.reference.context.FileContextResolver;
import ksp.kos.ideaplugin.reference.context.FileDuality;
import ksp.kos.ideaplugin.reference.context.PsiFileDuality;
import org.jetbrains.annotations.NotNull;
/**
* Created on 08/10/16.
*
* @author ptasha
*/
public class PsiFileResolver implements FileContextResolver {
private final KerboScriptFile anyFile;
public PsiFileResolver(KerboScriptFile anyFile) {
this.anyFile = anyFile;
}
@Override
public @NotNull FileDuality ensureFile(String name) {
KerboScriptFile file = anyFile.findFile(name);
if (file == null) {
file = (KerboScriptFile) PsiFileFactory.getInstance(anyFile.getProject()).createFileFromText(
name + ".ks", KerboScriptLanguage.INSTANCE, "@lazyglobal off.");
file = (KerboScriptFile) anyFile.getContainingDirectory().add(file);
}
return file;
}
@Override
public FileDuality resolveFile(String name) {
KerboScriptFile file = anyFile.resolveFile(name);
if (file!=null) {
return new PsiFileDuality(file);
}
return null;
}
}
| 1,343 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
DualityReferenceImpl.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/DualityReferenceImpl.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.reference.context.LocalContext;
/**
* Created on 23/10/16.
*
* @author ptasha
*/
public class DualityReferenceImpl extends ReferenceImpl implements DualitySelfResolvable {
public DualityReferenceImpl(LocalContext kingdom, ReferableType referableType, String name) {
super(kingdom, referableType, name);
}
}
| 393 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
PsiFileContext.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/PsiFileContext.java | package ksp.kos.ideaplugin.reference;
import com.intellij.openapi.diagnostic.Logger;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.psi.KerboScriptElementFactory;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
import ksp.kos.ideaplugin.psi.KerboScriptNamedElement;
import ksp.kos.ideaplugin.reference.context.Duality;
import ksp.kos.ideaplugin.reference.context.FileContext;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import ksp.kos.ideaplugin.reference.context.PsiDuality;
import ksp.kos.utils.MapBuilder;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
/**
* Created on 08/01/16.
*
* @author ptasha
*/
public class PsiFileContext extends FileContext {
private static final Logger log = Logger.getInstance(PsiFileContext.class);
private final KerboScriptFile kerboScriptFile;
public PsiFileContext(KerboScriptFile kerboScriptFile) {
// TODO combine virtual context and resolver together into SuperContext for whole project
super(new LocalContext(null), kerboScriptFile.getPureName(), new PsiFileResolver(kerboScriptFile));
this.kerboScriptFile = kerboScriptFile;
}
@Override
protected Duality resolve(Reference reference, boolean createAllowed) {
Duality resolved = super.resolve(reference, createAllowed);
if (resolved == null && createAllowed) {
return createVirtual(reference);
}
return resolved;
}
@Override
public void clear() {
getParent().clear();
super.clear();
}
private static final Map<ReferableType, String> MOCKS = new MapBuilder<ReferableType, String>(new HashMap<>())
.put(ReferableType.VARIABLE, "local %s to 0.")
.put(ReferableType.FUNCTION, "function %s {}").getMap();
public PsiDuality createVirtual(Reference reference) {
String text = MOCKS.get(reference.getReferableType());
if (text == null) {
return null;
}
try {
KerboScriptInstruction instruction = KerboScriptElementFactory.instruction(kerboScriptFile.getProject(), String.format(text, reference.getName()));
PsiDuality declaration = new PsiDuality(instruction.downTill(KerboScriptNamedElement.class));
getParent().register(declaration);
return declaration;
} catch (IllegalArgumentException e) {
log.error("Failed to create virtual reference", e);
return null;
}
}
@Override
public @NotNull KerboScriptFile getSyntax() {
return kerboScriptFile;
}
}
| 2,640 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ReferenceType.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/ReferenceType.java | package ksp.kos.ideaplugin.reference;
/**
* Created on 03/01/16.
*
* @author ptasha
*/
public class ReferenceType {
private final ReferableType type;
private final OccurrenceType occurrenceType;
public ReferenceType(ReferableType type, OccurrenceType occurrenceType) {
this.type = type;
this.occurrenceType = occurrenceType;
}
public ReferableType getType() {
return type;
}
public OccurrenceType getOccurrenceType() {
return occurrenceType;
}
}
| 518 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Reference.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/Reference.java | package ksp.kos.ideaplugin.reference;
import ksp.kos.ideaplugin.dataflow.ReferenceFlow;
import ksp.kos.ideaplugin.psi.KerboScriptNamedElement;
import ksp.kos.ideaplugin.reference.context.LocalContext;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public interface Reference {
LocalContext getKingdom();
ReferableType getReferableType();
String getName();
default boolean matches(Reference declaration) {
return true;
}
}
| 462 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
FileContextResolver.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/context/FileContextResolver.java | package ksp.kos.ideaplugin.reference.context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 08/10/16.
*
* @author ptasha
*/
public interface FileContextResolver {
@NotNull FileDuality ensureFile(String name);
@Nullable FileDuality resolveFile(String name);
}
| 330 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ReferenceResolver.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/context/ReferenceResolver.java | package ksp.kos.ideaplugin.reference.context;
import ksp.kos.ideaplugin.reference.Reference;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 10/10/16.
*
* @author ptasha
*/
public interface ReferenceResolver<C extends LocalContext> {
@Nullable Duality resolve(C context, @NotNull Reference reference, boolean createAllowed);
}
| 391 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
PsiDuality.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/context/PsiDuality.java | package ksp.kos.ideaplugin.reference.context;
import ksp.kos.ideaplugin.dataflow.ReferenceFlow;
import ksp.kos.ideaplugin.psi.KerboScriptNamedElement;
import ksp.kos.ideaplugin.reference.ReferableType;
import org.jetbrains.annotations.NotNull;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public class PsiDuality implements Duality {
private final KerboScriptNamedElement psi;
public PsiDuality(@NotNull KerboScriptNamedElement psi) {
this.psi = psi;
}
@Override
public LocalContext getKingdom() {
return psi.getKingdom();
}
@Override
public ReferableType getReferableType() {
return psi.getReferableType();
}
@Override
public String getName() {
return psi.getName();
}
@Override
public KerboScriptNamedElement getSyntax() {
return psi;
}
@Override
public ReferenceFlow<?> getSemantics() {
return psi.getCachedFlow();
}
}
| 958 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
PsiFileDuality.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/context/PsiFileDuality.java | package ksp.kos.ideaplugin.reference.context;
import ksp.kos.ideaplugin.KerboScriptFile;
import org.jetbrains.annotations.NotNull;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public class PsiFileDuality extends PsiDuality implements FileDuality {
public PsiFileDuality(KerboScriptFile psi) {
super(psi);
}
@Override
public @NotNull KerboScriptFile getSyntax() {
return (KerboScriptFile) super.getSyntax();
}
@Override
public FileContext getSemantics() {
return (FileContext) super.getSemantics();
}
}
| 570 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Duality.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/context/Duality.java | package ksp.kos.ideaplugin.reference.context;
import ksp.kos.ideaplugin.dataflow.ReferenceFlow;
import ksp.kos.ideaplugin.psi.KerboScriptNamedElement;
import ksp.kos.ideaplugin.reference.Reference;
import org.jetbrains.annotations.Nullable;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public interface Duality extends Reference {
// TODO simplify duality tree
static KerboScriptNamedElement getSyntax(Duality duality) {
if (duality!=null) {
return duality.getSyntax();
}
return null;
}
@Nullable KerboScriptNamedElement getSyntax();
ReferenceFlow<?> getSemantics();
}
| 637 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
FileDuality.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/reference/context/FileDuality.java | package ksp.kos.ideaplugin.reference.context;
import ksp.kos.ideaplugin.KerboScriptFile;
import org.jetbrains.annotations.NotNull;
/**
* Created on 22/10/16.
*
* @author ptasha
*/
public interface FileDuality extends Duality {
@NotNull KerboScriptFile getSyntax();
FileContext getSemantics();
}
| 309 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Normalize.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/Normalize.java | package ksp.kos.ideaplugin.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.util.PsiTreeUtil;
import ksp.kos.ideaplugin.expressions.Expression;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.ExpressionHolder;
import ksp.kos.ideaplugin.psi.KerboScriptElementFactory;
import ksp.kos.ideaplugin.psi.KerboScriptExpr;
/**
* Created on 13/11/16.
*
* @author ptasha
*/
public class Normalize extends BaseAction {
@Override
public void actionPerformed(AnActionEvent event) {
KerboScriptExpr expr = getSimplifiable(event);
if (expr != null) {
WriteCommandAction.runWriteCommandAction(getEventProject(event), () -> {
try {
expr.replace(normalize(expr));
} catch (ActionFailedException e) {
e.printStackTrace();
Messages.showDialog(e.getMessage(), "Failed:", new String[]{"OK"}, -1, null);
}
});
}
}
private KerboScriptExpr normalize(KerboScriptExpr expr) throws ActionFailedException {
try {
Expression parse = Expression.parse(expr);
String simple = parse.normalize().simplify().getText();
return KerboScriptElementFactory.expression(expr.getProject(), simple);
} catch (SyntaxException e) {
throw new ActionFailedException(e);
}
}
@Override
public void update(AnActionEvent event) {
event.getPresentation().setEnabled(getSimplifiable(event) != null);
}
private KerboScriptExpr getSimplifiable(AnActionEvent event) {
ExpressionHolder holder = PsiTreeUtil.getParentOfType(getPsiElement(event), ExpressionHolder.class, false);
if (holder == null) {
return null;
}
return holder.getExpr();
}
}
| 1,985 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
BaseAction.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/BaseAction.java | package ksp.kos.ideaplugin.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.Nullable;
/**
* Created on 24/01/16.
*
* @author ptasha
*/
public abstract class BaseAction extends AnAction {
@Nullable
protected PsiElement getPsiElement(AnActionEvent event) {
Editor editor = event.getData(CommonDataKeys.EDITOR);
PsiFile file = event.getData(CommonDataKeys.PSI_FILE);
if (editor != null && file != null) {
int offset = editor.getCaretModel().getOffset();
return file.findElementAt(offset);
}
return null;
}
}
| 856 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ActionFailedException.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/ActionFailedException.java | package ksp.kos.ideaplugin.actions;
/**
* Created on 24/01/16.
*
* @author ptasha
*/
public class ActionFailedException extends Exception {
public ActionFailedException(String message) {
super(message);
}
public ActionFailedException(Throwable cause) {
super(cause);
}
}
| 309 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Simplify.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/Simplify.java | package ksp.kos.ideaplugin.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.util.PsiTreeUtil;
import ksp.kos.ideaplugin.expressions.Expression;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.*;
/**
* Created on 24/01/16.
*
* @author ptasha
*/
public class Simplify extends BaseAction {
@Override
public void actionPerformed(AnActionEvent event) {
KerboScriptExpr expr = getSimplifiable(event);
if (expr != null) {
WriteCommandAction.runWriteCommandAction(getEventProject(event), () -> {
try {
expr.replace(simplify(expr));
} catch (ActionFailedException e) {
e.printStackTrace();
Messages.showDialog(e.getMessage(), "Failed:", new String[]{"OK"}, -1, null);
}
});
}
}
private KerboScriptExpr simplify(KerboScriptExpr expr) throws ActionFailedException {
try {
Expression parse = Expression.parse(expr);
String simple = parse.simplify().getText();
return KerboScriptElementFactory.expression(expr.getProject(), simple);
} catch (SyntaxException e) {
throw new ActionFailedException(e);
}
}
@Override
public void update(AnActionEvent event) {
event.getPresentation().setEnabled(getSimplifiable(event) != null);
}
private KerboScriptExpr getSimplifiable(AnActionEvent event) {
ExpressionHolder holder = PsiTreeUtil.getParentOfType(getPsiElement(event), ExpressionHolder.class, false);
if (holder == null) {
return null;
}
return holder.getExpr();
}
}
| 1,851 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
DiffContext.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/DiffContext.java | package ksp.kos.ideaplugin.actions.differentiate;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.dataflow.FunctionFlow;
import ksp.kos.ideaplugin.dataflow.FunctionFlowImporter;
import ksp.kos.ideaplugin.dataflow.ImportFlow;
import ksp.kos.ideaplugin.dataflow.ImportFlowImporter;
import ksp.kos.ideaplugin.reference.FlowSelfResolvable;
import ksp.kos.ideaplugin.reference.OccurrenceType;
import ksp.kos.ideaplugin.reference.ReferableType;
import ksp.kos.ideaplugin.reference.Reference;
import ksp.kos.ideaplugin.reference.context.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* Created on 23/10/16.
*
* @author ptasha
*/
public class DiffContext extends FileContext {
private final FileDuality file;
private final FileContextResolver fileResolver;// TODO get rid of me
public DiffContext(FileContext origFile, FileDuality diffFile, FileContextResolver fileResolver) {
super(null, origFile.getName() + "_", createDiffResolvers(fileResolver));
this.file = diffFile;
this.fileResolver = fileResolver;
for (String name : origFile.getImports().keySet()) {
registerFile(name);
registerFile(name+"_");
}
registerFile(origFile.getName());
}
public static List<ReferenceResolver<LocalContext>> createDiffResolvers(FileContextResolver fileResolver) {
List<ReferenceResolver<LocalContext>> resolvers = FileContext.createResolvers(fileResolver);
resolvers.add((context, reference, createAllowed) -> {
if (createAllowed && reference.getName().endsWith("_")) {
String name1 = reference.getName();
name1 = name1.substring(0, name1.length()-1);
FunctionFlow original = (FunctionFlow) FlowSelfResolvable.function(context, name1).findDeclaration();
if (original!=null) {
String fileName = original.getKingdom().getFileContext().getName();
FileDuality diffFile = fileResolver.resolveFile(fileName + "_");
return original.differentiate(diffFile.getSemantics());
}
}
return null;
});
return resolvers;
}
@Nullable
@Override
public Duality findLocalDeclaration(@NotNull Reference reference, @Nullable OccurrenceType occurrenceTypeFilter) {
Duality declaration = super.findLocalDeclaration(reference, occurrenceTypeFilter);
if (declaration==null && file!=null) {
return file.getSemantics().findLocalDeclaration(reference, occurrenceTypeFilter);
}
return declaration;
}
public void importFlows() {
for (Duality duality : getDeclarations(ReferableType.FUNCTION).values()) {
importFlow((FunctionFlow) duality.getSemantics());
}
ensureImports();
}
private KerboScriptFile ensureFile() {
FileDuality diffFile = fileResolver.ensureFile(getName());
return diffFile.getSyntax();
}
private void importFlow(FunctionFlow flow) {
if (flow.hasDependees()) {
FunctionFlowImporter.INSTANCE.importFlow(ensureFile(), flow);
}
}
private void ensureImports() {
ImportFlowImporter importImporter = ImportFlowImporter.INSTANCE;
for (Duality importDuality : getDeclarations(ReferableType.FILE).values()) {
ImportFlow importFlow = (ImportFlow) importDuality.getSemantics();
if (importFlow.hasDependees()) {
importImporter.importFlow(ensureFile(), importFlow);
}
}
}
private void registerFile(String name) {
register(new ImportFlow(name));
}
@Override
public @NotNull KerboScriptFile getSyntax() {
return ensureFile();
}
public void checkUsage() {
for (Duality duality : getDeclarations(ReferableType.FUNCTION).values()) {
((FunctionFlow) duality.getSemantics()).checkUsages();
}
}
}
| 4,068 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
DeclareDiffer.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/DeclareDiffer.java | package ksp.kos.ideaplugin.actions.differentiate;
import ksp.kos.ideaplugin.dataflow.VariableFlow;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.KerboScriptDeclareStmt;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
import org.jetbrains.annotations.NotNull;
/**
* Created on 27/03/16.
*
* @author ptasha
*/
public class DeclareDiffer extends DuplicateDiffer<KerboScriptDeclareStmt> {
public DeclareDiffer() {
super(KerboScriptDeclareStmt.class);
}
@Override
public boolean canDo(KerboScriptInstruction instruction) {
return super.canDo(instruction) && ((KerboScriptDeclareStmt) instruction).getDeclareIdentifierClause() !=null;
}
@Override
@NotNull
protected VariableFlow parse(KerboScriptDeclareStmt variable) throws SyntaxException {
return VariableFlow.parse(variable.getDeclareIdentifierClause());
}
}
| 921 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
SetDiffer.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/SetDiffer.java | package ksp.kos.ideaplugin.actions.differentiate;
import ksp.kos.ideaplugin.dataflow.VariableFlow;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
import ksp.kos.ideaplugin.psi.KerboScriptSetStmt;
/**
* Created on 27/03/16.
*
* @author ptasha
*/
public class SetDiffer extends DuplicateDiffer<KerboScriptSetStmt> {
public SetDiffer() {
super(KerboScriptSetStmt.class);
}
@Override
public boolean canDo(KerboScriptInstruction instruction) {
try {
return super.canDo(instruction) && (parse((KerboScriptSetStmt) instruction)!=null);
} catch (SyntaxException e) {
return true;
}
}
@Override
protected VariableFlow parse(KerboScriptSetStmt variable) throws SyntaxException {
return VariableFlow.parse(variable);
}
}
| 876 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
DiffContextResolver.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/DiffContextResolver.java | package ksp.kos.ideaplugin.actions.differentiate;
import ksp.kos.ideaplugin.reference.PsiFileResolver;
import ksp.kos.ideaplugin.reference.context.FileContextResolver;
import ksp.kos.ideaplugin.reference.context.FileDuality;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
/**
* Created on 27/10/16.
*
* @author ptasha
*/
public class DiffContextResolver implements FileContextResolver {
private final PsiFileResolver fileResolver;
private final HashMap<String, DiffContext> contexts = new HashMap<>();
public DiffContextResolver(PsiFileResolver fileResolver) {
this.fileResolver = fileResolver;
}
public void importFlows() {
for (DiffContext diffContext : contexts.values()) {
diffContext.checkUsage();
}
for (DiffContext diffContext : contexts.values()) {
diffContext.importFlows();
}
}
@Override
public @NotNull FileDuality ensureFile(String name) {
return fileResolver.ensureFile(name);
}
@Override
public FileDuality resolveFile(String name) {
DiffContext context = contexts.get(name);
if (context!=null) {
return context;
} else if (name.endsWith("__")) {
return resolveFile(name.substring(0, name.length() - 1));
} else if (name.endsWith("_")) {
context = new DiffContext(fileResolver.resolveFile(name.substring(0, name.length() - 1)).getSemantics(),
fileResolver.resolveFile(name),
this);
contexts.put(name, context);
return context;
} else {
return fileResolver.resolveFile(name);
}
}
}
| 1,707 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
FunctionDiffer.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/FunctionDiffer.java | package ksp.kos.ideaplugin.actions.differentiate;
import com.intellij.openapi.project.Project;
import ksp.kos.ideaplugin.actions.ActionFailedException;
import ksp.kos.ideaplugin.dataflow.FunctionFlow;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.KerboScriptDeclareFunctionClause;
import ksp.kos.ideaplugin.psi.KerboScriptDeclareStmt;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
import ksp.kos.ideaplugin.reference.PsiFileResolver;
import ksp.kos.ideaplugin.reference.PsiSelfResolvable;
import ksp.kos.ideaplugin.reference.context.FileContext;
/**
* Created on 27/03/16.
*
* @author ptasha
*/
public class FunctionDiffer implements Differ {
@Override
public boolean canDo(KerboScriptInstruction instruction) {
return instruction instanceof KerboScriptDeclareStmt && ((KerboScriptDeclareStmt) instruction).getDeclareFunctionClause() != null;
}
@SuppressWarnings("unchecked")
@Override
public void doIt(Project project, KerboScriptInstruction instruction) throws ActionFailedException {
KerboScriptDeclareStmt declare = (KerboScriptDeclareStmt) instruction;
try {
DiffContextResolver contextResolver = new DiffContextResolver(new PsiFileResolver(instruction.getKerboScriptFile()));
PsiSelfResolvable ref = declare.getDeclareFunctionClause();
FileContext diffContext = contextResolver.resolveFile(ref.getKingdom().getFileContext().getName()+"_").getSemantics();
FunctionFlow diff = FunctionFlow.parse((KerboScriptDeclareFunctionClause) ref.findDeclaration()).differentiate(diffContext);
diff.addDependee(diff);
contextResolver.importFlows();
} catch (SyntaxException e) {
throw new ActionFailedException(e);
}
}
}
| 1,822 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Differ.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/Differ.java | package ksp.kos.ideaplugin.actions.differentiate;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import ksp.kos.ideaplugin.actions.ActionFailedException;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
/**
* Created on 27/03/16.
*
* @author ptasha
*/
public interface Differ {
boolean canDo(KerboScriptInstruction instruction);
void doIt(Project project, KerboScriptInstruction instruction) throws ActionFailedException;
}
| 477 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
Differentiate.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/Differentiate.java | package ksp.kos.ideaplugin.actions.differentiate;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.util.PsiTreeUtil;
import ksp.kos.ideaplugin.actions.ActionFailedException;
import ksp.kos.ideaplugin.actions.BaseAction;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
import org.jetbrains.annotations.Nullable;
import java.util.function.BiFunction;
/**
* Created on 19/01/16.
*
* @author ptasha
*/
public class Differentiate extends BaseAction {
private final static Differ[] differs = new Differ[]{
new DeclareDiffer(),
new SetDiffer(),
new ReturnDiffer(),
new FunctionDiffer()
};
@Override
public void actionPerformed(AnActionEvent event) {
processPair(event, (instruction, differ) -> {
Project project = getEventProject(event);
WriteCommandAction.runWriteCommandAction(project, () -> {
try {
differ.doIt(project, instruction);
} catch (ActionFailedException e) {
Messages.showDialog(e.getMessage(), "Failed:", new String[]{"OK"}, -1, null);
}
});
return null;
});
}
public <R> R processPair(AnActionEvent event, BiFunction<KerboScriptInstruction, Differ, R> pair) {
KerboScriptInstruction instruction = getInstruction(event);
if (instruction != null) {
Differ differ = findDiffer(instruction);
if (differ != null) {
return pair.apply(instruction, differ);
}
}
return null;
}
@Nullable
public KerboScriptInstruction getInstruction(AnActionEvent event) {
return PsiTreeUtil.getParentOfType(getPsiElement(event), KerboScriptInstruction.class, false);
}
private Differ findDiffer(KerboScriptInstruction instruction) {
for (Differ differ : differs) {
if (differ.canDo(instruction)) {
return differ;
}
}
return null;
}
@Override
public void update(AnActionEvent event) {
event.getPresentation().setEnabled(processPair(event, (instruction, differ) -> true) != null);
}
}
| 2,382 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
DuplicateDiffer.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/DuplicateDiffer.java | package ksp.kos.ideaplugin.actions.differentiate;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.CodeStyleManager;
import ksp.kos.ideaplugin.actions.ActionFailedException;
import ksp.kos.ideaplugin.dataflow.Flow;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.KerboScriptBase;
import ksp.kos.ideaplugin.psi.KerboScriptElementFactory;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
/**
* Created on 27/03/16.
*
* @author ptasha
*/
public abstract class DuplicateDiffer<P extends KerboScriptBase> implements Differ {
private final Class<P> clazz;
public DuplicateDiffer(Class<P> clazz) {
this.clazz = clazz;
}
@Override
public boolean canDo(KerboScriptInstruction instruction) {
return clazz.isInstance(instruction);
}
@SuppressWarnings("unchecked")
@Override
public void doIt(Project project, KerboScriptInstruction instruction) throws ActionFailedException {
P variable = (P) instruction;
KerboScriptInstruction copy = (KerboScriptInstruction) instruction.copy();
separator(copy);
instruction.getParent().addBefore(copy, instruction);
PsiElement diff = variable.replace(KerboScriptElementFactory.instruction(project, diff(variable)));
CodeStyleManager.getInstance(project).reformatNewlyAddedElement(diff.getParent().getNode(), diff.getNode());
}
protected void separator(KerboScriptBase copy) {
copy.newLine();
}
protected String diff(P variable) throws ActionFailedException {
try {
return parse(variable).differentiate(variable.getScope().getCachedScope()).getText();
} catch (SyntaxException e) {
throw new ActionFailedException(e);
}
}
protected abstract Flow<?> parse(P variable) throws SyntaxException;
}
| 1,916 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ReturnDiffer.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/ReturnDiffer.java | package ksp.kos.ideaplugin.actions.differentiate;
import com.intellij.openapi.project.Project;
import ksp.kos.ideaplugin.actions.ActionFailedException;
import ksp.kos.ideaplugin.expressions.Expression;
import ksp.kos.ideaplugin.expressions.SyntaxException;
import ksp.kos.ideaplugin.psi.KerboScriptElementFactory;
import ksp.kos.ideaplugin.psi.KerboScriptExpr;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
import ksp.kos.ideaplugin.psi.KerboScriptReturnStmt;
/**
* Created on 27/03/16.
*
* @author ptasha
*/
public class ReturnDiffer implements Differ {
@Override
public boolean canDo(KerboScriptInstruction instruction) {
return instruction instanceof KerboScriptReturnStmt;
}
@Override
public void doIt(Project project, KerboScriptInstruction instruction) throws ActionFailedException {
if (instruction instanceof KerboScriptReturnStmt) {
KerboScriptReturnStmt returnStmt = (KerboScriptReturnStmt) instruction;
KerboScriptExpr expr = returnStmt.getExpr();
expr.replace(KerboScriptElementFactory.expression(project, diff(expr)));
}
}
protected String diff(KerboScriptExpr expr) throws ActionFailedException {
try {
return Expression.parse(expr).differentiate(expr.getScope().getCachedScope()).getText();
} catch (SyntaxException e) {
throw new ActionFailedException(e);
}
}
}
| 1,434 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ExpressionHolder.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/psi/ExpressionHolder.java | package ksp.kos.ideaplugin.psi;
import com.intellij.psi.PsiElement;
/**
* Created on 06/02/16.
*
* @author ptasha
*/
public interface ExpressionHolder extends PsiElement {
KerboScriptExpr getExpr();
}
| 211 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptTokenType.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/psi/KerboScriptTokenType.java | package ksp.kos.ideaplugin.psi;
import com.intellij.psi.tree.IElementType;
import ksp.kos.ideaplugin.KerboScriptLanguage;
/**
* Created on 26/12/15.
*
* @author ptasha
*/
public class KerboScriptTokenType extends IElementType {
public KerboScriptTokenType(String debugName) {
super(debugName, KerboScriptLanguage.INSTANCE);
}
}
| 350 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptBase.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/psi/KerboScriptBase.java | package ksp.kos.ideaplugin.psi;
import com.intellij.lang.ASTFactory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiTreeUtil;
import ksp.kos.ideaplugin.KerboScriptFile;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.function.Supplier;
/**
* Created on 03/01/16.
*
* @author ptasha
*/
public interface KerboScriptBase extends PsiElement {
default KerboScriptFile getKerboScriptFile() {
return (KerboScriptFile) getContainingFile();
}
default KerboScriptScope getScope() {
PsiElement parent = getParent();
while (!(parent instanceof KerboScriptScope)) {
parent = parent.getParent();
}
return (KerboScriptScope) parent;
}
default <P extends PsiElement> P upTill(Class<P> clazz) {
return PsiTreeUtil.getParentOfType(this, clazz, false);
}
default <P extends PsiElement> P downTill(Class<P> clazz) {
return PsiTreeUtil.findChildOfType(this, clazz, false);
}
@NotNull
default <P extends PsiElement> Collection<P> getChildren(Class<P> clazz) {
return PsiTreeUtil.findChildrenOfType(this, clazz);
}
@NotNull
default <T> CachedValue<T> createCachedValue(Supplier<T> supplier) {
return createCachedValue(supplier, this);
}
@NotNull
default <T> CachedValue<T> createCachedValue(Supplier<T> supplier, Object... dependencies) {
return CachedValuesManager.getManager(getProject()).createCachedValue(
() -> new CachedValueProvider.Result<>(
supplier.get(),
dependencies), false);
}
default void newLine() {
getNode().addChild(ASTFactory.whitespace("\n"));
}
default boolean isReal() {
PsiFile file = getContainingFile();
return file.isPhysical() && file instanceof KerboScriptFile;
}
}
| 2,087 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptElementFactory.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/psi/KerboScriptElementFactory.java | package ksp.kos.ideaplugin.psi;
import com.intellij.lang.ASTFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.impl.source.tree.LeafElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.KerboScriptLanguage;
import org.jetbrains.annotations.NotNull;
/**
* Created on 22/01/16.
*
* @author ptasha
*/
public class KerboScriptElementFactory {
public static final String FILE_NAME = "generated.ks";
public static KerboScriptFile file(String text) {
return file(ProjectManager.getInstance().getDefaultProject(), text);
}
public static KerboScriptFile file(Project project, String text) {
return (KerboScriptFile) PsiFileFactory.getInstance(project).createFileFromText(
FILE_NAME, KerboScriptLanguage.INSTANCE,
text, false, false);
}
public static KerboScriptExpr expression(Project project, String expr) {
KerboScriptInstruction instruction = instruction(project, "return " + expr+".");
return ((KerboScriptReturnStmt)instruction).getExpr();
}
public static KerboScriptInstruction instruction(Project project, String text) {
KerboScriptFile file = file(project, text);
PsiElement child = file.getFirstChild();
if (child instanceof KerboScriptInstruction) {
return ((KerboScriptInstruction) child);
} else {
throw new IllegalArgumentException(text+" is not instruction");
}
}
@NotNull
public static LeafElement leaf(IElementType type, String text) {
LeafElement leaf = ASTFactory.leaf(type, text);
CodeEditUtil.setNodeGenerated(leaf, true);
return leaf;
}
}
| 1,995 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptScope.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/psi/KerboScriptScope.java | package ksp.kos.ideaplugin.psi;
import ksp.kos.ideaplugin.reference.context.LocalContext;
import ksp.kos.ideaplugin.reference.Reference;
/**
* Created on 07/01/16.
*
* @author ptasha
*/
public interface KerboScriptScope extends KerboScriptBase { // TODO remove me
LocalContext getCachedScope();
default KerboScriptNamedElement resolve(Reference reference) {
return getCachedScope().resolve(reference).getSyntax();
}
}
| 445 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
ExpressionListHolder.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/psi/ExpressionListHolder.java | package ksp.kos.ideaplugin.psi;
import java.util.List;
// TODO it's a kludge to deal with expression lists
public interface ExpressionListHolder extends ExpressionHolder {
@Override
default KerboScriptExpr getExpr() {
return getExprList().get(0);
}
List<KerboScriptExpr> getExprList();
}
| 315 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptElementType.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/psi/KerboScriptElementType.java | package ksp.kos.ideaplugin.psi;
import com.intellij.psi.tree.IElementType;
import ksp.kos.ideaplugin.KerboScriptLanguage;
/**
* Created on 26/12/15.
*
* @author ptasha
*/
public class KerboScriptElementType extends IElementType {
public KerboScriptElementType(String debugName) {
super(debugName, KerboScriptLanguage.INSTANCE);
}
}
| 354 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
NotSupportedInlineHandler.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/refactoring/NotSupportedInlineHandler.java | package ksp.kos.ideaplugin.refactoring;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 06/03/16.
*
* @author ptasha
*/
public class NotSupportedInlineHandler extends DoNothingInlineHandler {
@Nullable
@Override
public Settings prepareInlineElement(@NotNull PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
CommonRefactoringUtil.showErrorHint(element.getProject(), editor, "Cannot inline "+element, InlineSettings.REFACTORING_NAME, null);
return Settings.CANNOT_INLINE_SETTINGS;
}
}
| 741 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
VariableInlineHandler.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/refactoring/VariableInlineHandler.java | package ksp.kos.ideaplugin.refactoring;
import com.intellij.codeInsight.TargetElementUtil;
import com.intellij.lang.refactoring.InlineHandler;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.containers.MultiMap;
import ksp.kos.ideaplugin.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 24/01/16.
*
* @author ptasha
*/
public class VariableInlineHandler implements InlineHandler {
@Nullable
@Override
public Settings prepareInlineElement(@NotNull PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
final PsiReference invocationReference = editor != null ? TargetElementUtil.findReference(editor) : null;
if (element instanceof KerboScriptDeclareIdentifierClause) {
return new InlineSettings(invocationReference!=null && invocationReference.getElement()!=element);
}
return null;
}
@Override
public void removeDefinition(@NotNull PsiElement element, @NotNull Settings settings) {
PsiElement parent = element.getParent();
if (parent instanceof KerboScriptDeclareStmt) {
parent.delete();
}
}
@Nullable
@Override
public Inliner createInliner(@NotNull PsiElement element, @NotNull Settings settings) {
if (element instanceof KerboScriptDeclareIdentifierClause) {
return new Inliner() {
@Nullable
@Override
public MultiMap<PsiElement, String> getConflicts(@NotNull PsiReference reference, @NotNull PsiElement referenced) {
return null;
}
@Override
public void inlineUsage(@NotNull UsageInfo usage, @NotNull PsiElement referenced) {
if (referenced instanceof KerboScriptDeclareIdentifierClause) {
KerboScriptExpr expr = ((KerboScriptDeclareIdentifierClause) referenced).getExpr();
PsiElement element = usage.getElement();
if (element != null) {
PsiElement parent = element.getParent();
if (parent instanceof KerboScriptAtom) {
parent.getParent().replace(KerboScriptElementFactory.expression(expr.getProject(), "(" + expr.getText() + ")"));
}
}
}
}
};
}
return null;
}
}
| 2,647 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
DoNothingInlineHandler.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/refactoring/DoNothingInlineHandler.java | package ksp.kos.ideaplugin.refactoring;
import com.intellij.lang.refactoring.InlineHandler;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 06/03/16.
*
* @author ptasha
*/
public abstract class DoNothingInlineHandler implements InlineHandler{
@Nullable
@Override
public Settings prepareInlineElement(@NotNull PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
return null;
}
@Override
public void removeDefinition(@NotNull PsiElement element, @NotNull InlineHandler.Settings settings) {
}
@Override
@Nullable
public InlineHandler.Inliner createInliner(@NotNull PsiElement element, @NotNull InlineHandler.Settings settings) {
return null;
}
}
| 868 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
FunctionInlineHandler.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/refactoring/FunctionInlineHandler.java | package ksp.kos.ideaplugin.refactoring;
import com.intellij.codeInsight.TargetElementUtil;
import com.intellij.lang.refactoring.InlineHandler;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.containers.MultiMap;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Created on 06/03/16.
*
* @author ptasha
*/
public class FunctionInlineHandler implements InlineHandler {
@Nullable
@Override
public Settings prepareInlineElement(@NotNull PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
final PsiReference invocationReference = editor != null ? TargetElementUtil.findReference(editor) : null;
if (element instanceof KerboScriptDeclareFunctionClause) {
FunctionSettings settings = new FunctionSettings(invocationReference!=null && invocationReference.getElement()!=element);
List<KerboScriptInstruction> instructions = ((KerboScriptDeclareFunctionClause) element).getInstructionBlock().getInstructionList();
for (KerboScriptInstruction instruction : instructions) {
if (instruction instanceof KerboScriptDeclareStmt) {
KerboScriptDeclareStmt declareStmt = (KerboScriptDeclareStmt) instruction;
KerboScriptDeclareParameterClause declareParameter = declareStmt.getDeclareParameterClause();
if (declareParameter == null) {
return toHardToInline(element, editor);
}
Collection<PsiReference> references = ReferencesSearch.search(declareParameter).findAll();
ArrayList<Integer> usageIndexes = new ArrayList<>();
for (PsiReference reference : references) {
usageIndexes.add(reference.getElement().getTextOffset());
}
settings.paramUsages.add(usageIndexes);
} else if (instruction instanceof KerboScriptReturnStmt) {
settings.returnStmt = (KerboScriptReturnStmt) instruction;
} else {
return toHardToInline(element, editor);
}
}
if (settings.returnStmt == null) {
CommonRefactoringUtil.showErrorHint(element.getProject(), editor, "Cannot inline: return statement is not found", InlineSettings.REFACTORING_NAME, null);
return Settings.CANNOT_INLINE_SETTINGS;
}
int offset = settings.returnStmt.getTextOffset();
for (ArrayList<Integer> paramIndexes : settings.paramUsages) {
for (int i = 0; i < paramIndexes.size(); i++) {
paramIndexes.set(i, paramIndexes.get(i) - offset);
}
}
return settings;
}
return null;
}
private Settings toHardToInline(PsiElement element, Editor editor) {
CommonRefactoringUtil.showErrorHint(element.getProject(), editor, "Cannot inline: only simple functions are supported", InlineSettings.REFACTORING_NAME, null);
return Settings.CANNOT_INLINE_SETTINGS;
}
@Override
public void removeDefinition(@NotNull PsiElement element, @NotNull Settings settings) {
element.delete();
}
@Nullable
@Override
public Inliner createInliner(@NotNull PsiElement element, @NotNull Settings settings) {
if (settings instanceof FunctionSettings) {
FunctionSettings functionSettings = (FunctionSettings) settings;
return new Inliner() {
@Nullable
@Override
public MultiMap<PsiElement, String> getConflicts(@NotNull PsiReference reference, @NotNull PsiElement referenced) {
return null;
}
@Override
public void inlineUsage(@NotNull UsageInfo usage, @NotNull PsiElement referenced) {
KerboScriptFile file = KerboScriptElementFactory.file(referenced.getProject(), functionSettings.returnStmt.getText());
ArrayList<ArrayList<PsiElement>> paramsUsages = new ArrayList<>();
for (ArrayList<Integer> paramIndexes : functionSettings.paramUsages) {
ArrayList<PsiElement> paramUsages = new ArrayList<>();
for (Integer index : paramIndexes) {
if (index > 0) {
PsiElement paramUsage = PsiTreeUtil.getParentOfType(file.findElementAt(index), KerboScriptExpr.class, false);
if (paramUsage != null) {
paramUsages.add(paramUsage);
}
}
}
paramsUsages.add(paramUsages);
}
KerboScriptSuffixterm functionCall = PsiTreeUtil.getParentOfType(usage.getElement(), KerboScriptSuffixterm.class, false);
if (functionCall != null) {
List<KerboScriptSuffixtermTrailer> trailers = functionCall.getSuffixtermTrailerList();
if (trailers.size() > 0) {
KerboScriptSuffixtermTrailer trailer = trailers.get(0);
if (trailer instanceof KerboScriptFunctionTrailer) {
KerboScriptArglist arglist = ((KerboScriptFunctionTrailer) trailer).getArglist();
if (arglist != null) {
List<KerboScriptExpr> arguments = arglist.getExprList();
for (int i = 0; i < Math.min(arguments.size(), paramsUsages.size()); i++) {
KerboScriptExpr argument = arguments.get(i);
ArrayList<PsiElement> paramUsages = paramsUsages.get(i);
for (PsiElement paramUsage : paramUsages) {
paramUsage.replace(KerboScriptElementFactory.expression(functionCall.getProject(), "(" + argument.getText() + ")"));
}
}
}
}
}
KerboScriptReturnStmt returnStmt = (KerboScriptReturnStmt) file.getFirstChild();
KerboScriptExpr expression = returnStmt.getExpr();
if (expression != null) {
functionCall.replace(KerboScriptElementFactory.expression(functionCall.getProject(), "(" + expression.getText() + ")"));
}
}
}
};
}
return null;
}
private static class FunctionSettings extends InlineSettings {
private final ArrayList<ArrayList<Integer>> paramUsages = new ArrayList<>();
private KerboScriptReturnStmt returnStmt;
public FunctionSettings(boolean onlyReference) {
super(onlyReference);
}
}
}
| 7,620 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
VirtualCheckInlineHandler.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/refactoring/VirtualCheckInlineHandler.java | package ksp.kos.ideaplugin.refactoring;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 06/03/16.
*
* @author ptasha
*/
public class VirtualCheckInlineHandler extends DoNothingInlineHandler {
@Nullable
@Override
public Settings prepareInlineElement(@NotNull PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
if (element.getContainingFile().getVirtualFile()==null) {
CommonRefactoringUtil.showErrorHint(element.getProject(), editor, "Cannot inline: definition is not found", InlineSettings.REFACTORING_NAME, null);
return Settings.CANNOT_INLINE_SETTINGS;
}
return null;
}
}
| 861 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
InlineSettings.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/refactoring/InlineSettings.java | package ksp.kos.ideaplugin.refactoring;
import com.intellij.lang.refactoring.InlineHandler;
import com.intellij.refactoring.RefactoringBundle;
/**
* Created on 06/03/16.
*
* @author ptasha
*/
public class InlineSettings implements InlineHandler.Settings {
public static final String REFACTORING_NAME = RefactoringBundle.message("inline.title");
private boolean onlyReference;
public InlineSettings(boolean onlyReference) {
this.onlyReference = onlyReference;
}
@Override
public boolean isOnlyOneReferenceToInline() {
return onlyReference;
}
}
| 596 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptFormattingModelBuilder.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/format/KerboScriptFormattingModelBuilder.java | package ksp.kos.ideaplugin.format;
import com.intellij.formatting.FormattingContext;
import com.intellij.formatting.FormattingModel;
import com.intellij.formatting.FormattingModelBuilder;
import com.intellij.formatting.FormattingModelProvider;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created on 17/01/16.
*
* @author ptasha
*/
public class KerboScriptFormattingModelBuilder implements FormattingModelBuilder {
@Override
public @NotNull FormattingModel createModel(@NotNull FormattingContext formattingContext) {
return FormattingModelProvider.createFormattingModelForPsiFile(formattingContext.getContainingFile(),
new KerboScriptBlock(formattingContext.getNode(), null, null), formattingContext.getCodeStyleSettings());
}
@Nullable
@Override
public TextRange getRangeAffectingIndent(PsiFile file, int offset, ASTNode elementAtOffset) {
return null;
}}
| 1,081 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
KerboScriptBlock.java | /FileExtraction/Java_unseen/KSP-KOS_EditorTools/IDEA/src/main/java/ksp/kos/ideaplugin/format/KerboScriptBlock.java | package ksp.kos.ideaplugin.format;
import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.TokenType;
import com.intellij.psi.formatter.common.AbstractBlock;
import com.intellij.psi.impl.source.tree.LeafElement;
import com.intellij.psi.tree.IElementType;
import ksp.kos.ideaplugin.KerboScriptFile;
import ksp.kos.ideaplugin.psi.KerboScriptIfStmt;
import ksp.kos.ideaplugin.psi.KerboScriptInstruction;
import ksp.kos.ideaplugin.psi.KerboScriptInstructionBlock;
import ksp.kos.ideaplugin.psi.KerboScriptTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import static ksp.kos.ideaplugin.psi.KerboScriptTypes.CURLYCLOSE;
/**
* Created on 17/01/16.
*
* @author ptasha
*/
public class KerboScriptBlock extends AbstractBlock {
private static final Set<IElementType> IF_ELSE = new HashSet<>(Arrays.asList(KerboScriptTypes.IF, KerboScriptTypes.ELSE));
protected KerboScriptBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment) {
super(node, wrap, alignment);
}
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<>();
ASTNode child = myNode.getFirstChildNode();
while (child != null) {
addChild(blocks, child);
child = child.getTreeNext();
}
return blocks;
}
private void addChild(List<Block> blocks, ASTNode child) {
if (child.getElementType() != TokenType.WHITE_SPACE && child.getTextRange().getLength() > 0) {
Block block = new KerboScriptBlock(child, null, null);
blocks.add(block);
}
}
@Override
public Indent getIndent() {
PsiElement psi = getNode().getPsi();
if (psi.getParent() == null || psi.getParent() instanceof KerboScriptFile) {
return Indent.getNoneIndent();
} else if (psi.getParent() instanceof KerboScriptInstructionBlock) {
if (psi.getNode().getElementType() == CURLYCLOSE) {
return Indent.getNoneIndent();
}
return Indent.getNormalIndent();
} else if (psi.getParent() instanceof KerboScriptIfStmt && IF_ELSE.contains(psi.getNode().getElementType())) {
return Indent.getNoneIndent();
} else {
// return Indent.getNormalIndent();
return Indent.getContinuationWithoutFirstIndent();
}
}
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
return null;
}
@Override
public boolean isLeaf() {
return getNode() instanceof LeafElement;
}
@Nullable
@Override
protected Indent getChildIndent() {
return getNode().getPsi() instanceof KerboScriptInstructionBlock ? Indent.getNormalIndent() : Indent.getNoneIndent();
}
}
| 2,941 | Java | .java | KSP-KOS/EditorTools | 51 | 42 | 2 | 2015-04-13T18:45:12Z | 2023-06-09T09:20:51Z |
OCSSWInfoGUITest.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/test/java/gov/nasa/gsfc/seadas/processing/ocssw/OCSSWInfoGUITest.java | package gov.nasa.gsfc.seadas.processing.ocssw;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Iterator;
import static org.junit.Assert.*;
public class OCSSWInfoGUITest {
OCSSWInfoGUI ocsswInfoGUI;
@Before
public void setUp() throws Exception {
ocsswInfoGUI = new OCSSWInfoGUI();
}
@After
public void tearDown() throws Exception {
}
@Test
public void main() {
}
@Test
public void init() {
}
@Test
public void getDir() {
}
@Test
public void createConstraints() {
}
@Test
public void isTextFieldValidBranch() {
}
@Test
public void isDefaultBranch() {
}
@Test
public void isValidBranch() {
}
@Test
public void isTextFieldValidIP() {
}
@Test
public void isTextFieldValidPort() {
}
@Test
public void textfieldHasValue() {
}
@Test
public void isValidPort() {
}
@Test
public void isValidIP() {
}
@Test
public void isNumeric() {
}
} | 1,104 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ProcessObserverTest.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/test/java/gov/nasa/gsfc/seadas/processing/core/ProcessObserverTest.java | package gov.nasa.gsfc.seadas.processing.core;
import com.bc.ceres.core.NullProgressMonitor;
import com.bc.ceres.core.ProgressMonitor;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.net.URL;
/**
* @author Norman Fomferra
*/
public class ProcessObserverTest {
private File shellExec;
@Before
public void setUp() throws Exception {
String osName = System.getProperty("os.name");
String shellExt = osName.toLowerCase().contains("windows") ? ".bat" : ".sh";
URL shellExecUrl = getClass().getResource(getClass().getSimpleName() + shellExt);
shellExec = new File(shellExecUrl.toURI());
shellExec.setExecutable(true);
}
@Test
public void testHandlersAreNotified() throws Exception {
Process process = (Process) Runtime.getRuntime().exec(shellExec.getPath());
ProcessObserver processObserver = new ProcessObserver(process, "test", new NullProgressMonitor());
MyHandler handler = new MyHandler();
processObserver.addHandler(handler);
processObserver.startAndWait();
Assert.assertEquals(0, process.exitValue());
Assert.assertEquals("This is some output for stdout.", handler.stdout);
// Assert.assertEquals("This is some output for stderr.", handler.stderr);
}
private static class MyHandler implements ProcessObserver.Handler {
String stdout;
String stderr;
@Override
public void handleLineOnStdoutRead(String line, Process process, ProgressMonitor progressMonitor) {
stdout = line;
}
@Override
public void handleLineOnStderrRead(String line, Process process, ProgressMonitor progressMonitor) {
stderr = line;
}
}
}
| 1,804 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ProcessorModelTest.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/test/java/gov.nasa.gsfc.seadas.processing/common/ProcessorModelTest.java | package gov.nasa.gsfc.seadas.processing.common;
import org.junit.Test;
/**
* Created by IntelliJ IDEA.
* User: Aynur Abdurazik (aabduraz)
* Date: 4/16/12
* Time: 1:53 PM
* To change this template use File | Settings | File Templates.
*/
public class ProcessorModelTest {
// @Test
// public void testIsValidProcessor() throws Exception {
// ProcessorModel pm = new ProcessorModel("userInterface", "l2gen.xml");
// //pm.setDefaultEnv();
// assertTrue(pm.isValidProcessor() );
// }
@Test
public void testGetProgramName() throws Exception {
}
@Test
public void testGetProgramLocation() throws Exception {
}
@Test
public void testGetProgramRoot() throws Exception {
}
@Test
public void testGetProgramParamList() throws Exception {
}
@Test
public void testSetParFile() throws Exception {
}
@Test
public void testGetParFile() throws Exception {
}
@Test
public void testSetParString() throws Exception {
}
@Test
public void testSetAcceptsParFile() throws Exception {
}
@Test
public void testAcceptsParFile() throws Exception {
}
@Test
public void testGetProgramErrorMessage() throws Exception {
}
@Test
public void testSetInputFile() throws Exception {
}
@Test
public void testGetInputFile() throws Exception {
}
@Test
public void testSetOutputFile() throws Exception {
}
@Test
public void testSetOutputFileName() throws Exception {
}
@Test
public void testSetOutputFileDir() throws Exception {
}
@Test
public void testGetOutputFile() throws Exception {
}
@Test
public void testUpdateParamInfo() throws Exception {
}
@Test
public void testGetProgramCmdArray() throws Exception {
}
@Test
public void testGetProgramEnv() throws Exception {
}
@Test
public void testExecuteProcess() throws Exception {
}
}
| 2,012 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
RSClientTest.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/test/java/gov.nasa.gsfc.seadas.processing/common/RSClientTest.java | package gov.nasa.gsfc.seadas.processing.common;
import junit.framework.TestCase;
/**
* Created by IntelliJ IDEA.
* User: Aynur Abdurazik (aabduraz)
* Date: 8/9/12
* Time: 10:48 AM
* To change this template use File | Settings | File Templates.
*/
public class RSClientTest extends TestCase {
public void testGetOCSSWService() throws Exception {
}
public void testUploadParam() throws Exception {
//RSClient rs = new RSClient();
//rs.uploadParam("test:/Users/Shared/ocssw/run/scripts/ocssw_runner\ntest:l1bgen\ntest:ifile=/Users/Shared/ocssw/test/l2gen/A2002365234500.L1A_LAC\ntest:ofile=/Users/Shared/ocssw/test/l2gen/A2002365234500.L1B_LAC");
}
public void testUploadFile() throws Exception {
}
public void testRunOCSSW() throws Exception {
}
public void testDownloadFile() throws Exception {
}
public void testMain() throws Exception {
}
}
| 926 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
CallCloProgramActionTest.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/test/java/gov.nasa.gsfc.seadas.processing/common/CallCloProgramActionTest.java | package gov.nasa.gsfc.seadas.processing.common;
import org.junit.Test;
/**
* Created by IntelliJ IDEA.
* User: Aynur Abdurazik (aabduraz)
* Date: 4/16/12
* Time: 1:31 PM
* To change this template use File | Settings | File Templates.
*/
public class CallCloProgramActionTest {
@Test
public void testConfigure() throws Exception {
}
@Test
public void testActionPerformed() throws Exception {
}
}
| 431 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
DesktopHelper.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/DesktopHelper.java | package gov.nasa.gsfc.seadas.processing.help;
import org.esa.snap.rcp.util.Dialogs;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created by Norman on 30.05.2015.
*/
public class DesktopHelper {
public static void browse(String uriString) {
final Desktop desktop = Desktop.getDesktop();
URI uri;
try {
uri = new URI(uriString);
} catch (URISyntaxException e) {
Dialogs.showError(String.format("Internal error: Invalid URI:\n%s", uriString));
return;
}
try {
desktop.browse(uri);
} catch (IOException e) {
Dialogs.showError(String.format("<html>Failed to open URL in browser:<br><a href=\"%s\">%s</a>",
uriString, uriString));
} catch (UnsupportedOperationException e) {
Dialogs.showError("Sorry, it seems that there is no browser available.");
}
}
}
| 1,025 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowSeadasPresentationsPageAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/ShowSeadasPresentationsPageAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowSeaDASPresentationsAction")
@ActionRegistration(
displayName = "#CTL_ShowSeaDASPresentationsAction_MenuText",
popupText = "#CTL_ShowSeaDASPresentationsAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS",
position = 40
)
@NbBundle.Messages({
"CTL_ShowSeaDASPresentationsAction_MenuText=Presentations",
"CTL_ShowSeaDASPresentationsAction_ShortDescription=Browse the SeaDAS presentations web page"
})
public class ShowSeadasPresentationsPageAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seadas.gsfc.nasa.gov/tutorials/presentations/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.presentations", DEFAULT_PAGE_URL));
}
}
| 2,158 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowSeadasHomePageAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/ShowSeadasHomePageAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowSeaDASHomePageAction")
@ActionRegistration(
displayName = "#CTL_ShowSeadasHomePageAction_MenuText",
popupText = "#CTL_ShowSeadasHomePageAction_MenuText")
@ActionReferences({
@ActionReference(
path = "Menu/Help/SeaDAS",
position = 10,
separatorBefore = 5,
separatorAfter = 15
)
// @ActionReference(
// path = "Menu/SeaDAS-Toolbox",
// position = 3001,
// separatorBefore = 3000
// )
})
@NbBundle.Messages({
"CTL_ShowSeadasHomePageAction_MenuText=SeaDAS Web",
"CTL_ShowSeadasHomePageAction_ShortDescription=Browse the SeaDAS home page"
})
public class ShowSeadasHomePageAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seadas.gsfc.nasa.gov/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.homepage.url", DEFAULT_PAGE_URL));
}
}
| 2,394 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowOceanColorForumAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/ShowOceanColorForumAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowOceanColorForumAction")
@ActionRegistration(
displayName = "#CTL_ShowOceanColorForumAction_MenuText",
popupText = "#CTL_ShowOceanColorForumAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS",
position = 30
)
@NbBundle.Messages({
"CTL_ShowOceanColorForumAction_MenuText=Forum",
"CTL_ShowOceanColorForumAction_ShortDescription=Browse the SeaDAS/OceanColor forum web page"
})
public class ShowOceanColorForumAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceancolor.gsfc.nasa.gov/forum/oceancolor/forum_show.pl";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.oceanColorForum", DEFAULT_PAGE_URL));
}
}
| 2,113 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowSeadasVideosPageAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/ShowSeadasVideosPageAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help;
import org.esa.snap.runtime.Config;
//import org.esa.snap;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowSeaDASVideosAction")
@ActionRegistration(
displayName = "#CTL_ShowSeaDASVideosAction_MenuText",
popupText = "#CTL_ShowSeaDASVideosAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS",
position = 50)
@NbBundle.Messages({
"CTL_ShowSeaDASVideosAction_MenuText=Video Tutorials",
"CTL_ShowSeaDASVideosAction_ShortDescription=Browse the SeaDAS video tutorials web page"
})
public class ShowSeadasVideosPageAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seadas.gsfc.nasa.gov/tutorials/video_tutorials/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.videoTutorials", DEFAULT_PAGE_URL));
}
}
| 2,162 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebUsgsEarthExplorerAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowWebUsgsEarthExplorerAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebEarthExplorerAction")
@ActionRegistration(
displayName = "#CTL_ShowWebEarthExplorerAction_MenuText",
popupText = "#CTL_ShowWebEarthExplorerAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 80)
@NbBundle.Messages({
"CTL_ShowWebEarthExplorerAction_MenuText=USGS Earth Explorer",
"CTL_ShowWebEarthExplorerAction_ShortDescription=Open the USGS Earth Explorer web page"
})
public class ShowWebUsgsEarthExplorerAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://earthexplorer.usgs.gov/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebEarthExplorer", DEFAULT_PAGE_URL));
}
}
| 2,209 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowDataAccessFileSearchAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowDataAccessFileSearchAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowDateAccessFileSearchAction")
@ActionRegistration(
displayName = "#CTL_ShowDateAccessFileSearchAction_MenuText",
popupText = "#CTL_ShowDateAccessFileSearchAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 20)
@NbBundle.Messages({
"CTL_ShowDateAccessFileSearchAction_MenuText=File Search",
"CTL_ShowDateAccessFileSearchAction_ShortDescription=Browse the NASA ocean color file search web page"
})
public class ShowDataAccessFileSearchAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceandata.sci.gsfc.nasa.gov/api/file_search";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.dataAccessFileSearch", DEFAULT_PAGE_URL));
}
}
| 2,252 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowDataAccessDirectAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowDataAccessDirectAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowDateAccessDirectAction")
@ActionRegistration(
displayName = "#CTL_ShowDateAccessDirectAction_MenuText",
popupText = "#CTL_ShowDateAccessDirectAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 10)
@NbBundle.Messages({
"CTL_ShowDateAccessDirectAction_MenuText=Direct Access",
"CTL_ShowDateAccessDirectAction_ShortDescription=Browse the NASA ocean color direct data access web page"
})
public class ShowDataAccessDirectAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceandata.sci.gsfc.nasa.gov/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.dataAccessDirect", DEFAULT_PAGE_URL));
}
}
| 2,218 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebSeabassAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowWebSeabassAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebSeabassAction")
@ActionRegistration(
displayName = "#CTL_ShowWebSeabassAction_MenuText",
popupText = "#CTL_ShowWebSeabassAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 70)
@NbBundle.Messages({
"CTL_ShowWebSeabassAction_MenuText=SeaBASS",
"CTL_ShowWebSeabassAction_ShortDescription=Open the NASA SeaBASS web page"
})
public class ShowWebSeabassAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seabass.gsfc.nasa.gov/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebSeabass", DEFAULT_PAGE_URL));
}
}
| 2,143 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebL12BrowserAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowWebL12BrowserAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebL12BrowserAction")
@ActionRegistration(
displayName = "#CTL_ShowWebL12BrowserAction_MenuText",
popupText = "#CTL_ShowWebL12BrowserAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 30)
@NbBundle.Messages({
"CTL_ShowWebL12BrowserAction_MenuText=Level 1 & 2 Browser",
"CTL_ShowWebL12BrowserAction_ShortDescription=Open the NASA ocean color Level 1 & 2 Browser web page"
})
public class ShowWebL12BrowserAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceancolor.gsfc.nasa.gov/cgi/browse.pl";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebLevel12Browser", DEFAULT_PAGE_URL));
}
}
| 2,220 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebOcSubscriptionsAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowWebOcSubscriptionsAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebOcSubscriptionsAction")
@ActionRegistration(
displayName = "#CTL_ShowWebOcSubscriptionsAction_MenuText",
popupText = "#CTL_ShowWebOcSubscriptionsAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 50)
@NbBundle.Messages({
"CTL_ShowWebOcSubscriptionsAction_MenuText=Ocean Color Subscriptions",
"CTL_ShowWebOcSubscriptionsAction_ShortDescription=Open the NASA Ocean Color data subscriptions web page"
})
public class ShowWebOcSubscriptionsAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceandata.sci.gsfc.nasa.gov/subscriptions/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebOcSubscriptions", DEFAULT_PAGE_URL));
}
}
| 2,260 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebOpendapAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowWebOpendapAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebOpenDapAction")
@ActionRegistration(
displayName = "#CTL_ShowWebOpenDapAction_MenuText",
popupText = "#CTL_ShowWebOpenDapAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 60)
@NbBundle.Messages({
"CTL_ShowWebOpenDapAction_MenuText=OPeNDAP",
"CTL_ShowWebOpenDapAction_ShortDescription=Open the NASA ocean color OPeNDAP data access web page"
})
public class ShowWebOpendapAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceandata.sci.gsfc.nasa.gov/opendap/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebOpendap", DEFAULT_PAGE_URL));
}
}
| 2,181 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebL3BrowserAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/dataAccess/ShowWebL3BrowserAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.dataAccess;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebL3BrowserAction")
@ActionRegistration(
displayName = "#CTL_ShowWebL3BrowserAction_MenuText",
popupText = "#CTL_ShowWebL3BrowserAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Data Access",
position = 40)
@NbBundle.Messages({
"CTL_ShowWebL3BrowserAction_MenuText=Level 3 Browser",
"CTL_ShowWebL3BrowserAction_ShortDescription=Open the NASA ocean color Level 1 & 2 Browser web page"
})
public class ShowWebL3BrowserAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceancolor.gsfc.nasa.gov/cgi/l3";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebLevel3Browser", DEFAULT_PAGE_URL));
}
}
| 2,202 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebObpgAlgorithmDescriptionsAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/ocsswDocumentation/ShowWebObpgAlgorithmDescriptionsAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.ocsswDocumentation;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebObpgAlgorithmDescriptionsAction")
@ActionRegistration(
displayName = "#CTL_ShowWebObpgAlgorithmDescriptionsAction_MenuText",
popupText = "#CTL_ShowWebObpgAlgorithmDescriptionsAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Documentation",
position = 20)
@NbBundle.Messages({
"CTL_ShowWebObpgAlgorithmDescriptionsAction_MenuText=OBPG Algorithm Descriptions",
"CTL_ShowWebObpgAlgorithmDescriptionsAction_ShortDescription=Open the NASA Ocean Color Algorithm Descriptions web page"
})
public class ShowWebObpgAlgorithmDescriptionsAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceancolor.gsfc.nasa.gov/atbd/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebObpgAlgorithmDescriptions", DEFAULT_PAGE_URL));
}
}
| 2,334 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowWebObpgProductDefinitionsAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/ocsswDocumentation/ShowWebObpgProductDefinitionsAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.ocsswDocumentation;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
//import org.esa.snap;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowWebObpgProductDefinitionsAction")
@ActionRegistration(
displayName = "#CTL_ShowWebObpgProductDefinitionsAction_MenuText",
popupText = "#CTL_ShowWebObpgProductDefinitionsAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Documentation",
position = 10)
@NbBundle.Messages({
"CTL_ShowWebObpgProductDefinitionsAction_MenuText=OBPG Product Definitions",
"CTL_ShowWebObpgProductDefinitionsAction_ShortDescription=Open the NASA Ocean Color OBPG Product Definitions web page"
})
public class ShowWebObpgProductDefinitionsAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://oceancolor.gsfc.nasa.gov/products/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.showWebObpgProductDefinitions", DEFAULT_PAGE_URL));
}
}
| 2,316 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowSeadasInstallationAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/configuration/ShowSeadasInstallationAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.configuration;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowSeaDASInstallationAction")
@ActionRegistration(
displayName = "#CTL_ShowSeaDASInstallationAction_MenuText",
popupText = "#CTL_ShowSeaDASInstallationAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Configuration",
position = 20
)
@NbBundle.Messages({
"CTL_ShowSeaDASInstallationAction_MenuText=Installation",
"CTL_ShowSeaDASInstallationAction_ShortDescription=Browse the SeaDAS installation web page"
})
public class ShowSeadasInstallationAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seadas.gsfc.nasa.gov/downloads/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.installation", DEFAULT_PAGE_URL));
}
}
| 2,194 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowSeadasSystemRequirementsAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/configuration/ShowSeadasSystemRequirementsAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.configuration;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowSeadasSystemRequirementsAction")
@ActionRegistration(
displayName = "#CTL_ShowSeadasSystemRequirementsAction_MenuText",
popupText = "#CTL_ShowSeadasSystemRequirementsAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Configuration",
position = 10
)
@NbBundle.Messages({
"CTL_ShowSeadasSystemRequirementsAction_MenuText=System Requirements",
"CTL_ShowSeadasSystemRequirementsAction_ShortDescription=Browse the SeaDAS system requirements web page"
})
public class ShowSeadasSystemRequirementsAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seadas.gsfc.nasa.gov/requirements/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.systemRequirements", DEFAULT_PAGE_URL));
}
}
| 2,253 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowSeadasInstallationEnvironmentAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/configuration/ShowSeadasInstallationEnvironmentAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.configuration;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowSeaDASInstallationEnvironmentAction")
@ActionRegistration(
displayName = "#CTL_ShowSeaDASInstallationEnvironmentAction_MenuText",
popupText = "#CTL_ShowSeaDASInstallationEnvironmentAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Configuration",
position = 30
)
@NbBundle.Messages({
"CTL_ShowSeaDASInstallationEnvironmentAction_MenuText=Environment Setup",
"CTL_ShowSeaDASInstallationEnvironmentAction_ShortDescription=Browse the SeaDAS environment installation details web page"
})
public class ShowSeadasInstallationEnvironmentAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seadas.gsfc.nasa.gov/tutorials/installation_tutorial/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.installationDetails", DEFAULT_PAGE_URL));
}
}
| 2,314 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ShowSeadasClientServerAction.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/help/configuration/ShowSeadasClientServerAction.java | /*
* Copyright (C) 2014 by Array Systems Computing Inc. http://www.array.ca
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package gov.nasa.gsfc.seadas.processing.help.configuration;
import gov.nasa.gsfc.seadas.processing.help.DesktopHelper;
import org.esa.snap.runtime.Config;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This action launches the default browser to display the project web page.
*/
@ActionID(category = "Help", id = "ShowSeadasClientServerAction")
@ActionRegistration(
displayName = "#CTL_ShowSeadasClientServerAction_MenuText",
popupText = "#CTL_ShowSeadasClientServerAction_MenuText")
@ActionReference(
path = "Menu/Help/SeaDAS/Configuration",
position = 40
)
@NbBundle.Messages({
"CTL_ShowSeadasClientServerAction_MenuText=Client Server Setup",
"CTL_ShowSeadasClientServerAction_ShortDescription=Browse the SeaDAS client server configuration web page"
})
public class ShowSeadasClientServerAction extends AbstractAction {
private static final String DEFAULT_PAGE_URL = "https://seadas.gsfc.nasa.gov/client_server/";
/**
* Launches the default browser to display the web site.
* Invoked when a command action is performed.
*
* @param event the command event.
*/
@Override
public void actionPerformed(ActionEvent event) {
DesktopHelper.browse(Config.instance().preferences().get("seadas.clientServer", DEFAULT_PAGE_URL));
}
}
| 2,220 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
OCSSWInstallerFormRemote.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/common/OCSSWInstallerFormRemote.java | package gov.nasa.gsfc.seadas.processing.common;
import gov.nasa.gsfc.seadas.processing.ocssw.OCSSW;
import gov.nasa.gsfc.seadas.processing.ocssw.OCSSWClient;
import org.esa.snap.ui.AppContext;
import org.glassfish.jersey.server.ResourceConfig;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static gov.nasa.gsfc.seadas.processing.ocssw.OCSSWInfo.OCSSW_SRC_DIR_NAME;
/**
* Created by IntelliJ IDEA.
* User: Aynur Abdurazik (aabduraz)
* Date: 1/20/15
* Time: 11:56 AM
* To change this template use File | Settings | File Templates.
*/
public class OCSSWInstallerFormRemote extends OCSSWInstallerForm {
OCSSWClient ocsswClient;
WebTarget target;
OCSSW ocssw;
OCSSWInstallerFormRemote(AppContext appContext, String programName, String xmlFileName, OCSSW ocssw) {
super(appContext, programName, xmlFileName, ocssw);
}
void init(){
ocsswClient = new OCSSWClient();
final ResourceConfig rc = new ResourceConfig();
target = new OCSSWClient().getOcsswWebTarget();
}
@Override
void updateMissionStatus(){
}
@Override
void updateMissionValues() {
Response response0 = target.path("file").path("test").request().get();
response0 = target.path("ocssw").path("missions").request().get();
missionDataStatus = target.path("ocssw").path("missions").request(MediaType.APPLICATION_JSON_TYPE).get(new GenericType<HashMap<String, Boolean>>() {});
//missionDataStatus = (HashMap<String, Boolean>) response.getEntity();
for (Map.Entry<String, Boolean> entry : missionDataStatus.entrySet()) {
String missionName = entry.getKey();
Boolean missionStatus = entry.getValue();
if (missionStatus) {
processorModel.setParamValue("--" + missionName.toLowerCase(), "1");
}
}
try{
if (target.path("ocssw").path("srcDirInfo").request(MediaType.APPLICATION_JSON_TYPE).get(new GenericType<HashMap<String, Boolean>>() {}).get(OCSSW_SRC_DIR_NAME)) {
processorModel.setParamValue("--src", "1");
}} catch (Exception e) {
e.printStackTrace();
}
if (target.path("ocssw").path("viirsDemInfo").request(MediaType.APPLICATION_JSON_TYPE).get(new GenericType<HashMap<String, Boolean>>() {}).get("viirs-dem")) {
processorModel.setParamValue("--viirsdem", "1");
}
}
}
| 2,597 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
ModisGEO_L1B_UI.java | /FileExtraction/Java_unseen/seadas_seadas-toolbox/seadas-processing/src/main/java/gov/nasa/gsfc/seadas/processing/common/ModisGEO_L1B_UI.java | package gov.nasa.gsfc.seadas.processing.common;
import gov.nasa.gsfc.seadas.processing.ocssw.OCSSW;
import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
/**
* Created by IntelliJ IDEA.
* User: Aynur Abdurazik (aabduraz)
* Date: 10/4/12
* Time: 3:25 PM
* To change this template use File | Settings | File Templates.
*/
public class ModisGEO_L1B_UI extends ProgramUIFactory {
HashMap<String, String> validLutMissionNameMap;
OCSSW ocssw;
final LUTManager lutManager;
public ModisGEO_L1B_UI(String programName, String xmlFileName, OCSSW ocssw) {
super(programName, xmlFileName, ocssw);
this.ocssw = ocssw;
lutManager = new LUTManager(ocssw);
}
private void initMissionNameMap() {
}
@Override
public JPanel getParamPanel() {
initMissionNameMap();
JPanel paramPanel = super.getParamPanel();
processorModel.addPropertyChangeListener(processorModel.getPrimaryInputFileOptionName(), new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
String missionName = getMissionName();
if (missionName != null && missionName.trim().length() > 0) {
lutManager.enableLUTButton(missionName);
} else {
lutManager.disableLUTButton();
}
}
});
JScrollPane scrollPane = (JScrollPane) paramPanel.getComponent(0);
if (lutManager != null) {
final JPanel lutPanel = (JPanel) findJButton(scrollPane, paramPanel.getName());
lutPanel.remove(0);
lutPanel.add(lutManager.getLUTButton());
lutPanel.revalidate();
lutPanel.repaint();
paramPanel.revalidate();
paramPanel.repaint();
}
return paramPanel;
}
/*
* usage: update_luts [-h] [-e] [-v] [-n] [--timeout TIMEOUT] MISSION
* Retrieve latest lookup tables for specified sensor.
* positional arguments:
* MISSION sensor or platform to process; one of:
seawifs, aquarius, modisa, modist, viirsn, viirsj1, viirsj2, aqua, terra, npp, j1
*/
private String getMissionName() {
String missionName = processorModel.getOcssw().getMissionName();
if (missionName != null) {
missionName = missionName.toLowerCase();
if (missionName.contains("aqua")) {
missionName = "aqua";
} else if (missionName.contains("terra")) {
missionName = "terra";
} else if (missionName.contains("seawifs")) {
missionName = "seawifs";
} else if (missionName.contains("aquarius")) {
missionName = "aquarius";
} else if (missionName.contains("viirsn") ) {
missionName = "viirsn";
} else if (missionName.contains("viirsj1") ) {
missionName = "viirsj1";
} else if (missionName.contains("viirsj2") ) {
missionName = "viirsj2";
}
}
return missionName;
}
private Component findJPanel(Component comp, String panelName) {
if (comp.getClass() == JPanel.class) return comp;
if (comp instanceof Container) {
Component[] components = ((Container) comp).getComponents();
for (int i = 0; i < components.length; i++) {
Component child = findJPanel(components[i], components[i].getName());
if (child != null) {
return child;
}
}
}
return null;
}
private Component findJButton(Component comp, String panelName) {
//System.out.println(comp.getClass() + " " + comp.getName());
if (comp.getClass() == JButton.class && comp.getName() != null && comp.getName().contains("actionButton")) return comp.getParent();
if (comp instanceof Container) {
Component[] components = ((Container) comp).getComponents();
for (int i = 0; i < components.length; i++) {
Component child = findJButton(components[i], components[i].getName());
if (child != null) {
return child;
}
}
}
return null;
}
}
| 4,480 | Java | .java | seadas/seadas-toolbox | 17 | 2 | 5 | 2018-06-28T18:46:30Z | 2024-05-08T21:01:05Z |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.