public boolean visit(PHPFieldDeclaration declaration) throws Exception { // This is variable declaration: ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.modifiers = declaration.getModifiers(); info.name = declaration.getName(); SimpleReference var = declaration.getRef(); info.nameSourceEnd = var.sourceEnd() - 1; info.nameSourceStart = var.sourceStart(); info.declarationStart = declaration.getDeclarationStart(); info.modifiers = markAsDeprecated(info.modifiers, declaration); PHPDocBlock doc = declaration.getPHPDoc(); if (doc != null) { for (PHPDocTag tag : doc.getTags(PHPDocTag.VAR)) { // do it like for // PHPDocumentationContentAccess#handleBlockTags(List tags): // variable name can be optional, but if present keep only // the good ones if (tag.getVariableReference() != null && !tag.getVariableReference().getName().equals(declaration.getName())) { continue; } if (tag.getTypeReferences().size() > 0) { info.type = PHPModelUtils.appendTypeReferenceNames(tag.getTypeReferences()); break; } } } fInfoStack.push(info); fRequestor.enterField(info); return true; }
private String getParamType(PHPDocBlock docBlock, String paramName, String defaultType) { String result = defaultType; if (docBlock != null) { for (PHPDocTag tag : docBlock.getTags(PHPDocTag.PARAM)) { if (tag.isValidParamTag() && tag.getVariableReference().getName().equals(paramName)) { String typeNames = tag.getSingleTypeReference().getName(); result = typeNames.replace(Constants.TYPE_SEPERATOR_CHAR, Constants.DOT); break; } } } return result; }
private String[] processParameterTypes(MethodDeclaration methodDeclaration) { List<?> args = methodDeclaration.getArguments(); PHPDocBlock docBlock = ((PHPMethodDeclaration) methodDeclaration).getPHPDoc(); String[] parameterType = new String[args.size()]; for (int a = 0; a < args.size(); a++) { Argument arg = (Argument) args.get(a); if (arg instanceof FormalParameter) { SimpleReference type = ((FormalParameter) arg).getParameterType(); if (type != null) { parameterType[a] = type.getName(); } else if (docBlock != null) { for (PHPDocTag tag : docBlock.getTags(PHPDocTag.PARAM)) { if (tag.isValidParamTag() && tag.getVariableReference().getName().equals(arg.getName())) { parameterType[a] = tag.getSingleTypeReference().getName(); break; } } } } } return parameterType; }
public IGoal[] init() { PHPDocClassVariableGoal typedGoal = (PHPDocClassVariableGoal) goal; TypeContext context = (TypeContext) typedGoal.getContext(); String variableName = typedGoal.getVariableName(); int offset = typedGoal.getOffset(); IModelAccessCache cache = context.getCache(); IType[] types = PHPTypeInferenceUtils.getModelElements(context.getInstanceType(), context, offset, cache); Map<PHPDocBlock, IField> docs = new HashMap<PHPDocBlock, IField>(); // remove array index from field name if (variableName.endsWith("]")) { // $NON-NLS-1$ int index = variableName.indexOf("["); // $NON-NLS-1$ if (index != -1) { variableName = variableName.substring(0, index); } } if (types != null) { for (IType type : types) { try { // we look in whole hiearchy ITypeHierarchy superHierarchy; if (cache != null) { superHierarchy = cache.getSuperTypeHierarchy(type, null); } else { superHierarchy = type.newSupertypeHierarchy(null); } IType[] superTypes = superHierarchy.getAllTypes(); for (IType superType : superTypes) { IField[] typeField = PHPModelUtils.getTypeField(superType, variableName, true); if (typeField.length > 0) { PHPDocBlock docBlock = PHPModelUtils.getDocBlock(typeField[0]); if (docBlock != null) { docs.put(docBlock, typeField[0]); } } } } catch (ModelException e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } } } for (Entry<PHPDocBlock, IField> entry : docs.entrySet()) { PHPDocBlock doc = entry.getKey(); IField typeField = entry.getValue(); IType currentNamespace = PHPModelUtils.getCurrentNamespace(typeField); IModelElement space = currentNamespace != null ? currentNamespace : typeField.getSourceModule(); for (PHPDocTag tag : doc.getTags(PHPDocTag.VAR)) { // do it like for // PHPDocumentationContentAccess#handleBlockTags(List tags): // variable name can be optional, but if present keep only // the good ones if (tag.getVariableReference() != null && !tag.getVariableReference().getName().equals(variableName)) { continue; } evaluated.addAll( Arrays.asList( PHPEvaluationUtils.evaluatePHPDocType( tag.getTypeReferences(), space, tag.sourceStart(), null))); } } return IGoal.NO_GOALS; }