public boolean visit(Assignment assignment) throws Exception { Expression left = assignment.getVariable(); if (left instanceof FieldAccess) { // class variable ($this->a = .) FieldAccess fieldAccess = (FieldAccess) left; Expression dispatcher = fieldAccess.getDispatcher(); if (dispatcher instanceof VariableReference && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$ Expression field = fieldAccess.getField(); if (field instanceof SimpleReference) { SimpleReference var = (SimpleReference) field; int modifiers = Modifiers.AccPublic; int offset = var.sourceStart(); int length = var.sourceEnd() - offset; StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } modifyDeclaration( assignment, new DeclarationInfo( IModelElement.FIELD, modifiers, offset, length, offset, length, '$' + var.getName(), metadata.length() == 0 ? null : metadata.toString(), null, fCurrentQualifier, fCurrentParent)); } } } else if (left instanceof VariableReference) { int modifiers = Modifiers.AccPublic | Modifiers.AccGlobal; if (!declarations.empty() && declarations.peek() instanceof MethodDeclaration && !methodGlobalVars.peek().contains(((VariableReference) left).getName())) { return visitGeneral(assignment); } int offset = left.sourceStart(); int length = left.sourceEnd() - offset; modifyDeclaration( assignment, new DeclarationInfo( IModelElement.FIELD, modifiers, offset, length, offset, length, ((VariableReference) left).getName(), null, null, null, null)); } return visitGeneral(assignment); }
public boolean visit(ListVariable listVariable) throws Exception { final Collection<? extends Expression> variables = (listVariable).getVariables(); for (final Expression expression : variables) { if (expression instanceof VariableReference) { final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.modifiers = Modifiers.AccPublic; info.name = ((VariableReference) expression).getName(); info.nameSourceEnd = expression.sourceEnd() - 1; info.nameSourceStart = expression.sourceStart(); info.declarationStart = expression.sourceStart(); fRequestor.enterField(info); fRequestor.exitField(expression.sourceEnd() - 1); } } return true; }
public boolean visit(Assignment assignment) throws Exception { Expression left = assignment.getVariable(); if (left instanceof FieldAccess) { // class variable ($this->a = .) FieldAccess fieldAccess = (FieldAccess) left; Expression dispatcher = fieldAccess.getDispatcher(); if (dispatcher instanceof VariableReference && "$this" //$NON-NLS-1$ .equals(((VariableReference) dispatcher).getName())) { Expression field = fieldAccess.getField(); if (field instanceof SimpleReference) { SimpleReference ref = (SimpleReference) field; ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.modifiers = Modifiers.AccPublic; info.name = '$' + ref.getName(); info.nameSourceEnd = ref.sourceEnd() - 1; info.nameSourceStart = ref.sourceStart(); info.declarationStart = assignment.sourceStart(); fInfoStack.push(info); fRequestor.enterField(info); fNodes.push(assignment); } } } else if (left instanceof VariableReference && !(left instanceof ArrayVariableReference)) { if (!declarations.empty()) { ASTNode parentDeclaration = declarations.peek(); if (parentDeclaration instanceof MethodDeclaration && methodGlobalVars.peek().contains(((VariableReference) left).getName()) || parentDeclaration == fLastNamespace) { deferredDeclarations.add(assignment); return false; } } if (!fInfoStack.isEmpty() && fInfoStack.peek() instanceof ISourceElementRequestor.FieldInfo) { if (!fDeferredVariables.containsKey(fInfoStack.peek())) { fDeferredVariables.put(fInfoStack.peek(), new LinkedList<Assignment>()); } fDeferredVariables.get(fInfoStack.peek()).add(assignment); return false; } ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.modifiers = Modifiers.AccPublic; info.name = ((VariableReference) left).getName(); info.nameSourceEnd = left.sourceEnd() - 1; info.nameSourceStart = left.sourceStart(); info.declarationStart = assignment.sourceStart(); fInfoStack.push(info); if (assignment.getOperatorType() == Assignment.OP_EQUAL) { fRequestor.enterField(info); } else { ISourceElementRequestor sourceElementRequestor = (ISourceElementRequestor) fRequestor; sourceElementRequestor.enterFieldCheckDuplicates(info); } fNodes.push(assignment); } return true; }
public boolean visit(Expression e) throws Exception { if (typeDeclaration.sourceStart() < e.sourceStart() && typeDeclaration.sourceEnd() > e.sourceEnd()) { if (e instanceof Assignment) { if (e.sourceStart() == offset && e.sourceEnd() - e.sourceStart() == length) { result = ((Assignment) e).getValue(); context = contextStack.peek(); } else if (variableName != null) { Assignment assignment = (Assignment) e; Expression left = assignment.getVariable(); Expression right = assignment.getValue(); if (left instanceof StaticFieldAccess) { StaticFieldAccess fieldAccess = (StaticFieldAccess) left; Expression dispatcher = fieldAccess.getDispatcher(); if (dispatcher instanceof TypeReference && "self".equals(((TypeReference) dispatcher).getName())) { // $NON-NLS-1$ Expression field = fieldAccess.getField(); if (field instanceof VariableReference && variableName.equals(((VariableReference) field).getName())) { staticDeclarations.put(right, contextStack.peek()); } } } else if (left instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess) left; Expression dispatcher = fieldAccess.getDispatcher(); if (dispatcher instanceof VariableReference && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$ Expression field = fieldAccess.getField(); if (field instanceof SimpleReference && variableName.equals('$' + ((SimpleReference) field).getName())) { staticDeclarations.put(right, contextStack.peek()); } } } } } } return visitGeneral(e); }
public boolean visit(Assignment assignment) throws Exception { final Expression left = assignment.getVariable(); if (left instanceof FieldAccess) { // class variable ($this->a = .) final FieldAccess fieldAccess = (FieldAccess) left; final Expression dispatcher = fieldAccess.getDispatcher(); if (dispatcher instanceof VariableReference && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$ final Expression field = fieldAccess.getField(); if (field instanceof SimpleReference) { final SimpleReference ref = (SimpleReference) field; final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.modifiers = Modifiers.AccPublic; info.name = '$' + ref.getName(); info.nameSourceEnd = ref.sourceEnd() - 1; info.nameSourceStart = ref.sourceStart(); info.declarationStart = assignment.sourceStart(); fRequestor.enterField(info); fNodes.push(assignment); } } } else if (left instanceof VariableReference) { if (!declarations.empty()) { final Declaration parentDeclaration = declarations.peek(); if (parentDeclaration instanceof MethodDeclaration && methodGlobalVars.peek().contains(((VariableReference) left).getName()) || parentDeclaration == fLastNamespace) { deferredDeclarations.add(assignment); return false; } } final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.modifiers = Modifiers.AccPublic; info.name = ((VariableReference) left).getName(); info.nameSourceEnd = left.sourceEnd() - 1; info.nameSourceStart = left.sourceStart(); info.declarationStart = assignment.sourceStart(); fRequestor.enterField(info); fNodes.push(assignment); } return true; }
public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) throws Exception { ASTNode parentDeclaration = null; if (!declarations.empty()) { parentDeclaration = declarations.peek(); } if (parentDeclaration instanceof TypeDeclaration) { return false; } fNodes.push(anonymousClassDeclaration); declarations.push(anonymousClassDeclaration); for (PHPSourceElementRequestorExtension visitor : extensions) { visitor.visit(anonymousClassDeclaration); } List<String> superClasses = new ArrayList<String>(); String name = null; if (anonymousClassDeclaration.getSuperClass() != null) { name = String.format( ANONYMOUS_CLASS_TEMPLATE, anonymousClassDeclaration.getSuperClass().getName()); String superClass = processNameNode(anonymousClassDeclaration.getSuperClass()); if (superClass != null) { superClasses.add(superClass); } } if (anonymousClassDeclaration.getInterfaceList() != null && !anonymousClassDeclaration.getInterfaceList().isEmpty()) { if (name == null) { name = String.format( ANONYMOUS_CLASS_TEMPLATE, anonymousClassDeclaration.getInterfaceList().get(0).getName()); } for (TypeReference reference : anonymousClassDeclaration.getInterfaceList()) { String interfaceName = processNameNode(reference); if (interfaceName != null) { superClasses.add(interfaceName); } } } if (name == null) { name = String.format(ANONYMOUS_CLASS_TEMPLATE, PHPCoreConstants.ANONYMOUS); } ISourceElementRequestor.TypeInfo mi = new ISourceElementRequestor.TypeInfo(); mi.name = name; mi.modifiers = Modifiers.AccPrivate | IPHPModifiers.AccAnonymous; if (fLastInstanceCreation != null) { Expression className = fLastInstanceCreation.getClassName(); mi.nameSourceStart = className.sourceStart(); mi.nameSourceEnd = className.sourceEnd() - 1; } mi.declarationStart = mi.nameSourceStart; mi.superclasses = superClasses.toArray(new String[0]); fInfoStack.push(mi); this.fRequestor.enterType(mi); this.fInClass = true; return true; }