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; }
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(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; }
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; }
/** * 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; }
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; }
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; }
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(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 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(NamespaceDeclaration s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("name", s.getName()); xmlWriter.startTag("NamespaceDeclaration", parameters); return true; }
public boolean visit(TypeDeclaration type) throws Exception { if (type instanceof NamespaceDeclaration) { NamespaceDeclaration namespaceDecl = (NamespaceDeclaration) type; fCurrentNamespace = namespaceDecl; fLastUseParts.clear(); if (namespaceDecl.isGlobal()) { return visitGeneral(type); } declarations.push(type); int modifiers = type.getModifiers() | Modifiers.AccNameSpace; fCurrentQualifier = type.getName(); Integer count = fCurrentQualifierCounts.get(fCurrentQualifier); count = count != null ? count + 1 : 1; fCurrentQualifierCounts.put(fCurrentQualifier, count); modifiers = markAsDeprecated(modifiers, type); StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } modifyDeclaration( type, new DeclarationInfo( IModelElement.PACKAGE_DECLARATION, modifiers, type.sourceStart(), type.sourceEnd() - type.sourceStart(), type.getNameStart(), type.getNameEnd() - type.getNameStart(), type.getName(), metadata.length() == 0 ? null : metadata.toString(), encodeDocInfo(type), null, null)); } else { Declaration parentDeclaration = null; if (!declarations.empty()) { parentDeclaration = declarations.peek(); } declarations.push(type); if (!(parentDeclaration instanceof NamespaceDeclaration)) { type.setModifier(Modifiers.AccGlobal); } // In case we are entering a nested element if (parentDeclaration instanceof MethodDeclaration) { if (fCurrentNamespace == null) { deferredDeclarations.add(type); } else { deferredNamespacedDeclarations.add(type); } return visitGeneral(type); } int modifiers = type.getModifiers(); fCurrentParent = type.getName(); String[] superClasses = processSuperClasses(type); StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } for (int i = 0; i < superClasses.length; ++i) { metadata.append(superClasses[i]); if (i < superClasses.length - 1) { metadata.append(","); // $NON-NLS-1$ } } modifiers = markAsDeprecated(modifiers, type); modifyDeclaration( type, new DeclarationInfo( IModelElement.TYPE, modifiers, type.sourceStart(), type.sourceEnd() - type.sourceStart(), type.getNameStart(), type.getNameEnd() - type.getNameStart(), type.getName(), metadata.length() == 0 ? null : metadata.toString(), encodeDocInfo(type), fCurrentQualifier, null)); } for (PhpIndexingVisitorExtension visitor : extensions) { visitor.visit(type); } return visitGeneral(type); }
/** * Resolve class members that were defined using the @property tag * * @param type declaration for wich we add the magic variables */ private void resolveMagicMembers(TypeDeclaration type) { if (type instanceof IPHPDocAwareDeclaration) { IPHPDocAwareDeclaration declaration = (IPHPDocAwareDeclaration) type; final PHPDocBlock doc = declaration.getPHPDoc(); if (doc != null) { for (PHPDocTag docTag : doc.getTags()) { final int tagKind = docTag.getTagKind(); if (tagKind == PHPDocTag.PROPERTY || tagKind == PHPDocTag.PROPERTY_READ || tagKind == PHPDocTag.PROPERTY_WRITE) { // http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.property.pkg.html final String[] split = WHITESPACE_SEPERATOR.split(docTag.getValue().trim()); if (split.length < 2) { break; } String name = removeParenthesis(split); int offset = docTag.sourceStart(); int length = docTag.sourceStart() + 9; Map<String, String> info = new HashMap<String, String>(); info.put("v", split[0]); // $NON-NLS-1$ StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } modifyDeclaration( null, new DeclarationInfo( IModelElement.FIELD, Modifiers.AccPublic, offset, length, offset, length, name, metadata.length() == 0 ? null : metadata.toString(), encodeDocInfo(info), fCurrentQualifier, fCurrentParent)); } else if (tagKind == PHPDocTag.METHOD) { // http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.method.pkg.html String[] split = WHITESPACE_SEPERATOR.split(docTag.getValue().trim()); if (split.length < 2) { break; } int methodModifiers = Modifiers.AccPublic; if (Constants.STATIC.equals(split[0].trim())) { if (split.length < 3) { break; } methodModifiers |= Modifiers.AccStatic; split = Arrays.copyOfRange(split, 1, split.length); } String name = removeParenthesis(split); int index = name.indexOf('('); if (index > 0) { name = name.substring(0, index); } int offset = docTag.sourceStart(); int length = docTag.sourceStart() + 6; Map<String, String> info = new HashMap<String, String>(); info.put("r", split[0]); // $NON-NLS-1$ StringBuilder metadata = new StringBuilder(); if (fCurrentQualifier != null) { metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier)); metadata.append(";"); // $NON-NLS-1$ } modifyDeclaration( null, new DeclarationInfo( IModelElement.METHOD, methodModifiers, offset, length, offset, length, name, metadata.length() == 0 ? null : metadata.toString(), encodeDocInfo(info), fCurrentQualifier, fCurrentParent)); } } } } }
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(GotoStatement s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("label", s.getLabel()); xmlWriter.startTag("GotoStatement", 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; }
public boolean visit(CastExpression s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("type", CastExpression.getCastType(s.getCastType())); xmlWriter.startTag("CastExpression", 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(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; }