/**
* Maps each terminal symbol in the php-grammar into a unique integer. This
* integer is used to represent the terminal when computing a parsing action.
- *
+ *
* @see IScanner
* @since 2.0
*/
final static int TokenNamearrayCAST = 178;
final static int TokenNameobjectCAST = 179;
final static int TokenNameunsetCAST = 180;
-
+
// �
final static int TokenNameEncapsedString0 = 190;
// '
// final static int TokenNameEncapsedString1 = 191;
// "
// final static int TokenNameEncapsedString2 = 192;
-
+
final static int TokenNameSTRING = 193;
-
+
final static int TokenNameLBRACE_DOLLAR = 194;
-
+
// start SQL token - the SQL tokens are only used in the
// PHPCompletionprocessor:
public final static int TokenNameSQLselect = 901;
public final static int TokenNameCLASS_C = 1072;
public final static int TokenNameMETHOD_C = 1073;
public final static int TokenNameFUNC_C = 1074;
-
+
// special tokens not normally used in the parser
public final static int TokenNamethis_PHP_COMPLETION = 2000;
}
// | rw_variable T_INC
// | rw_variable T_DEC
case TokenNameIdentifier:
- char[] ident = scanner.getCurrentTokenSource();
- Expression lhsIdentifier = identifier(true, true);
- if (lhsIdentifier != null) {
- expression = lhsIdentifier;
- }
- if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL
- || token == TokenNameMINUS_EQUAL || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL
- || token == TokenNameDOT_EQUAL || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL
- || token == TokenNameOR_EQUAL || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL
- || token == TokenNameLEFT_SHIFT_EQUAL) {
- String error = "Assignment operator '"+scanner.toStringAction(token)+"' not allowed after identifier '"+new String(ident)+"' (use 'define(...)' to define constants).";
- throwSyntaxError(error);
- }
- break;
case TokenNameVariable:
case TokenNameDOLLAR:
+ Expression lhs = null;
boolean rememberedVar = false;
- Expression lhs = variable(true, true);
- if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
- && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
- && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
- && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
- && token != TokenNameLEFT_SHIFT_EQUAL) {
- FieldReference ref = (FieldReference) lhs;
- if (!containsVariableSet(ref.token)) {
- problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(), referenceContext,
- compilationUnit.compilationResult);
- addVariableSet(ref.token);
+ if (token == TokenNameIdentifier) {
+ lhs = identifier(true, true);
+ if (lhs != null) {
+ expression = lhs;
+ }
+ } else {
+ lhs = variable(true, true);
+ if (lhs != null) {
+ expression = lhs;
+ }
+ if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
+ && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
+ && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
+ && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
+ && token != TokenNameLEFT_SHIFT_EQUAL) {
+ FieldReference ref = (FieldReference) lhs;
+ if (!containsVariableSet(ref.token)) {
+ problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(),
+ referenceContext, compilationUnit.compilationResult);
+ addVariableSet(ref.token);
+ }
}
}
-
switch (token) {
case TokenNameEQUAL:
if (lhs != null && lhs instanceof FieldReference) {
// base_variable_with_function_calls T_OBJECT_OPERATOR
// object_property method_or_not variable_properties
// | base_variable_with_function_calls
- Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
+
+ // Expression ref = function_call(lefthandside, ignoreVar);
+
+ // function_call:
+ // T_STRING '(' function_call_parameter_list ')'
+ // | class_constant '(' function_call_parameter_list ')'
+ // | static_member '(' function_call_parameter_list ')'
+ // | variable_without_objects '(' function_call_parameter_list ')'
+ char[] defineName = null;
+ char[] ident = null;
+ int startPos = 0;
+ int endPos = 0;
+ Expression ref = null;
+ if (Scanner.TRACE) {
+ System.out.println("TRACE: function_call()");
+ }
+ if (token == TokenNameIdentifier) {
+ ident = scanner.getCurrentIdentifierSource();
+ defineName = ident;
+ startPos = scanner.getCurrentTokenStartPosition();
+ endPos = scanner.getCurrentTokenEndPosition();
+ getNextToken();
+
+ if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
+ || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
+ || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
+ || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
+ String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
+ + new String(ident) + "' (use 'define(...)' to define constants).";
+ reportSyntaxError(error);
+ }
+
+ switch (token) {
+ case TokenNamePAAMAYIM_NEKUDOTAYIM:
+ // static member:
+ defineName = null;
+ getNextToken();
+ if (token == TokenNameIdentifier) {
+ // class _constant
+ getNextToken();
+ } else {
+ // static member:
+ variable_without_objects(true, false);
+ }
+ break;
+ }
+ } else {
+ ref = variable_without_objects(lefthandside, ignoreVar);
+ }
+ 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 ref;
+ // throwSyntaxError("'(' expected in function call.");
+ }
+ getNextToken();
+ if (token == TokenNameRPAREN) {
+ getNextToken();
+ return ref;
+ }
+ non_empty_function_call_parameter_list();
+ if (token != TokenNameRPAREN) {
+ String functionName;
+ if (ident == null) {
+ functionName = new String(" ");
+ } else {
+ functionName = new String(ident);
+ }
+ throwSyntaxError("')' expected in function call (" + functionName + ").");
+ }
+ getNextToken();
+
if (token == TokenNameMINUS_GREATER) {
ref = null;
getNextToken();
* stream - currentPosition-1 gives the sourceEnd position into the stream
*/
// 1.4 feature
-// private boolean assertMode;
-
+ // private boolean assertMode;
public boolean useAssertAsAnIndentifier = false;
// flag indicating if processed source contains occurrences of keyword assert
ObviousIdentCharNatures['"'] = C_SEPARATOR;
ObviousIdentCharNatures['\''] = C_SEPARATOR;
}
+
static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' };
static final int TableSize = 30, InternalTableSize = 6;
*/
public static boolean isPHPIdentOrVarStart(char ch) {
if (ch < MAX_OBVIOUS) {
- return ObviousIdentCharNatures[ch]==C_LETTER || ObviousIdentCharNatures[ch]==C_DOLLAR;
+ return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DOLLAR;
}
return false;
- //return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
+ // return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <=
+ // ch && ch <= 0xFF);
}
/**
*/
public static boolean isPHPIdentifierStart(char ch) {
if (ch < MAX_OBVIOUS) {
- return ObviousIdentCharNatures[ch]==C_LETTER;
+ return ObviousIdentCharNatures[ch] == C_LETTER;
}
return false;
-// return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
+ // return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <=
+ // 0xFF);
}
/**
*/
public static boolean isPHPIdentifierPart(char ch) {
if (ch < MAX_OBVIOUS) {
- return ObviousIdentCharNatures[ch]==C_LETTER || ObviousIdentCharNatures[ch]==C_DIGIT;
+ return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT;
}
return false;
-// return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
+ // return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch
+ // <= 0xFF);
}
public static boolean isSQLIdentifierPart(char ch) {
if (ch < MAX_OBVIOUS) {
- return ObviousIdentCharNatures[ch]==C_LETTER || ObviousIdentCharNatures[ch]==C_DIGIT;
+ return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT;
}
return false;
}
return false;
}
for (int i = 0; i < word.length; i++) {
- if (word[i]!=source[startPosition+i]){
+ if (word[i] != source[startPosition + i]) {
return false;
}
}
do {
currentCharacter = source[currentPosition++];
} while (currentCharacter == ' ' || currentCharacter == '\t');
- while (ObviousIdentCharNatures[currentCharacter]==C_LETTER) {
- // while((currentCharacter >= 'a' && currentCharacter <= 'z') || (currentCharacter >= 'A' && currentCharacter <= 'Z')) {
+ while (ObviousIdentCharNatures[currentCharacter] == C_LETTER) {
+ // while((currentCharacter >= 'a' && currentCharacter <= 'z') ||
+ // (currentCharacter >= 'A' && currentCharacter <= 'Z')) {
buf.append(currentCharacter);
currentCharacter = source[currentPosition++];
}
break;
}
default:
- if (isPHPIdentOrVarStart(currentCharacter) ) {
+ if (isPHPIdentOrVarStart(currentCharacter)) {
try {
scanIdentifierOrKeyword((currentCharacter == '$'));
} catch (InvalidInputException ex) {
;
break;
}
- if ( ObviousIdentCharNatures[currentCharacter]==C_DIGIT) {
-// if (Character.isDigit(currentCharacter)) {
+ if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
+ // if (Character.isDigit(currentCharacter)) {
try {
scanNumber(false);
} catch (InvalidInputException ex) {
} else
return TokenNameIdentifier;
case 's':
- // static switch
+ // self static switch
switch (length) {
+// case 4:
+// if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index] == 'f')) {
+// return TokenNameself;
+// }
+// return TokenNameIdentifier;
case 6:
if (data[++index] == 't')
if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
return "require_once"; //$NON-NLS-1$
case TokenNamereturn:
return "return"; //$NON-NLS-1$
+// case TokenNameself:
+// return "self"; //$NON-NLS-1$
case TokenNamestatic:
return "static"; //$NON-NLS-1$
case TokenNameswitch:
return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
case TokenNameEncapsedString0:
return "`"; //$NON-NLS-1$
- // case TokenNameEncapsedString1:
- // return "\'"; //$NON-NLS-1$
- // case TokenNameEncapsedString2:
- // return "\""; //$NON-NLS-1$
+ // case TokenNameEncapsedString1:
+ // return "\'"; //$NON-NLS-1$
+ // case TokenNameEncapsedString2:
+ // return "\""; //$NON-NLS-1$
case TokenNameSTRING:
return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
case TokenNameHEREDOC:
this.tokenizeWhiteSpace = tokenizeWhiteSpace;
this.tokenizeStrings = tokenizeStrings;
this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
-// this.assertMode = assertMode;
+ // this.assertMode = assertMode;
// this.encapsedStringStack = null;
this.taskTags = taskTags;
this.taskPriorities = taskPriorities;
continue nextTag;
if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case
- // insensitive
- // check
+ // insensitive
+ // check
continue nextTag;
}
}
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
*/
public void complete(ITextViewer viewer, int completionPosition, ICompilationUnit compilationUnit) {
IDocument document= viewer.getDocument();
-
+
if (!(fContextType instanceof CompilationUnitContextType))
return;
} catch (BadLocationException e) {}
}
-
+
CompilationUnitContext context= ((CompilationUnitContextType) fContextType).createContext(document, completionPosition, selection.y, compilationUnit);
context.setVariable("selection", selectedText); //$NON-NLS-1$
int start= context.getStart();
int end= context.getEnd();
IRegion region= new Region(start, end - start);
- Template[] templates= PHPeclipsePlugin.getDefault().getTemplateStore().getTemplates();
+ Template[] templates= PHPeclipsePlugin.getDefault().getTemplateStore().getTemplates();
if (selection.y == 0) {
for (int i= 0; i != templates.length; i++)
context.setForceEvaluation(true);
boolean multipleLinesSelected= areMultipleLinesSelected(viewer);
-
+
for (int i= 0; i != templates.length; i++) {
- Template template= templates[i];
+ Template template= templates[i];
if (context.canEvaluate(template) &&
- template.getContextTypeId().equals(context.getContextType().getId()) &&
+ template.getContextTypeId().equals(context.getContextType().getId()) &&
(!multipleLinesSelected && template.getPattern().indexOf($_WORD_SELECTION) != -1 || (multipleLinesSelected && template.getPattern().indexOf($_LINE_SELECTION) != -1)))
{
fProposals.add(new TemplateProposal(templates[i], context, region, PHPUiImages.get(PHPUiImages.IMG_OBJS_TEMPLATE)));
}
}
}
-
+
/**
* Returns <code>true</code> if one line is completely selected or if multiple lines are selected.
- * Being completely selected means that all characters except the new line characters are
+ * Being completely selected means that all characters except the new line characters are
* selected.
- *
+ *
* @return <code>true</code> if one or multiple lines are selected
* @since 2.1
*/
private boolean areMultipleLinesSelected(ITextViewer viewer) {
if (viewer == null)
return false;
-
+
Point s= viewer.getSelectedRange();
if (s.y == 0)
return false;
-
+
try {
-
+
IDocument document= viewer.getDocument();
int startLine= document.getLineOfOffset(s.x);
int endLine= document.getLineOfOffset(s.x + s.y);
IRegion line= document.getLineInformation(startLine);
return startLine != endLine || (s.x == line.getOffset() && s.y == line.getLength());
-
+
} catch (BadLocationException x) {
return false;
}
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
private IRegion fSelectedRegion; // initialized by apply()
private String fDisplayString;
-
+
/**
* Creates a template proposal with a template and its context.
- *
+ *
* @param template the template
* @param context the context in which the template was requested
* @param region the region this proposal applies to
* @param image the icon of the proposal
- */
+ */
public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image) {
Assert.isNotNull(template);
Assert.isNotNull(context);
Assert.isNotNull(region);
-
+
fTemplate= template;
fContext= context;
fImage= image;
fRegion= region;
-
+
fDisplayString= null;
-
+
if (context instanceof JavaContext) {
switch (((JavaContext) context).getCharacterBeforeStart()) {
// high relevance after whitespace
fRelevance= 0;
}
} else {
- fRelevance= 90;
- }
+ fRelevance= 90;
+ }
}
/*
public final void apply(IDocument document) {
// not called anymore
}
-
+
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
*/
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
try {
-
+
fContext.setReadOnly(false);
TemplateBuffer templateBuffer;
try {
fSelectedRegion= fRegion;
return;
}
-
+
int start= getReplaceOffset();
int end= getReplaceEndOffset();
end= Math.max(end, offset);
-
+
// insert template string
IDocument document= viewer.getDocument();
- String templateString= templateBuffer.getString();
- document.replace(start, end - start, templateString);
-
+ String templateString= templateBuffer.getString();
+ document.replace(start, end - start, templateString);
+
// translate positions
LinkedModeModel model= new LinkedModeModel();
TemplateVariable[] variables= templateBuffer.getVariables();
-
+
MultiVariableGuess guess= fContext instanceof CompilationUnitContext ? ((CompilationUnitContext) fContext).getMultiVariableGuess() : null;
-
+
boolean hasPositions= false;
for (int i= 0; i != variables.length; i++) {
TemplateVariable variable= variables[i];
if (variable.isUnambiguous())
continue;
-
+
LinkedPositionGroup group= new LinkedPositionGroup();
-
+
int[] offsets= variable.getOffsets();
int length= variable.getLength();
-
+
LinkedPosition first;
if (guess != null && variable instanceof MultiVariable) {
first= new VariablePosition(document, offsets[0] + start, length, guess, (MultiVariable) variable);
document.addPosition(getCategory(), pos);
proposals[j]= new PositionBasedCompletionProposal(values[j], pos, length);
}
-
+
if (proposals.length > 1)
first= new ProposalPosition(document, offsets[0] + start, length, proposals);
else
first= new LinkedPosition(document, offsets[0] + start, length);
}
-
+
for (int j= 0; j != offsets.length; j++)
if (j == 0)
group.addPosition(first);
else
group.addPosition(new LinkedPosition(document, offsets[j] + start, length));
-
+
model.addGroup(group);
hasPositions= true;
}
-
+
if (hasPositions) {
model.forceInstall();
PHPEditor editor= getJavaEditor();
if (editor != null) {
model.addLinkingListener(new EditorHighlightingSynchronizer(editor));
}
-
+
LinkedModeUI ui= new EditorLinkedModeUI(model, viewer);
ui.setExitPosition(viewer, getCaretOffset(templateBuffer) + start, 0, Integer.MAX_VALUE);
ui.enter();
-
+
fSelectedRegion= ui.getSelectedRegion();
} else
fSelectedRegion= new Region(getCaretOffset(templateBuffer) + start, 0);
-
+
} catch (BadLocationException e) {
PHPeclipsePlugin.log(e);
- openErrorDialog(viewer.getTextWidget().getShell(), e);
+ openErrorDialog(viewer.getTextWidget().getShell(), e);
fSelectedRegion= fRegion;
} catch (BadPositionCategoryException e) {
PHPeclipsePlugin.log(e);
- openErrorDialog(viewer.getTextWidget().getShell(), e);
+ openErrorDialog(viewer.getTextWidget().getShell(), e);
fSelectedRegion= fRegion;
}
- }
-
+ }
+
/**
- * Returns the currently active java editor, or <code>null</code> if it
+ * Returns the currently active java editor, or <code>null</code> if it
* cannot be determined.
- *
+ *
* @return the currently active java editor, or <code>null</code>
*/
private PHPEditor getJavaEditor() {
/**
* Returns the offset of the range in the document that will be replaced by
* applying this template.
- *
+ *
* @return the offset of the range in the document that will be replaced by
* applying this template
*/
/**
* Returns the end offset of the range in the document that will be replaced
* by applying this template.
- *
+ *
* @return the end offset of the range in the document that will be replaced
* by applying this template
*/
document.addPositionCategory(getCategory());
final InclusivePositionUpdater updater= new InclusivePositionUpdater(getCategory());
document.addPositionUpdater(updater);
-
+
model.addLinkingListener(new ILinkedModeListener() {
/*
}
private int getCaretOffset(TemplateBuffer buffer) {
-
+
TemplateVariable[] variables= buffer.getVariables();
for (int i= 0; i != variables.length; i++) {
TemplateVariable variable= variables[i];
return buffer.getString().length();
}
-
+
/*
* @see ICompletionProposal#getSelection(IDocument)
*/
}
return fDisplayString;
}
-
+
public void setDisplayString(String displayString) {
fDisplayString= displayString;
- }
+ }
/*
* @see ICompletionProposal#getImage()
public void setRelevance(int relevance) {
fRelevance= relevance;
}
-
+
public Template getTemplate() {
return fTemplate;
}