11/********************************************************************************
2- * Copyright (c) 2015-2019 TU Darmstadt, Paderborn University
3- *
4- * This program and the accompanying materials are made available under the
5- * terms of the Eclipse Public License v. 2.0 which is available at
6- * http://www.eclipse.org/legal/epl-2.0.
7- *
8- * SPDX-License-Identifier: EPL-2.0
2+ * Copyright (c) 2015-2019 TU Darmstadt, Paderborn University This program and the accompanying materials are made available under the terms of the Eclipse Public License v. 2.0
3+ * which is available at http://www.eclipse.org/legal/epl-2.0. SPDX-License-Identifier: EPL-2.0
94 ********************************************************************************/
105
116package de .cognicrypt .codegenerator .testutilities ;
@@ -189,7 +184,7 @@ public static HashMap<Question, Answer> setDefaultConstraintsForTask(final Task
189184
190185 return contraintsForTask ;
191186 }
192-
187+
193188 /**
194189 * This method creates a HashMap. This HashMap contains the Questions and the associated given Answers for the selected Task.
195190 *
@@ -199,23 +194,23 @@ public static HashMap<Question, Answer> setDefaultConstraintsForTask(final Task
199194 public static HashMap <Question , Answer > setConstraintsForTask (final Task task , ArrayList <String > answers ) {
200195 final List <Page > pageList = (new QuestionsJSONReader ()).getPages (task .getQuestionsJSONFile ());
201196 final HashMap <Question , Answer > contraintsForTask = new LinkedHashMap <>();
202-
197+
203198 if (pageList .isEmpty ()) {
204199 return contraintsForTask ;
205200 }
206-
207- for (Page page : pageList ) {
201+
202+ for (Page page : pageList ) {
208203 for (int i = 0 ; i < page .getContent ().size (); i ++) {
209204 Question tmpQuestion = page .getContent ().get (i );
210- for (Answer answer : tmpQuestion .getAnswers ()) {
211- if (answer .getValue ().equals (answers .get (i ))) {
205+ for (Answer answer : tmpQuestion .getAnswers ()) {
206+ if (answer .getValue ().equals (answers .get (i ))) {
212207 contraintsForTask .put (tmpQuestion , answer );
213208 break ;
214209 }
215210 }
216211 }
217212 }
218-
213+
219214 return contraintsForTask ;
220215 }
221216
@@ -290,7 +285,7 @@ public static ICompilationUnit getICompilationUnit(final DeveloperProject projec
290285 final IPackageFragment packageFragment = project .getPackagesOfProject (packageName );
291286 for (int i = 0 ; i < packageFragment .getCompilationUnits ().length ; i ++) {
292287 if (packageFragment .getCompilationUnits ()[i ].getElementName ().equals (cuName )) {
293-
288+
294289 return packageFragment .getCompilationUnits ()[i ];
295290 }
296291 }
@@ -304,7 +299,8 @@ public static void printSourceCode(final DeveloperProject project, final String
304299 for (int i = 0 ; i < packageFragment .getCompilationUnits ().length ; i ++) {
305300 log .info ("\n " + packageFragment .getCompilationUnits ()[i ].getSource ());
306301 }
307- } catch (CoreException e ) {
302+ }
303+ catch (CoreException e ) {
308304 Activator .getDefault ().logError (e , Constants .ERROR_CANNOT_PRINT_SRC_CODE );
309305 }
310306 }
@@ -324,7 +320,8 @@ public static byte[] fileToByteArray(final DeveloperProject project, final Strin
324320 try {
325321 f = new File (getFilePathInProject (project , packageName , cu ));
326322 return Files .readAllBytes (Paths .get (f .getPath ()));
327- } catch (CoreException | IOException e ) {
323+ }
324+ catch (CoreException | IOException e ) {
328325 Activator .getDefault ().logError (e , Constants .ERROR_CANNOT_FILE_TO_BYTEARRAY );
329326 }
330327 return null ;
@@ -340,9 +337,8 @@ public static byte[] fileToByteArray(final DeveloperProject project, final Strin
340337 * @throws CoreException
341338 */
342339 private static String getFilePathInProject (final DeveloperProject project , final String packageName , final ICompilationUnit cu ) throws CoreException {
343- final String srcPath = project .getProjectPath () + Constants .innerFileSeparator + project .getSourcePath ();
344- final String cuPath = srcPath + Constants .innerFileSeparator + packageName + Constants .innerFileSeparator + cu .getElementName ();
345- return cuPath ;
340+ return project .getProjectPath () + Constants .innerFileSeparator + project .getSourcePath () + Constants .innerFileSeparator + packageName + Constants .innerFileSeparator
341+ + cu .getElementName ();
346342 }
347343
348344 /**
@@ -367,16 +363,12 @@ public static int countStatements(ICompilationUnit unit, String method) throws J
367363 }
368364
369365 public static IPackageFragment generatePackageInJavaProject (IJavaProject generatedProject , String packageName ) throws JavaModelException {
370- final IPackageFragment pack = generatedProject .getPackageFragmentRoot (generatedProject .getProject ().getFolder ("src" )).createPackageFragment (packageName , false , null );
371- return pack ;
366+ return generatedProject .getPackageFragmentRoot (generatedProject .getProject ().getFolder ("src" )).createPackageFragment (packageName , false , null );
372367 }
373368
374-
375369 public static boolean packageExists (IJavaProject generatedProject , String packagenameasname ) {
376370 final IPackageFragment expectedPackage = generatedProject .getPackageFragmentRoot (generatedProject .getProject ().getFolder ("src" )).getPackageFragment (packagenameasname );
377- if (expectedPackage != null ) {
378- return true ;
379- }return false ;
371+ return expectedPackage != null ;
380372 }
381373
382374}
0 commit comments