IntelliJ with Existing Java File
I'm new to IntelliJ, but have loved PHPStorm for years. I'm trying to do something simple (I think) and not succeeding yet...
TL:DR: See block of code at the end of this post. It is an example robot op mode written in java. How would I copy and paste code similar to that into a new file in IntelliJ, toward getting Java code formatting/indentation and coloring, and git integration? (I don't need it to run... Just hope to write and manage from IntelliJ, while copying into the robot for running and testing, etc.)
I.e. Is there any way to just make a new java file in IntelliJ, similar to how one can make a new .php file, etc.
Long Version: FTC robot programs are written in Java, but are typically stuck in a robot controller that is not (or not well) connected to the outside world. The coding environment there is minimal and slow due to being served up in a web UI from a several-years old cell phone. There is no inherent backup or version control.
The robot program is in a single ".java" file such as the one shown at https://stemrobotics.cs.pdx.edu/node/4699. I simply want to be able to copy this into a new file in IntelliJ, to get Git integration, code formatting and coloring, and increased reliability and performance.
NOTE: I do not need to compile or run anything from IntelliJ... I just want to type and commit from there, while manually copying the code over to run from the robot.
I can't seem to get this to work... I've tried downloading and configuring the FTC SDK and the Android SDK, but nothing I do makes IntelliJ recognize (and therefore format) the code as Java. If I paste something like the following in, it gets all messed up for formatting... Switch statements make the indenting go really badly, etc.
---- ADAPTED FROM: https://stemrobotics.cs.pdx.edu/node/4699 -------------------------------
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.util.ElapsedTime;
import java.text.SimpleDateFormat;
import java.util.Date;
@Autonomous(name="NullOp")
public class NullOp extends OpMode
{
private String startDate;
private ElapsedTime runtime = new ElapsedTime();
// Here is the init() method. We don't have anything to do here so we could
// have left it out.
@Override
public void init()
{
}
@Override
public void init_loop()
{
startDate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date());
runtime.reset();
telemetry.addData("Null Op Init Loop", runtime.toString());
}
// The loop() method is called over and over until the Stop button is pressed.
@Override
public void loop()
{
telemetry.addData("Start", "NullOp started at " + startDate);
telemetry.addData("Status", "running for " + runtime.toString());
}
}
------------------------------------------------------------------------------------------------------------------
Thanks.
Please sign in to leave a comment.
Hello Jeff,
Do you create new file under folder marked as "sources root"?
No, but I think I've figured it out... I originally created a github repo that was empty except for the readme. I cloned this into IntelliJ as the method to create my project. Apparently this process precludes one from using the repo as a Java project... Or at least makes it vastly more complicated.
I've created a new project, and it now appears I can do what I need with it. (It has an src folder, which I suspect is equivalent to the sources root that you mention.)
Thanks for looking at this for me. I think this is resolved.