/* * (non-Javadoc) * @see org.eclipse.jface.preference.PreferencePage#performOk() */ public boolean performOk() { if (fConfigurationBlock != null) { if (!fConfigurationBlock.performOk()) { return false; } PHPVersionProvider.getInstance() .notifyChange( (IProject) getElement().getAdapter(IProject.class), PHPVersion.byAlias(fConfigurationBlock.getPHPVersionValue())); } return super.performOk(); }
/** * Finds a PHPDoc comment above the offset in the source that is read from the given * BufferedReader. * * @param offset * @param reader * @param isParameter Indicate that the docs we are looking for are for a parameter. * @return * @throws IOException * @throws Exception */ private static PHPDocBlock innerParsePHPDoc( int offset, BufferedReader reader, boolean isParameter) throws IOException, Exception // $codepro.audit.disable { StringBuffer moduleData = new StringBuffer(); try { char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) // $codepro.audit.disable { String readData = String.valueOf(buf, 0, numRead); moduleData.append(readData); } } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error closing a BufferedReader in the PDTPHPModuleIndexer", e, //$NON-NLS-1$ PHPEditorPlugin.INDEXER_SCOPE); } } } String contents = moduleData.toString(); int b = -1; for (int a = offset; a >= 0; a--) { char c = contents.charAt(a); if (c == '(') { b = a; break; } if (c == '\r' || c == '\n') { b = a; break; } } if (b != -1) { String str = contents.substring(b, offset); if (str.indexOf(';') == -1) { offset = b; } // System.out.println(str); } // TODO: Shalom - Get the version from the module? PHPVersion version = PHPVersionProvider.getDefaultPHPVersion(); // TODO - Perhaps we'll need to pass a preference value for the 'short-tags' instead of passing // 'true' by // default. ASTParser parser = ASTParser.newParser(new StringReader(contents), version, true); // $codepro.audit.disable // closeWhereCreated Program program = parser.createAST(null); CommentsVisitor commentsVisitor = new CommentsVisitor(); program.accept(commentsVisitor); List<Comment> _comments = commentsVisitor.getComments(); PHPDocBlock docBlock = findPHPDocComment(_comments, offset, contents); if (docBlock == null && isParameter) { // We could not locate a doc right before the given offset, so we traverse up to locate the // docs for the // wrapping function. The includeWrappingFunction is true only when the entry we are looking // for is a // parameter variable, so there is a function that wraps it. ASTNode node = program.getElementAt(offset); if (node instanceof FunctionDeclaration) { offset = node.getStart(); if (node.getParent() instanceof MethodDeclaration) { offset = node.getParent().getStart(); } docBlock = findPHPDocComment(_comments, offset, contents); } } return docBlock; }