Skip to content

Commit

Permalink
Merge pull request #18 from Krzmbrzl/plugin
Browse files Browse the repository at this point in the history
b
  • Loading branch information
Krzmbrzl committed Jan 10, 2016
2 parents 6169563 + afef219 commit 5775fd4
Show file tree
Hide file tree
Showing 28 changed files with 643 additions and 11 deletions.
17 changes: 17 additions & 0 deletions plugin/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SQDev</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.UpdateSiteBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.UpdateSiteNature</nature>
</natures>
</projectDescription>
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/StringUtils.class
Binary file not shown.
3 changes: 1 addition & 2 deletions plugin/Raven.SQDev.Util/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
resources/
src.includes = resources/,\
build.properties
src.includes = resources/
157 changes: 153 additions & 4 deletions plugin/Raven.SQDev.Util/src/raven/sqdev/util/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
package raven.sqdev.util;

import java.util.ArrayList;

/**
* A class containing various static String functions
*
* @author Raven
*
*
*/
public class StringUtils {

/**
* An array containing all sort of brackets
*/
public static final char[] BRACKETS = { '(', ')', '[', ']', '{', '}' };
/**
* An array containing all special characters that are allowed in project names
*/
public static final char[] ALLOWED_SPECIAL_CHARACTER_PROJECTNAME = {'.', ' ', '_'};

/**
* Counts the occurence of a String in another String
* @param str The String to be searched
* @param match The String to be searched for
*
* @param str
* The String to be searched
* @param match
* The String to be searched for
* @return How often the searched string has been found
*/
public static int countMatches(String str, String match) {
int counter = 0;

while(str.contains(match)) {
while (str.contains(match)) {
counter++;

str = str.substring(str.indexOf(match) + match.length());
Expand All @@ -25,4 +40,138 @@ public static int countMatches(String str, String match) {
return counter;
}

/**
* Checks if the given name is valid.<br>
* A name is considered valid if it starts with a letter and then continues
* with either letters or digits or any character specified in
* <code>allowedChars</code>.<br>
* If you don't want any additional characters to be allowed just pass
* <code>null</code>
*
* @param name
* The name to validate
* @param allowedChars
* A list of additional characters that are allowed for this
* name. May be <code>null</code>
*/
public static boolean isValidName(String name, ArrayList<Character> allowedChars) {
if (name.isEmpty() || name == null) {
// an empty name can't be valid
return false;
}

if (allowedChars == null) {
// initialize empty list
allowedChars = new ArrayList<Character>();
}

char[] chars = name.toCharArray();

if (!Character.isLetter(chars[0])) {
// name has to start with a letter
return false;
}

for (char currentChar : chars) {
if (!Character.isLetterOrDigit(currentChar)) {
// check if special character is allowed
if (!allowedChars.contains((Character) currentChar)) {
return false;
}
}
}

return true;
}

/**
* Checks for the reason the given name is invalid.
*
* @param name
* The invalid name (mustn't be valid)
* @param allowedChars
* A list of additional characters that are allowed for this
* name. May be <code>null</code>
* @return The error message explaining why the given name isn't valid.
*/
public static String whyIsInvalidName(String name, ArrayList<Character> allowedChars) {
if (isValidName(name, allowedChars) || name == null) {
// if it is a valid name no error message can be found
return null;
}

if(name.isEmpty()) {
return "A name must not be empty!";
}

if (allowedChars == null) {
// initialize empty list
allowedChars = new ArrayList<Character>();
}

char[] chars = name.toCharArray();

if (!Character.isLetter(chars[0])) {
// name has to start with a letter
return "A name has to start with a letter!";
}

for (char currentChar : chars) {
if (!Character.isLetterOrDigit(currentChar)) {
// check if special character is allowed
if (!allowedChars.contains((Character) currentChar)) {
return "Invalid character '" + currentChar + "' in \"" + name + "\"!";
}
}
}

// one of the above has to have matched
return null;
}

/**
* Checks if the given name is a valid project name
* @param name The name to check
* @see #isValidName
*/
public static boolean isValidProjectName(String name) {
ArrayList<Character> allowedChars = new ArrayList<Character>();

for(char currentChar : ALLOWED_SPECIAL_CHARACTER_PROJECTNAME) {
allowedChars.add((Character) currentChar);
}

return isValidName(name, allowedChars);
}

/**
* Get the error code for why the name isn't valid
* @param name The name to check (mustn't be valid)
* @see #whyIsInvalidName
*/
public static String whyIsInvalidProjectName(String name) {
ArrayList<Character> allowedChars = new ArrayList<Character>();

for(char currentChar : ALLOWED_SPECIAL_CHARACTER_PROJECTNAME) {
allowedChars.add((Character) currentChar);
}

return whyIsInvalidName(name, allowedChars);
}

/**
* Checks if the given character is a bracket
* @param c
* @see #BRACKETS
*/
public static boolean isBracket(char c) {
for(char currentChar : BRACKETS) {
if(currentChar == c) {
return true;
}
}

return false;
}

}
4 changes: 3 additions & 1 deletion plugin/Raven.SQDev.Wizards/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
raven.sqdev.editors,
org.eclipse.ui.workbench,
org.eclipse.ui.editors,
raven.sqdev.util;bundle-version="0.1.0"
raven.sqdev.util;bundle-version="0.1.0",
org.eclipse.swt,
org.eclipse.jface
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 14 additions & 2 deletions plugin/Raven.SQDev.Wizards/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@
name="SQDev">
</category>
<wizard
category="raven.sqdev.wizards.sqfNewFileWizard"
category="raven.sqdev.wizards.SQdev"
class="raven.sqdev.wizards.sqfNewFileWizard.SqfNewFileWizard"
icon="platform:plugin/raven.sqdev.util/resources/icons/SQF_image.gif"
id="raven.sqdev.wizards.sqfNewFileWizard.SqfNewFileWizard"
name="New SQF file">
name="New SQF file"
project="false">
</wizard>
</extension>
<extension
point="org.eclipse.ui.newWizards">
<wizard
category="raven.sqdev.wizards.SQdev"
class="raven.sqdev.wizards.sqdevProject.SQDevProjectWizard"
icon="platform:plugin/raven.sqdev.util/resources/icons/prj_obj.gif"
id="Raven.SQDev.Wizards.sqdevProject"
name="SQDev Project"
project="true">
</wizard>
</extension>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package raven.sqdev.wizards.exceptions;

import raven.sqdev.exceptions.SQDevException;

public class FailedAtCreatingFileException extends SQDevException {

/**
*
*/
private static final long serialVersionUID = 3841747047339787544L;

public FailedAtCreatingFileException() {}

public FailedAtCreatingFileException(String message) {
super(message);
}

public FailedAtCreatingFileException(Throwable cause) {
super(cause);
}

public FailedAtCreatingFileException(String message, Throwable cause) {
super(message, cause);
}

public FailedAtCreatingFileException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

}
Loading

0 comments on commit 5775fd4

Please sign in to comment.