*/
public static final String COMPILER_PB_PHP_VAR_DEPRECATED = PLUGIN_ID
+ ".compiler.problem.phpVarDeprecatedWarning"; //$NON-NLS-1$
-
+
+ public static final String COMPILER_PB_PHP_KEYWORD = PLUGIN_ID
+ + ".compiler.problem.phpBadStyleKeywordWarning"; //$NON-NLS-1$
+
+ public static final String COMPILER_PB_PHP_UPPERCASE_IDENTIFIER = PLUGIN_ID
+ + ".compiler.problem.phpBadStyleUppercaseIdentifierWarning"; //$NON-NLS-1$
+
/**
* Possible configurable option ID.
*
preferences.setDefault(COMPILER_PB_PHP_VAR_DEPRECATED, WARNING);
optionNames.add(COMPILER_PB_PHP_VAR_DEPRECATED);
-
+ preferences.setDefault(COMPILER_PB_PHP_KEYWORD, WARNING);
+ optionNames.add(COMPILER_PB_PHP_KEYWORD);
+ preferences.setDefault(COMPILER_PB_PHP_UPPERCASE_IDENTIFIER, IGNORE);
+ optionNames.add(COMPILER_PB_PHP_UPPERCASE_IDENTIFIER);
+
preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR);
optionNames.add(COMPILER_PB_UNREACHABLE_CODE);
int PHPParsingError = Syntax + Internal + 211;
int PHPParsingWarning = Syntax + Internal + 212;
int PHPVarDeprecatedWarning = Syntax + Internal + 213;
+ int PHPBadStyleKeywordWarning = Syntax + Internal + 214;
+ int PHPBadStyleUppercaseIdentifierWarning = Syntax + Internal + 215;
int UnmatchedBracket = Syntax + Internal + 220;
int NoFieldOnBaseType = FieldRelated + 221;
* Option IDs
*/
public static final String OPTION_PHPVarDeprecatedWarning = "net.sourceforge.phpeclipse.compiler.problem.phpVarDeprecatedWarning"; //$NON-NLS-1$
-
+ public static final String OPTION_PHPBadStyleKeywordWarning = "net.sourceforge.phpeclipse.compiler.problem.phpBadStyleKeywordWarning"; //$NON-NLS-1$
+ public static final String OPTION_PHPBadStyleUppercaseIdentifierWarning = "net.sourceforge.phpeclipse.compiler.problem.phpBadStyleUppercaseIdentifierWarning"; //$NON-NLS-1$
public static final String OPTION_LocalVariableAttribute = "net.sourceforge.phpeclipse.compiler.debug.localVariable"; //$NON-NLS-1$
public static final String OPTION_LineNumberAttribute = "net.sourceforge.phpeclipse.compiler.debug.lineNumber"; //$NON-NLS-1$
public static final String OPTION_SourceFileAttribute = "net.sourceforge.phpeclipse.compiler.debug.sourceFile"; //$NON-NLS-1$
public static final long MissingJavadocComments = 0x10000000000L;
public static final long PHPVarDeprecatedWarning = 0x20000000000L;
+ public static final long PHPBadStyleKeywordWarning = 0x40000000000L;
+ public static final long PHPBadStyleUppercaseIdentifierWarning = 0x80000000000L;
// Default severity level for handlers
public long errorThreshold = 0;
| NoImplicitStringConversion
| FinallyBlockNotCompleting
| AssertUsedAsAnIdentifier
- | PHPVarDeprecatedWarning;
+ | PHPVarDeprecatedWarning
+ | PHPBadStyleKeywordWarning
+ | PHPBadStyleUppercaseIdentifierWarning;
// Debug attributes
public static final int Source = 1; // SourceFileAttribute
public Map getMap() {
Map optionsMap = new HashMap(30);
optionsMap.put(OPTION_PHPVarDeprecatedWarning, getSeverityString(PHPVarDeprecatedWarning));
+ optionsMap.put(OPTION_PHPBadStyleKeywordWarning, getSeverityString(PHPBadStyleKeywordWarning));
+ optionsMap.put(OPTION_PHPBadStyleUppercaseIdentifierWarning, getSeverityString(PHPBadStyleUppercaseIdentifierWarning));
optionsMap.put(OPTION_LocalVariableAttribute, (this.produceDebugAttributes & Vars) != 0 ? GENERATE : DO_NOT_GENERATE);
optionsMap.put(OPTION_LineNumberAttribute, (this.produceDebugAttributes & Lines) != 0 ? GENERATE : DO_NOT_GENERATE);
}
}
if ((optionValue = optionsMap.get(OPTION_PHPVarDeprecatedWarning)) != null) updateSeverity(PHPVarDeprecatedWarning, optionValue);
+ if ((optionValue = optionsMap.get(OPTION_PHPBadStyleKeywordWarning)) != null) updateSeverity(PHPBadStyleKeywordWarning, optionValue);
+ if ((optionValue = optionsMap.get(OPTION_PHPBadStyleUppercaseIdentifierWarning)) != null) updateSeverity(PHPBadStyleUppercaseIdentifierWarning, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportMethodWithConstructorName)) != null) updateSeverity(MethodWithConstructorName, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportOverridingPackageDefaultMethod)) != null) updateSeverity(OverriddenPackageDefaultMethod, optionValue);
StringBuffer buf = new StringBuffer("CompilerOptions:"); //$NON-NLS-1$
buf.append("\n\t- var is deprecated keyword: ").append(getSeverityString(PHPVarDeprecatedWarning)); //$NON-NLS-1$
+ buf.append("\n\t- don't use keywords as identifiers: ").append(getSeverityString(PHPBadStyleKeywordWarning)); //$NON-NLS-1$
+ buf.append("\n\t- non-variable idenifiers should contain only uppercase characters: ").append(getSeverityString(PHPBadStyleUppercaseIdentifierWarning)); //$NON-NLS-1$
buf.append("\n\t- local variables debug attributes: ").append((this.produceDebugAttributes & Vars) != 0 ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
buf.append("\n\t- line number debug attributes: ").append((this.produceDebugAttributes & Lines) != 0 ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// '(' parameter_list ')' method_body
initializeModifiers();
int declarationSourceStart = scanner.getCurrentTokenStartPosition();
- ;
+
if (token == TokenNamevar) {
checkAndSetModifiers(AccPublic);
problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
if (Scanner.isIdentifierOrKeyword(token)) {
methodDecl.selector = scanner.getCurrentIdentifierSource();
if (token > TokenNameKEYWORD) {
- reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
- scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
-// throwSyntaxError("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].");
+ problemReporter.phpKeywordWarning(new String[]{scanner.toStringAction(token)}, scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
+ referenceContext, compilationUnit.compilationResult);
+// reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
+// scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
}
getNextToken();
if (token == TokenNameLPAREN) {
throwSyntaxError("'(' expected in function declaration.");
}
if (token != TokenNameRPAREN) {
- parameter_list();
+ parameter_list();
}
if (token != TokenNameRPAREN) {
throwSyntaxError("')' expected in function declaration.");
//| class_constant '(' function_call_parameter_list ')'
//| static_member '(' function_call_parameter_list ')'
//| variable_without_objects '(' function_call_parameter_list ')'
+ char[] defineName = null;
+ int startPos=0;
+ int endPos=0;
if (Scanner.TRACE) {
System.out.println("TRACE: function_call()");
}
if (token == TokenNameIdentifier) {
+ defineName = scanner.getCurrentIdentifierSource();
+ startPos = scanner.getCurrentTokenStartPosition();
+ endPos = scanner.getCurrentTokenEndPosition();
getNextToken();
switch (token) {
case TokenNamePAAMAYIM_NEKUDOTAYIM :
// static member:
+ defineName = null;
getNextToken();
if (token == TokenNameIdentifier) {
// class _constant
variable_without_objects();
}
if (token != TokenNameLPAREN) {
+ if (defineName!=null) {
+ // does this identifier contain only uppercase characters?
+ if (defineName.length==3) {
+ if (defineName[0]=='d' &&
+ defineName[1]=='i' &&
+ defineName[2]=='e' ) {
+ defineName=null;
+ }
+ } else if (defineName.length==4) {
+ if (defineName[0]=='t' &&
+ defineName[1]=='r' &&
+ defineName[2]=='u' &&
+ defineName[3]=='e' ) {
+ defineName=null;
+ } else if (defineName[0]=='n' &&
+ defineName[1]=='u' &&
+ defineName[2]=='l' &&
+ defineName[3]=='l' ) {
+ defineName=null;
+ }
+ } else if (defineName.length==5) {
+ if (defineName[0]=='f' &&
+ defineName[1]=='a' &&
+ defineName[2]=='l' &&
+ defineName[3]=='s' &&
+ defineName[4]=='e' ) {
+ defineName=null;
+ }
+ }
+ if (defineName!=null) {
+ for (int i=0; i<defineName.length;i++) {
+ if (Character.isLowerCase(defineName[i])) {
+ problemReporter.phpUppercaseIdentifierWarning(startPos, endPos,
+ referenceContext, compilationUnit.compilationResult);
+ break;
+ }
+ }
+ }
+ }
// TODO is this ok ?
return;
// throwSyntaxError("'(' expected in function call.");
switch(problemId){
case IProblem.PHPVarDeprecatedWarning :
return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
-
+ case IProblem.PHPBadStyleKeywordWarning :
+ return this.options.getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
+ case IProblem.PHPBadStyleUppercaseIdentifierWarning :
+ return this.options.getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
+
case IProblem.MaskedCatch :
return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[]{},
problemStartPosition, problemEndPosition, context, compilationResult);
}
+
+ public void phpKeywordWarning(String[] messageArguments,
+ int problemStartPosition, int problemEndPosition,
+ ReferenceContext context, CompilationResult compilationResult) {
+ if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
+ return;
+ this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument, messageArguments,
+ problemStartPosition, problemEndPosition, context, compilationResult);
+ }
+
+ public void phpUppercaseIdentifierWarning(
+ int problemStartPosition, int problemEndPosition,
+ ReferenceContext context, CompilationResult compilationResult) {
+ if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
+ return;
+ this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument, new String[]{},
+ problemStartPosition, problemEndPosition, context, compilationResult);
+ }
}
211 = Parser error "{0}"
212 = Parser warning "{0}"
213 = Keyword 'var' is deprecated. Please use 'public' 'private' or 'protected' modifier for field declarations.
+214 = Bad style: don't use keyword "{0}" as an identifier.
+215 = Bad style: non-variable identifiers should contain only uppercase characters.
220 = Unmatched bracket
221 = The primitive type {0} of {1} does not have a field {2}
// Preference store keys, see JavaCore.getOptions
private static final String PREF_PB_PHP_VAR_DEPRECATED= JavaCore.COMPILER_PB_PHP_VAR_DEPRECATED;
+ private static final String PREF_PB_PHP_KEYWORD= JavaCore.COMPILER_PB_PHP_KEYWORD;
+ private static final String PREF_PB_PHP_UPPERCASE_IDENTIFIER= JavaCore.COMPILER_PB_PHP_UPPERCASE_IDENTIFIER;
// private static final String PREF_LOCAL_VARIABLE_ATTR= JavaCore.COMPILER_LOCAL_VARIABLE_ATTR;
// private static final String PREF_LINE_NUMBER_ATTR= JavaCore.COMPILER_LINE_NUMBER_ATTR;
private final static String[] KEYS= new String[] {
PREF_PB_PHP_VAR_DEPRECATED,
+ PREF_PB_PHP_KEYWORD,
+ PREF_PB_PHP_UPPERCASE_IDENTIFIER,
// PREF_LOCAL_VARIABLE_ATTR,
// PREF_LINE_NUMBER_ATTR, PREF_SOURCE_FILE_ATTR, PREF_CODEGEN_UNUSED_LOCAL,
// PREF_CODEGEN_TARGET_PLATFORM,
String label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_var_deprecated.label"); //$NON-NLS-1$
addComboBox(composite, label, PREF_PB_PHP_VAR_DEPRECATED, errorWarningIgnore, errorWarningIgnoreLabels, 0);
-
+
+ label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_keyword.label"); //$NON-NLS-1$
+ addComboBox(composite, label, PREF_PB_PHP_KEYWORD, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
+ label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_uppercase_identifier.label"); //$NON-NLS-1$
+ addComboBox(composite, label, PREF_PB_PHP_UPPERCASE_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, 0);
+
label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_overriding_pkg_dflt.label"); //$NON-NLS-1$
// addComboBox(composite, label, PREF_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, 0);
CompilerConfigurationBlock.classfiles.group.label=Classfile Generation
CompilerConfigurationBlock.pb_var_deprecated.label=Keyword 'var' is deprecated:
+CompilerConfigurationBlock.pb_keyword.label=Don't use keyword as identifier:
+CompilerConfigurationBlock.pb_uppercase_identifier.label=Non-variable identifiers should contain only uppercase characters:
CompilerConfigurationBlock.pb_unreachable_code.label=&Unreachable code:
CompilerConfigurationBlock.pb_invalid_import.label=Unresol&vable import statements:
******************************************************************************/
package net.sourceforge.phpeclipse.actions;
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;
List locationsList = indexManager.getLocations(word);
if (locationsList != null && locationsList.size() > 0) {
- String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot()
- .getLocation().toString();
+// String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot()
+// .getLocation().toString();
+
+ String workspaceLocation = fProject.getLocation().toString()+File.separatorChar;
// TODO show all entries of the list in a dialog box
// at the moment always the first entry will be opened
if (locationsList.size() > 1) {
// InputStream iStream;
LineCreator lineCreator = createLineCreator();
try {
- addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getFullPath().toString(), lineCreator);
+ addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getProjectRelativePath().toString(), lineCreator);
} catch (CoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();