List of usage examples for org.eclipse.jdt.core.dom CompilationUnit hashCode
@Override
public final int hashCode()
From source file:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
public Integer ProcessParseRequest(String contentFile, String fileName) throws Exception { CompilationUnit cu = Parse(contentFile, fileName); int hashCode = cu.hashCode(); ActiveUnits.put(hashCode, cu);// w w w . j a va 2s .c o m return hashCode; }
From source file:edu.buffalo.cse.green.test.designpattern.SingletonTest.java
License:Open Source License
public void testSingletonPatterMultipleGeneration() throws JavaModelException { IType testSingleton = createClass("MyS", "" + "public MyS() {\n" + " // default constructor\n" + "}\n") .getType();/* w w w.j a v a 2 s . c o m*/ List constructors = new ArrayList(); List nonConstructors = new ArrayList(); for (int x = 0; x < testSingleton.getMethods().length; x++) { assertTrue("All methods should be public to begin with", Flags.isPublic(testSingleton.getMethods()[x].getFlags())); // add the method to the appropriate list if (testSingleton.getMethods()[x].isConstructor()) { constructors.add(testSingleton.getMethods()[x]); } else { nonConstructors.add(testSingleton.getMethods()[x]); } } // create the compilation unit CompilationUnit cu = RelationshipVisitor.getCompilationUnit(testSingleton); // run the recognizer on the generator - make sure there's no singleton SingletonRecognizer recognizer = new SingletonRecognizer(); cu.accept(recognizer); assertEquals("The type shouldn't be a singleton yet", 0, recognizer.getSingletonCount()); // run the generator SingletonGenerator generator = new SingletonGenerator(testSingleton); cu.accept(generator); // run the recognizer on the generator cu.accept(recognizer); assertEquals("The type should be a singleton, but it's not", 1, recognizer.getSingletonCount()); int oldCUValue = cu.hashCode(); // Run the generator again and make sure nothing has changed cu.accept(generator); cu.accept(recognizer); assertEquals("The type should be a singleton, but it's not", 1, recognizer.getSingletonCount()); assertEquals("The previous compilation unit does not match the current", oldCUValue, cu.hashCode()); ASTVisitor typeAsserter = new ASTVisitor(false) { public boolean visit(MethodDeclaration node) { if (node.isConstructor()) { assertTrue("A constructor (" + node.getName() + ") was not private", Flags.isPrivate(node.getModifiers())); } else { assertTrue("A method (" + node.getName() + ") was private", !Flags.isPrivate(node.getModifiers())); } return true; } }; // make sure all constructors are public and other methods are not cu.accept(typeAsserter); }