repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
fsmk/MCA-VTU-Lab-Manual
Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // }
import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle;
{ // Initialize Scanner to get inputs from the console/STDIN scanner = new Scanner(System.in); System.out.println("Welcome to the program to demonstrate usage of classes from another package."); System.out.println("1. Square"); System.out.println("2. Rectangle"); System.out.println("3. Circle"); System.out.println("4. Triangle"); System.out.println("5. Exit the program!!!"); System.out.println("Please select one of the option given below to choose the shape for which you want to find the area or perimeter."); System.out.println("Your option: "); int shape_choice = scanner.nextInt(); switch(shape_choice) { case 1: { System.out.println("Enter the side of the square:"); int side = scanner.nextInt(); Square square = new Square(side); calcValue(square); break; } case 2: { System.out.println("Enter the length of the rectangle:"); int length = scanner.nextInt(); System.out.println("Enter the breadth of the rectangle:"); int breadth = scanner.nextInt();
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // } // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle; { // Initialize Scanner to get inputs from the console/STDIN scanner = new Scanner(System.in); System.out.println("Welcome to the program to demonstrate usage of classes from another package."); System.out.println("1. Square"); System.out.println("2. Rectangle"); System.out.println("3. Circle"); System.out.println("4. Triangle"); System.out.println("5. Exit the program!!!"); System.out.println("Please select one of the option given below to choose the shape for which you want to find the area or perimeter."); System.out.println("Your option: "); int shape_choice = scanner.nextInt(); switch(shape_choice) { case 1: { System.out.println("Enter the side of the square:"); int side = scanner.nextInt(); Square square = new Square(side); calcValue(square); break; } case 2: { System.out.println("Enter the length of the rectangle:"); int length = scanner.nextInt(); System.out.println("Enter the breadth of the rectangle:"); int breadth = scanner.nextInt();
Rectangle rect = new Rectangle(length, breadth);
fsmk/MCA-VTU-Lab-Manual
Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // }
import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle;
System.out.println("4. Triangle"); System.out.println("5. Exit the program!!!"); System.out.println("Please select one of the option given below to choose the shape for which you want to find the area or perimeter."); System.out.println("Your option: "); int shape_choice = scanner.nextInt(); switch(shape_choice) { case 1: { System.out.println("Enter the side of the square:"); int side = scanner.nextInt(); Square square = new Square(side); calcValue(square); break; } case 2: { System.out.println("Enter the length of the rectangle:"); int length = scanner.nextInt(); System.out.println("Enter the breadth of the rectangle:"); int breadth = scanner.nextInt(); Rectangle rect = new Rectangle(length, breadth); calcValue(rect); break; } case 3: { System.out.println("Enter the radius of the circle:"); int radius = scanner.nextInt();
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // } // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle; System.out.println("4. Triangle"); System.out.println("5. Exit the program!!!"); System.out.println("Please select one of the option given below to choose the shape for which you want to find the area or perimeter."); System.out.println("Your option: "); int shape_choice = scanner.nextInt(); switch(shape_choice) { case 1: { System.out.println("Enter the side of the square:"); int side = scanner.nextInt(); Square square = new Square(side); calcValue(square); break; } case 2: { System.out.println("Enter the length of the rectangle:"); int length = scanner.nextInt(); System.out.println("Enter the breadth of the rectangle:"); int breadth = scanner.nextInt(); Rectangle rect = new Rectangle(length, breadth); calcValue(rect); break; } case 3: { System.out.println("Enter the radius of the circle:"); int radius = scanner.nextInt();
Circle circle = new Circle(radius);
fsmk/MCA-VTU-Lab-Manual
Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // }
import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle;
Square square = new Square(side); calcValue(square); break; } case 2: { System.out.println("Enter the length of the rectangle:"); int length = scanner.nextInt(); System.out.println("Enter the breadth of the rectangle:"); int breadth = scanner.nextInt(); Rectangle rect = new Rectangle(length, breadth); calcValue(rect); break; } case 3: { System.out.println("Enter the radius of the circle:"); int radius = scanner.nextInt(); Circle circle = new Circle(radius); calcValue(circle); break; } case 4: { System.out.println("Enter the length of the first side of the triangle:"); int first = scanner.nextInt(); System.out.println("Enter the length of the second side of the triangle:"); int second = scanner.nextInt(); System.out.println("Enter the length of the third side of the triangle:"); int third = scanner.nextInt();
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // } // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle; Square square = new Square(side); calcValue(square); break; } case 2: { System.out.println("Enter the length of the rectangle:"); int length = scanner.nextInt(); System.out.println("Enter the breadth of the rectangle:"); int breadth = scanner.nextInt(); Rectangle rect = new Rectangle(length, breadth); calcValue(rect); break; } case 3: { System.out.println("Enter the radius of the circle:"); int radius = scanner.nextInt(); Circle circle = new Circle(radius); calcValue(circle); break; } case 4: { System.out.println("Enter the length of the first side of the triangle:"); int first = scanner.nextInt(); System.out.println("Enter the length of the second side of the triangle:"); int second = scanner.nextInt(); System.out.println("Enter the length of the third side of the triangle:"); int third = scanner.nextInt();
Triangle triangle = new Triangle(first, second, third);
fsmk/MCA-VTU-Lab-Manual
Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // }
import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle;
System.out.println("Enter the radius of the circle:"); int radius = scanner.nextInt(); Circle circle = new Circle(radius); calcValue(circle); break; } case 4: { System.out.println("Enter the length of the first side of the triangle:"); int first = scanner.nextInt(); System.out.println("Enter the length of the second side of the triangle:"); int second = scanner.nextInt(); System.out.println("Enter the length of the third side of the triangle:"); int third = scanner.nextInt(); Triangle triangle = new Triangle(first, second, third); calcValue(triangle); break; } case 5: { System.out.println("Program is exitting!!!"); System.exit(0); } } } }
// Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/IShape.java // public interface IShape // { // // public double calcArea(); // // public double calcPerimeter(); // public String getName(); // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Circle.java // public class Circle implements IShape { // // int m_radius; // // public Circle(int radius) // { // m_radius = radius; // } // // @Override // public double calcArea() { // //Area of circle = PI * Square of radius of the circle // return Math.PI*m_radius*m_radius; // } // // @Override // public double calcPerimeter() { // //Perimeter of circle = 2 * PI * radius of the circle // return 2*Math.PI*m_radius; // } // // @Override // public String getName() { // return "Circle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Rectangle.java // public class Rectangle implements IShape { // // private int m_breadth; // private int m_length; // // public Rectangle(int length, int breadth) // { // m_length = length; // m_breadth = breadth; // // } // // @Override // public double calcArea() { // return m_length*m_breadth; // } // // @Override // public double calcPerimeter() { // return 2*(m_length*m_breadth); // } // // @Override // public String getName() { // return "Rectangle"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Square.java // public class Square implements IShape { // // private int m_side; // // public Square(int side) // { // m_side =side; // } // // @Override // public double calcArea() { // return m_side*m_side; // } // // // @Override // public double calcPerimeter() { // return 4*m_side; // } // // @Override // public String getName() { // return "Square"; // } // // } // // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/shape/Triangle.java // public class Triangle implements IShape { // // int m_s1; // int m_s2; // int m_s3; // // public Triangle(int s1, int s2, int s3) // { // m_s1 = s1; // m_s2 = s2; // m_s3 = s3; // } // // @Override // public double calcArea() { // //Heron's formula // float semi_perimeter = (m_s1+m_s2+m_s3)/2; // float s = semi_perimeter * (semi_perimeter -m_s1) * (semi_perimeter -m_s2) * (semi_perimeter -m_s3); // double area = Math.sqrt(s); // return area; // } // // @Override // public double calcPerimeter() { // return m_s1+m_s2+m_s3; // } // // @Override // public String getName() { // return "Triangle"; // } // // } // Path: Sem3/Java_Prog_Lab/7/org/fsmk/mca/example7/client/Client.java import java.util.Scanner; import org.fsmk.mca.example7.shape.IShape; import org.fsmk.mca.example7.shape.Circle; import org.fsmk.mca.example7.shape.Rectangle; import org.fsmk.mca.example7.shape.Square; import org.fsmk.mca.example7.shape.Triangle; System.out.println("Enter the radius of the circle:"); int radius = scanner.nextInt(); Circle circle = new Circle(radius); calcValue(circle); break; } case 4: { System.out.println("Enter the length of the first side of the triangle:"); int first = scanner.nextInt(); System.out.println("Enter the length of the second side of the triangle:"); int second = scanner.nextInt(); System.out.println("Enter the length of the third side of the triangle:"); int third = scanner.nextInt(); Triangle triangle = new Triangle(first, second, third); calcValue(triangle); break; } case 5: { System.out.println("Program is exitting!!!"); System.exit(0); } } } }
private static void calcValue(IShape shape) {
eb4j/eb4j
src/main/java/io/github/eb4j/DataFiles.java
// Path: src/main/java/io/github/eb4j/io/EBFormat.java // public enum EBFormat { // /** // * PLAIN. // */ // FORMAT_PLAIN, // /** // * EBZIP. // */ // FORMAT_EBZIP, // /** // * EPWING V4/V5. // */ // FORMAT_EPWING, // /** // * EPWING V6. // */ // FORMAT_EPWING6, // /** // * S-EBXA. // */ // FORMAT_SEBXA, // /** // * Unkown. // */ // FORMAT_UNKNOWN // }
import io.github.eb4j.io.EBFormat;
package io.github.eb4j; /** * ifeval::["{lang}" == "en"] * EBook main data files. * * endif::[] * Created by Hiroshi Miura on 16/07/01. * @author Hiroshi Miura */ class DataFiles { private String honmonFileName;
// Path: src/main/java/io/github/eb4j/io/EBFormat.java // public enum EBFormat { // /** // * PLAIN. // */ // FORMAT_PLAIN, // /** // * EBZIP. // */ // FORMAT_EBZIP, // /** // * EPWING V4/V5. // */ // FORMAT_EPWING, // /** // * EPWING V6. // */ // FORMAT_EPWING6, // /** // * S-EBXA. // */ // FORMAT_SEBXA, // /** // * Unkown. // */ // FORMAT_UNKNOWN // } // Path: src/main/java/io/github/eb4j/DataFiles.java import io.github.eb4j.io.EBFormat; package io.github.eb4j; /** * ifeval::["{lang}" == "en"] * EBook main data files. * * endif::[] * Created by Hiroshi Miura on 16/07/01. * @author Hiroshi Miura */ class DataFiles { private String honmonFileName;
private EBFormat honmonFormat;
eb4j/eb4j
src/main/java/io/github/eb4j/util/ImageUtil.java
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // // Path: src/main/java/io/github/eb4j/EBException.java // public static final int FAILED_CONVERT_IMAGE = 9;
import io.github.eb4j.EBException; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.zip.CRC32; import java.util.zip.Deflater; import javax.imageio.ImageIO; import javax.imageio.ImageWriter; import static io.github.eb4j.EBException.FAILED_CONVERT_IMAGE;
cnt = width - x; } int mask = 0x80; for (int i = 0; i < cnt; i++) { if ((b[offb] & mask) > 0) { c = fRGB; } else { c = bRGB; } image[offi++] = c[0]; // R image[offi++] = c[1]; // G image[offi++] = c[2]; // B image[offi++] = c[3]; // alpha mask = mask >>> 1; } offb++; } } return _encodePNG(width, height, image, level); } /** * デフォルトの圧縮レベルでDIB (Device Independent Bitmaps) を * PNG (Portable Network Graphics) に変換します。 * * @param b DIBデータ * @return PNGデータ * @throws EBException when image conversion error occurred. */
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // // Path: src/main/java/io/github/eb4j/EBException.java // public static final int FAILED_CONVERT_IMAGE = 9; // Path: src/main/java/io/github/eb4j/util/ImageUtil.java import io.github.eb4j.EBException; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.zip.CRC32; import java.util.zip.Deflater; import javax.imageio.ImageIO; import javax.imageio.ImageWriter; import static io.github.eb4j.EBException.FAILED_CONVERT_IMAGE; cnt = width - x; } int mask = 0x80; for (int i = 0; i < cnt; i++) { if ((b[offb] & mask) > 0) { c = fRGB; } else { c = bRGB; } image[offi++] = c[0]; // R image[offi++] = c[1]; // G image[offi++] = c[2]; // B image[offi++] = c[3]; // alpha mask = mask >>> 1; } offb++; } } return _encodePNG(width, height, image, level); } /** * デフォルトの圧縮レベルでDIB (Device Independent Bitmaps) を * PNG (Portable Network Graphics) に変換します。 * * @param b DIBデータ * @return PNGデータ * @throws EBException when image conversion error occurred. */
public static byte[] dibToPNG(final byte[] b) throws EBException {
eb4j/eb4j
src/main/java/io/github/eb4j/util/ImageUtil.java
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // // Path: src/main/java/io/github/eb4j/EBException.java // public static final int FAILED_CONVERT_IMAGE = 9;
import io.github.eb4j.EBException; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.zip.CRC32; import java.util.zip.Deflater; import javax.imageio.ImageIO; import javax.imageio.ImageWriter; import static io.github.eb4j.EBException.FAILED_CONVERT_IMAGE;
} /** * デフォルトの圧縮レベルでDIB (Device Independent Bitmaps) を * PNG (Portable Network Graphics) に変換します。 * * @param b DIBデータ * @return PNGデータ * @throws EBException when image conversion error occurred. */ public static byte[] dibToPNG(final byte[] b) throws EBException { return dibToPNG(b, Deflater.DEFAULT_COMPRESSION); } /** * 指定された圧縮レベルでDIB (Device Independent Bitmaps) を * PNG (Portable Network Graphics) に変換します。 * * @param b DIBデータ * @param level 圧縮レベル (0-9) * @return PNGデータ * @throws EBException when image conversion error occurred. */ public static byte[] dibToPNG(final byte[] b, final int level) throws EBException { Bitmap bitmap; byte[] image; try { bitmap = new Bitmap(b); } catch (IOException e) {
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // // Path: src/main/java/io/github/eb4j/EBException.java // public static final int FAILED_CONVERT_IMAGE = 9; // Path: src/main/java/io/github/eb4j/util/ImageUtil.java import io.github.eb4j.EBException; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.zip.CRC32; import java.util.zip.Deflater; import javax.imageio.ImageIO; import javax.imageio.ImageWriter; import static io.github.eb4j.EBException.FAILED_CONVERT_IMAGE; } /** * デフォルトの圧縮レベルでDIB (Device Independent Bitmaps) を * PNG (Portable Network Graphics) に変換します。 * * @param b DIBデータ * @return PNGデータ * @throws EBException when image conversion error occurred. */ public static byte[] dibToPNG(final byte[] b) throws EBException { return dibToPNG(b, Deflater.DEFAULT_COMPRESSION); } /** * 指定された圧縮レベルでDIB (Device Independent Bitmaps) を * PNG (Portable Network Graphics) に変換します。 * * @param b DIBデータ * @param level 圧縮レベル (0-9) * @return PNGデータ * @throws EBException when image conversion error occurred. */ public static byte[] dibToPNG(final byte[] b, final int level) throws EBException { Bitmap bitmap; byte[] image; try { bitmap = new Bitmap(b); } catch (IOException e) {
throw new EBException(FAILED_CONVERT_IMAGE, e);
eb4j/eb4j
src/main/java/io/github/eb4j/io/BookInputStream.java
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // }
import java.io.RandomAccessFile; import java.io.EOFException; import java.io.FileNotFoundException; import java.io.IOException; import io.github.eb4j.EBException;
package io.github.eb4j.io; /** * Base InputStream class for book. * * @author Hisaya FUKUMOTO * @author Hiroshi Miura */ public abstract class BookInputStream implements AutoCloseable { /** Page size */ public static final int PAGE_SIZE = 2048; /** File information. */ protected FileInfo info = null; /** Input stream. */ protected RandomAccessFile stream = null; /** File pointer position. */ protected long filePos = 0; /** Cache buffer. */ protected byte[] cache = null; /** Position in cache buffer. */ protected long cachePos = -1; /** * Constructor. * * @param info File information. */ protected BookInputStream(final FileInfo info) { super(); this.info = info; } /** * このオブジェクトで使用されているシステムリソースを破棄します。 * * @exception Throwable このメソッドで生じた例外 */ @Override protected void finalize() throws Throwable { close(); super.finalize(); } /** * このファイルのファイルサイズを返します。 * * @return ファイルサイズ */ public long getFileSize() { return info.getFileSize(); } /** * このファイルの実ファイルサイズを返します。 * * @return 実ファイルサイズ */ public long getRealFileSize() { return info.getRealFileSize(); } /** * このファイルのスライスサイズを返します。 * * @return スライスサイズ */ public int getSliceSize() { return info.getSliceSize(); } /** * ファイル情報を初期化します。 * * @exception EBException 入出力エラーが発生した場合 */
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // Path: src/main/java/io/github/eb4j/io/BookInputStream.java import java.io.RandomAccessFile; import java.io.EOFException; import java.io.FileNotFoundException; import java.io.IOException; import io.github.eb4j.EBException; package io.github.eb4j.io; /** * Base InputStream class for book. * * @author Hisaya FUKUMOTO * @author Hiroshi Miura */ public abstract class BookInputStream implements AutoCloseable { /** Page size */ public static final int PAGE_SIZE = 2048; /** File information. */ protected FileInfo info = null; /** Input stream. */ protected RandomAccessFile stream = null; /** File pointer position. */ protected long filePos = 0; /** Cache buffer. */ protected byte[] cache = null; /** Position in cache buffer. */ protected long cachePos = -1; /** * Constructor. * * @param info File information. */ protected BookInputStream(final FileInfo info) { super(); this.info = info; } /** * このオブジェクトで使用されているシステムリソースを破棄します。 * * @exception Throwable このメソッドで生じた例外 */ @Override protected void finalize() throws Throwable { close(); super.finalize(); } /** * このファイルのファイルサイズを返します。 * * @return ファイルサイズ */ public long getFileSize() { return info.getFileSize(); } /** * このファイルの実ファイルサイズを返します。 * * @return 実ファイルサイズ */ public long getRealFileSize() { return info.getRealFileSize(); } /** * このファイルのスライスサイズを返します。 * * @return スライスサイズ */ public int getSliceSize() { return info.getSliceSize(); } /** * ファイル情報を初期化します。 * * @exception EBException 入出力エラーが発生した場合 */
protected void initFileInfo() throws EBException {
eb4j/eb4j
src/main/java/io/github/eb4j/io/EBFile.java
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // }
import java.io.File; import org.apache.commons.lang3.ArrayUtils; import io.github.eb4j.EBException;
package io.github.eb4j.io; /** * ファイルおよびディレクトリの抽象表現クラス。 * * @author Hisaya FUKUMOTO */ public class EBFile { /** PLAIN形式 */ @Deprecated public static final int FORMAT_PLAIN = 0; /** EBZIP形式 */ @Deprecated public static final int FORMAT_EBZIP = 1; /** EPWING V4/V5形式 */ @Deprecated public static final int FORMAT_EPWING = 2; /** EPWING V6形式 */ @Deprecated public static final int FORMAT_EPWING6 = 3; /** S-EBXA形式 */ @Deprecated public static final int FORMAT_SEBXA = 4; /** ファイル情報 */ private FileInfo _info; /** オリジナルファイル名 */ private String _name = null; /** * EBFile constructor for backward compatibility. * * @param dir directory. * @param name file name. * @param defaultFormat default file format type. * @exception EBException if not exist a file. * @see EBFile#FORMAT_PLAIN * @see EBFile#FORMAT_EBZIP * @see EBFile#FORMAT_EPWING * @see EBFile#FORMAT_EPWING6 */ @Deprecated public EBFile(final File dir, final String name,
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // Path: src/main/java/io/github/eb4j/io/EBFile.java import java.io.File; import org.apache.commons.lang3.ArrayUtils; import io.github.eb4j.EBException; package io.github.eb4j.io; /** * ファイルおよびディレクトリの抽象表現クラス。 * * @author Hisaya FUKUMOTO */ public class EBFile { /** PLAIN形式 */ @Deprecated public static final int FORMAT_PLAIN = 0; /** EBZIP形式 */ @Deprecated public static final int FORMAT_EBZIP = 1; /** EPWING V4/V5形式 */ @Deprecated public static final int FORMAT_EPWING = 2; /** EPWING V6形式 */ @Deprecated public static final int FORMAT_EPWING6 = 3; /** S-EBXA形式 */ @Deprecated public static final int FORMAT_SEBXA = 4; /** ファイル情報 */ private FileInfo _info; /** オリジナルファイル名 */ private String _name = null; /** * EBFile constructor for backward compatibility. * * @param dir directory. * @param name file name. * @param defaultFormat default file format type. * @exception EBException if not exist a file. * @see EBFile#FORMAT_PLAIN * @see EBFile#FORMAT_EBZIP * @see EBFile#FORMAT_EPWING * @see EBFile#FORMAT_EPWING6 */ @Deprecated public EBFile(final File dir, final String name,
final int defaultFormat) throws EBException {
eb4j/eb4j
src/main/java/io/github/eb4j/ext/UnicodeMap.java
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // }
import io.github.eb4j.EBException; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer;
package io.github.eb4j.ext; /** * UnicodeMap class to search alternative unicode for extfont codepoint. */ public class UnicodeMap { private HashMap<Integer, String> narrowMap = new HashMap<>(); private HashMap<Integer, String> wideMap = new HashMap<>(); /** * Constructor. * * @param title target dictionary title * @param dir target dictionary directory * @throws EBException when unicode map does not exist. */
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // Path: src/main/java/io/github/eb4j/ext/UnicodeMap.java import io.github.eb4j.EBException; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; package io.github.eb4j.ext; /** * UnicodeMap class to search alternative unicode for extfont codepoint. */ public class UnicodeMap { private HashMap<Integer, String> narrowMap = new HashMap<>(); private HashMap<Integer, String> wideMap = new HashMap<>(); /** * Constructor. * * @param title target dictionary title * @param dir target dictionary directory * @throws EBException when unicode map does not exist. */
public UnicodeMap(final String title, final File dir) throws EBException {
eb4j/eb4j
src/test/java/io/github/eb4j/ext/UnicodeMapTest.java
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // }
import io.github.eb4j.EBException; import org.testng.annotations.Test; import java.io.File; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull;
package io.github.eb4j.ext; /** * Test for unicode map feature. */ public class UnicodeMapTest { private UnicodeMap unicodeMap; /** * Test to read unicode map file(.map). * * @throws EBException when map file loading failed. */ @Test(groups = "init")
// Path: src/main/java/io/github/eb4j/EBException.java // public class EBException extends Exception { // // /** Error code: Directory not found. */ // public static final int DIR_NOT_FOUND = 0; // /** Error code: Cannot read directory. */ // public static final int CANT_READ_DIR = 1; // // /** Error code: File not found. */ // public static final int FILE_NOT_FOUND = 2; // /** Error code: cannot read file. */ // public static final int CANT_READ_FILE = 3; // /** Error code: failed to read file. */ // public static final int FAILED_READ_FILE = 4; // /** Error code: unexceptional file format. */ // public static final int UNEXP_FILE = 5; // /** Error code: failed to seek file. */ // public static final int FAILED_SEEK_FILE = 6; // /** Error code: cannot find unicode map. */ // public static final int CANT_FIND_UNICODEMAP = 7; // /** Error code: failed to convert gaiji image. */ // public static final int FAILED_CONVERT_GAIJI = 8; // /** Error code: failed to convert image data */ // public static final int FAILED_CONVERT_IMAGE = 9; // // /** Error messages */ // private static final String[] ERR_MSG = { // "directory not found", // "can't read directory", // // "file not found", // "can't read a file", // "failed to read a file", // "unexpected format in a file", // "failed to seek a file", // "can not find unicode map" // }; // // /** Error code */ // private int _code = -1; // // // /** // * Build EBException from specified message. // * // * @param msg message // */ // private EBException(final String msg) { // super(msg); // } // // /** // * Build EBException from specified message. // * // * @param msg message // * @param cause cause // */ // private EBException(final String msg, final Throwable cause) { // super(msg, cause); // } // // /** // * Build EBException from specified error code. // * // * @param code error code // */ // public EBException(final int code) { // this(ERR_MSG[code]); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param cause cause // */ // public EBException(final int code, final Throwable cause) { // this(ERR_MSG[code] + " (" + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException from specified error code. // * // * @param code error code // * @param msg additional message // */ // public EBException(final int code, final String msg) { // this(ERR_MSG[code] + " (" + msg + ")"); // _code = code; // } // // /** // * Build EBException with specified error code, additional message, and cause. // * // * @param code error code // * @param msg additional message // * @param cause cause // */ // public EBException(final int code, final String msg, final Throwable cause) { // this(ERR_MSG[code] + " (" + msg + ": " + cause.getMessage() + ")", cause); // _code = code; // } // // /** // * Build EBException with specified error code and additional message. // * // * @param code error code // * @param msg1 additional message 1 // * @param msg2 additional message 2 // */ // public EBException(final int code, final String msg1, final String msg2) { // this(ERR_MSG[code] + " (" + msg1 + ": " + msg2 + ")"); // _code = code; // } // // // /** // * Return error code. // * // * @return error code. // */ // public int getErrorCode() { // return _code; // } // } // Path: src/test/java/io/github/eb4j/ext/UnicodeMapTest.java import io.github.eb4j.EBException; import org.testng.annotations.Test; import java.io.File; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; package io.github.eb4j.ext; /** * Test for unicode map feature. */ public class UnicodeMapTest { private UnicodeMap unicodeMap; /** * Test to read unicode map file(.map). * * @throws EBException when map file loading failed. */ @Test(groups = "init")
public void testConstructor() throws EBException {
jDramaix/SlidingPuzzle
src/be/dramaix/ai/slidingpuzzle/server/search/AStar.java
// Path: src/be/dramaix/ai/slidingpuzzle/server/search/heuristic/HeuristicFunction.java // public interface HeuristicFunction { // // // public int h(Node n); // // } // // Path: src/be/dramaix/ai/slidingpuzzle/server/search/heuristic/UseHeuristic.java // public interface UseHeuristic { // // public void setHeuristic(HeuristicFunction h); // // } // // Path: src/be/dramaix/ai/slidingpuzzle/shared/Node.java // public class Node implements IsSerializable { // // private State state; // //private Move move; // private int cost = 0; // private int heuristic = -1; // private Node parent = null; // private Action nextAction; // // public Node() {} // // public Node(State state/*, Move m*/) { // this.state = state; // //this.move = m; // } // // public State getState() { // return state; // } // // // /** // * equality based on state // */ // @Override // public boolean equals(Object obj) { // if (obj instanceof Node){ // return state.equals(((Node)obj).state); // } // return false; // } // // /** // * equality based on state // */ // @Override // public int hashCode() { // return state.hashCode(); // } // // public void setParent(Node parent) { // this.parent = parent; // cost = parent.getCost() + 1; // } // // public Node getParent() { // return parent; // } // // public int getCost() { // return cost; // } // // public Action getAction() { // return nextAction; // } // // public void setAction(Action next){ // this.nextAction = next; // } // // public int getHeuristic() { // return heuristic; // } // // public void setHeuristic(int heuristic) { // this.heuristic = heuristic; // // } // // }
import java.util.Comparator; import java.util.PriorityQueue; import be.dramaix.ai.slidingpuzzle.server.search.heuristic.HeuristicFunction; import be.dramaix.ai.slidingpuzzle.server.search.heuristic.UseHeuristic; import be.dramaix.ai.slidingpuzzle.shared.Node;
/* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.server.search; public class AStar extends GraphSearch implements UseHeuristic { public static class HeuristicComparator implements Comparator<Node>{
// Path: src/be/dramaix/ai/slidingpuzzle/server/search/heuristic/HeuristicFunction.java // public interface HeuristicFunction { // // // public int h(Node n); // // } // // Path: src/be/dramaix/ai/slidingpuzzle/server/search/heuristic/UseHeuristic.java // public interface UseHeuristic { // // public void setHeuristic(HeuristicFunction h); // // } // // Path: src/be/dramaix/ai/slidingpuzzle/shared/Node.java // public class Node implements IsSerializable { // // private State state; // //private Move move; // private int cost = 0; // private int heuristic = -1; // private Node parent = null; // private Action nextAction; // // public Node() {} // // public Node(State state/*, Move m*/) { // this.state = state; // //this.move = m; // } // // public State getState() { // return state; // } // // // /** // * equality based on state // */ // @Override // public boolean equals(Object obj) { // if (obj instanceof Node){ // return state.equals(((Node)obj).state); // } // return false; // } // // /** // * equality based on state // */ // @Override // public int hashCode() { // return state.hashCode(); // } // // public void setParent(Node parent) { // this.parent = parent; // cost = parent.getCost() + 1; // } // // public Node getParent() { // return parent; // } // // public int getCost() { // return cost; // } // // public Action getAction() { // return nextAction; // } // // public void setAction(Action next){ // this.nextAction = next; // } // // public int getHeuristic() { // return heuristic; // } // // public void setHeuristic(int heuristic) { // this.heuristic = heuristic; // // } // // } // Path: src/be/dramaix/ai/slidingpuzzle/server/search/AStar.java import java.util.Comparator; import java.util.PriorityQueue; import be.dramaix.ai.slidingpuzzle.server.search.heuristic.HeuristicFunction; import be.dramaix.ai.slidingpuzzle.server.search.heuristic.UseHeuristic; import be.dramaix.ai.slidingpuzzle.shared.Node; /* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.server.search; public class AStar extends GraphSearch implements UseHeuristic { public static class HeuristicComparator implements Comparator<Node>{
private HeuristicFunction heuristic;
jDramaix/SlidingPuzzle
src/be/dramaix/ai/slidingpuzzle/shared/Action.java
// Path: src/be/dramaix/ai/slidingpuzzle/shared/State.java // public static class CellLocation implements IsSerializable { // // private int rowIndex; // private int columnIndex; // // public CellLocation() { // } // // public CellLocation(int rowIndex, int columnIndex) { // this.rowIndex = rowIndex; // this.columnIndex = columnIndex; // } // // public int getRowIndex() { // return rowIndex; // } // // public int getColumnIndex() { // return columnIndex; // } // }
import com.google.gwt.user.client.rpc.IsSerializable; import be.dramaix.ai.slidingpuzzle.shared.State.CellLocation;
/* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.shared; public class Action implements IsSerializable{ private Move m;
// Path: src/be/dramaix/ai/slidingpuzzle/shared/State.java // public static class CellLocation implements IsSerializable { // // private int rowIndex; // private int columnIndex; // // public CellLocation() { // } // // public CellLocation(int rowIndex, int columnIndex) { // this.rowIndex = rowIndex; // this.columnIndex = columnIndex; // } // // public int getRowIndex() { // return rowIndex; // } // // public int getColumnIndex() { // return columnIndex; // } // } // Path: src/be/dramaix/ai/slidingpuzzle/shared/Action.java import com.google.gwt.user.client.rpc.IsSerializable; import be.dramaix.ai.slidingpuzzle.shared.State.CellLocation; /* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.shared; public class Action implements IsSerializable{ private Move m;
private CellLocation cell;
jDramaix/SlidingPuzzle
src/be/dramaix/ai/slidingpuzzle/client/ConfigPanel.java
// Path: src/be/dramaix/ai/slidingpuzzle/shared/AlgorithmType.java // public enum AlgorithmType { // // BDF("Breadth-first search (BDF)"), A_STAR("A*"), IDA_STAR("Iterative Deepening A* (IDA*)"); // // private String label; // // private AlgorithmType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // // } // // Path: src/be/dramaix/ai/slidingpuzzle/shared/HeuristicType.java // public enum HeuristicType { // // //TODO use resources for label // MANHATTAN_DISTANCE("manhattan distance"), LINEAR_CONFLICT("linear conflict"), PATTERN_DATABASE("pattern database"); // // private String label; // // private HeuristicType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // }
import static be.dramaix.ai.slidingpuzzle.client.MySelectors.SELECTOR; import static com.google.gwt.query.client.GQuery.$; import be.dramaix.ai.slidingpuzzle.shared.AlgorithmType; import be.dramaix.ai.slidingpuzzle.shared.HeuristicType; import com.google.gwt.core.client.GWT; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.Element;
/* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.client; /** * Class managing the ui of the configuration of the puzzle * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class ConfigPanel { public interface Templates extends SafeHtmlTemplates { Templates INSTANCE = GWT.create(Templates.class); @Template("<option value=\"{0}\">{1}</option>") SafeHtml option(String value, String label); @Template("<option value=\"{0}\" selected=\"selected\">{1}</option>") SafeHtml selectedOption(String value, String label); }
// Path: src/be/dramaix/ai/slidingpuzzle/shared/AlgorithmType.java // public enum AlgorithmType { // // BDF("Breadth-first search (BDF)"), A_STAR("A*"), IDA_STAR("Iterative Deepening A* (IDA*)"); // // private String label; // // private AlgorithmType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // // } // // Path: src/be/dramaix/ai/slidingpuzzle/shared/HeuristicType.java // public enum HeuristicType { // // //TODO use resources for label // MANHATTAN_DISTANCE("manhattan distance"), LINEAR_CONFLICT("linear conflict"), PATTERN_DATABASE("pattern database"); // // private String label; // // private HeuristicType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // } // Path: src/be/dramaix/ai/slidingpuzzle/client/ConfigPanel.java import static be.dramaix.ai.slidingpuzzle.client.MySelectors.SELECTOR; import static com.google.gwt.query.client.GQuery.$; import be.dramaix.ai.slidingpuzzle.shared.AlgorithmType; import be.dramaix.ai.slidingpuzzle.shared.HeuristicType; import com.google.gwt.core.client.GWT; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.Element; /* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.client; /** * Class managing the ui of the configuration of the puzzle * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class ConfigPanel { public interface Templates extends SafeHtmlTemplates { Templates INSTANCE = GWT.create(Templates.class); @Template("<option value=\"{0}\">{1}</option>") SafeHtml option(String value, String label); @Template("<option value=\"{0}\" selected=\"selected\">{1}</option>") SafeHtml selectedOption(String value, String label); }
private HeuristicType heuristicType;
jDramaix/SlidingPuzzle
src/be/dramaix/ai/slidingpuzzle/client/ConfigPanel.java
// Path: src/be/dramaix/ai/slidingpuzzle/shared/AlgorithmType.java // public enum AlgorithmType { // // BDF("Breadth-first search (BDF)"), A_STAR("A*"), IDA_STAR("Iterative Deepening A* (IDA*)"); // // private String label; // // private AlgorithmType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // // } // // Path: src/be/dramaix/ai/slidingpuzzle/shared/HeuristicType.java // public enum HeuristicType { // // //TODO use resources for label // MANHATTAN_DISTANCE("manhattan distance"), LINEAR_CONFLICT("linear conflict"), PATTERN_DATABASE("pattern database"); // // private String label; // // private HeuristicType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // }
import static be.dramaix.ai.slidingpuzzle.client.MySelectors.SELECTOR; import static com.google.gwt.query.client.GQuery.$; import be.dramaix.ai.slidingpuzzle.shared.AlgorithmType; import be.dramaix.ai.slidingpuzzle.shared.HeuristicType; import com.google.gwt.core.client.GWT; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.Element;
/* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.client; /** * Class managing the ui of the configuration of the puzzle * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class ConfigPanel { public interface Templates extends SafeHtmlTemplates { Templates INSTANCE = GWT.create(Templates.class); @Template("<option value=\"{0}\">{1}</option>") SafeHtml option(String value, String label); @Template("<option value=\"{0}\" selected=\"selected\">{1}</option>") SafeHtml selectedOption(String value, String label); } private HeuristicType heuristicType;
// Path: src/be/dramaix/ai/slidingpuzzle/shared/AlgorithmType.java // public enum AlgorithmType { // // BDF("Breadth-first search (BDF)"), A_STAR("A*"), IDA_STAR("Iterative Deepening A* (IDA*)"); // // private String label; // // private AlgorithmType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // // } // // Path: src/be/dramaix/ai/slidingpuzzle/shared/HeuristicType.java // public enum HeuristicType { // // //TODO use resources for label // MANHATTAN_DISTANCE("manhattan distance"), LINEAR_CONFLICT("linear conflict"), PATTERN_DATABASE("pattern database"); // // private String label; // // private HeuristicType(String label) { // this.label = label; // } // // public String getLabel() { // return label; // } // } // Path: src/be/dramaix/ai/slidingpuzzle/client/ConfigPanel.java import static be.dramaix.ai.slidingpuzzle.client.MySelectors.SELECTOR; import static com.google.gwt.query.client.GQuery.$; import be.dramaix.ai.slidingpuzzle.shared.AlgorithmType; import be.dramaix.ai.slidingpuzzle.shared.HeuristicType; import com.google.gwt.core.client.GWT; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.Element; /* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.client; /** * Class managing the ui of the configuration of the puzzle * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class ConfigPanel { public interface Templates extends SafeHtmlTemplates { Templates INSTANCE = GWT.create(Templates.class); @Template("<option value=\"{0}\">{1}</option>") SafeHtml option(String value, String label); @Template("<option value=\"{0}\" selected=\"selected\">{1}</option>") SafeHtml selectedOption(String value, String label); } private HeuristicType heuristicType;
private AlgorithmType algorithmType;
jDramaix/SlidingPuzzle
src/be/dramaix/ai/slidingpuzzle/client/ResultPanel.java
// Path: src/be/dramaix/ai/slidingpuzzle/shared/PuzzleSolution.java // public class PuzzleSolution implements IsSerializable { // // private Path path; // private long time; // private long exploredNode; // private boolean timeout; // // public PuzzleSolution() { // } // // /** // * @return the optimal path to reach to goal // */ // public Path getPath() { // return path; // } // // public void setPath(Path path) { // this.path = path; // } // // /** // * @return the time in nanoseconds take by the algorithm to find the // * solution // */ // public long getTime() { // return time; // } // // public void setTime(long time) { // this.time = time; // } // // /** // * @return the number of nodes explored by the algorithm // */ // public long getExploredNode() { // return exploredNode; // } // // public void setExploredNode(long exploredNode) { // this.exploredNode = exploredNode; // } // // public boolean isTimeoutOccured(){ // return timeout; // } // // public void setTimeoutOccured(boolean timeout){ // this.timeout = timeout; // } // }
import static be.dramaix.ai.slidingpuzzle.client.MySelectors.SELECTOR; import be.dramaix.ai.slidingpuzzle.shared.PuzzleSolution;
/* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.client; /** * Display the result to the user. * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class ResultPanel { public ResultPanel() { } public void reset() { SELECTOR.getNbrOfMoveSpan().text(""); SELECTOR.getEllapsedTimeSpan().text(""); SELECTOR.getPathSpan().text(""); }
// Path: src/be/dramaix/ai/slidingpuzzle/shared/PuzzleSolution.java // public class PuzzleSolution implements IsSerializable { // // private Path path; // private long time; // private long exploredNode; // private boolean timeout; // // public PuzzleSolution() { // } // // /** // * @return the optimal path to reach to goal // */ // public Path getPath() { // return path; // } // // public void setPath(Path path) { // this.path = path; // } // // /** // * @return the time in nanoseconds take by the algorithm to find the // * solution // */ // public long getTime() { // return time; // } // // public void setTime(long time) { // this.time = time; // } // // /** // * @return the number of nodes explored by the algorithm // */ // public long getExploredNode() { // return exploredNode; // } // // public void setExploredNode(long exploredNode) { // this.exploredNode = exploredNode; // } // // public boolean isTimeoutOccured(){ // return timeout; // } // // public void setTimeoutOccured(boolean timeout){ // this.timeout = timeout; // } // } // Path: src/be/dramaix/ai/slidingpuzzle/client/ResultPanel.java import static be.dramaix.ai.slidingpuzzle.client.MySelectors.SELECTOR; import be.dramaix.ai.slidingpuzzle.shared.PuzzleSolution; /* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.client; /** * Display the result to the user. * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class ResultPanel { public ResultPanel() { } public void reset() { SELECTOR.getNbrOfMoveSpan().text(""); SELECTOR.getEllapsedTimeSpan().text(""); SELECTOR.getPathSpan().text(""); }
public void loadSolution(PuzzleSolution solution){
jDramaix/SlidingPuzzle
src/be/dramaix/ai/slidingpuzzle/shared/Move.java
// Path: src/be/dramaix/ai/slidingpuzzle/shared/State.java // public static class CellLocation implements IsSerializable { // // private int rowIndex; // private int columnIndex; // // public CellLocation() { // } // // public CellLocation(int rowIndex, int columnIndex) { // this.rowIndex = rowIndex; // this.columnIndex = columnIndex; // } // // public int getRowIndex() { // return rowIndex; // } // // public int getColumnIndex() { // return columnIndex; // } // }
import be.dramaix.ai.slidingpuzzle.shared.State.CellLocation;
/* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.shared; public enum Move { UP(0, -1), DOWN(0, 1), RIGHT(1, 0), LEFT(-1, 0); private int horizontalMove; private int verticalMove; private Move(int horizontal, int vertical) { this.horizontalMove = horizontal; this.verticalMove = vertical; } public int getHorizontalMove() { return horizontalMove; } public int getVerticalMove() { return verticalMove; }
// Path: src/be/dramaix/ai/slidingpuzzle/shared/State.java // public static class CellLocation implements IsSerializable { // // private int rowIndex; // private int columnIndex; // // public CellLocation() { // } // // public CellLocation(int rowIndex, int columnIndex) { // this.rowIndex = rowIndex; // this.columnIndex = columnIndex; // } // // public int getRowIndex() { // return rowIndex; // } // // public int getColumnIndex() { // return columnIndex; // } // } // Path: src/be/dramaix/ai/slidingpuzzle/shared/Move.java import be.dramaix.ai.slidingpuzzle.shared.State.CellLocation; /* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.shared; public enum Move { UP(0, -1), DOWN(0, 1), RIGHT(1, 0), LEFT(-1, 0); private int horizontalMove; private int verticalMove; private Move(int horizontal, int vertical) { this.horizontalMove = horizontal; this.verticalMove = vertical; } public int getHorizontalMove() { return horizontalMove; } public int getVerticalMove() { return verticalMove; }
public CellLocation getNextCellLocation(CellLocation currentLocation) {
jDramaix/SlidingPuzzle
src/be/dramaix/ai/slidingpuzzle/server/search/BreadthFirstSearch.java
// Path: src/be/dramaix/ai/slidingpuzzle/shared/Node.java // public class Node implements IsSerializable { // // private State state; // //private Move move; // private int cost = 0; // private int heuristic = -1; // private Node parent = null; // private Action nextAction; // // public Node() {} // // public Node(State state/*, Move m*/) { // this.state = state; // //this.move = m; // } // // public State getState() { // return state; // } // // // /** // * equality based on state // */ // @Override // public boolean equals(Object obj) { // if (obj instanceof Node){ // return state.equals(((Node)obj).state); // } // return false; // } // // /** // * equality based on state // */ // @Override // public int hashCode() { // return state.hashCode(); // } // // public void setParent(Node parent) { // this.parent = parent; // cost = parent.getCost() + 1; // } // // public Node getParent() { // return parent; // } // // public int getCost() { // return cost; // } // // public Action getAction() { // return nextAction; // } // // public void setAction(Action next){ // this.nextAction = next; // } // // public int getHeuristic() { // return heuristic; // } // // public void setHeuristic(int heuristic) { // this.heuristic = heuristic; // // } // // }
import java.util.LinkedList; import java.util.Queue; import be.dramaix.ai.slidingpuzzle.shared.Node;
/* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.server.search; /** * BFS implemntation * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class BreadthFirstSearch extends GraphSearch { @Override
// Path: src/be/dramaix/ai/slidingpuzzle/shared/Node.java // public class Node implements IsSerializable { // // private State state; // //private Move move; // private int cost = 0; // private int heuristic = -1; // private Node parent = null; // private Action nextAction; // // public Node() {} // // public Node(State state/*, Move m*/) { // this.state = state; // //this.move = m; // } // // public State getState() { // return state; // } // // // /** // * equality based on state // */ // @Override // public boolean equals(Object obj) { // if (obj instanceof Node){ // return state.equals(((Node)obj).state); // } // return false; // } // // /** // * equality based on state // */ // @Override // public int hashCode() { // return state.hashCode(); // } // // public void setParent(Node parent) { // this.parent = parent; // cost = parent.getCost() + 1; // } // // public Node getParent() { // return parent; // } // // public int getCost() { // return cost; // } // // public Action getAction() { // return nextAction; // } // // public void setAction(Action next){ // this.nextAction = next; // } // // public int getHeuristic() { // return heuristic; // } // // public void setHeuristic(int heuristic) { // this.heuristic = heuristic; // // } // // } // Path: src/be/dramaix/ai/slidingpuzzle/server/search/BreadthFirstSearch.java import java.util.LinkedList; import java.util.Queue; import be.dramaix.ai.slidingpuzzle.shared.Node; /* * Copyright 2011 Julien Dramaix. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package be.dramaix.ai.slidingpuzzle.server.search; /** * BFS implemntation * * @author Julien Dramaix (https://plus.google.com/u/0/103916508880440628637) * */ public class BreadthFirstSearch extends GraphSearch { @Override
protected Queue<Node> createFrontier() {
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchResource.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // }
import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.List; import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import org.apache.solr.client.solrj.SolrServerException; import org.elasticsearch.action.search.SearchResponse;
package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * */ @Path("/elasticsearch") @Produces("text/html; charset=utf-8") public class ElasticsearchResource { private final ElasticsearchSearcher searcher; public ElasticsearchResource(ElasticsearchSearcher searcher) { this.searcher = searcher; } @GET @Timed
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchResource.java import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.List; import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import org.apache.solr.client.solrj.SolrServerException; import org.elasticsearch.action.search.SearchResponse; package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * */ @Path("/elasticsearch") @Produces("text/html; charset=utf-8") public class ElasticsearchResource { private final ElasticsearchSearcher searcher; public ElasticsearchResource(ElasticsearchSearcher searcher) { this.searcher = searcher; } @GET @Timed
public SearchResultView search(@QueryParam("query") Optional<String> query, @QueryParam("sort") Optional<String> sort,
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchResource.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // }
import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.List; import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import org.apache.solr.client.solrj.SolrServerException; import org.elasticsearch.action.search.SearchResponse;
package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * */ @Path("/elasticsearch") @Produces("text/html; charset=utf-8") public class ElasticsearchResource { private final ElasticsearchSearcher searcher; public ElasticsearchResource(ElasticsearchSearcher searcher) { this.searcher = searcher; } @GET @Timed public SearchResultView search(@QueryParam("query") Optional<String> query, @QueryParam("sort") Optional<String> sort, @QueryParam("fq") Set<String> fqs) throws SolrServerException { final SearchResponse response = searcher.search(query.or(""), fqs);
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchResource.java import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.List; import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import org.apache.solr.client.solrj.SolrServerException; import org.elasticsearch.action.search.SearchResponse; package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * */ @Path("/elasticsearch") @Produces("text/html; charset=utf-8") public class ElasticsearchResource { private final ElasticsearchSearcher searcher; public ElasticsearchResource(ElasticsearchSearcher searcher) { this.searcher = searcher; } @GET @Timed public SearchResultView search(@QueryParam("query") Optional<String> query, @QueryParam("sort") Optional<String> sort, @QueryParam("fq") Set<String> fqs) throws SolrServerException { final SearchResponse response = searcher.search(query.or(""), fqs);
List<Result> results = searcher.getResults(response);
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchResource.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // }
import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.List; import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import org.apache.solr.client.solrj.SolrServerException; import org.elasticsearch.action.search.SearchResponse;
package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * */ @Path("/elasticsearch") @Produces("text/html; charset=utf-8") public class ElasticsearchResource { private final ElasticsearchSearcher searcher; public ElasticsearchResource(ElasticsearchSearcher searcher) { this.searcher = searcher; } @GET @Timed public SearchResultView search(@QueryParam("query") Optional<String> query, @QueryParam("sort") Optional<String> sort, @QueryParam("fq") Set<String> fqs) throws SolrServerException { final SearchResponse response = searcher.search(query.or(""), fqs); List<Result> results = searcher.getResults(response);
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchResource.java import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.List; import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import org.apache.solr.client.solrj.SolrServerException; import org.elasticsearch.action.search.SearchResponse; package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * */ @Path("/elasticsearch") @Produces("text/html; charset=utf-8") public class ElasticsearchResource { private final ElasticsearchSearcher searcher; public ElasticsearchResource(ElasticsearchSearcher searcher) { this.searcher = searcher; } @GET @Timed public SearchResultView search(@QueryParam("query") Optional<String> query, @QueryParam("sort") Optional<String> sort, @QueryParam("fq") Set<String> fqs) throws SolrServerException { final SearchResponse response = searcher.search(query.or(""), fqs); List<Result> results = searcher.getResults(response);
Faceting faceting = searcher.getFacets(response);
fhopf/lucene-solr-talk
lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/TikaIndexer.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // }
import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.sax.BodyContentHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.*;
package de.fhopf.lucenesolrtalk.lucene; /** * Indexes files where the content is extracted by Tika. */ public class TikaIndexer { private final Indexer indexer; private final Logger logger = LoggerFactory.getLogger(TikaIndexer.class); public TikaIndexer(Indexer indexer) { this.indexer = indexer; } public void indexDir(String path) { File [] files = new File(path).listFiles(); AutoDetectParser parser = new AutoDetectParser(); logger.debug("Found {} files in dir", files.length);
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/TikaIndexer.java import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.sax.BodyContentHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; package de.fhopf.lucenesolrtalk.lucene; /** * Indexes files where the content is extracted by Tika. */ public class TikaIndexer { private final Indexer indexer; private final Logger logger = LoggerFactory.getLogger(TikaIndexer.class); public TikaIndexer(Indexer indexer) { this.indexer = indexer; } public void indexDir(String path) { File [] files = new File(path).listFiles(); AutoDetectParser parser = new AutoDetectParser(); logger.debug("Found {} files in dir", files.length);
List<Talk> talks = new ArrayList<Talk>();
fhopf/lucene-solr-talk
elasticsearch-indexer/src/test/java/de/fhopf/lucenesolrtalk/elasticsearch/IndexerTest.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // }
import de.fhopf.elasticsearch.test.ElasticsearchTestNode; import de.fhopf.lucenesolrtalk.Talk; import java.io.IOException; import java.util.Arrays; import java.util.Date; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals;
package de.fhopf.lucenesolrtalk.elasticsearch; /** * */ public class IndexerTest { @Rule public ElasticsearchTestNode testNode = new ElasticsearchTestNode(); private Indexer indexer;
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // Path: elasticsearch-indexer/src/test/java/de/fhopf/lucenesolrtalk/elasticsearch/IndexerTest.java import de.fhopf.elasticsearch.test.ElasticsearchTestNode; import de.fhopf.lucenesolrtalk.Talk; import java.io.IOException; import java.util.Arrays; import java.util.Date; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; package de.fhopf.lucenesolrtalk.elasticsearch; /** * */ public class IndexerTest { @Rule public ElasticsearchTestNode testNode = new ElasticsearchTestNode(); private Indexer indexer;
private Talk talk = new Talk("/foo/bar", "Testen mit Elasticsearch", Arrays.asList("Florian Hopf"),
fhopf/lucene-solr-talk
lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/TikaIndexerTest.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // }
import com.google.common.io.Files; import com.google.common.io.Resources; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.sax.BodyContentHandler; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.xml.sax.SAXException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import static junit.framework.Assert.*; import org.apache.lucene.queryparser.classic.ParseException; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify;
package de.fhopf.lucenesolrtalk.lucene; public class TikaIndexerTest { private static String dataDir; @BeforeClass public static void copySlides() throws IOException { File directory = Files.createTempDir(); File pdf = new File(directory, "enter-the-gradle.pdf"); FileOutputStream out = new FileOutputStream(pdf); Resources.copy(Resources.getResource(TikaIndexerTest.class, "enter-the-gradle.pdf"), out); out.close(); dataDir = directory.getAbsolutePath(); } @Test public void pdfIsTransformed() throws IOException { Indexer indexer = mock(Indexer.class); TikaIndexer tikaIndexer = new TikaIndexer(indexer); tikaIndexer.indexDir(dataDir);
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // Path: lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/TikaIndexerTest.java import com.google.common.io.Files; import com.google.common.io.Resources; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.sax.BodyContentHandler; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.xml.sax.SAXException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import static junit.framework.Assert.*; import org.apache.lucene.queryparser.classic.ParseException; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; package de.fhopf.lucenesolrtalk.lucene; public class TikaIndexerTest { private static String dataDir; @BeforeClass public static void copySlides() throws IOException { File directory = Files.createTempDir(); File pdf = new File(directory, "enter-the-gradle.pdf"); FileOutputStream out = new FileOutputStream(pdf); Resources.copy(Resources.getResource(TikaIndexerTest.class, "enter-the-gradle.pdf"), out); out.close(); dataDir = directory.getAbsolutePath(); } @Test public void pdfIsTransformed() throws IOException { Indexer indexer = mock(Indexer.class); TikaIndexer tikaIndexer = new TikaIndexer(indexer); tikaIndexer.indexDir(dataDir);
ArgumentCaptor<Talk> argument = ArgumentCaptor.forClass(Talk.class);
fhopf/lucene-solr-talk
lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/TikaIndexerTest.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // }
import com.google.common.io.Files; import com.google.common.io.Resources; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.sax.BodyContentHandler; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.xml.sax.SAXException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import static junit.framework.Assert.*; import org.apache.lucene.queryparser.classic.ParseException; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify;
package de.fhopf.lucenesolrtalk.lucene; public class TikaIndexerTest { private static String dataDir; @BeforeClass public static void copySlides() throws IOException { File directory = Files.createTempDir(); File pdf = new File(directory, "enter-the-gradle.pdf"); FileOutputStream out = new FileOutputStream(pdf); Resources.copy(Resources.getResource(TikaIndexerTest.class, "enter-the-gradle.pdf"), out); out.close(); dataDir = directory.getAbsolutePath(); } @Test public void pdfIsTransformed() throws IOException { Indexer indexer = mock(Indexer.class); TikaIndexer tikaIndexer = new TikaIndexer(indexer); tikaIndexer.indexDir(dataDir); ArgumentCaptor<Talk> argument = ArgumentCaptor.forClass(Talk.class); verify(indexer).index(argument.capture()); assertEquals("enter-the-gradle.pdf", argument.getValue().title); assertFalse(argument.getValue().content.isEmpty()); } @Test public void gradleIsGroovy() throws ParseException { Directory dir = new RAMDirectory(); Indexer indexer = new Indexer(dir); TikaIndexer tikaIndexer = new TikaIndexer(indexer); tikaIndexer.indexDir(dataDir); Searcher searcher = new Searcher(dir);
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // Path: lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/TikaIndexerTest.java import com.google.common.io.Files; import com.google.common.io.Resources; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.sax.BodyContentHandler; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.xml.sax.SAXException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import static junit.framework.Assert.*; import org.apache.lucene.queryparser.classic.ParseException; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; package de.fhopf.lucenesolrtalk.lucene; public class TikaIndexerTest { private static String dataDir; @BeforeClass public static void copySlides() throws IOException { File directory = Files.createTempDir(); File pdf = new File(directory, "enter-the-gradle.pdf"); FileOutputStream out = new FileOutputStream(pdf); Resources.copy(Resources.getResource(TikaIndexerTest.class, "enter-the-gradle.pdf"), out); out.close(); dataDir = directory.getAbsolutePath(); } @Test public void pdfIsTransformed() throws IOException { Indexer indexer = mock(Indexer.class); TikaIndexer tikaIndexer = new TikaIndexer(indexer); tikaIndexer.indexDir(dataDir); ArgumentCaptor<Talk> argument = ArgumentCaptor.forClass(Talk.class); verify(indexer).index(argument.capture()); assertEquals("enter-the-gradle.pdf", argument.getValue().title); assertFalse(argument.getValue().content.isEmpty()); } @Test public void gradleIsGroovy() throws ParseException { Directory dir = new RAMDirectory(); Indexer indexer = new Indexer(dir); TikaIndexer tikaIndexer = new TikaIndexer(indexer); tikaIndexer.indexDir(dataDir); Searcher searcher = new Searcher(dir);
List<Result> results = searcher.search("Groovy");
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // }
import com.yammer.dropwizard.views.View; import de.fhopf.lucenesolrtalk.Result; import java.util.List;
package de.fhopf.lucenesolrtalk.web; public class SearchResultView extends View { private final Categories categories; private final String query;
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java import com.yammer.dropwizard.views.View; import de.fhopf.lucenesolrtalk.Result; import java.util.List; package de.fhopf.lucenesolrtalk.web; public class SearchResultView extends View { private final Categories categories; private final String query;
private final List<Result> results;
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchSearcher.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // }
import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; import org.elasticsearch.common.text.Text; import org.elasticsearch.index.query.FilterBuilder; import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.facet.FacetBuilders; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacet; import org.elasticsearch.search.facet.terms.TermsFacet; import org.elasticsearch.search.highlight.HighlightField;
package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * Retrieves results from elasticsearch. */ public class ElasticsearchSearcher { private final Client client; static final String INDEX = "jug"; public ElasticsearchSearcher(Client client) { this.client = client; } public SearchResponse search(String token) { return search(token, Collections.<String>emptyList()); }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchSearcher.java import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; import org.elasticsearch.common.text.Text; import org.elasticsearch.index.query.FilterBuilder; import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.facet.FacetBuilders; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacet; import org.elasticsearch.search.facet.terms.TermsFacet; import org.elasticsearch.search.highlight.HighlightField; package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * Retrieves results from elasticsearch. */ public class ElasticsearchSearcher { private final Client client; static final String INDEX = "jug"; public ElasticsearchSearcher(Client client) { this.client = client; } public SearchResponse search(String token) { return search(token, Collections.<String>emptyList()); }
public List<Result> getResults(SearchResponse response) {
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchSearcher.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // }
import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; import org.elasticsearch.common.text.Text; import org.elasticsearch.index.query.FilterBuilder; import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.facet.FacetBuilders; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacet; import org.elasticsearch.search.facet.terms.TermsFacet; import org.elasticsearch.search.highlight.HighlightField;
package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * Retrieves results from elasticsearch. */ public class ElasticsearchSearcher { private final Client client; static final String INDEX = "jug"; public ElasticsearchSearcher(Client client) { this.client = client; } public SearchResponse search(String token) { return search(token, Collections.<String>emptyList()); } public List<Result> getResults(SearchResponse response) { List<Result> results = new ArrayList<>(); for (SearchHit hit : response.getHits()) { Result res = new Result(getTitle(hit), getExcerpt(hit), getCategories(hit), getAuthors(hit), getDate(hit)); results.add(res); } return results; }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchSearcher.java import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; import org.elasticsearch.common.text.Text; import org.elasticsearch.index.query.FilterBuilder; import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.facet.FacetBuilders; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacet; import org.elasticsearch.search.facet.terms.TermsFacet; import org.elasticsearch.search.highlight.HighlightField; package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * Retrieves results from elasticsearch. */ public class ElasticsearchSearcher { private final Client client; static final String INDEX = "jug"; public ElasticsearchSearcher(Client client) { this.client = client; } public SearchResponse search(String token) { return search(token, Collections.<String>emptyList()); } public List<Result> getResults(SearchResponse response) { List<Result> results = new ArrayList<>(); for (SearchHit hit : response.getHits()) { Result res = new Result(getTitle(hit), getExcerpt(hit), getCategories(hit), getAuthors(hit), getDate(hit)); results.add(res); } return results; }
public Faceting getFacets(SearchResponse response) {
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchSearcher.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // }
import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; import org.elasticsearch.common.text.Text; import org.elasticsearch.index.query.FilterBuilder; import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.facet.FacetBuilders; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacet; import org.elasticsearch.search.facet.terms.TermsFacet; import org.elasticsearch.search.highlight.HighlightField;
package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * Retrieves results from elasticsearch. */ public class ElasticsearchSearcher { private final Client client; static final String INDEX = "jug"; public ElasticsearchSearcher(Client client) { this.client = client; } public SearchResponse search(String token) { return search(token, Collections.<String>emptyList()); } public List<Result> getResults(SearchResponse response) { List<Result> results = new ArrayList<>(); for (SearchHit hit : response.getHits()) { Result res = new Result(getTitle(hit), getExcerpt(hit), getCategories(hit), getAuthors(hit), getDate(hit)); results.add(res); } return results; } public Faceting getFacets(SearchResponse response) { return new Faceting(buildFacets(response, "category"), buildFacets(response, "speaker"), buildYearFacets(response, "date"), buildFacets(response, "organizer")); }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/elasticsearch/ElasticsearchSearcher.java import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; import org.elasticsearch.common.text.Text; import org.elasticsearch.index.query.FilterBuilder; import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.facet.FacetBuilders; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacet; import org.elasticsearch.search.facet.terms.TermsFacet; import org.elasticsearch.search.highlight.HighlightField; package de.fhopf.lucenesolrtalk.web.elasticsearch; /** * Retrieves results from elasticsearch. */ public class ElasticsearchSearcher { private final Client client; static final String INDEX = "jug"; public ElasticsearchSearcher(Client client) { this.client = client; } public SearchResponse search(String token) { return search(token, Collections.<String>emptyList()); } public List<Result> getResults(SearchResponse response) { List<Result> results = new ArrayList<>(); for (SearchHit hit : response.getHits()) { Result res = new Result(getTitle(hit), getExcerpt(hit), getCategories(hit), getAuthors(hit), getDate(hit)); results.add(res); } return results; } public Faceting getFacets(SearchResponse response) { return new Faceting(buildFacets(response, "category"), buildFacets(response, "speaker"), buildYearFacets(response, "date"), buildFacets(response, "organizer")); }
private List<Facet> buildFacets(SearchResponse response, String name) {
fhopf/lucene-solr-talk
lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/SearcherTest.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // }
import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.junit.Before; import org.junit.Test; import java.util.*; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import org.apache.lucene.queryparser.classic.ParseException;
package de.fhopf.lucenesolrtalk.lucene; public class SearcherTest { private Indexer indexer; private Searcher searcher; @Before public void initIndexerAndSearcher() { Directory dir = new RAMDirectory(); indexer = new Indexer(dir); searcher = new Searcher(dir); } @Test public void searchAuthor() throws ParseException {
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // Path: lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/SearcherTest.java import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.junit.Before; import org.junit.Test; import java.util.*; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import org.apache.lucene.queryparser.classic.ParseException; package de.fhopf.lucenesolrtalk.lucene; public class SearcherTest { private Indexer indexer; private Searcher searcher; @Before public void initIndexerAndSearcher() { Directory dir = new RAMDirectory(); indexer = new Indexer(dir); searcher = new Searcher(dir); } @Test public void searchAuthor() throws ParseException {
Talk talk1 = newAuthorTalk("Florian Hopf");
fhopf/lucene-solr-talk
lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/SearcherTest.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // }
import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.junit.Before; import org.junit.Test; import java.util.*; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import org.apache.lucene.queryparser.classic.ParseException;
package de.fhopf.lucenesolrtalk.lucene; public class SearcherTest { private Indexer indexer; private Searcher searcher; @Before public void initIndexerAndSearcher() { Directory dir = new RAMDirectory(); indexer = new Indexer(dir); searcher = new Searcher(dir); } @Test public void searchAuthor() throws ParseException { Talk talk1 = newAuthorTalk("Florian Hopf"); Talk talk2 = newAuthorTalk("Florian"); indexer.index(talk1, talk2);
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // Path: lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/SearcherTest.java import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.junit.Before; import org.junit.Test; import java.util.*; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import org.apache.lucene.queryparser.classic.ParseException; package de.fhopf.lucenesolrtalk.lucene; public class SearcherTest { private Indexer indexer; private Searcher searcher; @Before public void initIndexerAndSearcher() { Directory dir = new RAMDirectory(); indexer = new Indexer(dir); searcher = new Searcher(dir); } @Test public void searchAuthor() throws ParseException { Talk talk1 = newAuthorTalk("Florian Hopf"); Talk talk2 = newAuthorTalk("Florian"); indexer.index(talk1, talk2);
List<Result> documents = searcher.search("speaker:Florian");
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearchResult.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // }
import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.List;
package de.fhopf.lucenesolrtalk.web.solr; public class SolrSearchResult { public final List<Result> results;
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearchResult.java import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Faceting; import java.util.List; package de.fhopf.lucenesolrtalk.web.solr; public class SolrSearchResult { public final List<Result> results;
public final Faceting faceting;
fhopf/lucene-solr-talk
elasticsearch-indexer/src/main/java/de/fhopf/lucenesolrtalk/elasticsearch/Indexer.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // }
import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import java.io.File; import java.io.IOException; import java.util.*; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder;
package de.fhopf.lucenesolrtalk.elasticsearch; //import static org.elasticsearch. /** * Indexes files in Solr. */ public class Indexer { static final String INDEX = "jug"; static final String TYPE = "talk"; private final Client client; public Indexer(Client client) { this.client = client; }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // } // Path: elasticsearch-indexer/src/main/java/de/fhopf/lucenesolrtalk/elasticsearch/Indexer.java import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import java.io.File; import java.io.IOException; import java.util.*; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; package de.fhopf.lucenesolrtalk.elasticsearch; //import static org.elasticsearch. /** * Indexes files in Solr. */ public class Indexer { static final String INDEX = "jug"; static final String TYPE = "talk"; private final Client client; public Indexer(Client client) { this.client = client; }
public void index(Collection<Talk> talks) throws IOException {
fhopf/lucene-solr-talk
elasticsearch-indexer/src/main/java/de/fhopf/lucenesolrtalk/elasticsearch/Indexer.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // }
import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import java.io.File; import java.io.IOException; import java.util.*; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder;
} client.admin().indices().prepareCreate(INDEX).execute().actionGet(); // TODO how to make the german analyzer the default? XContentBuilder builder = XContentFactory.jsonBuilder(). startObject(). startObject(TYPE). startObject("properties"). startObject("path").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("title").field("type", "string").field("store", "yes").field("analyzer", "german").endObject(). startObject("category").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("speaker").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("date").field("type", "date").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("content").field("type", "string").field("store", "yes").field("analyzer", "german").field("term_vector", "with_positions_offsets").endObject(). startObject("organizer").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). endObject(). endObject(). endObject(); client.admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(builder).execute().actionGet(); } public static void main(String[] args) throws IOException { if (args.length != 1) { System.out.println("Usage: java " + Indexer.class.getCanonicalName() + " <dataDir>"); System.exit(-1); } List<File> files = Arrays.asList(new File(args[0]).listFiles());
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // } // Path: elasticsearch-indexer/src/main/java/de/fhopf/lucenesolrtalk/elasticsearch/Indexer.java import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import java.io.File; import java.io.IOException; import java.util.*; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; } client.admin().indices().prepareCreate(INDEX).execute().actionGet(); // TODO how to make the german analyzer the default? XContentBuilder builder = XContentFactory.jsonBuilder(). startObject(). startObject(TYPE). startObject("properties"). startObject("path").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("title").field("type", "string").field("store", "yes").field("analyzer", "german").endObject(). startObject("category").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("speaker").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("date").field("type", "date").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("content").field("type", "string").field("store", "yes").field("analyzer", "german").field("term_vector", "with_positions_offsets").endObject(). startObject("organizer").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). endObject(). endObject(). endObject(); client.admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(builder).execute().actionGet(); } public static void main(String[] args) throws IOException { if (args.length != 1) { System.out.println("Usage: java " + Indexer.class.getCanonicalName() + " <dataDir>"); System.exit(-1); } List<File> files = Arrays.asList(new File(args[0]).listFiles());
Collection<Talk> talks = Collections2.transform(files, new TalkFromFile());
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearcher.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // }
import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import java.util.*; import static java.util.Collections.emptyList; import org.apache.solr.client.solrj.response.RangeFacet; import org.apache.solr.common.util.DateUtil;
package de.fhopf.lucenesolrtalk.web.solr; public class SolrSearcher { private final SolrServer solrServer; public SolrSearcher(SolrServer solrServer) { this.solrServer = solrServer; } public List<String> getAllCategories() { return emptyList(); } public SolrSearchResult search(Optional<String> query, Set<String> fq) throws SolrServerException { if (query.isPresent()) { SolrQuery solrQuery = new SolrQuery(query.get()); solrQuery.setRequestHandler("/jugka"); for (String filter : fq) { solrQuery.addFilterQuery(filter); } QueryResponse response = solrServer.query(solrQuery); // TODO move to a function?
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearcher.java import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import java.util.*; import static java.util.Collections.emptyList; import org.apache.solr.client.solrj.response.RangeFacet; import org.apache.solr.common.util.DateUtil; package de.fhopf.lucenesolrtalk.web.solr; public class SolrSearcher { private final SolrServer solrServer; public SolrSearcher(SolrServer solrServer) { this.solrServer = solrServer; } public List<String> getAllCategories() { return emptyList(); } public SolrSearchResult search(Optional<String> query, Set<String> fq) throws SolrServerException { if (query.isPresent()) { SolrQuery solrQuery = new SolrQuery(query.get()); solrQuery.setRequestHandler("/jugka"); for (String filter : fq) { solrQuery.addFilterQuery(filter); } QueryResponse response = solrServer.query(solrQuery); // TODO move to a function?
List<Result> results = new ArrayList<Result>();
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearcher.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // }
import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import java.util.*; import static java.util.Collections.emptyList; import org.apache.solr.client.solrj.response.RangeFacet; import org.apache.solr.common.util.DateUtil;
if (query.isPresent()) { SolrQuery solrQuery = new SolrQuery(query.get()); solrQuery.setRequestHandler("/jugka"); for (String filter : fq) { solrQuery.addFilterQuery(filter); } QueryResponse response = solrServer.query(solrQuery); // TODO move to a function? List<Result> results = new ArrayList<Result>(); for (SolrDocument doc : response.getResults()) { // highlighting is a map from document id to Field<=>Fragment mapping Map<String, List<String>> fragments = Collections.emptyMap(); if (response.getHighlighting() != null) { fragments = response.getHighlighting().get(doc.getFieldValue("path")); } Result result = asResult(doc, fragments); results.add(result); } FacetField categoryFacets = response.getFacetField("category"); FacetField speakerFacets = response.getFacetField("speaker"); FacetField organizerFacets = response.getFacetField("organizer"); RangeFacet.Date dateFacets = null; if (!response.getFacetRanges().isEmpty()) { // there is only one range facet dateFacets = (RangeFacet.Date) response.getFacetRanges().get(0); }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearcher.java import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import java.util.*; import static java.util.Collections.emptyList; import org.apache.solr.client.solrj.response.RangeFacet; import org.apache.solr.common.util.DateUtil; if (query.isPresent()) { SolrQuery solrQuery = new SolrQuery(query.get()); solrQuery.setRequestHandler("/jugka"); for (String filter : fq) { solrQuery.addFilterQuery(filter); } QueryResponse response = solrServer.query(solrQuery); // TODO move to a function? List<Result> results = new ArrayList<Result>(); for (SolrDocument doc : response.getResults()) { // highlighting is a map from document id to Field<=>Fragment mapping Map<String, List<String>> fragments = Collections.emptyMap(); if (response.getHighlighting() != null) { fragments = response.getHighlighting().get(doc.getFieldValue("path")); } Result result = asResult(doc, fragments); results.add(result); } FacetField categoryFacets = response.getFacetField("category"); FacetField speakerFacets = response.getFacetField("speaker"); FacetField organizerFacets = response.getFacetField("organizer"); RangeFacet.Date dateFacets = null; if (!response.getFacetRanges().isEmpty()) { // there is only one range facet dateFacets = (RangeFacet.Date) response.getFacetRanges().get(0); }
Faceting faceting = new Faceting(transform(categoryFacets), transform(speakerFacets), transform(dateFacets), transform(organizerFacets));
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearcher.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // }
import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import java.util.*; import static java.util.Collections.emptyList; import org.apache.solr.client.solrj.response.RangeFacet; import org.apache.solr.common.util.DateUtil;
List<String> contentFragments = fragments.get("content"); String excerpt = ""; if (contentFragments != null && !contentFragments.isEmpty()) { excerpt = join(contentFragments); } return new Result(title, excerpt, categories, speakers, date); } private String join(List<String> tokens) { // TODO use existing helper mehod StringBuilder builder = new StringBuilder(); for (String token : tokens) { builder.append(token); builder.append(" ... "); } return builder.toString(); } private List<String> toStrings(Collection<Object> values) { // TODO add a function List<String> result = new ArrayList<String>(); if (values != null) { for (Object obj : values) { result.add(obj.toString()); } } return result; }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearcher.java import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import java.util.*; import static java.util.Collections.emptyList; import org.apache.solr.client.solrj.response.RangeFacet; import org.apache.solr.common.util.DateUtil; List<String> contentFragments = fragments.get("content"); String excerpt = ""; if (contentFragments != null && !contentFragments.isEmpty()) { excerpt = join(contentFragments); } return new Result(title, excerpt, categories, speakers, date); } private String join(List<String> tokens) { // TODO use existing helper mehod StringBuilder builder = new StringBuilder(); for (String token : tokens) { builder.append(token); builder.append(" ... "); } return builder.toString(); } private List<String> toStrings(Collection<Object> values) { // TODO add a function List<String> result = new ArrayList<String>(); if (values != null) { for (Object obj : values) { result.add(obj.toString()); } } return result; }
private List<Facet> transform(FacetField facetField) {
fhopf/lucene-solr-talk
lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/Searcher.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // }
import com.google.common.base.Joiner; import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.de.GermanAnalyzer; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.Document; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.queryparser.classic.MultiFieldQueryParser; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.*; import org.apache.lucene.search.highlight.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package de.fhopf.lucenesolrtalk.lucene; /** * Searches on an index. * * Note: When used from a webapp this implementation is not as efficient as it should be. On each request it opens * a new IndexReader which can be quite costly. If you are interested in how to implement a SearchManager that takes * care of opening and updating IndexReaders have a look at Chapter 11 of Lucene in Action. */ public class Searcher { private Logger logger = LoggerFactory.getLogger(Searcher.class); private final Directory directory; public Searcher(Directory directory) { this.directory = directory; }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java // public class Result { // // private final String title; // private final String excerpt; // private final List<String> categories; // private final List<String> speakers; // private final Date date; // // public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) { // this.title = title; // this.excerpt = excerpt; // this.categories = categories; // this.speakers = speakers; // this.date = date; // } // // public String getTitle() { // return title; // } // // public String getExcerpt() { // return excerpt; // } // // public List<String> getCategories() { // return categories; // } // // public List<String> getSpeakers() { // return speakers; // } // // public Date getDate() { // return date; // } // } // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/Searcher.java import com.google.common.base.Joiner; import com.google.common.base.Optional; import de.fhopf.lucenesolrtalk.Result; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.de.GermanAnalyzer; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.Document; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.queryparser.classic.MultiFieldQueryParser; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.*; import org.apache.lucene.search.highlight.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package de.fhopf.lucenesolrtalk.lucene; /** * Searches on an index. * * Note: When used from a webapp this implementation is not as efficient as it should be. On each request it opens * a new IndexReader which can be quite costly. If you are interested in how to implement a SearchManager that takes * care of opening and updating IndexReaders have a look at Chapter 11 of Lucene in Action. */ public class Searcher { private Logger logger = LoggerFactory.getLogger(Searcher.class); private final Directory directory; public Searcher(Directory directory) { this.directory = directory; }
private List<Result> search(Query query, Optional<Sort> sort) {
fhopf/lucene-solr-talk
solr-indexer/src/main/java/de/fhopf/lucenesolrtalk/solr/Indexer.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // }
import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import java.io.File; import java.io.IOException; import java.util.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.impl.HttpSolrServer;
package de.fhopf.lucenesolrtalk.solr; /** * Indexes files in Solr. */ public class Indexer { private final SolrServer server; private final Log log = LogFactory.getLog(Indexer.class); public Indexer(SolrServer server) { this.server = server; }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // } // Path: solr-indexer/src/main/java/de/fhopf/lucenesolrtalk/solr/Indexer.java import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import java.io.File; import java.io.IOException; import java.util.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.impl.HttpSolrServer; package de.fhopf.lucenesolrtalk.solr; /** * Indexes files in Solr. */ public class Indexer { private final SolrServer server; private final Log log = LogFactory.getLog(Indexer.class); public Indexer(SolrServer server) { this.server = server; }
public void index(Collection<Talk> talks) throws IOException, SolrServerException {
fhopf/lucene-solr-talk
solr-indexer/src/main/java/de/fhopf/lucenesolrtalk/solr/Indexer.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // }
import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import java.io.File; import java.io.IOException; import java.util.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.impl.HttpSolrServer;
doc.addField("content", talk.content); doc.addField("organizer", talk.organizer); for (String category: talk.categories) { doc.addField("category", category); } for (String speaker: talk.speakers) { doc.addField("speaker", speaker); } docs.add(doc); } server.add(docs); server.commit(); } public void clearIndex() throws SolrServerException, IOException { server.deleteByQuery("*:*"); } public static void main(String [] args) throws IOException, SolrServerException { if (args.length != 2) { System.out.println("Usage: java " + Indexer.class.getCanonicalName() + " <solrUrl> <dataDir>"); System.exit(-1); } SolrServer server = new HttpSolrServer(args[0]); List<File> files = Arrays.asList(new File(args[1]).listFiles());
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // } // Path: solr-indexer/src/main/java/de/fhopf/lucenesolrtalk/solr/Indexer.java import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrInputDocument; import java.io.File; import java.io.IOException; import java.util.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.impl.HttpSolrServer; doc.addField("content", talk.content); doc.addField("organizer", talk.organizer); for (String category: talk.categories) { doc.addField("category", category); } for (String speaker: talk.speakers) { doc.addField("speaker", speaker); } docs.add(doc); } server.add(docs); server.commit(); } public void clearIndex() throws SolrServerException, IOException { server.deleteByQuery("*:*"); } public static void main(String [] args) throws IOException, SolrServerException { if (args.length != 2) { System.out.println("Usage: java " + Indexer.class.getCanonicalName() + " <solrUrl> <dataDir>"); System.exit(-1); } SolrServer server = new HttpSolrServer(args[0]); List<File> files = Arrays.asList(new File(args[1]).listFiles());
Collection<Talk> talks = Collections2.transform(files, new TalkFromFile());
fhopf/lucene-solr-talk
web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearchResource.java
// Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // }
import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.ArrayList; import java.util.List; import org.apache.solr.client.solrj.SolrServerException; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import java.util.Set; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.FacetField.Count;
package de.fhopf.lucenesolrtalk.web.solr; @Path("/solr") @Produces("text/html; charset=utf-8") public class SolrSearchResource { private final SolrSearcher searcher; public SolrSearchResource(SolrSearcher searcher) { this.searcher = searcher; } @GET @Timed
// Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java // public class Facet { // // private final String term; // private final long count; // // private final String fq; // // private Facet(String displayTerm, long count, String fq) { // this.term = displayTerm; // this.count = count; // this.fq = fq; // } // // public static Facet termFacet(String term, long count, String fieldname) { // return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term))); // } // // public static Facet withFilterQuery(String term, long count, String fq) { // return new Facet(term, count, fq); // } // // public String getTerm() { // return term; // } // // public long getCount() { // return count; // } // // public String getFq() { // return fq; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java // public class Faceting { // // private final List<Facet> categoryFacet; // private final List<Facet> speakerFacet; // private final List<Facet> dateFacet; // private final List<Facet> organizerFacet; // // public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) { // this.categoryFacet = categoryFacet; // this.speakerFacet = speakerFacet; // this.dateFacet = dateFacet; // this.organizerFacet = organizerFacet; // } // // public List<Facet> getCategoryFacet() { // return categoryFacet; // } // // public List<Facet> getSpeakerFacet() { // return speakerFacet; // } // // public List<Facet> getDateFacet() { // return dateFacet; // } // // public List<Facet> getOrganizerFacet() { // return organizerFacet; // } // } // // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/SearchResultView.java // public class SearchResultView extends View { // // private final Categories categories; // private final String query; // private final List<Result> results; // private final Faceting faceting; // private final String path; // private String currentQuery; // // public SearchResultView(String path, String query, List<Result> results, Categories categories) { // this(path, query, results, categories, null, null); // } // // public SearchResultView(String path, String query, List<Result> results, Categories categories, Faceting faceting, String currentQuery) { // super("result.fmt"); // this.query = query; // this.results = results; // this.categories = categories; // this.faceting = faceting; // this.currentQuery = currentQuery; // this.path = path; // } // // public Categories getCategories() { // return categories; // } // // public String getQuery() { // return query; // } // // public List<Result> getResults() { // return results; // } // // public Faceting getFaceting() { // return faceting; // } // // public String getPath() { // return path; // } // // public String getCurrentQuery() { // return currentQuery; // } // } // Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearchResource.java import com.google.common.base.Optional; import com.yammer.metrics.annotation.Timed; import de.fhopf.lucenesolrtalk.web.Facet; import de.fhopf.lucenesolrtalk.web.Faceting; import de.fhopf.lucenesolrtalk.web.SearchResultView; import java.util.ArrayList; import java.util.List; import org.apache.solr.client.solrj.SolrServerException; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import java.util.Set; import org.apache.solr.client.solrj.response.FacetField; import org.apache.solr.client.solrj.response.FacetField.Count; package de.fhopf.lucenesolrtalk.web.solr; @Path("/solr") @Produces("text/html; charset=utf-8") public class SolrSearchResource { private final SolrSearcher searcher; public SolrSearchResource(SolrSearcher searcher) { this.searcher = searcher; } @GET @Timed
public SearchResultView search(@QueryParam("query") Optional<String> query, @QueryParam("sort") Optional<String> sort,
fhopf/lucene-solr-talk
lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/Indexer.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // }
import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import org.apache.lucene.analysis.de.GermanAnalyzer; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField;
package de.fhopf.lucenesolrtalk.lucene; /** * Indexes talks in Lucene. */ public class Indexer { private Logger logger = LoggerFactory.getLogger(Indexer.class); private final Directory directory; public Indexer(Directory directory) { this.directory = directory; }
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // } // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/Indexer.java import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import org.apache.lucene.analysis.de.GermanAnalyzer; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; package de.fhopf.lucenesolrtalk.lucene; /** * Indexes talks in Lucene. */ public class Indexer { private Logger logger = LoggerFactory.getLogger(Indexer.class); private final Directory directory; public Indexer(Directory directory) { this.directory = directory; }
public void index(Talk...talks) {
fhopf/lucene-solr-talk
lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/Indexer.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // }
import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import org.apache.lucene.analysis.de.GermanAnalyzer; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField;
IndexWriter writer = null; try { writer = new IndexWriter(directory, config); for (Talk talk: talks) { logger.info(String.format("Indexing talk %s", talk.title)); writer.addDocument(asDocument(talk)); } writer.commit(); } catch (IOException ex) { if (writer != null) { try { writer.rollback(); } catch (IOException e) { e.printStackTrace(); } } } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } public void indexDirectory(String path) { Collection<File> paths = Arrays.asList(new File(path).listFiles());
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/TalkFromFile.java // public class TalkFromFile implements Function<File, Talk> { // // private DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // // @Override // public Talk apply(File input) { // Properties props = read(input); // String speakerValue = props.getProperty("speaker"); // String title = props.getProperty("title"); // String dateValue = props.getProperty("date"); // String contents = props.getProperty("content"); // String categoriesValue = props.getProperty("categories"); // String organizer = props.getProperty("organizer", ""); // // List<String> speakers = Arrays.asList(speakerValue.split(",")); // List<String> categories = Collections.emptyList(); // if (categoriesValue != null) { // categories = Arrays.asList(categoriesValue.split(",")); // } // // // return new Talk(input.getAbsolutePath(), title, speakers, parseDate(dateValue), contents, categories, organizer); // } // // private Date parseDate(String dateValue) { // try { // return format.parse(dateValue); // } catch (ParseException e) { // throw new IllegalStateException(e); // } // } // // private Properties read(File input) { // Properties props = new Properties(); // FileInputStream in = null; // try { // in = new FileInputStream(input); // props.load(in); // } catch (IOException e) { // throw new IllegalStateException(e); // } finally { // if (in != null) { // try { // in.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return props; // } // } // Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/lucene/Indexer.java import com.google.common.collect.Collections2; import de.fhopf.lucenesolrtalk.Talk; import de.fhopf.lucenesolrtalk.TalkFromFile; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import org.apache.lucene.analysis.de.GermanAnalyzer; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; IndexWriter writer = null; try { writer = new IndexWriter(directory, config); for (Talk talk: talks) { logger.info(String.format("Indexing talk %s", talk.title)); writer.addDocument(asDocument(talk)); } writer.commit(); } catch (IOException ex) { if (writer != null) { try { writer.rollback(); } catch (IOException e) { e.printStackTrace(); } } } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } public void indexDirectory(String path) { Collection<File> paths = Arrays.asList(new File(path).listFiles());
Collection<Talk> talks = Collections2.transform(paths, new TalkFromFile());
fhopf/lucene-solr-talk
lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/IndexerTest.java
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // }
import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Version; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import static junit.framework.Assert.assertEquals; import org.apache.lucene.analysis.core.KeywordAnalyzer; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader;
package de.fhopf.lucenesolrtalk.lucene; /** */ public class IndexerTest { private Directory directory; private Indexer indexer; @Before public void initIndexer() { directory = new RAMDirectory(); indexer = new Indexer(directory); } @Test public void twoTalksAreIndexed() throws IOException {
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java // public class Talk { // // public final String path; // public final String title; // public final List<String> speakers; // public final Date date; // public final String content; // public final List<String> categories; // public final String organizer; // // public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) { // this.path = path; // this.title = title; // this.speakers = speakers; // this.date = date; // this.content = content; // this.categories = categories; // this.organizer = organizer; // } // } // Path: lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/IndexerTest.java import de.fhopf.lucenesolrtalk.Talk; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Version; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import static junit.framework.Assert.assertEquals; import org.apache.lucene.analysis.core.KeywordAnalyzer; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; package de.fhopf.lucenesolrtalk.lucene; /** */ public class IndexerTest { private Directory directory; private Indexer indexer; @Before public void initIndexer() { directory = new RAMDirectory(); indexer = new Indexer(directory); } @Test public void twoTalksAreIndexed() throws IOException {
Talk talk1 = new Talk("/path/to/talk1", "Title 1", Arrays.asList("Author 1"), new Date(), "Contents", new ArrayList<String>(), "");
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/barcodeDiscovery/model/BarcodeParameters.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Arguments.java // public interface Arguments { // // // /** // * returns the argument for the given name (-name), or invalid if no argument exists for the given name // * @param sortName String | the name of the argument // * @return GBSargument if any exists for the given name, else GBSaguments.INVALID_ARGUMENT // */ // public Arguments getArgument(String sortName); // // // /** // * // * @return String | the option name of the argument // */ // public String getSortName(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeCollection.java // public class EnzymeCollection { // // // HashSet<Enzyme> enzymeSet = new HashSet(); // // /** // * creates a enzymeCollection from the known system enzymes // */ // public EnzymeCollection(){ // for (Enzyme enzyme : EnzymeEnum.values()){ // this.enzymeSet.add(enzyme); // } // } // // /** // * creates a new enzymeCollection from the given enzymes + the neutral enzyme // * @param enzymeCollection collection of enzymes // */ // public EnzymeCollection(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // this.enzymeSet.add(this.getNeutralEnzyme()); // } // // /** // * adds all given enzymes to the collection // * @param enzymeCollection | collection of enzymes // */ // public void addEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet.addAll(enzymeCollection); // } // // /** // * replaces the enzymes from this collection with the new collection // * @param enzymeCollection | collection of enzymes // */ // public void replaceEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // } // // /** // * // * @return a Collection of all known enzymes // */ // public Collection<Enzyme> getAllEnzymes(){ // return this.enzymeSet; // } // // /** // * // * @param name String | the name of the enzyme // * @return Enzyme | the enzyme with the given name // */ // public Enzyme getEnzyme(String name){ // for (Enzyme enzyme : this.enzymeSet){ // if (enzyme.getName().toLowerCase().equals(name.toLowerCase())){ // return enzyme; // } // } // return EnzymeEnum.NAN; // } // // /** // * returns the neutral NAN enzyme // * @return Enzyme | a neutral nan enzyme // * @see EnzymeEnum#NAN // */ // public Enzyme getNeutralEnzyme(){ // return EnzymeEnum.NAN; // } // // // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Parameters.java // public interface Parameters { // // // /** // * // * @param argument // * @return true if the given argument is a parameter // */ // public boolean containsParameter(Arguments argument); // // /** // * // * @param argument // * @return the asked argument as a String // */ // public String getParameter(Arguments argument); // // /** // * adds the given parameter for the given argument // * @param argument | the argument // * @param parameter String | the parameter // * @throws RuntimeException when the given argument is an invalid argument // */ // public void setParameter(Arguments argument, String parameter); // // /** // * checks if all required parameters are set // * @return the String "All values are set" if all required parameters are set, else an error message // */ // public boolean areRequiredParametersSet(); // // /** // * checks if all required parameters are set // * @return the boolean true if all required parameters are set // */ // public String getErrorRequiredParametersSet(); // // /** // * configures a log file for all known parameters // * @return String to put in the log file // */ // public String getParametersLogString(); // // /** // * makes a help for all known parameters // * @return String | the help page // */ // public String getParametersHelp(); // // /** // * // * @return String | the output directory of the tool // */ // public String getOutputDirectory(); // }
import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Arguments; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeCollection; import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Parameters; import java.util.Collection; import java.util.HashMap;
/** * checks if all required parameters are set * @return the String "All values are set" if all required parameters are set, else an error message */ @Override public String getErrorRequiredParametersSet(){ String error = ""; if (! this.arguments.containsKey(BarcodeArguments.FILENAME1)){ error += "Value required for option " + BarcodeArguments.FILENAME1.getSortName() + "\n"; } if (error.equals("")){ error = "All values are set"; } return error; } /** * checks if all required parameters are set * @return the boolean true if all required parameters are set */ @Override public boolean areRequiredParametersSet(){ if (! this.arguments.containsKey(BarcodeArguments.FILENAME1)){ return false; } return true; } @Override
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Arguments.java // public interface Arguments { // // // /** // * returns the argument for the given name (-name), or invalid if no argument exists for the given name // * @param sortName String | the name of the argument // * @return GBSargument if any exists for the given name, else GBSaguments.INVALID_ARGUMENT // */ // public Arguments getArgument(String sortName); // // // /** // * // * @return String | the option name of the argument // */ // public String getSortName(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeCollection.java // public class EnzymeCollection { // // // HashSet<Enzyme> enzymeSet = new HashSet(); // // /** // * creates a enzymeCollection from the known system enzymes // */ // public EnzymeCollection(){ // for (Enzyme enzyme : EnzymeEnum.values()){ // this.enzymeSet.add(enzyme); // } // } // // /** // * creates a new enzymeCollection from the given enzymes + the neutral enzyme // * @param enzymeCollection collection of enzymes // */ // public EnzymeCollection(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // this.enzymeSet.add(this.getNeutralEnzyme()); // } // // /** // * adds all given enzymes to the collection // * @param enzymeCollection | collection of enzymes // */ // public void addEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet.addAll(enzymeCollection); // } // // /** // * replaces the enzymes from this collection with the new collection // * @param enzymeCollection | collection of enzymes // */ // public void replaceEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // } // // /** // * // * @return a Collection of all known enzymes // */ // public Collection<Enzyme> getAllEnzymes(){ // return this.enzymeSet; // } // // /** // * // * @param name String | the name of the enzyme // * @return Enzyme | the enzyme with the given name // */ // public Enzyme getEnzyme(String name){ // for (Enzyme enzyme : this.enzymeSet){ // if (enzyme.getName().toLowerCase().equals(name.toLowerCase())){ // return enzyme; // } // } // return EnzymeEnum.NAN; // } // // /** // * returns the neutral NAN enzyme // * @return Enzyme | a neutral nan enzyme // * @see EnzymeEnum#NAN // */ // public Enzyme getNeutralEnzyme(){ // return EnzymeEnum.NAN; // } // // // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Parameters.java // public interface Parameters { // // // /** // * // * @param argument // * @return true if the given argument is a parameter // */ // public boolean containsParameter(Arguments argument); // // /** // * // * @param argument // * @return the asked argument as a String // */ // public String getParameter(Arguments argument); // // /** // * adds the given parameter for the given argument // * @param argument | the argument // * @param parameter String | the parameter // * @throws RuntimeException when the given argument is an invalid argument // */ // public void setParameter(Arguments argument, String parameter); // // /** // * checks if all required parameters are set // * @return the String "All values are set" if all required parameters are set, else an error message // */ // public boolean areRequiredParametersSet(); // // /** // * checks if all required parameters are set // * @return the boolean true if all required parameters are set // */ // public String getErrorRequiredParametersSet(); // // /** // * configures a log file for all known parameters // * @return String to put in the log file // */ // public String getParametersLogString(); // // /** // * makes a help for all known parameters // * @return String | the help page // */ // public String getParametersHelp(); // // /** // * // * @return String | the output directory of the tool // */ // public String getOutputDirectory(); // } // Path: src/be/uzleuven/gc/logistics/GBSX/barcodeDiscovery/model/BarcodeParameters.java import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Arguments; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeCollection; import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Parameters; import java.util.Collection; import java.util.HashMap; /** * checks if all required parameters are set * @return the String "All values are set" if all required parameters are set, else an error message */ @Override public String getErrorRequiredParametersSet(){ String error = ""; if (! this.arguments.containsKey(BarcodeArguments.FILENAME1)){ error += "Value required for option " + BarcodeArguments.FILENAME1.getSortName() + "\n"; } if (error.equals("")){ error = "All values are set"; } return error; } /** * checks if all required parameters are set * @return the boolean true if all required parameters are set */ @Override public boolean areRequiredParametersSet(){ if (! this.arguments.containsKey(BarcodeArguments.FILENAME1)){ return false; } return true; } @Override
public boolean containsParameter(Arguments argument) {
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/barcodeDiscovery/model/BarcodeParameters.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Arguments.java // public interface Arguments { // // // /** // * returns the argument for the given name (-name), or invalid if no argument exists for the given name // * @param sortName String | the name of the argument // * @return GBSargument if any exists for the given name, else GBSaguments.INVALID_ARGUMENT // */ // public Arguments getArgument(String sortName); // // // /** // * // * @return String | the option name of the argument // */ // public String getSortName(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeCollection.java // public class EnzymeCollection { // // // HashSet<Enzyme> enzymeSet = new HashSet(); // // /** // * creates a enzymeCollection from the known system enzymes // */ // public EnzymeCollection(){ // for (Enzyme enzyme : EnzymeEnum.values()){ // this.enzymeSet.add(enzyme); // } // } // // /** // * creates a new enzymeCollection from the given enzymes + the neutral enzyme // * @param enzymeCollection collection of enzymes // */ // public EnzymeCollection(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // this.enzymeSet.add(this.getNeutralEnzyme()); // } // // /** // * adds all given enzymes to the collection // * @param enzymeCollection | collection of enzymes // */ // public void addEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet.addAll(enzymeCollection); // } // // /** // * replaces the enzymes from this collection with the new collection // * @param enzymeCollection | collection of enzymes // */ // public void replaceEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // } // // /** // * // * @return a Collection of all known enzymes // */ // public Collection<Enzyme> getAllEnzymes(){ // return this.enzymeSet; // } // // /** // * // * @param name String | the name of the enzyme // * @return Enzyme | the enzyme with the given name // */ // public Enzyme getEnzyme(String name){ // for (Enzyme enzyme : this.enzymeSet){ // if (enzyme.getName().toLowerCase().equals(name.toLowerCase())){ // return enzyme; // } // } // return EnzymeEnum.NAN; // } // // /** // * returns the neutral NAN enzyme // * @return Enzyme | a neutral nan enzyme // * @see EnzymeEnum#NAN // */ // public Enzyme getNeutralEnzyme(){ // return EnzymeEnum.NAN; // } // // // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Parameters.java // public interface Parameters { // // // /** // * // * @param argument // * @return true if the given argument is a parameter // */ // public boolean containsParameter(Arguments argument); // // /** // * // * @param argument // * @return the asked argument as a String // */ // public String getParameter(Arguments argument); // // /** // * adds the given parameter for the given argument // * @param argument | the argument // * @param parameter String | the parameter // * @throws RuntimeException when the given argument is an invalid argument // */ // public void setParameter(Arguments argument, String parameter); // // /** // * checks if all required parameters are set // * @return the String "All values are set" if all required parameters are set, else an error message // */ // public boolean areRequiredParametersSet(); // // /** // * checks if all required parameters are set // * @return the boolean true if all required parameters are set // */ // public String getErrorRequiredParametersSet(); // // /** // * configures a log file for all known parameters // * @return String to put in the log file // */ // public String getParametersLogString(); // // /** // * makes a help for all known parameters // * @return String | the help page // */ // public String getParametersHelp(); // // /** // * // * @return String | the output directory of the tool // */ // public String getOutputDirectory(); // }
import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Arguments; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeCollection; import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Parameters; import java.util.Collection; import java.util.HashMap;
}else{ return false; } } /** * * @return String | the location of the output directory */ public String getOutputDirectory(){ return this.arguments.get(BarcodeArguments.OUTPUT_DIRECTORY); } /** * * @return true if the enzyme must also be found */ public boolean mustSearchEnzyme(){ if (this.getParameter(BarcodeArguments.FIND_ENZYME).toLowerCase().equals("true")){ return true; }else{ return false; } } /** * * @return a Collection of all known enzymes * @see EnzymeCollection#getAllEnzymes() */
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Arguments.java // public interface Arguments { // // // /** // * returns the argument for the given name (-name), or invalid if no argument exists for the given name // * @param sortName String | the name of the argument // * @return GBSargument if any exists for the given name, else GBSaguments.INVALID_ARGUMENT // */ // public Arguments getArgument(String sortName); // // // /** // * // * @return String | the option name of the argument // */ // public String getSortName(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeCollection.java // public class EnzymeCollection { // // // HashSet<Enzyme> enzymeSet = new HashSet(); // // /** // * creates a enzymeCollection from the known system enzymes // */ // public EnzymeCollection(){ // for (Enzyme enzyme : EnzymeEnum.values()){ // this.enzymeSet.add(enzyme); // } // } // // /** // * creates a new enzymeCollection from the given enzymes + the neutral enzyme // * @param enzymeCollection collection of enzymes // */ // public EnzymeCollection(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // this.enzymeSet.add(this.getNeutralEnzyme()); // } // // /** // * adds all given enzymes to the collection // * @param enzymeCollection | collection of enzymes // */ // public void addEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet.addAll(enzymeCollection); // } // // /** // * replaces the enzymes from this collection with the new collection // * @param enzymeCollection | collection of enzymes // */ // public void replaceEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // } // // /** // * // * @return a Collection of all known enzymes // */ // public Collection<Enzyme> getAllEnzymes(){ // return this.enzymeSet; // } // // /** // * // * @param name String | the name of the enzyme // * @return Enzyme | the enzyme with the given name // */ // public Enzyme getEnzyme(String name){ // for (Enzyme enzyme : this.enzymeSet){ // if (enzyme.getName().toLowerCase().equals(name.toLowerCase())){ // return enzyme; // } // } // return EnzymeEnum.NAN; // } // // /** // * returns the neutral NAN enzyme // * @return Enzyme | a neutral nan enzyme // * @see EnzymeEnum#NAN // */ // public Enzyme getNeutralEnzyme(){ // return EnzymeEnum.NAN; // } // // // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Parameters.java // public interface Parameters { // // // /** // * // * @param argument // * @return true if the given argument is a parameter // */ // public boolean containsParameter(Arguments argument); // // /** // * // * @param argument // * @return the asked argument as a String // */ // public String getParameter(Arguments argument); // // /** // * adds the given parameter for the given argument // * @param argument | the argument // * @param parameter String | the parameter // * @throws RuntimeException when the given argument is an invalid argument // */ // public void setParameter(Arguments argument, String parameter); // // /** // * checks if all required parameters are set // * @return the String "All values are set" if all required parameters are set, else an error message // */ // public boolean areRequiredParametersSet(); // // /** // * checks if all required parameters are set // * @return the boolean true if all required parameters are set // */ // public String getErrorRequiredParametersSet(); // // /** // * configures a log file for all known parameters // * @return String to put in the log file // */ // public String getParametersLogString(); // // /** // * makes a help for all known parameters // * @return String | the help page // */ // public String getParametersHelp(); // // /** // * // * @return String | the output directory of the tool // */ // public String getOutputDirectory(); // } // Path: src/be/uzleuven/gc/logistics/GBSX/barcodeDiscovery/model/BarcodeParameters.java import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Arguments; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeCollection; import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Parameters; import java.util.Collection; import java.util.HashMap; }else{ return false; } } /** * * @return String | the location of the output directory */ public String getOutputDirectory(){ return this.arguments.get(BarcodeArguments.OUTPUT_DIRECTORY); } /** * * @return true if the enzyme must also be found */ public boolean mustSearchEnzyme(){ if (this.getParameter(BarcodeArguments.FIND_ENZYME).toLowerCase().equals("true")){ return true; }else{ return false; } } /** * * @return a Collection of all known enzymes * @see EnzymeCollection#getAllEnzymes() */
public Collection<Enzyme> getAllEnzymes(){
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaPairBufferedReader.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // }
import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger;
/* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.fasta.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class FastaPairBufferedReader { private FastaBufferedReader fastaBufferedReader1; private FastaBufferedReader fastaBufferedReader2; private ReentrantLock lock = new ReentrantLock(); /** * creates 2 new FastaBufferedReader of the given files. * @param fileRead1 | the file for read 1 * @param fileRead2 | the file for read 2 * @param ziped | boolean if the fastq file is ziped (gz) * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaPairBufferedReader(File fileRead1, File fileRead2, boolean ziped) throws FileNotFoundException, IOException{ this.fastaBufferedReader1 = new FastaBufferedReader(fileRead1, ziped); this.fastaBufferedReader2 = new FastaBufferedReader(fileRead2, ziped); } /** * reads the next lines in the fasta file. and returns it as an fastaread * @return null if there are no fasta files anymore, else a FastaRead * @throws IOException | if any error occures while reading the file */
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaPairBufferedReader.java import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; /* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.fasta.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class FastaPairBufferedReader { private FastaBufferedReader fastaBufferedReader1; private FastaBufferedReader fastaBufferedReader2; private ReentrantLock lock = new ReentrantLock(); /** * creates 2 new FastaBufferedReader of the given files. * @param fileRead1 | the file for read 1 * @param fileRead2 | the file for read 2 * @param ziped | boolean if the fastq file is ziped (gz) * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaPairBufferedReader(File fileRead1, File fileRead2, boolean ziped) throws FileNotFoundException, IOException{ this.fastaBufferedReader1 = new FastaBufferedReader(fileRead1, ziped); this.fastaBufferedReader2 = new FastaBufferedReader(fileRead2, ziped); } /** * reads the next lines in the fasta file. and returns it as an fastaread * @return null if there are no fasta files anymore, else a FastaRead * @throws IOException | if any error occures while reading the file */
public HashMap<String, FastaRead> next() throws IOException{
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaBufferedWriter.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // }
import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.BufferedWriter; import java.io.DataOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.net.URL; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.GZIPOutputStream;
*/ public FastaBufferedWriter(URL url, boolean ziped) throws FileNotFoundException, IOException{ if (ziped){ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(url.getPath())))); }else{ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new DataOutputStream(new FileOutputStream(url.getPath())))); } } /** * creates a new FastaBufferedReader of the given URL. * @param url | the URL of the file that must be writen * @param ziped | true if the file must be zipped * @param append | true if append to existing file * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaBufferedWriter(URL url, boolean ziped, boolean append) throws FileNotFoundException, IOException{ if (ziped){ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(url.getPath(), append)))); }else{ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new DataOutputStream(new FileOutputStream(url.getPath(), append)))); } } /** * writes the next lines in the fasta file. * @param fasta | a fastaRead * @throws IOException | if any error occures while writing the file */
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaBufferedWriter.java import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.BufferedWriter; import java.io.DataOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.net.URL; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.GZIPOutputStream; */ public FastaBufferedWriter(URL url, boolean ziped) throws FileNotFoundException, IOException{ if (ziped){ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(url.getPath())))); }else{ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new DataOutputStream(new FileOutputStream(url.getPath())))); } } /** * creates a new FastaBufferedReader of the given URL. * @param url | the URL of the file that must be writen * @param ziped | true if the file must be zipped * @param append | true if append to existing file * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaBufferedWriter(URL url, boolean ziped, boolean append) throws FileNotFoundException, IOException{ if (ziped){ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(url.getPath(), append)))); }else{ this.fastaBufferedWriter = new BufferedWriter(new OutputStreamWriter(new DataOutputStream(new FileOutputStream(url.getPath(), append)))); } } /** * writes the next lines in the fasta file. * @param fasta | a fastaRead * @throws IOException | if any error occures while writing the file */
public void write(FastaRead fasta) throws IOException{
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/infrastructure/EnzymeFileParser.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeClass.java // public class EnzymeClass implements Enzyme{ // // // private String name; // private String[] initialCutSiteRemnants; // // /** // * creates a new Enzyme from the name and the cut sites (as String array) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants String[] | all the cut sites // */ // public EnzymeClass(String name, String[] initialCutSiteRemnants){ // this.name = name; // for (int i = 0; i < initialCutSiteRemnants.length; i++){ // initialCutSiteRemnants[i] = initialCutSiteRemnants[i].toUpperCase(); // } // this.initialCutSiteRemnants = initialCutSiteRemnants; // } // // /** // * creates a new Enzyme from the name and the cut sites (as a collection) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants collection of String | all the cut sites // */ // public EnzymeClass(String name, Collection<String> initialCutSiteRemnants){ // this.name = name; // this.initialCutSiteRemnants = (String[]) initialCutSiteRemnants.toArray(); // for (int i = 0; i < this.initialCutSiteRemnants.length; i++){ // this.initialCutSiteRemnants[i] = this.initialCutSiteRemnants[i].toUpperCase(); // } // } // // /** // * // * @return String | the name of the Enzyme // */ // public String getName() { // return this.name; // } // // /** // * returns all cutsites // * @return Collection of String | all the cutsites of the enzyme in a collection // */ // public Collection<String> getInitialCutSiteRemnant(){ // HashSet<String> cutsitesSet = new HashSet(); // cutsitesSet.addAll(Arrays.asList(this.initialCutSiteRemnants)); // return cutsitesSet; // } // // /** // * returns all complement cutsites // * @return Collection of String | all the complement cutsites of the enzyme in a collection // */ // public Collection<String> getComplementCutSiteRemnant() { // HashSet<String> cutsitesSet = new HashSet(); // for (String cutsite : this.initialCutSiteRemnants){ // cutsitesSet.add(BasePair.getComplementSequence(cutsite)); // } // return cutsitesSet; // } // // }
import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeClass; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList;
/* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.enzyme.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class EnzymeFileParser { public EnzymeFileParser(){ } /** * opens the given file and search all samples * <br> the file has no header, and the following columns: * <br> enzyme name * <br> cutsites (comma separated) * @param filename String | the name of the file * @return an arrayList of all samples found in the file. Non found enzymes are skiped * @throws FileNotFoundException * @throws IOException */
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeClass.java // public class EnzymeClass implements Enzyme{ // // // private String name; // private String[] initialCutSiteRemnants; // // /** // * creates a new Enzyme from the name and the cut sites (as String array) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants String[] | all the cut sites // */ // public EnzymeClass(String name, String[] initialCutSiteRemnants){ // this.name = name; // for (int i = 0; i < initialCutSiteRemnants.length; i++){ // initialCutSiteRemnants[i] = initialCutSiteRemnants[i].toUpperCase(); // } // this.initialCutSiteRemnants = initialCutSiteRemnants; // } // // /** // * creates a new Enzyme from the name and the cut sites (as a collection) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants collection of String | all the cut sites // */ // public EnzymeClass(String name, Collection<String> initialCutSiteRemnants){ // this.name = name; // this.initialCutSiteRemnants = (String[]) initialCutSiteRemnants.toArray(); // for (int i = 0; i < this.initialCutSiteRemnants.length; i++){ // this.initialCutSiteRemnants[i] = this.initialCutSiteRemnants[i].toUpperCase(); // } // } // // /** // * // * @return String | the name of the Enzyme // */ // public String getName() { // return this.name; // } // // /** // * returns all cutsites // * @return Collection of String | all the cutsites of the enzyme in a collection // */ // public Collection<String> getInitialCutSiteRemnant(){ // HashSet<String> cutsitesSet = new HashSet(); // cutsitesSet.addAll(Arrays.asList(this.initialCutSiteRemnants)); // return cutsitesSet; // } // // /** // * returns all complement cutsites // * @return Collection of String | all the complement cutsites of the enzyme in a collection // */ // public Collection<String> getComplementCutSiteRemnant() { // HashSet<String> cutsitesSet = new HashSet(); // for (String cutsite : this.initialCutSiteRemnants){ // cutsitesSet.add(BasePair.getComplementSequence(cutsite)); // } // return cutsitesSet; // } // // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/infrastructure/EnzymeFileParser.java import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeClass; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; /* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.enzyme.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class EnzymeFileParser { public EnzymeFileParser(){ } /** * opens the given file and search all samples * <br> the file has no header, and the following columns: * <br> enzyme name * <br> cutsites (comma separated) * @param filename String | the name of the file * @return an arrayList of all samples found in the file. Non found enzymes are skiped * @throws FileNotFoundException * @throws IOException */
public ArrayList<Enzyme> parseEnzymeFile(String filename) throws FileNotFoundException, IOException{
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/infrastructure/EnzymeFileParser.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeClass.java // public class EnzymeClass implements Enzyme{ // // // private String name; // private String[] initialCutSiteRemnants; // // /** // * creates a new Enzyme from the name and the cut sites (as String array) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants String[] | all the cut sites // */ // public EnzymeClass(String name, String[] initialCutSiteRemnants){ // this.name = name; // for (int i = 0; i < initialCutSiteRemnants.length; i++){ // initialCutSiteRemnants[i] = initialCutSiteRemnants[i].toUpperCase(); // } // this.initialCutSiteRemnants = initialCutSiteRemnants; // } // // /** // * creates a new Enzyme from the name and the cut sites (as a collection) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants collection of String | all the cut sites // */ // public EnzymeClass(String name, Collection<String> initialCutSiteRemnants){ // this.name = name; // this.initialCutSiteRemnants = (String[]) initialCutSiteRemnants.toArray(); // for (int i = 0; i < this.initialCutSiteRemnants.length; i++){ // this.initialCutSiteRemnants[i] = this.initialCutSiteRemnants[i].toUpperCase(); // } // } // // /** // * // * @return String | the name of the Enzyme // */ // public String getName() { // return this.name; // } // // /** // * returns all cutsites // * @return Collection of String | all the cutsites of the enzyme in a collection // */ // public Collection<String> getInitialCutSiteRemnant(){ // HashSet<String> cutsitesSet = new HashSet(); // cutsitesSet.addAll(Arrays.asList(this.initialCutSiteRemnants)); // return cutsitesSet; // } // // /** // * returns all complement cutsites // * @return Collection of String | all the complement cutsites of the enzyme in a collection // */ // public Collection<String> getComplementCutSiteRemnant() { // HashSet<String> cutsitesSet = new HashSet(); // for (String cutsite : this.initialCutSiteRemnants){ // cutsitesSet.add(BasePair.getComplementSequence(cutsite)); // } // return cutsitesSet; // } // // }
import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeClass; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList;
/* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.enzyme.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class EnzymeFileParser { public EnzymeFileParser(){ } /** * opens the given file and search all samples * <br> the file has no header, and the following columns: * <br> enzyme name * <br> cutsites (comma separated) * @param filename String | the name of the file * @return an arrayList of all samples found in the file. Non found enzymes are skiped * @throws FileNotFoundException * @throws IOException */ public ArrayList<Enzyme> parseEnzymeFile(String filename) throws FileNotFoundException, IOException{ ArrayList<Enzyme> enzymeArrayList = new ArrayList(); File file = new File(filename); BufferedReader reader = new BufferedReader(new FileReader(file)); String line; while ((line = reader.readLine()) != null){ String[] splitedLine = line.split("\t"); String enzymeName = splitedLine[0]; String[] cutsites = splitedLine[1].split(",");
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeClass.java // public class EnzymeClass implements Enzyme{ // // // private String name; // private String[] initialCutSiteRemnants; // // /** // * creates a new Enzyme from the name and the cut sites (as String array) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants String[] | all the cut sites // */ // public EnzymeClass(String name, String[] initialCutSiteRemnants){ // this.name = name; // for (int i = 0; i < initialCutSiteRemnants.length; i++){ // initialCutSiteRemnants[i] = initialCutSiteRemnants[i].toUpperCase(); // } // this.initialCutSiteRemnants = initialCutSiteRemnants; // } // // /** // * creates a new Enzyme from the name and the cut sites (as a collection) // * @param name String | the name of the Enzyme // * @param initialCutSiteRemnants collection of String | all the cut sites // */ // public EnzymeClass(String name, Collection<String> initialCutSiteRemnants){ // this.name = name; // this.initialCutSiteRemnants = (String[]) initialCutSiteRemnants.toArray(); // for (int i = 0; i < this.initialCutSiteRemnants.length; i++){ // this.initialCutSiteRemnants[i] = this.initialCutSiteRemnants[i].toUpperCase(); // } // } // // /** // * // * @return String | the name of the Enzyme // */ // public String getName() { // return this.name; // } // // /** // * returns all cutsites // * @return Collection of String | all the cutsites of the enzyme in a collection // */ // public Collection<String> getInitialCutSiteRemnant(){ // HashSet<String> cutsitesSet = new HashSet(); // cutsitesSet.addAll(Arrays.asList(this.initialCutSiteRemnants)); // return cutsitesSet; // } // // /** // * returns all complement cutsites // * @return Collection of String | all the complement cutsites of the enzyme in a collection // */ // public Collection<String> getComplementCutSiteRemnant() { // HashSet<String> cutsitesSet = new HashSet(); // for (String cutsite : this.initialCutSiteRemnants){ // cutsitesSet.add(BasePair.getComplementSequence(cutsite)); // } // return cutsitesSet; // } // // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/infrastructure/EnzymeFileParser.java import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeClass; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; /* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.enzyme.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class EnzymeFileParser { public EnzymeFileParser(){ } /** * opens the given file and search all samples * <br> the file has no header, and the following columns: * <br> enzyme name * <br> cutsites (comma separated) * @param filename String | the name of the file * @return an arrayList of all samples found in the file. Non found enzymes are skiped * @throws FileNotFoundException * @throws IOException */ public ArrayList<Enzyme> parseEnzymeFile(String filename) throws FileNotFoundException, IOException{ ArrayList<Enzyme> enzymeArrayList = new ArrayList(); File file = new File(filename); BufferedReader reader = new BufferedReader(new FileReader(file)); String line; while ((line = reader.readLine()) != null){ String[] splitedLine = line.split("\t"); String enzymeName = splitedLine[0]; String[] cutsites = splitedLine[1].split(",");
EnzymeClass enzymeClass = new EnzymeClass(enzymeName, cutsites);
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaPairBufferedWriter.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // }
import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger;
/* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.fasta.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class FastaPairBufferedWriter { private FastaBufferedWriter fastaBufferedWriter1; private FastaBufferedWriter fastaBufferedWriter2; private ReentrantLock lock = new ReentrantLock(); /** * creates 2 new FastaBufferedWriter of the given files. * @param fileRead1 | the file for read 1 * @param fileRead2 | the file for read 2 * @param ziped | boolean if the fasta file is ziped (gz) * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaPairBufferedWriter(File fileRead1, File fileRead2, boolean ziped) throws FileNotFoundException, IOException{ this.fastaBufferedWriter1 = new FastaBufferedWriter(fileRead1, ziped); this.fastaBufferedWriter2 = new FastaBufferedWriter(fileRead2, ziped); } /** * reads the next lines in the fasta file. and returns it as an fastaread * @return null if there are no fasta files anymore, else a FastqRead * @throws IOException | if any error occures while reading the file */
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaPairBufferedWriter.java import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; /* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.fasta.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class FastaPairBufferedWriter { private FastaBufferedWriter fastaBufferedWriter1; private FastaBufferedWriter fastaBufferedWriter2; private ReentrantLock lock = new ReentrantLock(); /** * creates 2 new FastaBufferedWriter of the given files. * @param fileRead1 | the file for read 1 * @param fileRead2 | the file for read 2 * @param ziped | boolean if the fasta file is ziped (gz) * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaPairBufferedWriter(File fileRead1, File fileRead2, boolean ziped) throws FileNotFoundException, IOException{ this.fastaBufferedWriter1 = new FastaBufferedWriter(fileRead1, ziped); this.fastaBufferedWriter2 = new FastaBufferedWriter(fileRead2, ziped); } /** * reads the next lines in the fasta file. and returns it as an fastaread * @return null if there are no fasta files anymore, else a FastqRead * @throws IOException | if any error occures while reading the file */
public void write(FastaRead fastaRead1, FastaRead fastaRead2) throws IOException{
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/sampleBarcodeEnzyme/model/Sample.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // }
import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import java.util.Collection; import java.util.HashSet; import java.util.regex.Matcher; import java.util.regex.Pattern;
/* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.sampleBarcodeEnzyme.model; /** * * @author Koen Herten for the KU Leuven */ public class Sample implements Comparable<Sample> { private final String sampleID;
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/sampleBarcodeEnzyme/model/Sample.java import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import java.util.Collection; import java.util.HashSet; import java.util.regex.Matcher; import java.util.regex.Pattern; /* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.sampleBarcodeEnzyme.model; /** * * @author Koen Herten for the KU Leuven */ public class Sample implements Comparable<Sample> { private final String sampleID;
private final Enzyme enzyme;
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/barcodeCorrector/model/BarcodeCorrectorParameters.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Arguments.java // public interface Arguments { // // // /** // * returns the argument for the given name (-name), or invalid if no argument exists for the given name // * @param sortName String | the name of the argument // * @return GBSargument if any exists for the given name, else GBSaguments.INVALID_ARGUMENT // */ // public Arguments getArgument(String sortName); // // // /** // * // * @return String | the option name of the argument // */ // public String getSortName(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeCollection.java // public class EnzymeCollection { // // // HashSet<Enzyme> enzymeSet = new HashSet(); // // /** // * creates a enzymeCollection from the known system enzymes // */ // public EnzymeCollection(){ // for (Enzyme enzyme : EnzymeEnum.values()){ // this.enzymeSet.add(enzyme); // } // } // // /** // * creates a new enzymeCollection from the given enzymes + the neutral enzyme // * @param enzymeCollection collection of enzymes // */ // public EnzymeCollection(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // this.enzymeSet.add(this.getNeutralEnzyme()); // } // // /** // * adds all given enzymes to the collection // * @param enzymeCollection | collection of enzymes // */ // public void addEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet.addAll(enzymeCollection); // } // // /** // * replaces the enzymes from this collection with the new collection // * @param enzymeCollection | collection of enzymes // */ // public void replaceEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // } // // /** // * // * @return a Collection of all known enzymes // */ // public Collection<Enzyme> getAllEnzymes(){ // return this.enzymeSet; // } // // /** // * // * @param name String | the name of the enzyme // * @return Enzyme | the enzyme with the given name // */ // public Enzyme getEnzyme(String name){ // for (Enzyme enzyme : this.enzymeSet){ // if (enzyme.getName().toLowerCase().equals(name.toLowerCase())){ // return enzyme; // } // } // return EnzymeEnum.NAN; // } // // /** // * returns the neutral NAN enzyme // * @return Enzyme | a neutral nan enzyme // * @see EnzymeEnum#NAN // */ // public Enzyme getNeutralEnzyme(){ // return EnzymeEnum.NAN; // } // // // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Parameters.java // public interface Parameters { // // // /** // * // * @param argument // * @return true if the given argument is a parameter // */ // public boolean containsParameter(Arguments argument); // // /** // * // * @param argument // * @return the asked argument as a String // */ // public String getParameter(Arguments argument); // // /** // * adds the given parameter for the given argument // * @param argument | the argument // * @param parameter String | the parameter // * @throws RuntimeException when the given argument is an invalid argument // */ // public void setParameter(Arguments argument, String parameter); // // /** // * checks if all required parameters are set // * @return the String "All values are set" if all required parameters are set, else an error message // */ // public boolean areRequiredParametersSet(); // // /** // * checks if all required parameters are set // * @return the boolean true if all required parameters are set // */ // public String getErrorRequiredParametersSet(); // // /** // * configures a log file for all known parameters // * @return String to put in the log file // */ // public String getParametersLogString(); // // /** // * makes a help for all known parameters // * @return String | the help page // */ // public String getParametersHelp(); // // /** // * // * @return String | the output directory of the tool // */ // public String getOutputDirectory(); // }
import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Arguments; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeCollection; import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Parameters; import java.util.HashMap;
} /** * * @return String | the path to the enzyme file */ public String getEnzymeFile(){ return this.getParameter(BarcodeCorrectorArguments.ENZYME_FILE); } /** * * @return EnzymeCollection | the enzyme collection */ public EnzymeCollection getEnzymeCollection(){ return this.enzymeCollection; } /** * * @return String | the name of the enzyme given by the user */ public String getEnzymeName(){ return this.getParameter(BarcodeCorrectorArguments.ENZYME); } /** * * @return Enzyme | the used enzyme */
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Arguments.java // public interface Arguments { // // // /** // * returns the argument for the given name (-name), or invalid if no argument exists for the given name // * @param sortName String | the name of the argument // * @return GBSargument if any exists for the given name, else GBSaguments.INVALID_ARGUMENT // */ // public Arguments getArgument(String sortName); // // // /** // * // * @return String | the option name of the argument // */ // public String getSortName(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/Enzyme.java // public interface Enzyme{ // /** // * // * @return String the name of the enzyme // */ // public String getName(); // // /** // * // * @return collection of String the sites after the cut // */ // public Collection<String> getInitialCutSiteRemnant(); // // /** // * // * @return collection of String the complement sites after the cut // */ // public Collection<String> getComplementCutSiteRemnant(); // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeCollection.java // public class EnzymeCollection { // // // HashSet<Enzyme> enzymeSet = new HashSet(); // // /** // * creates a enzymeCollection from the known system enzymes // */ // public EnzymeCollection(){ // for (Enzyme enzyme : EnzymeEnum.values()){ // this.enzymeSet.add(enzyme); // } // } // // /** // * creates a new enzymeCollection from the given enzymes + the neutral enzyme // * @param enzymeCollection collection of enzymes // */ // public EnzymeCollection(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // this.enzymeSet.add(this.getNeutralEnzyme()); // } // // /** // * adds all given enzymes to the collection // * @param enzymeCollection | collection of enzymes // */ // public void addEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet.addAll(enzymeCollection); // } // // /** // * replaces the enzymes from this collection with the new collection // * @param enzymeCollection | collection of enzymes // */ // public void replaceEnzymes(Collection<Enzyme> enzymeCollection){ // this.enzymeSet = new HashSet(enzymeCollection); // } // // /** // * // * @return a Collection of all known enzymes // */ // public Collection<Enzyme> getAllEnzymes(){ // return this.enzymeSet; // } // // /** // * // * @param name String | the name of the enzyme // * @return Enzyme | the enzyme with the given name // */ // public Enzyme getEnzyme(String name){ // for (Enzyme enzyme : this.enzymeSet){ // if (enzyme.getName().toLowerCase().equals(name.toLowerCase())){ // return enzyme; // } // } // return EnzymeEnum.NAN; // } // // /** // * returns the neutral NAN enzyme // * @return Enzyme | a neutral nan enzyme // * @see EnzymeEnum#NAN // */ // public Enzyme getNeutralEnzyme(){ // return EnzymeEnum.NAN; // } // // // // } // // Path: src/be/uzleuven/gc/logistics/GBSX/utils/argumentsAndParameters/Parameters.java // public interface Parameters { // // // /** // * // * @param argument // * @return true if the given argument is a parameter // */ // public boolean containsParameter(Arguments argument); // // /** // * // * @param argument // * @return the asked argument as a String // */ // public String getParameter(Arguments argument); // // /** // * adds the given parameter for the given argument // * @param argument | the argument // * @param parameter String | the parameter // * @throws RuntimeException when the given argument is an invalid argument // */ // public void setParameter(Arguments argument, String parameter); // // /** // * checks if all required parameters are set // * @return the String "All values are set" if all required parameters are set, else an error message // */ // public boolean areRequiredParametersSet(); // // /** // * checks if all required parameters are set // * @return the boolean true if all required parameters are set // */ // public String getErrorRequiredParametersSet(); // // /** // * configures a log file for all known parameters // * @return String to put in the log file // */ // public String getParametersLogString(); // // /** // * makes a help for all known parameters // * @return String | the help page // */ // public String getParametersHelp(); // // /** // * // * @return String | the output directory of the tool // */ // public String getOutputDirectory(); // } // Path: src/be/uzleuven/gc/logistics/GBSX/barcodeCorrector/model/BarcodeCorrectorParameters.java import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Arguments; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.Enzyme; import be.uzleuven.gc.logistics.GBSX.utils.enzyme.model.EnzymeCollection; import be.uzleuven.gc.logistics.GBSX.utils.argumentsAndParameters.Parameters; import java.util.HashMap; } /** * * @return String | the path to the enzyme file */ public String getEnzymeFile(){ return this.getParameter(BarcodeCorrectorArguments.ENZYME_FILE); } /** * * @return EnzymeCollection | the enzyme collection */ public EnzymeCollection getEnzymeCollection(){ return this.enzymeCollection; } /** * * @return String | the name of the enzyme given by the user */ public String getEnzymeName(){ return this.getParameter(BarcodeCorrectorArguments.ENZYME); } /** * * @return Enzyme | the used enzyme */
public Enzyme getEnzyme(){
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaBufferedReader.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // }
import java.util.zip.GZIPInputStream; import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger;
/* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.fasta.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class FastaBufferedReader { private final BufferedReader fastaBufferedReader; private ReentrantLock lock = new ReentrantLock(); /** * creates a new FastaBufferedReader of the given file. * @param file | the file that must be read * @param ziped | boolean if the fasta file is ziped (gz) * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaBufferedReader(File file, boolean ziped) throws FileNotFoundException, IOException{ if (ziped){ this.fastaBufferedReader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)))); }else{ this.fastaBufferedReader = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(file)))); } } /** * reads the next lines in the fasta file. and returns it as an fastaread * @return null if there are no fasta files anymore, else a FastaRead * @throws IOException | if any error occures while reading the file */
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/model/FastaRead.java // public class FastaRead { // // private String sequence; // private String description; // // /** // * creates a new fasta read with "no description" and the given sequence // * @param sequence | String the sequence // */ // private FastaRead(String sequence){ // this.description = "> no description"; // this.sequence = sequence; // } // // /** // * creates a new fasta read with the given description and the given sequence // * @param sequence | String the sequence // */ // public FastaRead(String description, String sequence){ // if (! description.startsWith(">")){ // description = ">" + description; // } // this.description = description; // this.sequence = sequence; // } // // /** // * // * @return String | the description of the fasta read // */ // public String getDescription(){ // return this.description; // } // // /** // * // * @return String | the sequence of the fasta read // */ // public String getSequence(){ // return this.sequence; // } // // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/fasta/infrastructure/FastaBufferedReader.java import java.util.zip.GZIPInputStream; import be.uzleuven.gc.logistics.GBSX.utils.fasta.model.FastaRead; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; /* * This is GBSX v1.0. A toolkit for experimental design and demultiplexing genotyping by sequencing experiments. \n * \n * Copyright 2014 KU Leuven * * * This file is part of GBSX. * * GBSX 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. * * GBSX 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 GBSX. If not, see <http://www.gnu.org/licenses/>. */ package be.uzleuven.gc.logistics.GBSX.utils.fasta.infrastructure; /** * * @author Koen Herten for the KU Leuven */ public class FastaBufferedReader { private final BufferedReader fastaBufferedReader; private ReentrantLock lock = new ReentrantLock(); /** * creates a new FastaBufferedReader of the given file. * @param file | the file that must be read * @param ziped | boolean if the fasta file is ziped (gz) * @throws FileNotFoundException | if the given file isn't found * @throws IOException | if an error occures while opening the file */ public FastaBufferedReader(File file, boolean ziped) throws FileNotFoundException, IOException{ if (ziped){ this.fastaBufferedReader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)))); }else{ this.fastaBufferedReader = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(file)))); } } /** * reads the next lines in the fasta file. and returns it as an fastaread * @return null if there are no fasta files anymore, else a FastaRead * @throws IOException | if any error occures while reading the file */
public FastaRead next() throws IOException{
GenomicsCoreLeuven/GBSX
src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeEnum.java
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/sampleBarcodeEnzyme/model/BasePair.java // public class BasePair { // // /** // * returns true if the the found base can be the espected base // * @param base1 char | the espected base (A, C, G or T) // * @param base2 char | the found base (A,C,G,T,R,Y,K,M,S,W,B,D,H,V,N) // * @return true if base2 possible is base1 // */ // public static boolean canBeEqual(char base1, char base2){ // base1 = Character.toUpperCase(base1); // for (char possibleBase : BasePair.getPossibleBasePairs(base2)){ // if (possibleBase == base1){ // return true; // } // } // return false; // } // // /** // * transforms the given base to a list of possible bases (usefull for R,Y,...) // * @param base char | the base to transform // * @return arraylist of character | the possible corresponding bases. // */ // private static ArrayList<Character> getPossibleBasePairs(char base){ // base = Character.toUpperCase(base); // ArrayList<Character> base1List = new ArrayList(); // switch (base){ // case 'A' : base1List.add('A'); // break; // case 'C' : base1List.add('C'); // break; // case 'G' : base1List.add('G'); // break; // case 'T' : base1List.add('T'); // break; // case 'R' : base1List.add('A'); // base1List.add('G'); // break; // case 'Y' : base1List.add('T'); // base1List.add('G'); // break; // case 'K' : base1List.add('G'); // base1List.add('T'); // break; // case 'M' : base1List.add('A'); // base1List.add('C'); // break; // case 'S' : base1List.add('G'); // base1List.add('C'); // break; // case 'W' : base1List.add('A'); // base1List.add('T'); // break; // case 'B' : base1List.add('G'); // base1List.add('T'); // base1List.add('C'); // break; // case 'D' : base1List.add('G'); // base1List.add('A'); // base1List.add('T'); // break; // case 'H' : base1List.add('A'); // base1List.add('C'); // base1List.add('T'); // break; // case 'V' : base1List.add('G'); // base1List.add('C'); // base1List.add('A'); // break; // case 'N' : base1List.add('A'); // base1List.add('G'); // base1List.add('C'); // base1List.add('T'); // break; // default : base1List.add('A'); // base1List.add('G'); // base1List.add('C'); // base1List.add('T'); // break; // } // return base1List; // } // // /** // * creates the complement of the given DNA // * @param sequence String | the sequence of DNA where the complement must be searched // * @return the complement of the given DNA // */ // public static String getComplementSequence(String sequence){ // String complementDNApiece = ""; // //sequence = sequence.toUpperCase(); // for (char base : sequence.toCharArray()){ // switch (base){ // case 'A': complementDNApiece = 'T' + complementDNApiece; // break; // case 'T' : complementDNApiece = 'A' + complementDNApiece; // break; // case 'G' : complementDNApiece = 'C' + complementDNApiece; // break; // case 'C': complementDNApiece = 'G' + complementDNApiece; // break; // case 'a': complementDNApiece = 't' + complementDNApiece; // break; // case 't' : complementDNApiece = 'a' + complementDNApiece; // break; // case 'g' : complementDNApiece = 'c' + complementDNApiece; // break; // case 'c': complementDNApiece = 'g' + complementDNApiece; // break; // case '[' : complementDNApiece = ']' + complementDNApiece; // break; // case ']' : complementDNApiece = '[' + complementDNApiece; // break; // default : complementDNApiece = base + complementDNApiece; // break; // } // } // return complementDNApiece; // } // }
import java.util.HashSet; import be.uzleuven.gc.logistics.GBSX.utils.sampleBarcodeEnzyme.model.BasePair; import java.util.Arrays; import java.util.Collection;
private EnzymeEnum(String name, String[] initialCutSite){ this.name = name; this.initialCutSiteRemnant = initialCutSite; } /** * * @return String the name of the enzyme */ public String getName(){ return this.name; } /** * returns all cutsites * @return Collection of String | all the cutsites of the enzyme in a collection */ public Collection<String> getInitialCutSiteRemnant(){ HashSet<String> cutsitesSet = new HashSet(); cutsitesSet.addAll(Arrays.asList(this.initialCutSiteRemnant)); return cutsitesSet; } /** * returns all complement cutsites * @return Collection of String | all the complement cutsites of the enzyme in a collection */ public Collection<String> getComplementCutSiteRemnant() { HashSet<String> cutsitesSet = new HashSet(); for (String cutsite : this.initialCutSiteRemnant){
// Path: src/be/uzleuven/gc/logistics/GBSX/utils/sampleBarcodeEnzyme/model/BasePair.java // public class BasePair { // // /** // * returns true if the the found base can be the espected base // * @param base1 char | the espected base (A, C, G or T) // * @param base2 char | the found base (A,C,G,T,R,Y,K,M,S,W,B,D,H,V,N) // * @return true if base2 possible is base1 // */ // public static boolean canBeEqual(char base1, char base2){ // base1 = Character.toUpperCase(base1); // for (char possibleBase : BasePair.getPossibleBasePairs(base2)){ // if (possibleBase == base1){ // return true; // } // } // return false; // } // // /** // * transforms the given base to a list of possible bases (usefull for R,Y,...) // * @param base char | the base to transform // * @return arraylist of character | the possible corresponding bases. // */ // private static ArrayList<Character> getPossibleBasePairs(char base){ // base = Character.toUpperCase(base); // ArrayList<Character> base1List = new ArrayList(); // switch (base){ // case 'A' : base1List.add('A'); // break; // case 'C' : base1List.add('C'); // break; // case 'G' : base1List.add('G'); // break; // case 'T' : base1List.add('T'); // break; // case 'R' : base1List.add('A'); // base1List.add('G'); // break; // case 'Y' : base1List.add('T'); // base1List.add('G'); // break; // case 'K' : base1List.add('G'); // base1List.add('T'); // break; // case 'M' : base1List.add('A'); // base1List.add('C'); // break; // case 'S' : base1List.add('G'); // base1List.add('C'); // break; // case 'W' : base1List.add('A'); // base1List.add('T'); // break; // case 'B' : base1List.add('G'); // base1List.add('T'); // base1List.add('C'); // break; // case 'D' : base1List.add('G'); // base1List.add('A'); // base1List.add('T'); // break; // case 'H' : base1List.add('A'); // base1List.add('C'); // base1List.add('T'); // break; // case 'V' : base1List.add('G'); // base1List.add('C'); // base1List.add('A'); // break; // case 'N' : base1List.add('A'); // base1List.add('G'); // base1List.add('C'); // base1List.add('T'); // break; // default : base1List.add('A'); // base1List.add('G'); // base1List.add('C'); // base1List.add('T'); // break; // } // return base1List; // } // // /** // * creates the complement of the given DNA // * @param sequence String | the sequence of DNA where the complement must be searched // * @return the complement of the given DNA // */ // public static String getComplementSequence(String sequence){ // String complementDNApiece = ""; // //sequence = sequence.toUpperCase(); // for (char base : sequence.toCharArray()){ // switch (base){ // case 'A': complementDNApiece = 'T' + complementDNApiece; // break; // case 'T' : complementDNApiece = 'A' + complementDNApiece; // break; // case 'G' : complementDNApiece = 'C' + complementDNApiece; // break; // case 'C': complementDNApiece = 'G' + complementDNApiece; // break; // case 'a': complementDNApiece = 't' + complementDNApiece; // break; // case 't' : complementDNApiece = 'a' + complementDNApiece; // break; // case 'g' : complementDNApiece = 'c' + complementDNApiece; // break; // case 'c': complementDNApiece = 'g' + complementDNApiece; // break; // case '[' : complementDNApiece = ']' + complementDNApiece; // break; // case ']' : complementDNApiece = '[' + complementDNApiece; // break; // default : complementDNApiece = base + complementDNApiece; // break; // } // } // return complementDNApiece; // } // } // Path: src/be/uzleuven/gc/logistics/GBSX/utils/enzyme/model/EnzymeEnum.java import java.util.HashSet; import be.uzleuven.gc.logistics.GBSX.utils.sampleBarcodeEnzyme.model.BasePair; import java.util.Arrays; import java.util.Collection; private EnzymeEnum(String name, String[] initialCutSite){ this.name = name; this.initialCutSiteRemnant = initialCutSite; } /** * * @return String the name of the enzyme */ public String getName(){ return this.name; } /** * returns all cutsites * @return Collection of String | all the cutsites of the enzyme in a collection */ public Collection<String> getInitialCutSiteRemnant(){ HashSet<String> cutsitesSet = new HashSet(); cutsitesSet.addAll(Arrays.asList(this.initialCutSiteRemnant)); return cutsitesSet; } /** * returns all complement cutsites * @return Collection of String | all the complement cutsites of the enzyme in a collection */ public Collection<String> getComplementCutSiteRemnant() { HashSet<String> cutsitesSet = new HashSet(); for (String cutsite : this.initialCutSiteRemnant){
cutsitesSet.add(BasePair.getComplementSequence(cutsite));
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialDrawerContainer.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/ImaterialBinder.java // public interface ImaterialBinder { // int getLayout(); // // View init(View view); // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // }
import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.ImaterialBinder; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli;
package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialDrawerContainer<T extends TextView> implements ImaterialBinder, scrolli { public LinearLayout itemMenuHolder, items, background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public T current_head_item_title, current_head_item_sub_title;
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/ImaterialBinder.java // public interface ImaterialBinder { // int getLayout(); // // View init(View view); // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialDrawerContainer.java import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.ImaterialBinder; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli; package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialDrawerContainer<T extends TextView> implements ImaterialBinder, scrolli { public LinearLayout itemMenuHolder, items, background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public T current_head_item_title, current_head_item_sub_title;
public LAYOUT_DRAWER drawerType;
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialDrawerContainer.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/ImaterialBinder.java // public interface ImaterialBinder { // int getLayout(); // // View init(View view); // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // }
import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.ImaterialBinder; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli;
package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialDrawerContainer<T extends TextView> implements ImaterialBinder, scrolli { public LinearLayout itemMenuHolder, items, background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public T current_head_item_title, current_head_item_sub_title; public LAYOUT_DRAWER drawerType;
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/ImaterialBinder.java // public interface ImaterialBinder { // int getLayout(); // // View init(View view); // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialDrawerContainer.java import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.ImaterialBinder; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli; package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialDrawerContainer<T extends TextView> implements ImaterialBinder, scrolli { public LinearLayout itemMenuHolder, items, background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public T current_head_item_title, current_head_item_sub_title; public LAYOUT_DRAWER drawerType;
private LockableScrollView scrollor;
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/MainActivityDemo.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java // public enum structurebind { // main(R.id.main, MainActivityDemo.class), // blocktest(R.id.blocktset, testblock.class), // hb(R.id.hbstyle, demohb.class), // sys(R.id.system, MainActivityDemo.class), // profile(R.id.profiletype, MainActivityDemo.class); // private final Class<? extends AppCompatActivity> internalClazz; // private final int menu_id; // // structurebind(final @IdRes int menuid, final Class<? extends AppCompatActivity> triggerclassname) { // this.internalClazz = triggerclassname; // this.menu_id = menuid; // } // // public int getId() { // return menu_id; // } // // public Class<? extends AppCompatActivity> getClassName() { // return this.internalClazz; // } // // public static void startfromSelectionMenu(final @IdRes int menuID, final Context mcontext, @Nullable final Bundle mbundle) { // final int g = structurebind.values().length; // for (int i = 0; i < g; i++) { // structurebind bind = structurebind.values()[i]; // if (bind.getId() == menuID) { // if (mbundle != null) { // bind.newapp(mcontext, mbundle); // } else { // bind.newapp(mcontext); // } // return; // } // } // } // // public void newapp(final Context ctx) { // final Intent in = new Intent(ctx, internalClazz); // ctx.startActivity(in); // } // // // public void newapp(final Context ctx, final Bundle bun) { // final Intent in = new Intent(ctx, internalClazz); // in.putExtras(bun); // ctx.startActivity(in); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // }
import android.app.Fragment; import android.view.MenuItem; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.helpr.structurebind; import com.hypebeast.demoslidemenu.content.mainpageDemo;
package com.hypebeast.demoslidemenu; public class MainActivityDemo extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java // public enum structurebind { // main(R.id.main, MainActivityDemo.class), // blocktest(R.id.blocktset, testblock.class), // hb(R.id.hbstyle, demohb.class), // sys(R.id.system, MainActivityDemo.class), // profile(R.id.profiletype, MainActivityDemo.class); // private final Class<? extends AppCompatActivity> internalClazz; // private final int menu_id; // // structurebind(final @IdRes int menuid, final Class<? extends AppCompatActivity> triggerclassname) { // this.internalClazz = triggerclassname; // this.menu_id = menuid; // } // // public int getId() { // return menu_id; // } // // public Class<? extends AppCompatActivity> getClassName() { // return this.internalClazz; // } // // public static void startfromSelectionMenu(final @IdRes int menuID, final Context mcontext, @Nullable final Bundle mbundle) { // final int g = structurebind.values().length; // for (int i = 0; i < g; i++) { // structurebind bind = structurebind.values()[i]; // if (bind.getId() == menuID) { // if (mbundle != null) { // bind.newapp(mcontext, mbundle); // } else { // bind.newapp(mcontext); // } // return; // } // } // } // // public void newapp(final Context ctx) { // final Intent in = new Intent(ctx, internalClazz); // ctx.startActivity(in); // } // // // public void newapp(final Context ctx, final Bundle bun) { // final Intent in = new Intent(ctx, internalClazz); // in.putExtras(bun); // ctx.startActivity(in); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/MainActivityDemo.java import android.app.Fragment; import android.view.MenuItem; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.helpr.structurebind; import com.hypebeast.demoslidemenu.content.mainpageDemo; package com.hypebeast.demoslidemenu; public class MainActivityDemo extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override
protected MenuFragment getFirstMenuFragment() {
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demohb.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // }
import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo;
package com.hypebeast.demoslidemenu; /** * Created by hesk on 10/7/15. */ public class demohb extends SlidingAppCompactActivity<Fragment> { private static String[] sampledatagroup1 = { "peter", "http://google", "billy", "http://google", "lisa", "http://google", "visa", "http://google" }; private static String[] sampledatagroup2 = { "mother", "http://google", "father", "http://google", "son", "http://google", "holy spirit", "http://google", "god the son", "http://google" }; private static String[] sampledatagroup3 = { "SONY", "http://google", "LG", "http://google", "SAMSUNG", "http://google", "XIAOMI", "http://google", "HTC", "http://google" }; @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demohb.java import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo; package com.hypebeast.demoslidemenu; /** * Created by hesk on 10/7/15. */ public class demohb extends SlidingAppCompactActivity<Fragment> { private static String[] sampledatagroup1 = { "peter", "http://google", "billy", "http://google", "lisa", "http://google", "visa", "http://google" }; private static String[] sampledatagroup2 = { "mother", "http://google", "father", "http://google", "son", "http://google", "holy spirit", "http://google", "god the son", "http://google" }; private static String[] sampledatagroup3 = { "SONY", "http://google", "LG", "http://google", "SAMSUNG", "http://google", "XIAOMI", "http://google", "HTC", "http://google" }; @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override
protected MenuFragment getFirstMenuFragment() {
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demohb.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // }
import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo;
"holy spirit", "http://google", "god the son", "http://google" }; private static String[] sampledatagroup3 = { "SONY", "http://google", "LG", "http://google", "SAMSUNG", "http://google", "XIAOMI", "http://google", "HTC", "http://google" }; @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override protected MenuFragment getFirstMenuFragment() { return new MenuFragment(); } @Override protected int getRmenu() { return R.menu.menu_main; } @Override
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demohb.java import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo; "holy spirit", "http://google", "god the son", "http://google" }; private static String[] sampledatagroup3 = { "SONY", "http://google", "LG", "http://google", "SAMSUNG", "http://google", "XIAOMI", "http://google", "HTC", "http://google" }; @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override protected MenuFragment getFirstMenuFragment() { return new MenuFragment(); } @Override protected int getRmenu() { return R.menu.menu_main; } @Override
protected mainpageDemo getInitFragment() {
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/v4/banner/template_automatic_ll.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/normalfragment/banner/bind.java // public class bind { // public final static int FULL = 0, HALF = 1; // public int size; // public String link_url, tab_name; // public String image; // public Type mtype; // // // public bind(int size_con, // String tabName, // String url, // String imageUrl, // @Nullable String type) { // size = size_con; // link_url = url; // image = imageUrl; // tab_name = tabName; // if (type != null) { // if (type.equalsIgnoreCase("webpage")) { // mtype = Type.WEB; // } // } else { // mtype = Type.TAB; // } // } // }
import android.graphics.Point; import android.os.Bundle; import android.support.annotation.LayoutRes; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TableLayout; import android.widget.TableRow; import com.squareup.picasso.MemoryPolicy; import com.squareup.picasso.Picasso; import java.util.ArrayList; import java.util.Iterator; import mxh.kickassmenu.R; import mxh.kickassmenu.normalfragment.banner.bind;
package mxh.kickassmenu.v4.banner; /** * Created by zJJ on 2/19/2016. */ public abstract class template_automatic_ll extends Fragment { protected TableLayout ll; protected ProgressBar mProgress;
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/normalfragment/banner/bind.java // public class bind { // public final static int FULL = 0, HALF = 1; // public int size; // public String link_url, tab_name; // public String image; // public Type mtype; // // // public bind(int size_con, // String tabName, // String url, // String imageUrl, // @Nullable String type) { // size = size_con; // link_url = url; // image = imageUrl; // tab_name = tabName; // if (type != null) { // if (type.equalsIgnoreCase("webpage")) { // mtype = Type.WEB; // } // } else { // mtype = Type.TAB; // } // } // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/v4/banner/template_automatic_ll.java import android.graphics.Point; import android.os.Bundle; import android.support.annotation.LayoutRes; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TableLayout; import android.widget.TableRow; import com.squareup.picasso.MemoryPolicy; import com.squareup.picasso.Picasso; import java.util.ArrayList; import java.util.Iterator; import mxh.kickassmenu.R; import mxh.kickassmenu.normalfragment.banner.bind; package mxh.kickassmenu.v4.banner; /** * Created by zJJ on 2/19/2016. */ public abstract class template_automatic_ll extends Fragment { protected TableLayout ll; protected ProgressBar mProgress;
protected ArrayList<bind> list_configuration = new ArrayList<>();
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/HorzScrollWithImageMenu.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // }
import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ListView;
/* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * This example uses a FrameLayout to display a menu View and a HorizontalScrollView (HSV). * * The HSV has a transparent View as the first child, which means the menu will show through when the HSV is scrolled. */ public class HorzScrollWithImageMenu extends Activity { MyHorizontalScrollView scrollView; View menu; View app; ImageView btnSlide; boolean menuOut = false; Handler handler = new Handler(); int btnWidth; @SuppressLint("ResourceAsColor") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutInflater inflater = LayoutInflater.from(this); setContentView(inflater.inflate(R.layout.horz_scroll_with_image_menu, null)); scrollView = (MyHorizontalScrollView) findViewById(R.id.myScrollView); menu = findViewById(R.id.menu); app = inflater.inflate(R.layout.horz_scroll_app, null); ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar); ListView listView = (ListView) app.findViewById(R.id.list);
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/HorzScrollWithImageMenu.java import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ListView; /* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * This example uses a FrameLayout to display a menu View and a HorizontalScrollView (HSV). * * The HSV has a transparent View as the first child, which means the menu will show through when the HSV is scrolled. */ public class HorzScrollWithImageMenu extends Activity { MyHorizontalScrollView scrollView; View menu; View app; ImageView btnSlide; boolean menuOut = false; Handler handler = new Handler(); int btnWidth; @SuppressLint("ResourceAsColor") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutInflater inflater = LayoutInflater.from(this); setContentView(inflater.inflate(R.layout.horz_scroll_with_image_menu, null)); scrollView = (MyHorizontalScrollView) findViewById(R.id.myScrollView); menu = findViewById(R.id.menu); app = inflater.inflate(R.layout.horz_scroll_app, null); ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar); ListView listView = (ListView) app.findViewById(R.id.list);
ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/MainActivityDemo.java // public class MainActivityDemo extends SlidingAppCompactActivity<Fragment> { // // // @Override // protected int getDefaultMainActivityLayoutId() { // return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); // } // // @Override // protected MenuFragment getFirstMenuFragment() { // return new MenuFragment(); // } // // @Override // protected int getRmenu() { // return R.menu.menu_main; // } // // @Override // protected mainpageDemo getInitFragment() { // return new mainpageDemo(); // } // // @Override // protected void customizeSlideMenuEdge(SlidingMenu sm) { // sm.setFadeDegree(0.35f); // sm.setMode(SlidingMenu.LEFT); // sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); // sm.setBehindScrollScale(0.5f); // sm.setFadeDegree(0.34f); // sm.setBehindWidth(840); // sm.requestLayout(); // sm.invalidate(); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int t = item.getItemId(); // if (t != android.R.id.home) { // structurebind.startfromSelectionMenu(t, this, null); // return super.onOptionsItemSelected(item); // } else { // toggle(); // return true; // } // } // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demohb.java // public class demohb extends SlidingAppCompactActivity<Fragment> { // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // // // @Override // protected int getDefaultMainActivityLayoutId() { // return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); // } // // @Override // protected MenuFragment getFirstMenuFragment() { // return new MenuFragment(); // } // // // @Override // protected int getRmenu() { // return R.menu.menu_main; // } // // @Override // protected mainpageDemo getInitFragment() { // return new mainpageDemo(); // } // // @Override // protected void customizeSlideMenuEdge(SlidingMenu sm) { // sm.setFadeDegree(0.35f); // sm.setMode(SlidingMenu.LEFT); // sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); // sm.setBehindScrollScale(0.5f); // sm.setFadeDegree(0.34f); // sm.setBehindWidth(840); // sm.requestLayout(); // sm.invalidate(); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/testblock.java // public class testblock extends SlidingAppCompactActivity<Fragment> { // // // @Override // protected int getDefaultMainActivityLayoutId() { // return BODY_LAYOUT.actionbar.getResID(); // } // // @Override // protected mainpageDemo getFirstMenuFragment() { // return new mainpageDemo(); // } // // @Override // protected int getRmenu() { // return R.menu.function_test_blocking; // } // // @Override // protected mainpageDemo getInitFragment() { // return new mainpageDemo(); // } // // @Override // protected void customizeSlideMenuEdge(SlidingMenu sm) { // sm.setFadeDegree(0.35f); // sm.setMode(SlidingMenu.LEFT); // sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); // sm.setBehindScrollScale(0.5f); // sm.setFadeDegree(0.34f); // sm.setBehindWidth(840); // sm.requestLayout(); // sm.invalidate(); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int t = item.getItemId(); // if (t != android.R.id.home) { // // if (t == R.id.unblock) { // setUnblock(); // } // // if (t == R.id.block) { // setBlockEnableWithColor(R.color.block_color); // } // // structurebind.startfromSelectionMenu(t, this, null); // return super.onOptionsItemSelected(item); // } else { // toggle(); // return true; // } // } // // @Override // public void onBackPressed() { // super.onBackPressed(); // finish(); // } // // // }
import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.annotation.IdRes; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hypebeast.demoslidemenu.MainActivityDemo; import com.hypebeast.demoslidemenu.R; import com.hypebeast.demoslidemenu.demohb; import com.hypebeast.demoslidemenu.testblock;
package com.hypebeast.demoslidemenu.helpr; /** * Created by hesk on 10/7/15. */ public enum structurebind { main(R.id.main, MainActivityDemo.class),
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/MainActivityDemo.java // public class MainActivityDemo extends SlidingAppCompactActivity<Fragment> { // // // @Override // protected int getDefaultMainActivityLayoutId() { // return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); // } // // @Override // protected MenuFragment getFirstMenuFragment() { // return new MenuFragment(); // } // // @Override // protected int getRmenu() { // return R.menu.menu_main; // } // // @Override // protected mainpageDemo getInitFragment() { // return new mainpageDemo(); // } // // @Override // protected void customizeSlideMenuEdge(SlidingMenu sm) { // sm.setFadeDegree(0.35f); // sm.setMode(SlidingMenu.LEFT); // sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); // sm.setBehindScrollScale(0.5f); // sm.setFadeDegree(0.34f); // sm.setBehindWidth(840); // sm.requestLayout(); // sm.invalidate(); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int t = item.getItemId(); // if (t != android.R.id.home) { // structurebind.startfromSelectionMenu(t, this, null); // return super.onOptionsItemSelected(item); // } else { // toggle(); // return true; // } // } // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demohb.java // public class demohb extends SlidingAppCompactActivity<Fragment> { // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // // // @Override // protected int getDefaultMainActivityLayoutId() { // return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); // } // // @Override // protected MenuFragment getFirstMenuFragment() { // return new MenuFragment(); // } // // // @Override // protected int getRmenu() { // return R.menu.menu_main; // } // // @Override // protected mainpageDemo getInitFragment() { // return new mainpageDemo(); // } // // @Override // protected void customizeSlideMenuEdge(SlidingMenu sm) { // sm.setFadeDegree(0.35f); // sm.setMode(SlidingMenu.LEFT); // sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); // sm.setBehindScrollScale(0.5f); // sm.setFadeDegree(0.34f); // sm.setBehindWidth(840); // sm.requestLayout(); // sm.invalidate(); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/testblock.java // public class testblock extends SlidingAppCompactActivity<Fragment> { // // // @Override // protected int getDefaultMainActivityLayoutId() { // return BODY_LAYOUT.actionbar.getResID(); // } // // @Override // protected mainpageDemo getFirstMenuFragment() { // return new mainpageDemo(); // } // // @Override // protected int getRmenu() { // return R.menu.function_test_blocking; // } // // @Override // protected mainpageDemo getInitFragment() { // return new mainpageDemo(); // } // // @Override // protected void customizeSlideMenuEdge(SlidingMenu sm) { // sm.setFadeDegree(0.35f); // sm.setMode(SlidingMenu.LEFT); // sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); // sm.setBehindScrollScale(0.5f); // sm.setFadeDegree(0.34f); // sm.setBehindWidth(840); // sm.requestLayout(); // sm.invalidate(); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int t = item.getItemId(); // if (t != android.R.id.home) { // // if (t == R.id.unblock) { // setUnblock(); // } // // if (t == R.id.block) { // setBlockEnableWithColor(R.color.block_color); // } // // structurebind.startfromSelectionMenu(t, this, null); // return super.onOptionsItemSelected(item); // } else { // toggle(); // return true; // } // } // // @Override // public void onBackPressed() { // super.onBackPressed(); // finish(); // } // // // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.annotation.IdRes; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hypebeast.demoslidemenu.MainActivityDemo; import com.hypebeast.demoslidemenu.R; import com.hypebeast.demoslidemenu.demohb; import com.hypebeast.demoslidemenu.testblock; package com.hypebeast.demoslidemenu.helpr; /** * Created by hesk on 10/7/15. */ public enum structurebind { main(R.id.main, MainActivityDemo.class),
blocktest(R.id.blocktset, testblock.class),
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialHeadedDrawerContainer.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // }
import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli;
package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialHeadedDrawerContainer extends MaterialDrawerContainer implements scrolli { public LinearLayout background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public TextView current_head_item_title, current_head_item_sub_title;
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialHeadedDrawerContainer.java import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli; package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialHeadedDrawerContainer extends MaterialDrawerContainer implements scrolli { public LinearLayout background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public TextView current_head_item_title, current_head_item_sub_title;
private LockableScrollView scrollor;
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialHeadedDrawerContainer.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // }
import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli;
package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialHeadedDrawerContainer extends MaterialDrawerContainer implements scrolli { public LinearLayout background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public TextView current_head_item_title, current_head_item_sub_title; private LockableScrollView scrollor;
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/LAYOUT_DRAWER.java // public enum LAYOUT_DRAWER { // STICKY_UP(R.layout.layout_drawer_sticky_up), // STICKY_BOTTOM(R.layout.layout_drawer_sticky_bottom), // PROFILE_HEAD(R.layout.layout_drawer_headed), // USER_DEFINED_LAYOUT(-1); // private final int layout_id; // // LAYOUT_DRAWER(@LayoutRes int layout) { // this.layout_id = layout; // } // // public int getLayoutRes() { // return layout_id; // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/scrolli.java // public interface scrolli { // ScrollView getScrollView(); // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/containers/MaterialHeadedDrawerContainer.java import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.LAYOUT_DRAWER; import mxh.kickassmenu.menucontent.scrolli; package mxh.kickassmenu.menucontent.containers; /** * Created by hesk on 24/6/15. */ public class MaterialHeadedDrawerContainer extends MaterialDrawerContainer implements scrolli { public LinearLayout background_gradient; public ImageView background_switcher, current_back_item_background, current_head_item_photo, second_head_item_photo, third_head_item_photo, user_transition, user_switcher; public TextView current_head_item_title, current_head_item_sub_title; private LockableScrollView scrollor;
public MaterialHeadedDrawerContainer(LAYOUT_DRAWER layout_type) {
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/SlideAnimationThenCallLayout.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // }
import java.util.Date; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.TranslateAnimation; import android.widget.ListView;
anim = new TranslateAnimation(0, -left, 0, 0); animParams.init(0, 0, w, h); } anim.setDuration(500); anim.setAnimationListener(me); //Tell the animation to stay as it ended (we are going to set the app.layout first than remove this property) anim.setFillAfter(true); // Only use fillEnabled and fillAfter if we don't call layout ourselves. // We need to do the layout ourselves and not use fillEnabled and fillAfter because when the anim is finished // although the View appears to have moved, it is actually just a drawing effect and the View hasn't moved. // Therefore clicking on the screen where the button appears does not work, but clicking where the View *was* does // work. // anim.setFillEnabled(true); // anim.setFillAfter(true); app.startAnimation(anim); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slide_animation_then_call_layout); menu = findViewById(R.id.menu); app = findViewById(R.id.app);
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/SlideAnimationThenCallLayout.java import java.util.Date; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.TranslateAnimation; import android.widget.ListView; anim = new TranslateAnimation(0, -left, 0, 0); animParams.init(0, 0, w, h); } anim.setDuration(500); anim.setAnimationListener(me); //Tell the animation to stay as it ended (we are going to set the app.layout first than remove this property) anim.setFillAfter(true); // Only use fillEnabled and fillAfter if we don't call layout ourselves. // We need to do the layout ourselves and not use fillEnabled and fillAfter because when the anim is finished // although the View appears to have moved, it is actually just a drawing effect and the View hasn't moved. // Therefore clicking on the screen where the button appears does not work, but clicking where the View *was* does // work. // anim.setFillEnabled(true); // anim.setFillAfter(true); app.startAnimation(anim); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slide_animation_then_call_layout); menu = findViewById(R.id.menu); app = findViewById(R.id.app);
ViewUtils.printView("menu", menu);
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/testblock.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java // public enum structurebind { // main(R.id.main, MainActivityDemo.class), // blocktest(R.id.blocktset, testblock.class), // hb(R.id.hbstyle, demohb.class), // sys(R.id.system, MainActivityDemo.class), // profile(R.id.profiletype, MainActivityDemo.class); // private final Class<? extends AppCompatActivity> internalClazz; // private final int menu_id; // // structurebind(final @IdRes int menuid, final Class<? extends AppCompatActivity> triggerclassname) { // this.internalClazz = triggerclassname; // this.menu_id = menuid; // } // // public int getId() { // return menu_id; // } // // public Class<? extends AppCompatActivity> getClassName() { // return this.internalClazz; // } // // public static void startfromSelectionMenu(final @IdRes int menuID, final Context mcontext, @Nullable final Bundle mbundle) { // final int g = structurebind.values().length; // for (int i = 0; i < g; i++) { // structurebind bind = structurebind.values()[i]; // if (bind.getId() == menuID) { // if (mbundle != null) { // bind.newapp(mcontext, mbundle); // } else { // bind.newapp(mcontext); // } // return; // } // } // } // // public void newapp(final Context ctx) { // final Intent in = new Intent(ctx, internalClazz); // ctx.startActivity(in); // } // // // public void newapp(final Context ctx, final Bundle bun) { // final Intent in = new Intent(ctx, internalClazz); // in.putExtras(bun); // ctx.startActivity(in); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // }
import android.app.Fragment; import android.view.MenuItem; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.helpr.structurebind; import com.hypebeast.demoslidemenu.content.mainpageDemo;
package com.hypebeast.demoslidemenu; public class testblock extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return BODY_LAYOUT.actionbar.getResID(); } @Override
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java // public enum structurebind { // main(R.id.main, MainActivityDemo.class), // blocktest(R.id.blocktset, testblock.class), // hb(R.id.hbstyle, demohb.class), // sys(R.id.system, MainActivityDemo.class), // profile(R.id.profiletype, MainActivityDemo.class); // private final Class<? extends AppCompatActivity> internalClazz; // private final int menu_id; // // structurebind(final @IdRes int menuid, final Class<? extends AppCompatActivity> triggerclassname) { // this.internalClazz = triggerclassname; // this.menu_id = menuid; // } // // public int getId() { // return menu_id; // } // // public Class<? extends AppCompatActivity> getClassName() { // return this.internalClazz; // } // // public static void startfromSelectionMenu(final @IdRes int menuID, final Context mcontext, @Nullable final Bundle mbundle) { // final int g = structurebind.values().length; // for (int i = 0; i < g; i++) { // structurebind bind = structurebind.values()[i]; // if (bind.getId() == menuID) { // if (mbundle != null) { // bind.newapp(mcontext, mbundle); // } else { // bind.newapp(mcontext); // } // return; // } // } // } // // public void newapp(final Context ctx) { // final Intent in = new Intent(ctx, internalClazz); // ctx.startActivity(in); // } // // // public void newapp(final Context ctx, final Bundle bun) { // final Intent in = new Intent(ctx, internalClazz); // in.putExtras(bun); // ctx.startActivity(in); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/testblock.java import android.app.Fragment; import android.view.MenuItem; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.helpr.structurebind; import com.hypebeast.demoslidemenu.content.mainpageDemo; package com.hypebeast.demoslidemenu; public class testblock extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return BODY_LAYOUT.actionbar.getResID(); } @Override
protected mainpageDemo getFirstMenuFragment() {
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/testblock.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java // public enum structurebind { // main(R.id.main, MainActivityDemo.class), // blocktest(R.id.blocktset, testblock.class), // hb(R.id.hbstyle, demohb.class), // sys(R.id.system, MainActivityDemo.class), // profile(R.id.profiletype, MainActivityDemo.class); // private final Class<? extends AppCompatActivity> internalClazz; // private final int menu_id; // // structurebind(final @IdRes int menuid, final Class<? extends AppCompatActivity> triggerclassname) { // this.internalClazz = triggerclassname; // this.menu_id = menuid; // } // // public int getId() { // return menu_id; // } // // public Class<? extends AppCompatActivity> getClassName() { // return this.internalClazz; // } // // public static void startfromSelectionMenu(final @IdRes int menuID, final Context mcontext, @Nullable final Bundle mbundle) { // final int g = structurebind.values().length; // for (int i = 0; i < g; i++) { // structurebind bind = structurebind.values()[i]; // if (bind.getId() == menuID) { // if (mbundle != null) { // bind.newapp(mcontext, mbundle); // } else { // bind.newapp(mcontext); // } // return; // } // } // } // // public void newapp(final Context ctx) { // final Intent in = new Intent(ctx, internalClazz); // ctx.startActivity(in); // } // // // public void newapp(final Context ctx, final Bundle bun) { // final Intent in = new Intent(ctx, internalClazz); // in.putExtras(bun); // ctx.startActivity(in); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // }
import android.app.Fragment; import android.view.MenuItem; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.helpr.structurebind; import com.hypebeast.demoslidemenu.content.mainpageDemo;
@Override protected mainpageDemo getInitFragment() { return new mainpageDemo(); } @Override protected void customizeSlideMenuEdge(SlidingMenu sm) { sm.setFadeDegree(0.35f); sm.setMode(SlidingMenu.LEFT); sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); sm.setBehindScrollScale(0.5f); sm.setFadeDegree(0.34f); sm.setBehindWidth(840); sm.requestLayout(); sm.invalidate(); } @Override public boolean onOptionsItemSelected(MenuItem item) { final int t = item.getItemId(); if (t != android.R.id.home) { if (t == R.id.unblock) { setUnblock(); } if (t == R.id.block) { setBlockEnableWithColor(R.color.block_color); }
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/helpr/structurebind.java // public enum structurebind { // main(R.id.main, MainActivityDemo.class), // blocktest(R.id.blocktset, testblock.class), // hb(R.id.hbstyle, demohb.class), // sys(R.id.system, MainActivityDemo.class), // profile(R.id.profiletype, MainActivityDemo.class); // private final Class<? extends AppCompatActivity> internalClazz; // private final int menu_id; // // structurebind(final @IdRes int menuid, final Class<? extends AppCompatActivity> triggerclassname) { // this.internalClazz = triggerclassname; // this.menu_id = menuid; // } // // public int getId() { // return menu_id; // } // // public Class<? extends AppCompatActivity> getClassName() { // return this.internalClazz; // } // // public static void startfromSelectionMenu(final @IdRes int menuID, final Context mcontext, @Nullable final Bundle mbundle) { // final int g = structurebind.values().length; // for (int i = 0; i < g; i++) { // structurebind bind = structurebind.values()[i]; // if (bind.getId() == menuID) { // if (mbundle != null) { // bind.newapp(mcontext, mbundle); // } else { // bind.newapp(mcontext); // } // return; // } // } // } // // public void newapp(final Context ctx) { // final Intent in = new Intent(ctx, internalClazz); // ctx.startActivity(in); // } // // // public void newapp(final Context ctx, final Bundle bun) { // final Intent in = new Intent(ctx, internalClazz); // in.putExtras(bun); // ctx.startActivity(in); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/testblock.java import android.app.Fragment; import android.view.MenuItem; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.helpr.structurebind; import com.hypebeast.demoslidemenu.content.mainpageDemo; @Override protected mainpageDemo getInitFragment() { return new mainpageDemo(); } @Override protected void customizeSlideMenuEdge(SlidingMenu sm) { sm.setFadeDegree(0.35f); sm.setMode(SlidingMenu.LEFT); sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); sm.setBehindScrollScale(0.5f); sm.setFadeDegree(0.34f); sm.setBehindWidth(840); sm.requestLayout(); sm.invalidate(); } @Override public boolean onOptionsItemSelected(MenuItem item) { final int t = item.getItemId(); if (t != android.R.id.home) { if (t == R.id.unblock) { setUnblock(); } if (t == R.id.block) { setBlockEnableWithColor(R.color.block_color); }
structurebind.startfromSelectionMenu(t, this, null);
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demosys.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // }
import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo;
package com.hypebeast.demoslidemenu; /** * Created by hesk on 10/7/15. */ public class demosys extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demosys.java import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo; package com.hypebeast.demoslidemenu; /** * Created by hesk on 10/7/15. */ public class demosys extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override
protected MenuFragment getFirstMenuFragment() {
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demosys.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // }
import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo;
package com.hypebeast.demoslidemenu; /** * Created by hesk on 10/7/15. */ public class demosys extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override protected MenuFragment getFirstMenuFragment() { return new MenuFragment(); } @Override protected int getRmenu() { return R.menu.menu_main; } @Override
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/expandablemenu/MenuFragment.java // public class MenuFragment extends Fragment { // // private UltimateRecyclerView ultimateRecyclerView; // private expCustomAdapter simpleRecyclerViewAdapter = null; // private LinearLayoutManager linearLayoutManager; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.left_slid_menu, container, false); // } // // // private static String[] sampledatagroup1 = { // "peter", "http://google", // "billy", "http://google", // "lisa", "http://google", // "visa", "http://google" // }; // private static String[] sampledatagroup2 = { // "mother", "http://google", // "father", "http://google", // "son", "http://google", // "holy spirit", "http://google", // "god the son", "http://google" // }; // private static String[] sampledatagroup3 = { // "SONY", "http://google", // "LG", "http://google", // "SAMSUNG", "http://google", // "XIAOMI", "http://google", // "HTC", "http://google" // }; // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // ultimateRecyclerView = (UltimateRecyclerView) view.findViewById(R.id.ultimate_recycler_view_menu); // ultimateRecyclerView.setHasFixedSize(false); // /** // * this is the adapter for the expanx // */ // simpleRecyclerViewAdapter = new expCustomAdapter(getActivity()); // simpleRecyclerViewAdapter.addAll(expCustomAdapter.getPreCodeMenu( // sampledatagroup1, // sampledatagroup2, // sampledatagroup3), // 0); // // linearLayoutManager = new LinearLayoutManager(getActivity()); // ultimateRecyclerView.setLayoutManager(linearLayoutManager); // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter); // ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff")); // addExpandableFeatures(); // // } // // private void addExpandableFeatures() { // ultimateRecyclerView.getItemAnimator().setAddDuration(100); // ultimateRecyclerView.getItemAnimator().setRemoveDuration(100); // ultimateRecyclerView.getItemAnimator().setMoveDuration(200); // ultimateRecyclerView.getItemAnimator().setChangeDuration(100); // } // // } // // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java // public class mainpageDemo extends Fragment { // @Override // public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // return inflater.inflate(R.layout.activity_main, container, false); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // Button bIntent = (Button) view.findViewById(R.id.openNewIntent); // bIntent.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class); // } // }); // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/demosys.java import android.app.Fragment; import com.hkm.slidingmenulib.gestured.SlidingMenu; import com.hkm.slidingmenulib.layoutdesigns.app.SlidingAppCompactActivity; import com.hypebeast.demoslidemenu.content.expandablemenu.MenuFragment; import com.hypebeast.demoslidemenu.content.mainpageDemo; package com.hypebeast.demoslidemenu; /** * Created by hesk on 10/7/15. */ public class demosys extends SlidingAppCompactActivity<Fragment> { @Override protected int getDefaultMainActivityLayoutId() { return SlidingAppCompactActivity.BODY_LAYOUT.actionbar.getResID(); } @Override protected MenuFragment getFirstMenuFragment() { return new MenuFragment(); } @Override protected int getRmenu() { return R.menu.menu_main; } @Override
protected mainpageDemo getInitFragment() {
jjhesk/KickAssSlidingMenu
AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/CommonSingle.java // public class CommonSingle extends singleDetailPost<DemoFrag2>{ // @Override // protected void loadPageWithFullURL(String url) { // // } // // @Override // protected void loadPageWithPID(long pid) { // // } // // /** // * setting the first initial fragment at the beginning // * // * @return generic type fragment // * @throws Exception the exception for the wrongs // */ // @Override // protected DemoFrag2 getInitFragment() throws Exception { // return new DemoFrag2(); // } // // @Override // protected void onMenuItemSelected(@IdRes int Id) { // // } // }
import android.app.Fragment; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import com.hkm.slidingmenulib.Util.Utils; import com.hypebeast.demoslidemenu.CommonSingle; import com.hypebeast.demoslidemenu.R;
package com.hypebeast.demoslidemenu.content; /** * Created by hesk on 23/6/15. */ public class mainpageDemo extends Fragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.activity_main, container, false); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Button bIntent = (Button) view.findViewById(R.id.openNewIntent); bIntent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
// Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/CommonSingle.java // public class CommonSingle extends singleDetailPost<DemoFrag2>{ // @Override // protected void loadPageWithFullURL(String url) { // // } // // @Override // protected void loadPageWithPID(long pid) { // // } // // /** // * setting the first initial fragment at the beginning // * // * @return generic type fragment // * @throws Exception the exception for the wrongs // */ // @Override // protected DemoFrag2 getInitFragment() throws Exception { // return new DemoFrag2(); // } // // @Override // protected void onMenuItemSelected(@IdRes int Id) { // // } // } // Path: AdvancedSlidingMenu/demoslidemenu/src/main/java/com/hypebeast/demoslidemenu/content/mainpageDemo.java import android.app.Fragment; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import com.hkm.slidingmenulib.Util.Utils; import com.hypebeast.demoslidemenu.CommonSingle; import com.hypebeast.demoslidemenu.R; package com.hypebeast.demoslidemenu.content; /** * Created by hesk on 23/6/15. */ public class mainpageDemo extends Fragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.activity_main, container, false); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Button bIntent = (Button) view.findViewById(R.id.openNewIntent); bIntent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
Utils.routeSinglePage("nothing", getActivity(), CommonSingle.class);
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/TestSlideActivity.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // }
import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout;
/* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * This demo does not work. */ public class TestSlideActivity extends Activity { ViewGroup parentLayout; LinearLayout layout1; LinearLayout layout2; boolean layout1Shown = true; class ClickListener implements OnClickListener { @Override public void onClick(View v) {
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/TestSlideActivity.java import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; /* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * This demo does not work. */ public class TestSlideActivity extends Activity { ViewGroup parentLayout; LinearLayout layout1; LinearLayout layout2; boolean layout1Shown = true; class ClickListener implements OnClickListener { @Override public void onClick(View v) {
ViewUtils.printView("parentLayout", parentLayout);
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/sectionPlate/touchItems/MaterialListSection.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/ImaterialBinder.java // public interface ImaterialBinder { // int getLayout(); // // View init(View view); // }
import android.animation.Animator; import android.animation.ValueAnimator; import android.annotation.SuppressLint; import android.content.res.Resources; import android.support.v4.view.ViewCompat; import android.support.v7.widget.LinearLayoutManager; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.ImageView; import android.widget.TextView; import com.marshalchen.ultimaterecyclerview.UltimateRecyclerView; import com.marshalchen.ultimaterecyclerview.layoutmanagers.CustomLinearLayoutManager; import com.marshalchen.ultimaterecyclerview.quickAdapter.easyRegularAdapter; import java.util.List; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.ImaterialBinder;
package mxh.kickassmenu.menucontent.sectionPlate.touchItems; /** * Created by hesk on 25/6/15. * from the HB STORE project 2015 */ public class MaterialListSection<TD, CustomTextView extends TextView, RenderBinder extends MaterialListSection.RenderViewBindAdapter> implements ImaterialBinder { public CustomTextView text, notificationtext; public ImageView indicator, icon; public UltimateRecyclerView listview; public static String TAG = "txtNavigation"; private RenderBinder renderer; private boolean mstatusShown, animate_indicator; private View mContainer; private int mContainerOriginalHeight, itemcounts, bottomNavigationHeight;
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/LockableScrollView.java // public class LockableScrollView extends ScrollView { // private boolean mScrollable = true; // // public LockableScrollView(Context context) { // super(context); // } // // public LockableScrollView(Context context, AttributeSet attrs) { // super(context, attrs); // } // // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { // super(context, attrs, defStyleAttr); // } // // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { // super(context, attrs, defStyleAttr, defStyleRes); // } // // public void setScrollingEnabled(boolean enabled) { // mScrollable = enabled; // } // // public boolean isScrollable() { // return mScrollable; // } // // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // // if we can scroll pass the event to the superclass // if (mScrollable) return super.onTouchEvent(ev); // // only continue to handle the touch event if scrolling enabled // return mScrollable; // mScrollable is always false at this point // default: // return super.onTouchEvent(ev); // } // } // // @Override // public boolean onInterceptTouchEvent(MotionEvent ev) { // // Don't do anything with intercepted touch events if // // we are not scrollable // if (!mScrollable) return false; // else return super.onInterceptTouchEvent(ev); // } // } // // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/ImaterialBinder.java // public interface ImaterialBinder { // int getLayout(); // // View init(View view); // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/menucontent/sectionPlate/touchItems/MaterialListSection.java import android.animation.Animator; import android.animation.ValueAnimator; import android.annotation.SuppressLint; import android.content.res.Resources; import android.support.v4.view.ViewCompat; import android.support.v7.widget.LinearLayoutManager; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.ImageView; import android.widget.TextView; import com.marshalchen.ultimaterecyclerview.UltimateRecyclerView; import com.marshalchen.ultimaterecyclerview.layoutmanagers.CustomLinearLayoutManager; import com.marshalchen.ultimaterecyclerview.quickAdapter.easyRegularAdapter; import java.util.List; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.LockableScrollView; import mxh.kickassmenu.menucontent.ImaterialBinder; package mxh.kickassmenu.menucontent.sectionPlate.touchItems; /** * Created by hesk on 25/6/15. * from the HB STORE project 2015 */ public class MaterialListSection<TD, CustomTextView extends TextView, RenderBinder extends MaterialListSection.RenderViewBindAdapter> implements ImaterialBinder { public CustomTextView text, notificationtext; public ImageView indicator, icon; public UltimateRecyclerView listview; public static String TAG = "txtNavigation"; private RenderBinder renderer; private boolean mstatusShown, animate_indicator; private View mContainer; private int mContainerOriginalHeight, itemcounts, bottomNavigationHeight;
private LockableScrollView scrollcontainer;
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/HorzScrollWithListMenu.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // }
import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast; import java.util.Date; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.HorizontalScrollView;
/* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * This demo uses a custom HorizontalScrollView that ignores touch events, and therefore does NOT allow manual scrolling. * * The only scrolling allowed is scrolling in code triggered by the menu button. * * When the button is pressed, both the menu and the app will scroll. So the menu isn't revealed from beneath the app, it * adjoins the app and moves with the app. */ public class HorzScrollWithListMenu extends Activity { MyHorizontalScrollView scrollView; View menu; View app; ImageView btnSlide; boolean menuOut = false; Handler handler = new Handler(); int btnWidth; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutInflater inflater = LayoutInflater.from(this); scrollView = (MyHorizontalScrollView) inflater.inflate(R.layout.horz_scroll_with_list_menu, null); setContentView(scrollView); menu = inflater.inflate(R.layout.horz_scroll_menu, null); app = inflater.inflate(R.layout.horz_scroll_app, null); ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar); ListView listView = (ListView) app.findViewById(R.id.list);
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/HorzScrollWithListMenu.java import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast; import java.util.Date; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.HorizontalScrollView; /* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * This demo uses a custom HorizontalScrollView that ignores touch events, and therefore does NOT allow manual scrolling. * * The only scrolling allowed is scrolling in code triggered by the menu button. * * When the button is pressed, both the menu and the app will scroll. So the menu isn't revealed from beneath the app, it * adjoins the app and moves with the app. */ public class HorzScrollWithListMenu extends Activity { MyHorizontalScrollView scrollView; View menu; View app; ImageView btnSlide; boolean menuOut = false; Handler handler = new Handler(); int btnWidth; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutInflater inflater = LayoutInflater.from(this); scrollView = (MyHorizontalScrollView) inflater.inflate(R.layout.horz_scroll_with_list_menu, null); setContentView(scrollView); menu = inflater.inflate(R.layout.horz_scroll_menu, null); app = inflater.inflate(R.layout.horz_scroll_app, null); ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar); ListView listView = (ListView) app.findViewById(R.id.list);
ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
jjhesk/KickAssSlidingMenu
slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/AnimationStackedFrames.java
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // }
import android.widget.ListView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.FrameLayout;
/* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * Animates the menu view over the app view in a FrameLayout. * * As this uses animations, after the menu has moved over the app, touch events are still passed to the app, as the menu View * actually hasn't moved. The animation just renders the menu in a different location to its real position. */ public class AnimationStackedFrames extends Activity implements AnimationListener { FrameLayout mFrameLayout; View menu; View app; boolean menuOut = false; class ClickListener implements OnClickListener { @Override public void onClick(View v) { AnimationStackedFrames me = AnimationStackedFrames.this; Context context = me; Animation anim; if (!menuOut) { menu.setVisibility(View.VISIBLE);
// Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/Util/ViewUtils.java // public class ViewUtils { // private ViewUtils() { // } // // public static void setViewWidths(View view, View[] views) { // int w = view.getWidth(); // int h = view.getHeight(); // for (int i = 0; i < views.length; i++) { // View v = views[i]; // v.layout((i + 1) * w, 0, (i + 2) * w, h); // printView("view[" + i + "]", v); // } // } // // public static void printView(String msg, View v) { // System.out.println(msg + "=" + v); // if (null == v) { // return; // } // System.out.print("[" + v.getLeft()); // System.out.print(", " + v.getTop()); // System.out.print(", w=" + v.getWidth()); // System.out.println(", h=" + v.getHeight() + "]"); // System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); // System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); // } // // public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // // By using setAdpater method in listview we an add string array in list. // String[] arr = new String[numItems]; // for (int i = 0; i < arr.length; i++) { // arr[i] = prefix + (i + 1); // } // listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); // listView.setOnItemClickListener(new OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Context context = view.getContext(); // String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); // Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); // System.out.println(msg); // } // }); // } // } // Path: slideOutMenu/menux/src/main/java/mxh/kickassmenu/fbstyle/AnimationStackedFrames.java import android.widget.ListView; import mxh.kickassmenu.R; import mxh.kickassmenu.Util.ViewUtils; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.FrameLayout; /* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package mxh.kickassmenu.fbstyle; /** * Animates the menu view over the app view in a FrameLayout. * * As this uses animations, after the menu has moved over the app, touch events are still passed to the app, as the menu View * actually hasn't moved. The animation just renders the menu in a different location to its real position. */ public class AnimationStackedFrames extends Activity implements AnimationListener { FrameLayout mFrameLayout; View menu; View app; boolean menuOut = false; class ClickListener implements OnClickListener { @Override public void onClick(View v) { AnimationStackedFrames me = AnimationStackedFrames.this; Context context = me; Animation anim; if (!menuOut) { menu.setVisibility(View.VISIBLE);
ViewUtils.printView("menu", menu);
kristianmandrup/emberjs-plugin
src/org/emberjs/EmberJSTargetElementEvaluator.java
// Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import com.intellij.codeInsight.TargetElementEvaluator; import com.intellij.lang.javascript.psi.JSCallExpression; import com.intellij.lang.javascript.psi.JSExpression; import com.intellij.lang.javascript.psi.JSReferenceExpression; import com.intellij.lang.javascript.psi.impl.JSTextReference; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.util.PsiTreeUtil; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
package org.emberjs; /** * @author Kristian Mandrup */ public class EmberJSTargetElementEvaluator implements TargetElementEvaluator { @Override public boolean includeSelfInGotoImplementation(@NotNull PsiElement element) { return false; } @Nullable @Override public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) { if (ref instanceof JSTextReference) { final PsiElement element = ref.getElement(); final JSCallExpression call = PsiTreeUtil.getParentOfType(element, JSCallExpression.class); final JSExpression expression = call != null ? call.getMethodExpression() : null; if (expression instanceof JSReferenceExpression) { JSReferenceExpression callee = (JSReferenceExpression)expression; JSExpression qualifier = callee.getQualifier(); if (qualifier != null && "component".equals(callee.getReferencedName()) &&
// Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/EmberJSTargetElementEvaluator.java import com.intellij.codeInsight.TargetElementEvaluator; import com.intellij.lang.javascript.psi.JSCallExpression; import com.intellij.lang.javascript.psi.JSExpression; import com.intellij.lang.javascript.psi.JSReferenceExpression; import com.intellij.lang.javascript.psi.impl.JSTextReference; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.util.PsiTreeUtil; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; package org.emberjs; /** * @author Kristian Mandrup */ public class EmberJSTargetElementEvaluator implements TargetElementEvaluator { @Override public boolean includeSelfInGotoImplementation(@NotNull PsiElement element) { return false; } @Nullable @Override public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) { if (ref instanceof JSTextReference) { final PsiElement element = ref.getElement(); final JSCallExpression call = PsiTreeUtil.getParentOfType(element, JSCallExpression.class); final JSExpression expression = call != null ? call.getMethodExpression() : null; if (expression instanceof JSReferenceExpression) { JSReferenceExpression callee = (JSReferenceExpression)expression; JSExpression qualifier = callee.getQualifier(); if (qualifier != null && "component".equals(callee.getReferencedName()) &&
EmberIndexUtil.hasEmberJS(element.getProject())) {
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/ComponentUtil.java
// Path: src/org/emberjs/index/EmberComponentDocIndex.java // public class EmberComponentDocIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("angularjs.components.doc.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberComponentIndex.java // public class EmberComponentIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.component.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.util.Processor; import com.intellij.util.indexing.ID; import org.emberjs.index.EmberComponentDocIndex; import org.emberjs.index.EmberComponentIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.Nullable; import java.util.Collection;
package org.emberjs.codeInsight; /** * @author Kristian Mandrup */ public class ComponentUtil { public static String getAttributeName(final String text) { final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); for (int i = 0; i < split.length; i++) { split[i] = StringUtil.decapitalize(split[i]); } return StringUtil.join(split, "-"); } public static String attributeToComponent(String name) { final String[] words = name.split("-"); for (int i = 1; i < words.length; i++) { words[i] = StringUtil.capitalize(words[i]); } return StringUtil.join(words); } public static boolean processComponents(final Project project, Processor<JSNamedElementProxy> processor) {
// Path: src/org/emberjs/index/EmberComponentDocIndex.java // public class EmberComponentDocIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("angularjs.components.doc.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberComponentIndex.java // public class EmberComponentIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.component.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/codeInsight/ComponentUtil.java import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.util.Processor; import com.intellij.util.indexing.ID; import org.emberjs.index.EmberComponentDocIndex; import org.emberjs.index.EmberComponentIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.Nullable; import java.util.Collection; package org.emberjs.codeInsight; /** * @author Kristian Mandrup */ public class ComponentUtil { public static String getAttributeName(final String text) { final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); for (int i = 0; i < split.length; i++) { split[i] = StringUtil.decapitalize(split[i]); } return StringUtil.join(split, "-"); } public static String attributeToComponent(String name) { final String[] words = name.split("-"); for (int i = 1; i < words.length; i++) { words[i] = StringUtil.capitalize(words[i]); } return StringUtil.join(words); } public static boolean processComponents(final Project project, Processor<JSNamedElementProxy> processor) {
final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project);
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/ComponentUtil.java
// Path: src/org/emberjs/index/EmberComponentDocIndex.java // public class EmberComponentDocIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("angularjs.components.doc.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberComponentIndex.java // public class EmberComponentIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.component.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.util.Processor; import com.intellij.util.indexing.ID; import org.emberjs.index.EmberComponentDocIndex; import org.emberjs.index.EmberComponentIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.Nullable; import java.util.Collection;
package org.emberjs.codeInsight; /** * @author Kristian Mandrup */ public class ComponentUtil { public static String getAttributeName(final String text) { final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); for (int i = 0; i < split.length; i++) { split[i] = StringUtil.decapitalize(split[i]); } return StringUtil.join(split, "-"); } public static String attributeToComponent(String name) { final String[] words = name.split("-"); for (int i = 1; i < words.length; i++) { words[i] = StringUtil.capitalize(words[i]); } return StringUtil.join(words); } public static boolean processComponents(final Project project, Processor<JSNamedElementProxy> processor) {
// Path: src/org/emberjs/index/EmberComponentDocIndex.java // public class EmberComponentDocIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("angularjs.components.doc.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberComponentIndex.java // public class EmberComponentIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.component.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/codeInsight/ComponentUtil.java import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.util.Processor; import com.intellij.util.indexing.ID; import org.emberjs.index.EmberComponentDocIndex; import org.emberjs.index.EmberComponentIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.Nullable; import java.util.Collection; package org.emberjs.codeInsight; /** * @author Kristian Mandrup */ public class ComponentUtil { public static String getAttributeName(final String text) { final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); for (int i = 0; i < split.length; i++) { split[i] = StringUtil.decapitalize(split[i]); } return StringUtil.join(split, "-"); } public static String attributeToComponent(String name) { final String[] words = name.split("-"); for (int i = 1; i < words.length; i++) { words[i] = StringUtil.capitalize(words[i]); } return StringUtil.join(words); } public static boolean processComponents(final Project project, Processor<JSNamedElementProxy> processor) {
final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project);
kristianmandrup/emberjs-plugin
src/org/emberjs/lang/lexer/EmberJSTokenType.java
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // }
import com.intellij.psi.tree.IElementType; import org.emberjs.lang.EmberJSLanguage; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull;
package org.emberjs.lang.lexer; /** * @author Dennis.Ushakov */ public class EmberJSTokenType extends IElementType { public EmberJSTokenType(@NotNull @NonNls String debugName) {
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // } // Path: src/org/emberjs/lang/lexer/EmberJSTokenType.java import com.intellij.psi.tree.IElementType; import org.emberjs.lang.EmberJSLanguage; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; package org.emberjs.lang.lexer; /** * @author Dennis.Ushakov */ public class EmberJSTokenType extends IElementType { public EmberJSTokenType(@NotNull @NonNls String debugName) {
super(debugName, EmberJSLanguage.INSTANCE);
kristianmandrup/emberjs-plugin
src/org/emberjs/navigation/EmberGotoSymbolContributor.java
// Path: src/org/emberjs/index/EmberSymbolIndex.java // public class EmberSymbolIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.symbol.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import org.emberjs.index.EmberSymbolIndex; import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.navigation.ChooseByNameContributor; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.project.Project; import com.intellij.util.ArrayUtil; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull;
package org.emberjs.navigation; /** * @author Kristian Mandrup */ public class EmberGotoSymbolContributor implements ChooseByNameContributor { @NotNull @Override public String[] getNames(Project project, boolean includeNonProjectItems) {
// Path: src/org/emberjs/index/EmberSymbolIndex.java // public class EmberSymbolIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.symbol.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/navigation/EmberGotoSymbolContributor.java import org.emberjs.index.EmberSymbolIndex; import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.navigation.ChooseByNameContributor; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.project.Project; import com.intellij.util.ArrayUtil; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; package org.emberjs.navigation; /** * @author Kristian Mandrup */ public class EmberGotoSymbolContributor implements ChooseByNameContributor { @NotNull @Override public String[] getNames(Project project, boolean includeNonProjectItems) {
return ArrayUtil.toStringArray(EmberIndexUtil.getAllKeys(EmberSymbolIndex.INDEX_ID, project));
kristianmandrup/emberjs-plugin
src/org/emberjs/navigation/EmberGotoSymbolContributor.java
// Path: src/org/emberjs/index/EmberSymbolIndex.java // public class EmberSymbolIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.symbol.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import org.emberjs.index.EmberSymbolIndex; import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.navigation.ChooseByNameContributor; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.project.Project; import com.intellij.util.ArrayUtil; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull;
package org.emberjs.navigation; /** * @author Kristian Mandrup */ public class EmberGotoSymbolContributor implements ChooseByNameContributor { @NotNull @Override public String[] getNames(Project project, boolean includeNonProjectItems) {
// Path: src/org/emberjs/index/EmberSymbolIndex.java // public class EmberSymbolIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.symbol.index"); // // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/navigation/EmberGotoSymbolContributor.java import org.emberjs.index.EmberSymbolIndex; import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.navigation.ChooseByNameContributor; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.project.Project; import com.intellij.util.ArrayUtil; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; package org.emberjs.navigation; /** * @author Kristian Mandrup */ public class EmberGotoSymbolContributor implements ChooseByNameContributor { @NotNull @Override public String[] getNames(Project project, boolean includeNonProjectItems) {
return ArrayUtil.toStringArray(EmberIndexUtil.getAllKeys(EmberSymbolIndex.INDEX_ID, project));
kristianmandrup/emberjs-plugin
src/org/emberjs/findUsages/EmberJSReferenceSearcher.java
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // }
import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.Processor; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull;
package org.emberjs.findUsages; /** * @author Kristian Mandrup */ public class EmberJSReferenceSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> { protected EmberJSReferenceSearcher() { super(true); } // TODO: How can we do something similar/meaningful for Ember?? @Override public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) { final PsiElement element = queryParameters.getElementToSearch();
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // } // Path: src/org/emberjs/findUsages/EmberJSReferenceSearcher.java import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.Processor; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull; package org.emberjs.findUsages; /** * @author Kristian Mandrup */ public class EmberJSReferenceSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> { protected EmberJSReferenceSearcher() { super(true); } // TODO: How can we do something similar/meaningful for Ember?? @Override public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) { final PsiElement element = queryParameters.getElementToSearch();
final JSNamedElementProxy component = ComponentUtil.getComponent(element);
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/refs/EmberJSReferencesContributor.java
// Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.lang.javascript.psi.JSProperty; import com.intellij.patterns.PlatformPatterns; import com.intellij.patterns.PsiElementPattern; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReferenceContributor; import com.intellij.psi.PsiReferenceRegistrar; import com.intellij.psi.filters.ElementFilter; import com.intellij.psi.filters.position.FilterPattern; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
package org.emberjs.codeInsight.refs; /** * @author Dennis.Ushakov */ public class EmberJSReferencesContributor extends PsiReferenceContributor { private static final PsiElementPattern.Capture<JSLiteralExpression> TEMPLATE_PATTERN = literalInProperty("templateUrl"); private static final PsiElementPattern.Capture<JSLiteralExpression> CONTROLLER_PATTERN = literalInProperty("controller"); @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { final EmberJSTemplateReferencesProvider templateProvider = new EmberJSTemplateReferencesProvider(); registrar.registerReferenceProvider(TEMPLATE_PATTERN, templateProvider); registrar.registerReferenceProvider(CONTROLLER_PATTERN, new EmberJSControllerReferencesProvider()); } private static PsiElementPattern.Capture<JSLiteralExpression> literalInProperty(final String propertyName) { return PlatformPatterns.psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() { @Override public boolean isAcceptable(Object element, @Nullable PsiElement context) { if (element instanceof JSLiteralExpression) { final JSLiteralExpression literal = (JSLiteralExpression)element; if (literal.isQuotedLiteral()) { final PsiElement parent = literal.getParent(); if (parent instanceof JSProperty && propertyName.equals(((JSProperty)parent).getName())) {
// Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/codeInsight/refs/EmberJSReferencesContributor.java import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.lang.javascript.psi.JSProperty; import com.intellij.patterns.PlatformPatterns; import com.intellij.patterns.PsiElementPattern; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReferenceContributor; import com.intellij.psi.PsiReferenceRegistrar; import com.intellij.psi.filters.ElementFilter; import com.intellij.psi.filters.position.FilterPattern; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; package org.emberjs.codeInsight.refs; /** * @author Dennis.Ushakov */ public class EmberJSReferencesContributor extends PsiReferenceContributor { private static final PsiElementPattern.Capture<JSLiteralExpression> TEMPLATE_PATTERN = literalInProperty("templateUrl"); private static final PsiElementPattern.Capture<JSLiteralExpression> CONTROLLER_PATTERN = literalInProperty("controller"); @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { final EmberJSTemplateReferencesProvider templateProvider = new EmberJSTemplateReferencesProvider(); registrar.registerReferenceProvider(TEMPLATE_PATTERN, templateProvider); registrar.registerReferenceProvider(CONTROLLER_PATTERN, new EmberJSControllerReferencesProvider()); } private static PsiElementPattern.Capture<JSLiteralExpression> literalInProperty(final String propertyName) { return PlatformPatterns.psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() { @Override public boolean isAcceptable(Object element, @Nullable PsiElement context) { if (element instanceof JSLiteralExpression) { final JSLiteralExpression literal = (JSLiteralExpression)element; if (literal.isQuotedLiteral()) { final PsiElement parent = literal.getParent(); if (parent instanceof JSProperty && propertyName.equals(((JSProperty)parent).getName())) {
return EmberIndexUtil.hasEmberJS(literal.getProject());
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/EmberJSHtmlExtension.java
// Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import com.intellij.psi.PsiFile; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; import com.intellij.xml.HtmlXmlExtension; import org.emberjs.index.EmberIndexUtil;
package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSHtmlExtension extends HtmlXmlExtension { @Override public boolean isAvailable(PsiFile file) {
// Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/codeInsight/EmberJSHtmlExtension.java import com.intellij.psi.PsiFile; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; import com.intellij.xml.HtmlXmlExtension; import org.emberjs.index.EmberIndexUtil; package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSHtmlExtension extends HtmlXmlExtension { @Override public boolean isAvailable(PsiFile file) {
return super.isAvailable(file) && EmberIndexUtil.hasEmberJS(file.getProject());
kristianmandrup/emberjs-plugin
src/org/emberjs/lang/psi/EmberJSAsExpression.java
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // }
import com.intellij.lang.ASTNode; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.impl.JSBinaryExpressionImpl; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.PsiReference; import com.intellij.psi.impl.source.xml.XmlAttributeValueImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
package org.emberjs.lang.psi; /** * @author Dennis.Ushakov */ public class EmberJSAsExpression extends JSBinaryExpressionImpl { public EmberJSAsExpression(ASTNode node) { super(node); } @Nullable public JSDefinitionExpression getDefinition() { return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); } @Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof EmberJSElementVisitor) { ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); } else { super.accept(visitor); } } public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { return true; } final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; final String normalized = hostParent instanceof XmlAttribute ?
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // } // Path: src/org/emberjs/lang/psi/EmberJSAsExpression.java import com.intellij.lang.ASTNode; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.impl.JSBinaryExpressionImpl; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.PsiReference; import com.intellij.psi.impl.source.xml.XmlAttributeValueImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; package org.emberjs.lang.psi; /** * @author Dennis.Ushakov */ public class EmberJSAsExpression extends JSBinaryExpressionImpl { public EmberJSAsExpression(ASTNode node) { super(node); } @Nullable public JSDefinitionExpression getDefinition() { return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); } @Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof EmberJSElementVisitor) { ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); } else { super.accept(visitor); } } public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { return true; } final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; final String normalized = hostParent instanceof XmlAttribute ?
ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null;
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/EmberJSProcessor.java
// Path: src/org/emberjs/lang/psi/EmberJSAsExpression.java // public class EmberJSAsExpression extends JSBinaryExpressionImpl { // public EmberJSAsExpression(ASTNode node) { // super(node); // } // // @Nullable // public JSDefinitionExpression getDefinition() { // return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); // } else { // super.accept(visitor); // } // } // // public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { // if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { // return true; // } // final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); // final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); // final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; // final String normalized = hostParent instanceof XmlAttribute ? // ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null; // // // TODO: Do some kind of test // return true; // // return "ng-controller".equals(normalized); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRecursiveVisitor.java // public class EmberJSRecursiveVisitor extends EmberJSElementVisitor { // @Override // public void visitElement(PsiElement element) { // element.acceptChildren(this); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRepeatExpression.java // public class EmberJSRepeatExpression extends JSExpressionImpl { // public EmberJSRepeatExpression(ASTNode node) { // super(node); // } // // public Collection<JSDefinitionExpression> getDefinitions() { // final PsiElement firstChild = getFirstChild(); // if (firstChild instanceof JSDefinitionExpression) { // return Collections.singletonList((JSDefinitionExpression)firstChild); // } else if (firstChild instanceof JSParenthesizedExpression) { // final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); // if (commaExpression != null) { // return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); // } // } // return Collections.emptyList(); // } // // public JSExpression getCollection() { // final ASTNode myNode = getNode(); // final ASTNode secondExpression = myNode.findChildByType( // JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) // ); // return secondExpression != null ? (JSExpression)secondExpression.getPsi() : null; // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSRepeatExpression(this); // } else { // super.accept(visitor); // } // } // }
import com.intellij.codeInsight.completion.CompletionUtil; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.flex.XmlBackedJSClassImpl; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.JSFile; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.resolve.ImplicitJSVariableImpl; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.impl.source.html.HtmlEmbeddedContentImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; import com.intellij.util.Consumer; import org.emberjs.lang.psi.EmberJSAsExpression; import org.emberjs.lang.psi.EmberJSRecursiveVisitor; import org.emberjs.lang.psi.EmberJSRepeatExpression; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSProcessor { private static final Map<String, String> NG_REPEAT_IMPLICITS = new HashMap<String, String>(); static { NG_REPEAT_IMPLICITS.put("$alias", "String"); NG_REPEAT_IMPLICITS.put("$model", "String"); } public static void process(final PsiElement element, final Consumer<JSNamedElement> consumer) { final PsiElement original = CompletionUtil.getOriginalOrSelf(element); final PsiFile hostFile = FileContextUtil.getContextFile(original != element ? original : element.getContainingFile().getOriginalFile()); if (hostFile == null) return; final XmlFile file = (XmlFile)hostFile; final JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() { @Override protected void process(JSFile file) {
// Path: src/org/emberjs/lang/psi/EmberJSAsExpression.java // public class EmberJSAsExpression extends JSBinaryExpressionImpl { // public EmberJSAsExpression(ASTNode node) { // super(node); // } // // @Nullable // public JSDefinitionExpression getDefinition() { // return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); // } else { // super.accept(visitor); // } // } // // public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { // if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { // return true; // } // final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); // final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); // final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; // final String normalized = hostParent instanceof XmlAttribute ? // ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null; // // // TODO: Do some kind of test // return true; // // return "ng-controller".equals(normalized); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRecursiveVisitor.java // public class EmberJSRecursiveVisitor extends EmberJSElementVisitor { // @Override // public void visitElement(PsiElement element) { // element.acceptChildren(this); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRepeatExpression.java // public class EmberJSRepeatExpression extends JSExpressionImpl { // public EmberJSRepeatExpression(ASTNode node) { // super(node); // } // // public Collection<JSDefinitionExpression> getDefinitions() { // final PsiElement firstChild = getFirstChild(); // if (firstChild instanceof JSDefinitionExpression) { // return Collections.singletonList((JSDefinitionExpression)firstChild); // } else if (firstChild instanceof JSParenthesizedExpression) { // final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); // if (commaExpression != null) { // return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); // } // } // return Collections.emptyList(); // } // // public JSExpression getCollection() { // final ASTNode myNode = getNode(); // final ASTNode secondExpression = myNode.findChildByType( // JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) // ); // return secondExpression != null ? (JSExpression)secondExpression.getPsi() : null; // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSRepeatExpression(this); // } else { // super.accept(visitor); // } // } // } // Path: src/org/emberjs/codeInsight/EmberJSProcessor.java import com.intellij.codeInsight.completion.CompletionUtil; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.flex.XmlBackedJSClassImpl; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.JSFile; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.resolve.ImplicitJSVariableImpl; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.impl.source.html.HtmlEmbeddedContentImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; import com.intellij.util.Consumer; import org.emberjs.lang.psi.EmberJSAsExpression; import org.emberjs.lang.psi.EmberJSRecursiveVisitor; import org.emberjs.lang.psi.EmberJSRepeatExpression; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSProcessor { private static final Map<String, String> NG_REPEAT_IMPLICITS = new HashMap<String, String>(); static { NG_REPEAT_IMPLICITS.put("$alias", "String"); NG_REPEAT_IMPLICITS.put("$model", "String"); } public static void process(final PsiElement element, final Consumer<JSNamedElement> consumer) { final PsiElement original = CompletionUtil.getOriginalOrSelf(element); final PsiFile hostFile = FileContextUtil.getContextFile(original != element ? original : element.getContainingFile().getOriginalFile()); if (hostFile == null) return; final XmlFile file = (XmlFile)hostFile; final JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() { @Override protected void process(JSFile file) {
file.accept(new EmberJSRecursiveVisitor() {
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/EmberJSProcessor.java
// Path: src/org/emberjs/lang/psi/EmberJSAsExpression.java // public class EmberJSAsExpression extends JSBinaryExpressionImpl { // public EmberJSAsExpression(ASTNode node) { // super(node); // } // // @Nullable // public JSDefinitionExpression getDefinition() { // return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); // } else { // super.accept(visitor); // } // } // // public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { // if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { // return true; // } // final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); // final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); // final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; // final String normalized = hostParent instanceof XmlAttribute ? // ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null; // // // TODO: Do some kind of test // return true; // // return "ng-controller".equals(normalized); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRecursiveVisitor.java // public class EmberJSRecursiveVisitor extends EmberJSElementVisitor { // @Override // public void visitElement(PsiElement element) { // element.acceptChildren(this); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRepeatExpression.java // public class EmberJSRepeatExpression extends JSExpressionImpl { // public EmberJSRepeatExpression(ASTNode node) { // super(node); // } // // public Collection<JSDefinitionExpression> getDefinitions() { // final PsiElement firstChild = getFirstChild(); // if (firstChild instanceof JSDefinitionExpression) { // return Collections.singletonList((JSDefinitionExpression)firstChild); // } else if (firstChild instanceof JSParenthesizedExpression) { // final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); // if (commaExpression != null) { // return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); // } // } // return Collections.emptyList(); // } // // public JSExpression getCollection() { // final ASTNode myNode = getNode(); // final ASTNode secondExpression = myNode.findChildByType( // JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) // ); // return secondExpression != null ? (JSExpression)secondExpression.getPsi() : null; // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSRepeatExpression(this); // } else { // super.accept(visitor); // } // } // }
import com.intellij.codeInsight.completion.CompletionUtil; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.flex.XmlBackedJSClassImpl; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.JSFile; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.resolve.ImplicitJSVariableImpl; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.impl.source.html.HtmlEmbeddedContentImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; import com.intellij.util.Consumer; import org.emberjs.lang.psi.EmberJSAsExpression; import org.emberjs.lang.psi.EmberJSRecursiveVisitor; import org.emberjs.lang.psi.EmberJSRepeatExpression; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSProcessor { private static final Map<String, String> NG_REPEAT_IMPLICITS = new HashMap<String, String>(); static { NG_REPEAT_IMPLICITS.put("$alias", "String"); NG_REPEAT_IMPLICITS.put("$model", "String"); } public static void process(final PsiElement element, final Consumer<JSNamedElement> consumer) { final PsiElement original = CompletionUtil.getOriginalOrSelf(element); final PsiFile hostFile = FileContextUtil.getContextFile(original != element ? original : element.getContainingFile().getOriginalFile()); if (hostFile == null) return; final XmlFile file = (XmlFile)hostFile; final JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() { @Override protected void process(JSFile file) { file.accept(new EmberJSRecursiveVisitor() { @Override public void visitJSDefinitionExpression(JSDefinitionExpression node) { if (scopeMatches(original, node)) { consumer.consume(node); } super.visitJSDefinitionExpression(node); } // handlebars {{#each alias as @Override
// Path: src/org/emberjs/lang/psi/EmberJSAsExpression.java // public class EmberJSAsExpression extends JSBinaryExpressionImpl { // public EmberJSAsExpression(ASTNode node) { // super(node); // } // // @Nullable // public JSDefinitionExpression getDefinition() { // return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); // } else { // super.accept(visitor); // } // } // // public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { // if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { // return true; // } // final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); // final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); // final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; // final String normalized = hostParent instanceof XmlAttribute ? // ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null; // // // TODO: Do some kind of test // return true; // // return "ng-controller".equals(normalized); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRecursiveVisitor.java // public class EmberJSRecursiveVisitor extends EmberJSElementVisitor { // @Override // public void visitElement(PsiElement element) { // element.acceptChildren(this); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRepeatExpression.java // public class EmberJSRepeatExpression extends JSExpressionImpl { // public EmberJSRepeatExpression(ASTNode node) { // super(node); // } // // public Collection<JSDefinitionExpression> getDefinitions() { // final PsiElement firstChild = getFirstChild(); // if (firstChild instanceof JSDefinitionExpression) { // return Collections.singletonList((JSDefinitionExpression)firstChild); // } else if (firstChild instanceof JSParenthesizedExpression) { // final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); // if (commaExpression != null) { // return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); // } // } // return Collections.emptyList(); // } // // public JSExpression getCollection() { // final ASTNode myNode = getNode(); // final ASTNode secondExpression = myNode.findChildByType( // JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) // ); // return secondExpression != null ? (JSExpression)secondExpression.getPsi() : null; // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSRepeatExpression(this); // } else { // super.accept(visitor); // } // } // } // Path: src/org/emberjs/codeInsight/EmberJSProcessor.java import com.intellij.codeInsight.completion.CompletionUtil; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.flex.XmlBackedJSClassImpl; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.JSFile; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.resolve.ImplicitJSVariableImpl; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.impl.source.html.HtmlEmbeddedContentImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; import com.intellij.util.Consumer; import org.emberjs.lang.psi.EmberJSAsExpression; import org.emberjs.lang.psi.EmberJSRecursiveVisitor; import org.emberjs.lang.psi.EmberJSRepeatExpression; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSProcessor { private static final Map<String, String> NG_REPEAT_IMPLICITS = new HashMap<String, String>(); static { NG_REPEAT_IMPLICITS.put("$alias", "String"); NG_REPEAT_IMPLICITS.put("$model", "String"); } public static void process(final PsiElement element, final Consumer<JSNamedElement> consumer) { final PsiElement original = CompletionUtil.getOriginalOrSelf(element); final PsiFile hostFile = FileContextUtil.getContextFile(original != element ? original : element.getContainingFile().getOriginalFile()); if (hostFile == null) return; final XmlFile file = (XmlFile)hostFile; final JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() { @Override protected void process(JSFile file) { file.accept(new EmberJSRecursiveVisitor() { @Override public void visitJSDefinitionExpression(JSDefinitionExpression node) { if (scopeMatches(original, node)) { consumer.consume(node); } super.visitJSDefinitionExpression(node); } // handlebars {{#each alias as @Override
public void visitEmberJSAsExpression(EmberJSAsExpression asExpression) {
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/EmberJSProcessor.java
// Path: src/org/emberjs/lang/psi/EmberJSAsExpression.java // public class EmberJSAsExpression extends JSBinaryExpressionImpl { // public EmberJSAsExpression(ASTNode node) { // super(node); // } // // @Nullable // public JSDefinitionExpression getDefinition() { // return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); // } else { // super.accept(visitor); // } // } // // public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { // if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { // return true; // } // final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); // final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); // final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; // final String normalized = hostParent instanceof XmlAttribute ? // ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null; // // // TODO: Do some kind of test // return true; // // return "ng-controller".equals(normalized); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRecursiveVisitor.java // public class EmberJSRecursiveVisitor extends EmberJSElementVisitor { // @Override // public void visitElement(PsiElement element) { // element.acceptChildren(this); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRepeatExpression.java // public class EmberJSRepeatExpression extends JSExpressionImpl { // public EmberJSRepeatExpression(ASTNode node) { // super(node); // } // // public Collection<JSDefinitionExpression> getDefinitions() { // final PsiElement firstChild = getFirstChild(); // if (firstChild instanceof JSDefinitionExpression) { // return Collections.singletonList((JSDefinitionExpression)firstChild); // } else if (firstChild instanceof JSParenthesizedExpression) { // final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); // if (commaExpression != null) { // return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); // } // } // return Collections.emptyList(); // } // // public JSExpression getCollection() { // final ASTNode myNode = getNode(); // final ASTNode secondExpression = myNode.findChildByType( // JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) // ); // return secondExpression != null ? (JSExpression)secondExpression.getPsi() : null; // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSRepeatExpression(this); // } else { // super.accept(visitor); // } // } // }
import com.intellij.codeInsight.completion.CompletionUtil; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.flex.XmlBackedJSClassImpl; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.JSFile; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.resolve.ImplicitJSVariableImpl; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.impl.source.html.HtmlEmbeddedContentImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; import com.intellij.util.Consumer; import org.emberjs.lang.psi.EmberJSAsExpression; import org.emberjs.lang.psi.EmberJSRecursiveVisitor; import org.emberjs.lang.psi.EmberJSRepeatExpression; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
public static void process(final PsiElement element, final Consumer<JSNamedElement> consumer) { final PsiElement original = CompletionUtil.getOriginalOrSelf(element); final PsiFile hostFile = FileContextUtil.getContextFile(original != element ? original : element.getContainingFile().getOriginalFile()); if (hostFile == null) return; final XmlFile file = (XmlFile)hostFile; final JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() { @Override protected void process(JSFile file) { file.accept(new EmberJSRecursiveVisitor() { @Override public void visitJSDefinitionExpression(JSDefinitionExpression node) { if (scopeMatches(original, node)) { consumer.consume(node); } super.visitJSDefinitionExpression(node); } // handlebars {{#each alias as @Override public void visitEmberJSAsExpression(EmberJSAsExpression asExpression) { final JSDefinitionExpression def = asExpression.getDefinition(); if (def != null && scopeMatches(original, asExpression)) { consumer.consume(def); } } // handlebars {{#each @Override
// Path: src/org/emberjs/lang/psi/EmberJSAsExpression.java // public class EmberJSAsExpression extends JSBinaryExpressionImpl { // public EmberJSAsExpression(ASTNode node) { // super(node); // } // // @Nullable // public JSDefinitionExpression getDefinition() { // return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSAsExpression(this); // } else { // super.accept(visitor); // } // } // // public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { // if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { // return true; // } // final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); // final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); // final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; // final String normalized = hostParent instanceof XmlAttribute ? // ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null; // // // TODO: Do some kind of test // return true; // // return "ng-controller".equals(normalized); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRecursiveVisitor.java // public class EmberJSRecursiveVisitor extends EmberJSElementVisitor { // @Override // public void visitElement(PsiElement element) { // element.acceptChildren(this); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSRepeatExpression.java // public class EmberJSRepeatExpression extends JSExpressionImpl { // public EmberJSRepeatExpression(ASTNode node) { // super(node); // } // // public Collection<JSDefinitionExpression> getDefinitions() { // final PsiElement firstChild = getFirstChild(); // if (firstChild instanceof JSDefinitionExpression) { // return Collections.singletonList((JSDefinitionExpression)firstChild); // } else if (firstChild instanceof JSParenthesizedExpression) { // final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); // if (commaExpression != null) { // return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); // } // } // return Collections.emptyList(); // } // // public JSExpression getCollection() { // final ASTNode myNode = getNode(); // final ASTNode secondExpression = myNode.findChildByType( // JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) // ); // return secondExpression != null ? (JSExpression)secondExpression.getPsi() : null; // } // // @Override // public void accept(@NotNull PsiElementVisitor visitor) { // if (visitor instanceof EmberJSElementVisitor) { // ((EmberJSElementVisitor)visitor).visitEmberJSRepeatExpression(this); // } else { // super.accept(visitor); // } // } // } // Path: src/org/emberjs/codeInsight/EmberJSProcessor.java import com.intellij.codeInsight.completion.CompletionUtil; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.lang.javascript.flex.XmlBackedJSClassImpl; import com.intellij.lang.javascript.psi.JSDefinitionExpression; import com.intellij.lang.javascript.psi.JSFile; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.resolve.ImplicitJSVariableImpl; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.impl.source.html.HtmlEmbeddedContentImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; import com.intellij.util.Consumer; import org.emberjs.lang.psi.EmberJSAsExpression; import org.emberjs.lang.psi.EmberJSRecursiveVisitor; import org.emberjs.lang.psi.EmberJSRepeatExpression; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; public static void process(final PsiElement element, final Consumer<JSNamedElement> consumer) { final PsiElement original = CompletionUtil.getOriginalOrSelf(element); final PsiFile hostFile = FileContextUtil.getContextFile(original != element ? original : element.getContainingFile().getOriginalFile()); if (hostFile == null) return; final XmlFile file = (XmlFile)hostFile; final JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() { @Override protected void process(JSFile file) { file.accept(new EmberJSRecursiveVisitor() { @Override public void visitJSDefinitionExpression(JSDefinitionExpression node) { if (scopeMatches(original, node)) { consumer.consume(node); } super.visitJSDefinitionExpression(node); } // handlebars {{#each alias as @Override public void visitEmberJSAsExpression(EmberJSAsExpression asExpression) { final JSDefinitionExpression def = asExpression.getDefinition(); if (def != null && scopeMatches(original, asExpression)) { consumer.consume(def); } } // handlebars {{#each @Override
public void visitEmberJSRepeatExpression(EmberJSRepeatExpression repeatExpression) {
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/tags/EmberJSTagDescriptor.java
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // }
import com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor; import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.openapi.util.Condition; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.source.xml.XmlDocumentImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.xml.XmlAttributeDescriptor; import com.intellij.xml.XmlElementDescriptor; import com.intellij.xml.XmlElementsGroup; import com.intellij.xml.XmlNSDescriptor; import com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable;
public String getDefaultName() { return myName; } @Override public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) { XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class); if (xmlDocument == null) return EMPTY_ARRAY; return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument); } @Override public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) { XmlTag parent = contextTag.getParentTag(); if (parent == null) return null; final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true); return descriptor == null ? null : descriptor.getElementDescriptor(childTag); } @Override public XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable XmlTag context) { final String string = getDeclaration().getIndexItem().getTypeString(); final String attributes = string.split(";", -1)[3]; final String[] split = attributes.split(","); final XmlAttributeDescriptor[] result; if (split.length == 1 && split[0].isEmpty()) { result = XmlAttributeDescriptor.EMPTY; } else { result = new XmlAttributeDescriptor[split.length]; for (int i = 0; i < split.length; i++) {
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // } // Path: src/org/emberjs/codeInsight/tags/EmberJSTagDescriptor.java import com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor; import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.openapi.util.Condition; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.source.xml.XmlDocumentImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.xml.XmlAttributeDescriptor; import com.intellij.xml.XmlElementDescriptor; import com.intellij.xml.XmlElementsGroup; import com.intellij.xml.XmlNSDescriptor; import com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; public String getDefaultName() { return myName; } @Override public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) { XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class); if (xmlDocument == null) return EMPTY_ARRAY; return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument); } @Override public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) { XmlTag parent = contextTag.getParentTag(); if (parent == null) return null; final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true); return descriptor == null ? null : descriptor.getElementDescriptor(childTag); } @Override public XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable XmlTag context) { final String string = getDeclaration().getIndexItem().getTypeString(); final String attributes = string.split(";", -1)[3]; final String[] split = attributes.split(","); final XmlAttributeDescriptor[] result; if (split.length == 1 && split[0].isEmpty()) { result = XmlAttributeDescriptor.EMPTY; } else { result = new XmlAttributeDescriptor[split.length]; for (int i = 0; i < split.length; i++) {
result[i] = new AnyXmlAttributeDescriptor(ComponentUtil.getAttributeName(split[i]));
kristianmandrup/emberjs-plugin
src/org/emberjs/lang/EmberJSSyntaxHighlighterFactory.java
// Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSTokenTypes.java // public interface EmberJSTokenTypes extends JSTokenTypes { // EmberJSTokenType ESCAPE_SEQUENCE = new EmberJSTokenType("ESCAPE_SEQUENCE"); // EmberJSTokenType INVALID_ESCAPE_SEQUENCE = new EmberJSTokenType("INVALID_ESCAPE_SEQUENCE"); // EmberJSTokenType TRACK_BY_KEYWORD = new EmberJSTokenType("TRACK_BY_KEYWORD"); // EmberJSTokenType ONE_TIME_BINDING = new EmberJSTokenType("ONE_TIME_BINDING"); // }
import com.intellij.lang.javascript.JSTokenTypes; import com.intellij.lang.javascript.highlighting.JSHighlighter; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.psi.tree.IElementType; import gnu.trove.THashMap; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.lexer.EmberJSTokenTypes; import org.jetbrains.annotations.NotNull; import java.util.Map;
package org.emberjs.lang; /** * @author Dennis.Ushakov */ public class EmberJSSyntaxHighlighterFactory extends SingleLazyInstanceSyntaxHighlighterFactory { @NotNull protected SyntaxHighlighter createHighlighter() { return new AngularJSSyntaxHighlighter(); } private static class AngularJSSyntaxHighlighter extends JSHighlighter { private final Map<IElementType, TextAttributesKey> myKeysMap = new THashMap<IElementType, TextAttributesKey>(); public AngularJSSyntaxHighlighter() { super(EmberJSLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD);
// Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSTokenTypes.java // public interface EmberJSTokenTypes extends JSTokenTypes { // EmberJSTokenType ESCAPE_SEQUENCE = new EmberJSTokenType("ESCAPE_SEQUENCE"); // EmberJSTokenType INVALID_ESCAPE_SEQUENCE = new EmberJSTokenType("INVALID_ESCAPE_SEQUENCE"); // EmberJSTokenType TRACK_BY_KEYWORD = new EmberJSTokenType("TRACK_BY_KEYWORD"); // EmberJSTokenType ONE_TIME_BINDING = new EmberJSTokenType("ONE_TIME_BINDING"); // } // Path: src/org/emberjs/lang/EmberJSSyntaxHighlighterFactory.java import com.intellij.lang.javascript.JSTokenTypes; import com.intellij.lang.javascript.highlighting.JSHighlighter; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.psi.tree.IElementType; import gnu.trove.THashMap; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.lexer.EmberJSTokenTypes; import org.jetbrains.annotations.NotNull; import java.util.Map; package org.emberjs.lang; /** * @author Dennis.Ushakov */ public class EmberJSSyntaxHighlighterFactory extends SingleLazyInstanceSyntaxHighlighterFactory { @NotNull protected SyntaxHighlighter createHighlighter() { return new AngularJSSyntaxHighlighter(); } private static class AngularJSSyntaxHighlighter extends JSHighlighter { private final Map<IElementType, TextAttributesKey> myKeysMap = new THashMap<IElementType, TextAttributesKey>(); public AngularJSSyntaxHighlighter() { super(EmberJSLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD);
myKeysMap.put(EmberJSTokenTypes.TRACK_BY_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD);
kristianmandrup/emberjs-plugin
src/org/emberjs/lang/EmberJSSyntaxHighlighterFactory.java
// Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSTokenTypes.java // public interface EmberJSTokenTypes extends JSTokenTypes { // EmberJSTokenType ESCAPE_SEQUENCE = new EmberJSTokenType("ESCAPE_SEQUENCE"); // EmberJSTokenType INVALID_ESCAPE_SEQUENCE = new EmberJSTokenType("INVALID_ESCAPE_SEQUENCE"); // EmberJSTokenType TRACK_BY_KEYWORD = new EmberJSTokenType("TRACK_BY_KEYWORD"); // EmberJSTokenType ONE_TIME_BINDING = new EmberJSTokenType("ONE_TIME_BINDING"); // }
import com.intellij.lang.javascript.JSTokenTypes; import com.intellij.lang.javascript.highlighting.JSHighlighter; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.psi.tree.IElementType; import gnu.trove.THashMap; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.lexer.EmberJSTokenTypes; import org.jetbrains.annotations.NotNull; import java.util.Map;
package org.emberjs.lang; /** * @author Dennis.Ushakov */ public class EmberJSSyntaxHighlighterFactory extends SingleLazyInstanceSyntaxHighlighterFactory { @NotNull protected SyntaxHighlighter createHighlighter() { return new AngularJSSyntaxHighlighter(); } private static class AngularJSSyntaxHighlighter extends JSHighlighter { private final Map<IElementType, TextAttributesKey> myKeysMap = new THashMap<IElementType, TextAttributesKey>(); public AngularJSSyntaxHighlighter() { super(EmberJSLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); myKeysMap.put(EmberJSTokenTypes.TRACK_BY_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); } @NotNull public TextAttributesKey[] getTokenHighlights(final IElementType tokenType) { if (myKeysMap.containsKey(tokenType)) { return pack(myKeysMap.get(tokenType)); } return super.getTokenHighlights(tokenType); } @NotNull @Override public Lexer getHighlightingLexer() {
// Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSTokenTypes.java // public interface EmberJSTokenTypes extends JSTokenTypes { // EmberJSTokenType ESCAPE_SEQUENCE = new EmberJSTokenType("ESCAPE_SEQUENCE"); // EmberJSTokenType INVALID_ESCAPE_SEQUENCE = new EmberJSTokenType("INVALID_ESCAPE_SEQUENCE"); // EmberJSTokenType TRACK_BY_KEYWORD = new EmberJSTokenType("TRACK_BY_KEYWORD"); // EmberJSTokenType ONE_TIME_BINDING = new EmberJSTokenType("ONE_TIME_BINDING"); // } // Path: src/org/emberjs/lang/EmberJSSyntaxHighlighterFactory.java import com.intellij.lang.javascript.JSTokenTypes; import com.intellij.lang.javascript.highlighting.JSHighlighter; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.psi.tree.IElementType; import gnu.trove.THashMap; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.lexer.EmberJSTokenTypes; import org.jetbrains.annotations.NotNull; import java.util.Map; package org.emberjs.lang; /** * @author Dennis.Ushakov */ public class EmberJSSyntaxHighlighterFactory extends SingleLazyInstanceSyntaxHighlighterFactory { @NotNull protected SyntaxHighlighter createHighlighter() { return new AngularJSSyntaxHighlighter(); } private static class AngularJSSyntaxHighlighter extends JSHighlighter { private final Map<IElementType, TextAttributesKey> myKeysMap = new THashMap<IElementType, TextAttributesKey>(); public AngularJSSyntaxHighlighter() { super(EmberJSLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); myKeysMap.put(EmberJSTokenTypes.TRACK_BY_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); } @NotNull public TextAttributesKey[] getTokenHighlights(final IElementType tokenType) { if (myKeysMap.containsKey(tokenType)) { return pack(myKeysMap.get(tokenType)); } return super.getTokenHighlights(tokenType); } @NotNull @Override public Lexer getHighlightingLexer() {
return new EmberJSLexer();
kristianmandrup/emberjs-plugin
src/org/emberjs/lang/parser/EmberJSParserDefinition.java
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSComputedProperty.java // public class EmberJSComputedProperty extends JSExpressionImpl { // public EmberJSComputedProperty(ASTNode node) { // super(node); // } // }
import com.intellij.lang.ASTNode; import com.intellij.lang.PsiParser; import com.intellij.lang.javascript.JavascriptParserDefinition; import com.intellij.lang.javascript.types.JSFileElementType; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IFileElementType; import org.emberjs.lang.EmberJSLanguage; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.psi.EmberJSComputedProperty; import org.jetbrains.annotations.NotNull;
package org.emberjs.lang.parser; /** * @author Dennis.Ushakov */ public class EmberJSParserDefinition extends JavascriptParserDefinition { private static final IFileElementType FILE = new JSFileElementType(EmberJSLanguage.INSTANCE); @NotNull @Override public Lexer createLexer(Project project) {
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSComputedProperty.java // public class EmberJSComputedProperty extends JSExpressionImpl { // public EmberJSComputedProperty(ASTNode node) { // super(node); // } // } // Path: src/org/emberjs/lang/parser/EmberJSParserDefinition.java import com.intellij.lang.ASTNode; import com.intellij.lang.PsiParser; import com.intellij.lang.javascript.JavascriptParserDefinition; import com.intellij.lang.javascript.types.JSFileElementType; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IFileElementType; import org.emberjs.lang.EmberJSLanguage; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.psi.EmberJSComputedProperty; import org.jetbrains.annotations.NotNull; package org.emberjs.lang.parser; /** * @author Dennis.Ushakov */ public class EmberJSParserDefinition extends JavascriptParserDefinition { private static final IFileElementType FILE = new JSFileElementType(EmberJSLanguage.INSTANCE); @NotNull @Override public Lexer createLexer(Project project) {
return new EmberJSLexer();
kristianmandrup/emberjs-plugin
src/org/emberjs/lang/parser/EmberJSParserDefinition.java
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSComputedProperty.java // public class EmberJSComputedProperty extends JSExpressionImpl { // public EmberJSComputedProperty(ASTNode node) { // super(node); // } // }
import com.intellij.lang.ASTNode; import com.intellij.lang.PsiParser; import com.intellij.lang.javascript.JavascriptParserDefinition; import com.intellij.lang.javascript.types.JSFileElementType; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IFileElementType; import org.emberjs.lang.EmberJSLanguage; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.psi.EmberJSComputedProperty; import org.jetbrains.annotations.NotNull;
package org.emberjs.lang.parser; /** * @author Dennis.Ushakov */ public class EmberJSParserDefinition extends JavascriptParserDefinition { private static final IFileElementType FILE = new JSFileElementType(EmberJSLanguage.INSTANCE); @NotNull @Override public Lexer createLexer(Project project) { return new EmberJSLexer(); } @NotNull @Override public PsiParser createParser(Project project) { return new EmberParser(); } @NotNull @Override public PsiElement createElement(ASTNode node) { final IElementType type = node.getElementType(); if (type == EmberJSElementTypes.COMPUTED_PROPERTY) {
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // } // // Path: src/org/emberjs/lang/lexer/EmberJSLexer.java // public class EmberJSLexer extends MergingLexerAdapter { // public EmberJSLexer() { // // _EmberJSLexer is generated via ember.flex // super(new FlexAdapter(new _EmberJSLexer((Reader)null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); // } // } // // Path: src/org/emberjs/lang/psi/EmberJSComputedProperty.java // public class EmberJSComputedProperty extends JSExpressionImpl { // public EmberJSComputedProperty(ASTNode node) { // super(node); // } // } // Path: src/org/emberjs/lang/parser/EmberJSParserDefinition.java import com.intellij.lang.ASTNode; import com.intellij.lang.PsiParser; import com.intellij.lang.javascript.JavascriptParserDefinition; import com.intellij.lang.javascript.types.JSFileElementType; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IFileElementType; import org.emberjs.lang.EmberJSLanguage; import org.emberjs.lang.lexer.EmberJSLexer; import org.emberjs.lang.psi.EmberJSComputedProperty; import org.jetbrains.annotations.NotNull; package org.emberjs.lang.parser; /** * @author Dennis.Ushakov */ public class EmberJSParserDefinition extends JavascriptParserDefinition { private static final IFileElementType FILE = new JSFileElementType(EmberJSLanguage.INSTANCE); @NotNull @Override public Lexer createLexer(Project project) { return new EmberJSLexer(); } @NotNull @Override public PsiParser createParser(Project project) { return new EmberParser(); } @NotNull @Override public PsiElement createElement(ASTNode node) { final IElementType type = node.getElementType(); if (type == EmberJSElementTypes.COMPUTED_PROPERTY) {
return new EmberJSComputedProperty(node);
kristianmandrup/emberjs-plugin
src/org/emberjs/lang/parser/EmberJSParser.java
// Path: src/org/emberjs/lang/lexer/EmberJSTokenTypes.java // public interface EmberJSTokenTypes extends JSTokenTypes { // EmberJSTokenType ESCAPE_SEQUENCE = new EmberJSTokenType("ESCAPE_SEQUENCE"); // EmberJSTokenType INVALID_ESCAPE_SEQUENCE = new EmberJSTokenType("INVALID_ESCAPE_SEQUENCE"); // EmberJSTokenType TRACK_BY_KEYWORD = new EmberJSTokenType("TRACK_BY_KEYWORD"); // EmberJSTokenType ONE_TIME_BINDING = new EmberJSTokenType("ONE_TIME_BINDING"); // }
import com.intellij.lang.PsiBuilder; import com.intellij.lang.javascript.JSBundle; import com.intellij.lang.javascript.JSElementTypes; import com.intellij.lang.javascript.JSTokenTypes; import com.intellij.lang.javascript.JavaScriptSupportLoader; import com.intellij.lang.javascript.parsing.ExpressionParser; import com.intellij.lang.javascript.parsing.FunctionParser; import com.intellij.lang.javascript.parsing.JavaScriptParser; import com.intellij.lang.javascript.parsing.StatementParser; import com.intellij.psi.tree.IElementType; import org.emberjs.lang.lexer.EmberJSTokenTypes;
if (!getExpressionParser().parseInExpression()) { statement.drop(); return false; } statement.done(JSElementTypes.EXPRESSION_STATEMENT); return true; } }; } public void parseEmber(IElementType root) { final PsiBuilder.Marker rootMarker = builder.mark(); while (!builder.eof()) { getStatementParser().parseStatement(); } rootMarker.done(root); } protected class EmberJSExpressionParser extends ExpressionParser<EmberJSParser> { public EmberJSExpressionParser() { super(EmberJSParser.this); } @Override protected boolean parseUnaryExpression() { final IElementType tokenType = builder.getTokenType(); if (tokenType == JSTokenTypes.OR) { builder.advanceLexer(); return true; }
// Path: src/org/emberjs/lang/lexer/EmberJSTokenTypes.java // public interface EmberJSTokenTypes extends JSTokenTypes { // EmberJSTokenType ESCAPE_SEQUENCE = new EmberJSTokenType("ESCAPE_SEQUENCE"); // EmberJSTokenType INVALID_ESCAPE_SEQUENCE = new EmberJSTokenType("INVALID_ESCAPE_SEQUENCE"); // EmberJSTokenType TRACK_BY_KEYWORD = new EmberJSTokenType("TRACK_BY_KEYWORD"); // EmberJSTokenType ONE_TIME_BINDING = new EmberJSTokenType("ONE_TIME_BINDING"); // } // Path: src/org/emberjs/lang/parser/EmberJSParser.java import com.intellij.lang.PsiBuilder; import com.intellij.lang.javascript.JSBundle; import com.intellij.lang.javascript.JSElementTypes; import com.intellij.lang.javascript.JSTokenTypes; import com.intellij.lang.javascript.JavaScriptSupportLoader; import com.intellij.lang.javascript.parsing.ExpressionParser; import com.intellij.lang.javascript.parsing.FunctionParser; import com.intellij.lang.javascript.parsing.JavaScriptParser; import com.intellij.lang.javascript.parsing.StatementParser; import com.intellij.psi.tree.IElementType; import org.emberjs.lang.lexer.EmberJSTokenTypes; if (!getExpressionParser().parseInExpression()) { statement.drop(); return false; } statement.done(JSElementTypes.EXPRESSION_STATEMENT); return true; } }; } public void parseEmber(IElementType root) { final PsiBuilder.Marker rootMarker = builder.mark(); while (!builder.eof()) { getStatementParser().parseStatement(); } rootMarker.done(root); } protected class EmberJSExpressionParser extends ExpressionParser<EmberJSParser> { public EmberJSExpressionParser() { super(EmberJSParser.this); } @Override protected boolean parseUnaryExpression() { final IElementType tokenType = builder.getTokenType(); if (tokenType == JSTokenTypes.OR) { builder.advanceLexer(); return true; }
if (tokenType == EmberJSTokenTypes.ONE_TIME_BINDING) {
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/EmberJSSpecificHandlersFactory.java
// Path: src/org/emberjs/codeInsight/EmberJSTypeEvaluator.java // public class EmberJSTypeEvaluator extends JSTypeEvaluator { // public EmberJSTypeEvaluator(BaseJSSymbolProcessor.EvaluateContext context, // BaseJSSymbolProcessor.TypeProcessor processor, boolean ecma) { // super(context, processor, ecma); // } // // @Override // protected boolean addTypeFromElementResolveResult(JSReferenceExpression expression, // PsiElement parent, // PsiElement resolveResult, // boolean wasProtoType, // boolean hasSomeType) { // if (resolveResult instanceof JSDefinitionExpression) { // final PsiElement resolveParent = resolveResult.getParent(); // if (resolveParent instanceof EmberJSAsExpression) { // final String name = resolveParent.getFirstChild().getText(); // final JSTypeSource source = JSTypeSourceFactory.createTypeSource(resolveResult); // final JSType type = JSNamedType.createType(name, source, JSNamedType.StaticOrInstance.INSTANCE); // addType(type, resolveResult); // return true; // } else if (resolveParent instanceof EmberJSRepeatExpression) { // if (calculateRepeatParameterType((EmberJSRepeatExpression)resolveParent)) { // return true; // } // } // } // if (resolveResult instanceof JSParameter && // EmberIndexUtil.hasEmberJS(resolveResult.getProject())) { // final String name = ((JSParameter)resolveResult).getName(); // final JSTypeSource source = JSTypeSourceFactory.createTypeSource(resolveResult); // final JSType type = JSNamedType.createType(name, source, JSNamedType.StaticOrInstance.INSTANCE); // addType(type, resolveResult); // } // return super.addTypeFromElementResolveResult(expression, parent, resolveResult, wasProtoType, hasSomeType); // } // // // does Ember have any equivalent of this? // private boolean calculateRepeatParameterType(EmberJSRepeatExpression resolveParent) { // final PsiElement last = findReferenceExpression(resolveParent); // JSType arrayType = null; // if (last instanceof JSReferenceExpression) { // PsiElement resolve = ((JSReferenceExpression)last).resolve(); // resolve = resolve instanceof JSNamedElementProxy ? ((JSNamedElementProxy)resolve).getElement() : resolve; // resolve = resolve instanceof JSVariable ? ((JSVariable)resolve).getInitializer() : resolve; // if (resolve instanceof JSExpression) { // arrayType = evalExprType((JSExpression)resolve); // } // } else if (last instanceof JSExpression) { // arrayType = evalExprType((JSExpression)last); // } // final JSType elementType = findElementType(arrayType); // if (elementType != null) { // addType(elementType, null); // return true; // } // return false; // } // // private static JSType findElementType(JSType type) { // if (type instanceof JSArrayTypeImpl) { // return ((JSArrayTypeImpl)type).getType(); // } // if (type instanceof JSCompositeTypeImpl) { // for (JSType jsType : ((JSCompositeTypeImpl)type).getTypes()) { // final JSType elementType = findElementType(jsType); // if (elementType != null) { // return elementType; // } // } // } // return null; // } // // private static PsiElement findReferenceExpression(EmberJSRepeatExpression parent) { // JSExpression collection = parent.getCollection(); // // do stuff?? // return collection; // } // }
import com.intellij.lang.javascript.JavaScriptSpecificHandlersFactory; import com.intellij.lang.javascript.psi.impl.JSReferenceExpressionImpl; import com.intellij.lang.javascript.psi.resolve.BaseJSSymbolProcessor; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.lang.javascript.psi.resolve.JSTypeEvaluator; import com.intellij.psi.PsiFile; import org.emberjs.codeInsight.EmberJSTypeEvaluator; import org.jetbrains.annotations.NotNull;
package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSSpecificHandlersFactory extends JavaScriptSpecificHandlersFactory { @NotNull @Override public JSResolveUtil.Resolver<JSReferenceExpressionImpl> createReferenceExpressionResolver(JSReferenceExpressionImpl referenceExpression, PsiFile containingFile) { return new EmberJSReferenceExpressionResolver(referenceExpression, containingFile); } @NotNull @Override public JSTypeEvaluator newTypeEvaluator(BaseJSSymbolProcessor.EvaluateContext context, BaseJSSymbolProcessor.TypeProcessor processor, boolean ecma) {
// Path: src/org/emberjs/codeInsight/EmberJSTypeEvaluator.java // public class EmberJSTypeEvaluator extends JSTypeEvaluator { // public EmberJSTypeEvaluator(BaseJSSymbolProcessor.EvaluateContext context, // BaseJSSymbolProcessor.TypeProcessor processor, boolean ecma) { // super(context, processor, ecma); // } // // @Override // protected boolean addTypeFromElementResolveResult(JSReferenceExpression expression, // PsiElement parent, // PsiElement resolveResult, // boolean wasProtoType, // boolean hasSomeType) { // if (resolveResult instanceof JSDefinitionExpression) { // final PsiElement resolveParent = resolveResult.getParent(); // if (resolveParent instanceof EmberJSAsExpression) { // final String name = resolveParent.getFirstChild().getText(); // final JSTypeSource source = JSTypeSourceFactory.createTypeSource(resolveResult); // final JSType type = JSNamedType.createType(name, source, JSNamedType.StaticOrInstance.INSTANCE); // addType(type, resolveResult); // return true; // } else if (resolveParent instanceof EmberJSRepeatExpression) { // if (calculateRepeatParameterType((EmberJSRepeatExpression)resolveParent)) { // return true; // } // } // } // if (resolveResult instanceof JSParameter && // EmberIndexUtil.hasEmberJS(resolveResult.getProject())) { // final String name = ((JSParameter)resolveResult).getName(); // final JSTypeSource source = JSTypeSourceFactory.createTypeSource(resolveResult); // final JSType type = JSNamedType.createType(name, source, JSNamedType.StaticOrInstance.INSTANCE); // addType(type, resolveResult); // } // return super.addTypeFromElementResolveResult(expression, parent, resolveResult, wasProtoType, hasSomeType); // } // // // does Ember have any equivalent of this? // private boolean calculateRepeatParameterType(EmberJSRepeatExpression resolveParent) { // final PsiElement last = findReferenceExpression(resolveParent); // JSType arrayType = null; // if (last instanceof JSReferenceExpression) { // PsiElement resolve = ((JSReferenceExpression)last).resolve(); // resolve = resolve instanceof JSNamedElementProxy ? ((JSNamedElementProxy)resolve).getElement() : resolve; // resolve = resolve instanceof JSVariable ? ((JSVariable)resolve).getInitializer() : resolve; // if (resolve instanceof JSExpression) { // arrayType = evalExprType((JSExpression)resolve); // } // } else if (last instanceof JSExpression) { // arrayType = evalExprType((JSExpression)last); // } // final JSType elementType = findElementType(arrayType); // if (elementType != null) { // addType(elementType, null); // return true; // } // return false; // } // // private static JSType findElementType(JSType type) { // if (type instanceof JSArrayTypeImpl) { // return ((JSArrayTypeImpl)type).getType(); // } // if (type instanceof JSCompositeTypeImpl) { // for (JSType jsType : ((JSCompositeTypeImpl)type).getTypes()) { // final JSType elementType = findElementType(jsType); // if (elementType != null) { // return elementType; // } // } // } // return null; // } // // private static PsiElement findReferenceExpression(EmberJSRepeatExpression parent) { // JSExpression collection = parent.getCollection(); // // do stuff?? // return collection; // } // } // Path: src/org/emberjs/codeInsight/EmberJSSpecificHandlersFactory.java import com.intellij.lang.javascript.JavaScriptSpecificHandlersFactory; import com.intellij.lang.javascript.psi.impl.JSReferenceExpressionImpl; import com.intellij.lang.javascript.psi.resolve.BaseJSSymbolProcessor; import com.intellij.lang.javascript.psi.resolve.JSResolveUtil; import com.intellij.lang.javascript.psi.resolve.JSTypeEvaluator; import com.intellij.psi.PsiFile; import org.emberjs.codeInsight.EmberJSTypeEvaluator; import org.jetbrains.annotations.NotNull; package org.emberjs.codeInsight; /** * @author Dennis.Ushakov */ public class EmberJSSpecificHandlersFactory extends JavaScriptSpecificHandlersFactory { @NotNull @Override public JSResolveUtil.Resolver<JSReferenceExpressionImpl> createReferenceExpressionResolver(JSReferenceExpressionImpl referenceExpression, PsiFile containingFile) { return new EmberJSReferenceExpressionResolver(referenceExpression, containingFile); } @NotNull @Override public JSTypeEvaluator newTypeEvaluator(BaseJSSymbolProcessor.EvaluateContext context, BaseJSSymbolProcessor.TypeProcessor processor, boolean ecma) {
return new EmberJSTypeEvaluator(context, processor, ecma);
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/EmberJSCompletionContributor.java
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // }
import com.intellij.codeInsight.completion.CompletionContributor; import com.intellij.codeInsight.completion.CompletionParameters; import com.intellij.codeInsight.completion.CompletionResultSet; import com.intellij.lang.Language; import com.intellij.lang.javascript.completion.JSLookupUtilImpl; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.impl.JSReferenceExpressionImpl; import com.intellij.lang.javascript.psi.resolve.VariantsProcessor; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ReadAction; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.Consumer; import org.emberjs.lang.EmberJSLanguage; import org.jetbrains.annotations.NotNull;
package org.emberjs.codeInsight; /** * @author Kristian Mandrup */ public class EmberJSCompletionContributor extends CompletionContributor { private static final int EMBER_VARIABLE_PRIORITY = VariantsProcessor.LookupPriority.LOCAL_SCOPE_MAX_PRIORITY; @Override public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull final CompletionResultSet result) {
// Path: src/org/emberjs/lang/EmberJSLanguage.java // public class EmberJSLanguage extends JSLanguageDialect { // public static final EmberJSLanguage INSTANCE = new EmberJSLanguage(); // // protected EmberJSLanguage() { // super("EmberJS", DialectOptionHolder.OTHER); // } // // @Override // public String getFileExtension() { // return "js"; // } // } // Path: src/org/emberjs/codeInsight/EmberJSCompletionContributor.java import com.intellij.codeInsight.completion.CompletionContributor; import com.intellij.codeInsight.completion.CompletionParameters; import com.intellij.codeInsight.completion.CompletionResultSet; import com.intellij.lang.Language; import com.intellij.lang.javascript.completion.JSLookupUtilImpl; import com.intellij.lang.javascript.psi.JSNamedElement; import com.intellij.lang.javascript.psi.impl.JSReferenceExpressionImpl; import com.intellij.lang.javascript.psi.resolve.VariantsProcessor; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ReadAction; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.Consumer; import org.emberjs.lang.EmberJSLanguage; import org.jetbrains.annotations.NotNull; package org.emberjs.codeInsight; /** * @author Kristian Mandrup */ public class EmberJSCompletionContributor extends CompletionContributor { private static final int EMBER_VARIABLE_PRIORITY = VariantsProcessor.LookupPriority.LOCAL_SCOPE_MAX_PRIORITY; @Override public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull final CompletionResultSet result) {
if (!getElementLanguage(parameters).is(EmberJSLanguage.INSTANCE)) return;
kristianmandrup/emberjs-plugin
src/org/emberjs/refactoring/EmberJSComponentRenameProcessor.java
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // }
import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.lang.javascript.refactoring.JSDefaultRenameProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.ElementDescriptionLocation; import com.intellij.psi.ElementDescriptionProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNamedElement; import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.refactoring.rename.RenameDialog; import com.intellij.refactoring.rename.RenameUtil; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewTypeLocation; import com.intellij.util.IncorrectOperationException; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
package org.emberjs.refactoring; /** * @author Dennis.Ushakov */ public class EmberJSComponentRenameProcessor extends JSDefaultRenameProcessor { @Override public boolean canProcessElement(@NotNull PsiElement element) {
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // } // Path: src/org/emberjs/refactoring/EmberJSComponentRenameProcessor.java import com.intellij.lang.javascript.index.JSNamedElementProxy; import com.intellij.lang.javascript.refactoring.JSDefaultRenameProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.ElementDescriptionLocation; import com.intellij.psi.ElementDescriptionProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNamedElement; import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.refactoring.rename.RenameDialog; import com.intellij.refactoring.rename.RenameUtil; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewTypeLocation; import com.intellij.util.IncorrectOperationException; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; package org.emberjs.refactoring; /** * @author Dennis.Ushakov */ public class EmberJSComponentRenameProcessor extends JSDefaultRenameProcessor { @Override public boolean canProcessElement(@NotNull PsiElement element) {
return ComponentUtil.getComponent(element) != null;
kristianmandrup/emberjs-plugin
src/org/emberjs/index/EmberJSIndexingHandler.java
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // }
import com.intellij.lang.javascript.documentation.JSDocumentationProcessor; import com.intellij.lang.javascript.documentation.JSDocumentationUtils; import com.intellij.lang.javascript.index.*; import com.intellij.lang.javascript.psi.*; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.Function; import com.intellij.util.indexing.ID; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern;
package org.emberjs.index; /** * @author Dennis.Ushakov */ public class EmberJSIndexingHandler extends FrameworkIndexingHandler { private static final Map<String, ID<String, Void>> INDEXERS = new HashMap<String, ID<String, Void>>(); private static final Map<String, Function<String, String>> NAME_CONVERTERS = new HashMap<String, Function<String, String>>(); private static final Map<String, Function<Pair<JSSymbolVisitor, PsiElement>, String>> DATA_CALCULATORS = new HashMap<String, Function<Pair<JSSymbolVisitor, PsiElement>, String>>(); public static final Set<String> INTERESTING_OBJS = new HashSet<String>(); public static final String CONTROLLER = "controller"; public static final String COMPONENT = "component"; public static final String VIEW = "view"; public static final String MODEL = "model"; public static final String MIXIN = "mixin"; public static final String ROUTE = "route"; public static final String DEFAULT_RESTRICTIONS = "D"; static { Collections.addAll(INTERESTING_OBJS, "Ember.Mixin", "Ember.Model", "Ember.View", "Ember.Component", "Ember.Controller"); Collections.addAll(INTERESTING_OBJS, CONTROLLER, ROUTE, MODEL, VIEW, MIXIN, COMPONENT); INDEXERS.put(COMPONENT, EmberComponentIndex.INDEX_ID); NAME_CONVERTERS.put(COMPONENT, new Function<String, String>() { @Override public String fun(String s) {
// Path: src/org/emberjs/codeInsight/ComponentUtil.java // public class ComponentUtil { // public static String getAttributeName(final String text) { // final String[] split = StringUtil.unquoteString(text).split("(?=[A-Z])"); // for (int i = 0; i < split.length; i++) { // split[i] = StringUtil.decapitalize(split[i]); // } // return StringUtil.join(split, "-"); // } // // public static String attributeToComponent(String name) { // final String[] words = name.split("-"); // for (int i = 1; i < words.length; i++) { // words[i] = StringUtil.capitalize(words[i]); // } // return StringUtil.join(words); // } // // public static boolean processComponents(final Project project, // Processor<JSNamedElementProxy> processor) { // final Collection<String> docComponents = EmberIndexUtil.getAllKeys(EmberComponentDocIndex.INDEX_ID, project); // for (String componentName : docComponents) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // final Collection<String> components = EmberIndexUtil.getAllKeys(EmberComponentIndex.INDEX_ID, project); // for (String componentName : components) { // if (!docComponents.contains(componentName)) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID); // if (component != null) { // if (!processor.process(component)) { // return false; // } // } // } // } // return true; // } // // public static JSNamedElementProxy getComponentProxy(String componentName, Project project) { // final JSNamedElementProxy component = getComponentProxy(project, componentName, EmberComponentDocIndex.INDEX_ID); // return component == null ? getComponentProxy(project, componentName, EmberComponentIndex.INDEX_ID) : component; // } // // private static JSNamedElementProxy getComponentProxy(Project project, String componentName, final ID<String, Void> index) { // final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); // // TODO: do some stuff?? // return null; // } // // @Nullable // public static JSNamedElementProxy getComponent(@Nullable PsiElement element) { // if (element instanceof JSNamedElementProxy) { // return getComponent(element, ((JSNamedElementProxy)element).getName()); // } // if (element instanceof JSLiteralExpression && ((JSLiteralExpression)element).isQuotedLiteral()) { // return getComponent(element, StringUtil.unquoteString(element.getText())); // } // return null; // } // // private static JSNamedElementProxy getComponent(PsiElement element, final String name) { // final String componentName = getAttributeName(name); // final JSNamedElementProxy component = EmberIndexUtil.resolve(element.getProject(), EmberComponentIndex.INDEX_ID, componentName); // if (component != null && element.getTextRange().contains(component.getTextOffset())) { // return component; // } // return null; // } // } // Path: src/org/emberjs/index/EmberJSIndexingHandler.java import com.intellij.lang.javascript.documentation.JSDocumentationProcessor; import com.intellij.lang.javascript.documentation.JSDocumentationUtils; import com.intellij.lang.javascript.index.*; import com.intellij.lang.javascript.psi.*; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.Function; import com.intellij.util.indexing.ID; import org.emberjs.codeInsight.ComponentUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; package org.emberjs.index; /** * @author Dennis.Ushakov */ public class EmberJSIndexingHandler extends FrameworkIndexingHandler { private static final Map<String, ID<String, Void>> INDEXERS = new HashMap<String, ID<String, Void>>(); private static final Map<String, Function<String, String>> NAME_CONVERTERS = new HashMap<String, Function<String, String>>(); private static final Map<String, Function<Pair<JSSymbolVisitor, PsiElement>, String>> DATA_CALCULATORS = new HashMap<String, Function<Pair<JSSymbolVisitor, PsiElement>, String>>(); public static final Set<String> INTERESTING_OBJS = new HashSet<String>(); public static final String CONTROLLER = "controller"; public static final String COMPONENT = "component"; public static final String VIEW = "view"; public static final String MODEL = "model"; public static final String MIXIN = "mixin"; public static final String ROUTE = "route"; public static final String DEFAULT_RESTRICTIONS = "D"; static { Collections.addAll(INTERESTING_OBJS, "Ember.Mixin", "Ember.Model", "Ember.View", "Ember.Component", "Ember.Controller"); Collections.addAll(INTERESTING_OBJS, CONTROLLER, ROUTE, MODEL, VIEW, MIXIN, COMPONENT); INDEXERS.put(COMPONENT, EmberComponentIndex.INDEX_ID); NAME_CONVERTERS.put(COMPONENT, new Function<String, String>() { @Override public String fun(String s) {
return ComponentUtil.getAttributeName(s);
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/refs/EmberJSControllerReferencesProvider.java
// Path: src/org/emberjs/index/EmberControllerIndex.java // public class EmberControllerIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.controller.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.lang.javascript.completion.JSLookupUtilImpl; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.lang.javascript.psi.resolve.VariantsProcessor; import com.intellij.psi.*; import com.intellij.util.ProcessingContext; import org.emberjs.index.EmberControllerIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection;
package org.emberjs.codeInsight.refs; /** * @author Kristian Mandrup */ public class EmberJSControllerReferencesProvider extends PsiReferenceProvider { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[] { new EmberJSControllerReference((JSLiteralExpression)element) }; } public static class EmberJSControllerReference extends EmberJSReferenceBase<JSLiteralExpression> { public EmberJSControllerReference(@NotNull JSLiteralExpression element) { super(element, ElementManipulators.getValueTextRange(element)); } @Nullable @Override public PsiElement resolveInner() {
// Path: src/org/emberjs/index/EmberControllerIndex.java // public class EmberControllerIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.controller.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/codeInsight/refs/EmberJSControllerReferencesProvider.java import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.lang.javascript.completion.JSLookupUtilImpl; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.lang.javascript.psi.resolve.VariantsProcessor; import com.intellij.psi.*; import com.intellij.util.ProcessingContext; import org.emberjs.index.EmberControllerIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; package org.emberjs.codeInsight.refs; /** * @author Kristian Mandrup */ public class EmberJSControllerReferencesProvider extends PsiReferenceProvider { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[] { new EmberJSControllerReference((JSLiteralExpression)element) }; } public static class EmberJSControllerReference extends EmberJSReferenceBase<JSLiteralExpression> { public EmberJSControllerReference(@NotNull JSLiteralExpression element) { super(element, ElementManipulators.getValueTextRange(element)); } @Nullable @Override public PsiElement resolveInner() {
return EmberIndexUtil.resolve(getElement().getProject(), EmberControllerIndex.INDEX_ID, getCanonicalText());
kristianmandrup/emberjs-plugin
src/org/emberjs/codeInsight/refs/EmberJSControllerReferencesProvider.java
// Path: src/org/emberjs/index/EmberControllerIndex.java // public class EmberControllerIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.controller.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // }
import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.lang.javascript.completion.JSLookupUtilImpl; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.lang.javascript.psi.resolve.VariantsProcessor; import com.intellij.psi.*; import com.intellij.util.ProcessingContext; import org.emberjs.index.EmberControllerIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection;
package org.emberjs.codeInsight.refs; /** * @author Kristian Mandrup */ public class EmberJSControllerReferencesProvider extends PsiReferenceProvider { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[] { new EmberJSControllerReference((JSLiteralExpression)element) }; } public static class EmberJSControllerReference extends EmberJSReferenceBase<JSLiteralExpression> { public EmberJSControllerReference(@NotNull JSLiteralExpression element) { super(element, ElementManipulators.getValueTextRange(element)); } @Nullable @Override public PsiElement resolveInner() {
// Path: src/org/emberjs/index/EmberControllerIndex.java // public class EmberControllerIndex extends EmberIndexBase { // public static final ID<String, Void> INDEX_ID = ID.create("emberjs.controller.index"); // @NotNull // @Override // public ID<String, Void> getName() { // return INDEX_ID; // } // } // // Path: src/org/emberjs/index/EmberIndexUtil.java // public class EmberIndexUtil { // public static final int BASE_VERSION = 17; // private static final EmberKeysProvider PROVIDER = new EmberKeysProvider(); // // Not sure what this is used for // private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>(); // // public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) { // JSNamedElementProxy result = null; // final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project); // final GlobalSearchScope scope = GlobalSearchScope.allScope(project); // for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) { // final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope); // final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null; // if (resolve != null) { // result = resolve; // if (result.canNavigate()) break; // } // } // return result; // } // // // TODO: Determine is this project has ember.js available, which means looking into package.json I guess? // // Perhaps should be renamed to hasEmberCli // public static boolean hasEmberJS(final Project project) { // if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false; // return getEmberJSVersion(project) > 0; // } // // private static int getEmberJSVersion(final Project project) { // if (DumbService.isDumb(project)) return -1; // return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() { // @Nullable // @Override // public Result<Integer> compute() { // int version = -1; // // TODO: Find version of Ember used somehow! // // if (resolve(project, EmberIndex.INDEX_ID, "") != null) { // // version = 18; // // } // return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); // } // }); // } // // public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) { // final String indexId = index.toString(); // final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId)); // return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index)); // } // // private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> { // @Nullable // @Override // public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) { // final Set<String> allKeys = new THashSet<String>(); // final FileBasedIndex index = FileBasedIndex.getInstance(); // final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first); // final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) { // @Override // protected boolean accept(String key) { // return true; // } // }; // index.processAllKeys(projectAndIndex.second, processor, scope, null); // return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() { // @Override // public boolean value(String key) { // return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() { // @Override // public boolean process(VirtualFile file, Void value) { // return false; // } // }, scope); // } // }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker()); // } // } // } // Path: src/org/emberjs/codeInsight/refs/EmberJSControllerReferencesProvider.java import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.lang.javascript.completion.JSLookupUtilImpl; import com.intellij.lang.javascript.psi.JSLiteralExpression; import com.intellij.lang.javascript.psi.resolve.VariantsProcessor; import com.intellij.psi.*; import com.intellij.util.ProcessingContext; import org.emberjs.index.EmberControllerIndex; import org.emberjs.index.EmberIndexUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; package org.emberjs.codeInsight.refs; /** * @author Kristian Mandrup */ public class EmberJSControllerReferencesProvider extends PsiReferenceProvider { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[] { new EmberJSControllerReference((JSLiteralExpression)element) }; } public static class EmberJSControllerReference extends EmberJSReferenceBase<JSLiteralExpression> { public EmberJSControllerReference(@NotNull JSLiteralExpression element) { super(element, ElementManipulators.getValueTextRange(element)); } @Nullable @Override public PsiElement resolveInner() {
return EmberIndexUtil.resolve(getElement().getProject(), EmberControllerIndex.INDEX_ID, getCanonicalText());