public boolean visit(PHPDocTag s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("tagKind", PHPDocTag.getTagKind(s.getTagKind())); parameters.put("value", s.getValue()); xmlWriter.startTag("PHPDocTag", parameters); return true; }
public boolean visit(ArrayVariableReference s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("type", ArrayVariableReference.getArrayType(s.getArrayType())); parameters.put("name", s.getName()); xmlWriter.startTag("ArrayVariableReference", parameters); return true; }
protected void getGoalFromStaticDeclaration( String variableName, final List<IGoal> subGoals, final IType declaringType, IType realType) throws ModelException { ISourceModule sourceModule = declaringType.getSourceModule(); ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule); TypeDeclaration typeDeclaration = PHPModelUtils.getNodeByClass(moduleDeclaration, declaringType); // try to search declarations of type "self::$var =" or // "$this->var =" ClassDeclarationSearcher searcher; if (realType != null) { searcher = new ClassDeclarationSearcher( sourceModule, typeDeclaration, 0, 0, variableName, realType, declaringType); } else { searcher = new ClassDeclarationSearcher(sourceModule, typeDeclaration, 0, 0, variableName); } try { moduleDeclaration.traverse(searcher); Map<ASTNode, IContext> staticDeclarations = searcher.getStaticDeclarations(); for (ASTNode node : staticDeclarations.keySet()) { IContext context = staticDeclarations.get(node); if (context instanceof MethodContext) { MethodContext methodContext = (MethodContext) context; methodContext.setCurrentType(realType); } subGoals.add(new ExpressionTypeGoal(context, node)); } } catch (Exception e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } }
public boolean visit(LambdaFunctionDeclaration s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("isReference", Boolean.toString(s.isReference())); if (s.isStatic()) { parameters.put("isStatic", Boolean.toString(s.isStatic())); } xmlWriter.startTag("LambdaFunctionDeclaration", parameters); xmlWriter.startTag("Arguments", new HashMap<String, String>()); for (FormalParameter p : s.getArguments()) { p.traverse(this); } xmlWriter.endTag("Arguments"); Collection<? extends Expression> lexicalVars = s.getLexicalVars(); if (lexicalVars != null) { xmlWriter.startTag("LexicalVars", new HashMap<String, String>()); for (Expression var : lexicalVars) { var.traverse(this); } xmlWriter.endTag("LexicalVars"); } s.getBody().traverse(this); return false; }
public boolean visit(Scalar s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("type", s.getType()); parameters.put("value", s.getValue()); xmlWriter.startTag("Scalar", parameters); return true; }
protected Map<String, String> createInitialParameters(ASTNode s) throws Exception { Map<String, String> parameters = new LinkedHashMap<String, String>(); // Print offset information: parameters.put("start", Integer.toString(s.sourceStart())); parameters.put("end", Integer.toString(s.sourceEnd())); // Print modifiers: if (s instanceof Declaration) { Declaration declaration = (Declaration) s; StringBuilder buf = new StringBuilder(); if (declaration.isAbstract()) { buf.append(",abstract"); } if (declaration.isFinal()) { buf.append(",final"); } if (declaration.isPrivate()) { buf.append(",private"); } if (declaration.isProtected()) { buf.append(",protected"); } if (declaration.isPublic()) { buf.append(",public"); } if (declaration.isStatic()) { buf.append(",static"); } String modifiers = buf.toString(); parameters.put("modifiers", modifiers.length() > 0 ? modifiers.substring(1) : modifiers); } return parameters; }
/** * See {@link PhpElementResolver#decodeDocInfo(String)} for the decoding routine. * * @param declaration Declaration ASTNode * @return decoded PHPDoc info, or <code>null</code> if there's no PHPDoc info to store. */ protected static String encodeDocInfo(Declaration declaration) { if (declaration instanceof IPHPDocAwareDeclaration) { PHPDocBlock docBlock = ((IPHPDocAwareDeclaration) declaration).getPHPDoc(); if (docBlock != null) { Map<String, String> info = new HashMap<String, String>(); for (PHPDocTag tag : docBlock.getTags()) { if (tag.getTagKind() == PHPDocTag.DEPRECATED) { info.put("d", null); // $NON-NLS-1$ } else if (tag.getTagKind() == PHPDocTag.RETURN) { StringBuilder buf = new StringBuilder(); for (TypeReference ref : tag.getTypeReferences()) { String type = ref.getName().replaceAll(",", "~"); // $NON-NLS-1$ //$NON-NLS-2$ if (buf.length() > 0) { buf.append(','); } buf.append(type); } info.put("r", buf.toString()); // $NON-NLS-1$ } else if (tag.getTagKind() == PHPDocTag.VAR) { if (tag.getTypeReferences().size() > 0) { String typeNames = PHPModelUtils.appendTypeReferenceNames(tag.getTypeReferences()); typeNames = typeNames.replace(Constants.TYPE_SEPERATOR_CHAR, Constants.DOT); info.put("v", typeNames); // $NON-NLS-1$ } } } return encodeDocInfo(info); } } return null; }
public boolean visit(NamespaceReference s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("name", s.getName()); parameters.put("global", Boolean.toString(s.isGlobal())); parameters.put("local", Boolean.toString(s.isLocal())); xmlWriter.startTag("NamespaceReference", parameters); return true; }
public boolean visit(TraitAlias s) throws Exception { Map<String, String> parameters = createInitialParameters(s); if (s.getMethodName() != null) { parameters.put("methodName", s.getMethodName().getName()); } xmlWriter.startTag("TraitAlias", parameters); return true; }
public boolean visit(FullyQualifiedTraitMethodReference s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("functionName", s.getFunctionName()); xmlWriter.startTag("FullyQualifiedTraitMethodReference", parameters); xmlWriter.startTag("className", EMPTY_MAP); s.getClassName().traverse(this); xmlWriter.endTag("className"); xmlWriter.endTag("FullyQualifiedTraitMethodReference"); return false; }
private String processNameNode(ASTNode nameNode) { if (nameNode instanceof FullyQualifiedReference) { String name; FullyQualifiedReference fullyQualifiedName = (FullyQualifiedReference) nameNode; name = fullyQualifiedName.getFullyQualifiedName(); if (fullyQualifiedName.getNamespace() != null) { String namespace = fullyQualifiedName.getNamespace().getName(); String subnamespace = ""; // $NON-NLS-1$ if (namespace.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR && namespace.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0) { int firstNSLocation = namespace.indexOf(NamespaceReference.NAMESPACE_SEPARATOR); subnamespace = namespace.substring(firstNSLocation); namespace = namespace.substring(0, firstNSLocation); } if (name.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) { name = name.substring(1); } else if (fLastUseParts.containsKey(namespace)) { name = new StringBuilder(fLastUseParts.get(namespace).getNamespace().getFullyQualifiedName()) .append(subnamespace) .append(NamespaceReference.NAMESPACE_SEPARATOR) .append(fullyQualifiedName.getName()) .toString(); } else if (fLastNamespace != null) { name = new StringBuilder(fLastNamespace.getName()) .append(NamespaceReference.NAMESPACE_SEPARATOR) .append(name) .toString(); } } else if (fLastUseParts.containsKey(name)) { name = fLastUseParts.get(name).getNamespace().getFullyQualifiedName(); if (name.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) { name = name.substring(1); } } else { if (fLastNamespace != null) { name = new StringBuilder(fLastNamespace.getName()) .append(NamespaceReference.NAMESPACE_SEPARATOR) .append(name) .toString(); } } return name; } else if (nameNode instanceof SimpleReference) { return ((SimpleReference) nameNode).getName(); } return null; }
public boolean visit(PHPFieldDeclaration decl) throws Exception { // This is variable declaration: int modifiers = markAsDeprecated(decl.getModifiers(), decl); StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } modifyDeclaration( decl, new DeclarationInfo( IModelElement.FIELD, modifiers, decl.sourceStart(), decl.sourceEnd() - decl.sourceStart(), decl.getNameStart(), decl.getNameEnd() - decl.getNameStart(), decl.getName(), metadata.length() == 0 ? null : metadata.toString(), encodeDocInfo(decl), fCurrentQualifier, fCurrentParent)); return visitGeneral(decl); }
public boolean endvisit(TypeDeclaration type) throws Exception { if (type instanceof NamespaceDeclaration) { NamespaceDeclaration namespaceDecl = (NamespaceDeclaration) type; while (deferredNamespacedDeclarations != null && !deferredNamespacedDeclarations.isEmpty()) { final ASTNode[] declarations = deferredNamespacedDeclarations.toArray( new ASTNode[deferredNamespacedDeclarations.size()]); deferredNamespacedDeclarations.clear(); for (ASTNode deferred : declarations) { deferred.traverse(this); } } fCurrentNamespace = null; // there are no nested namespaces fCurrentQualifier = null; fLastUseParts.clear(); if (namespaceDecl.isGlobal()) { return visitGeneral(type); } } else { fCurrentParent = null; } declarations.pop(); // resolve more type member declarations resolveMagicMembers(type); for (PhpIndexingVisitorExtension visitor : extensions) { visitor.endvisit(type); } endvisitGeneral(type); 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".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(ConstantDeclaration declaration) throws Exception { int modifiers = Modifiers.AccConstant | Modifiers.AccPublic | Modifiers.AccFinal; if (fCurrentParent != null) { modifiers = modifiers | PHPCoreConstants.AccClassField; } modifiers = markAsDeprecated(modifiers, declaration); ConstantReference constantName = declaration.getConstantName(); int offset = constantName.sourceStart(); int length = constantName.sourceEnd(); StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } modifyDeclaration( declaration, new DeclarationInfo( IModelElement.FIELD, modifiers, offset, length, offset, length, ASTUtils.stripQuotes(constantName.getName()), metadata.length() == 0 ? null : metadata.toString(), encodeDocInfo(declaration), fCurrentQualifier, fCurrentParent)); return visitGeneral(declaration); }
public boolean visit(TypeDeclaration type) throws Exception { if (type instanceof NamespaceDeclaration) { NamespaceDeclaration namespaceDecl = (NamespaceDeclaration) type; fLastNamespace = namespaceDecl; fLastUseParts.clear(); if (namespaceDecl.isGlobal()) { return true; } } type.setModifiers(markAsDeprecated(type.getModifiers(), type)); // In case we are entering a nested element if (!declarations.empty() && declarations.peek() instanceof MethodDeclaration) { if (fLastNamespace == null) { deferredDeclarations.add(type); } else { deferredNamespacedDeclarations.add(type); } return false; } declarations.push(type); for (PHPSourceElementRequestorExtension visitor : extensions) { visitor.visit(type); } return super.visit(type); }
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); }
protected static String encodeDocInfo(Map<String, String> info) { if (info == null) { return null; } StringBuilder buf = new StringBuilder(); for (Entry<String, String> e : info.entrySet()) { if (buf.length() > 0) { buf.append(';'); } buf.append(e.getKey()); if (e.getValue() != null) { buf.append(':').append(e.getValue()); } } return buf.length() > 0 ? buf.toString() : null; }
public boolean visit(UseStatement declaration) throws Exception { Collection<UsePart> parts = declaration.getParts(); for (UsePart part : parts) { String name = null; if (part.getAlias() != null) { name = part.getAlias().getName(); } else { name = part.getNamespace().getName(); int index = name.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR); if (index >= 0) { name = name.substring(index + 1); } } fLastUseParts.put(name, part); } return visitGeneral(declaration); }
public boolean endvisit(ModuleDeclaration declaration) throws Exception { for (PHPSourceElementRequestorExtension visitor : extensions) { visitor.endvisit(declaration); } while (deferredDeclarations != null && !deferredDeclarations.isEmpty()) { final ASTNode[] declarations = deferredDeclarations.toArray(new ASTNode[deferredDeclarations.size()]); deferredDeclarations.clear(); for (ASTNode deferred : declarations) { deferred.traverse(this); } } fLastUseParts.clear(); return super.endvisit(declaration); }
public boolean endvisit(ModuleDeclaration declaration) throws Exception { while (deferredDeclarations != null && !deferredDeclarations.isEmpty()) { final ASTNode[] declarations = deferredDeclarations.toArray(new ASTNode[deferredDeclarations.size()]); deferredDeclarations.clear(); for (ASTNode deferred : declarations) { deferred.traverse(this); } } for (PhpIndexingVisitorExtension visitor : extensions) { visitor.endvisit(declaration); } fLastUseParts.clear(); endvisitGeneral(declaration); return true; }
public boolean visit(UseStatement declaration) throws Exception { Collection<UsePart> parts = declaration.getParts(); for (UsePart part : parts) { String name = null; if (part.getAlias() != null) { name = part.getAlias().getName(); } else { name = part.getNamespace().getName(); int index = name.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR); if (index >= 0) { name = name.substring(index + 1); } } ImportInfo info = new ImportInfo(); String containerName; if (fLastNamespace == null) { containerName = GLOBAL_NAMESPACE_CONTAINER_NAME; } else { containerName = fLastNamespace.getName(); } info.containerName = containerName; if (declaration.getNamespace() == null) { info.name = part.getNamespace().getFullyQualifiedName(); } else { info.name = PHPModelUtils.concatFullyQualifiedNames( declaration.getNamespace().getFullyQualifiedName(), part.getNamespace().getFullyQualifiedName()); } info.sourceStart = part.getNamespace().sourceStart(); info.sourceEnd = part.getNamespace().sourceEnd(); fRequestor.acceptImport(info); fLastUseParts.put(name, part); } return true; }
public IGoal[] init() { ClassVariableDeclarationGoal typedGoal = (ClassVariableDeclarationGoal) goal; IType[] types = typedGoal.getTypes(); if (types == null) { TypeContext context = (TypeContext) typedGoal.getContext(); types = PHPTypeInferenceUtils.getModelElements(context.getInstanceType(), context); } if (types == null) { return null; } IContext context = typedGoal.getContext(); IModelAccessCache cache = null; if (context instanceof IModelCacheContext) { cache = ((IModelCacheContext) context).getCache(); } String variableName = typedGoal.getVariableName(); final List<IGoal> subGoals = new LinkedList<IGoal>(); for (final IType type : types) { try { ITypeHierarchy hierarchy = null; if (cache != null) { hierarchy = cache.getSuperTypeHierarchy(type, null); } IField[] fields = PHPModelUtils.getTypeHierarchyField(type, hierarchy, variableName, true, null); Map<IType, IType> fieldDeclaringTypeSet = new HashMap<IType, IType>(); for (IField field : fields) { IType declaringType = field.getDeclaringType(); if (declaringType != null) { fieldDeclaringTypeSet.put(declaringType, type); ISourceModule sourceModule = declaringType.getSourceModule(); ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule); TypeDeclaration typeDeclaration = PHPModelUtils.getNodeByClass(moduleDeclaration, declaringType); if (typeDeclaration != null && field instanceof SourceRefElement) { SourceRefElement sourceRefElement = (SourceRefElement) field; ISourceRange sourceRange = sourceRefElement.getSourceRange(); ClassDeclarationSearcher searcher = new ClassDeclarationSearcher( sourceModule, typeDeclaration, sourceRange.getOffset(), sourceRange.getLength(), null, type, declaringType); try { moduleDeclaration.traverse(searcher); if (searcher.getResult() != null) { subGoals.add(new ExpressionTypeGoal(searcher.getContext(), searcher.getResult())); } } catch (Exception e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } } } } if (subGoals.size() == 0) { getGoalFromStaticDeclaration(variableName, subGoals, type, null); } fieldDeclaringTypeSet.remove(type); if (subGoals.size() == 0 && !fieldDeclaringTypeSet.isEmpty()) { for (Iterator iterator = fieldDeclaringTypeSet.keySet().iterator(); iterator.hasNext(); ) { IType fieldDeclaringType = (IType) iterator.next(); getGoalFromStaticDeclaration( variableName, subGoals, fieldDeclaringType, fieldDeclaringTypeSet.get(fieldDeclaringType)); } } } catch (CoreException e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } } resolveMagicClassVariableDeclaration(types, variableName, cache); return subGoals.toArray(new IGoal[subGoals.size()]); }
public boolean visit(FormalParameter s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("isMandatory", Boolean.toString(s.isMandatory())); xmlWriter.startTag("FormalParameter", parameters); return true; }
public boolean visit(Comment s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("type", Comment.getCommentType(s.getCommentType())); xmlWriter.startTag("Comment", parameters); return true; }
public boolean visit(NamespaceDeclaration s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("name", s.getName()); xmlWriter.startTag("NamespaceDeclaration", parameters); return true; }
public boolean visit(UnaryOperation s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("operator", s.getOperator()); xmlWriter.startTag("UnaryOperation", parameters); return true; }
public boolean visit(PHPDocBlock s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("shortDescription", s.getShortDescription()); xmlWriter.startTag("PHPDocBlock", parameters); return true; }
public boolean visit(FullyQualifiedReference s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("name", s.getFullyQualifiedName()); xmlWriter.startTag("FullyQualifiedReference", parameters); return true; }
public boolean visit(Quote s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("type", Quote.getType(s.getQuoteType())); xmlWriter.startTag("Quote", parameters); return true; }