public void updateTaskTags( final String contents, final Program program, final List<Comment> comments, IModule module) { try { if (module instanceof LocalModule) { LocalModule lm = (LocalModule) module; final IFile file = lm.getFile(); // TODO get project level task tags/prefs when we support them. Collection<TaskTag> tags = TaskTag.getTaskTags(); boolean isCaseSensitive = TaskTag.isCaseSensitive(); program.setLineEndTable(Util.lineEndTable(new Document(contents))); // visit the comment nodes and parse for tasks! Collection<Task> tasks = new ArrayList<Task>(); for (Comment comment : comments) { tasks.addAll(processCommentNode(program, contents, isCaseSensitive, tags, comment)); } final Task[] finalTasks = tasks.toArray(new Task[tasks.size()]); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) { doHandleErrorsJob(finalTasks, file); } }; ResourcesPlugin.getWorkspace() .run(runnable, getMarkerRule(file), IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); } } catch (Exception e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the PHP task-tags.", e, PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } }
void doHandleErrorsJob(Task[] errors, IFile file) { synchronized (this) // prevent simultaneous error updates on the same file { if (ResourcesPlugin.getWorkspace().isTreeLocked()) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the document errors. The workspace tree is locked.", PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } if (file == null || !file.exists()) { return; } int depth = IResource.DEPTH_INFINITE; try { IMarker[] problemMarkers = file.findMarkers(IMarker.TASK, true, depth); for (IMarker m : problemMarkers) { Object attribute2 = m.getAttribute(APTANA_TASK); if (attribute2 != null && attribute2.equals("true")) // $NON-NLS-1$ { m.delete(); } } for (Task t : errors) { IMarker problemMarker = file.createMarker(IMarker.TASK); problemMarker.setAttribute(IMarker.PRIORITY, t.getPriority()); problemMarker.setAttribute(IMarker.CHAR_START, t.getStart()); problemMarker.setAttribute(IMarker.CHAR_END, t.getEnd()); problemMarker.setAttribute(APTANA_TASK, Boolean.TRUE.toString()); problemMarker.setAttribute(IMarker.MESSAGE, t.getDescription()); problemMarker.setAttribute(IMarker.LINE_NUMBER, t.getLineNumber()); } } catch (Exception e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the PHP task-tags.", e, PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } } }
/** * Select a PHP version. * * @param phpAlias The version alias. */ private void setSelectedVersion(String phpAlias) { int index = PHPVersionConfigurationBlock.PHP_ALIASES.indexOf(phpAlias); if (index < 0) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Unresolved PHP version: " + phpAlias, new Exception("Unresolved PHP version"), PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ //$NON-NLS-2$ index = 0; } fPHPVersions.select(index); }
protected void loadState(IMemento memento) { IMemento child = memento.getChild(ELEMENT_NAME); if (child != null) { name = child.getTextData(); } child = memento.getChild(ELEMENT_SOURCE); if (child != null) { URI uri = URI.create(child.getTextData()); sourceConnectionPoint = ConnectionPointUtils.findConnectionPoint(uri); if (sourceConnectionPoint == null) { IdeLog.logWarning( SyncingPlugin.getDefault(), "Failed to load source connection point from URI " + uri, // $NON-NLS-1$ IDebugScopes.DEBUG); } } child = memento.getChild(ELEMENT_DESTINATION); if (child != null) { URI uri = URI.create(child.getTextData()); destinationConnectionPoint = ConnectionPointUtils.findConnectionPoint(uri); if (destinationConnectionPoint == null) { IdeLog.logWarning( SyncingPlugin.getDefault(), "Failed to load destination connection point from URI " + uri, // $NON-NLS-1$ IDebugScopes.DEBUG); } } child = memento.getChild(ELEMENT_EXCLUDES); if (child != null) { for (IMemento i : child.getChildren(ELEMENT_PATH)) { excludes.add(Path.fromPortableString(i.getTextData())); } for (IMemento i : child.getChildren(ELEMENT_WILDCARD)) { excludes.add(i.getTextData()); } } }
/** * Constructs include path from one module to another. * * @param from - module to construct include path from. * @param to - module to construct include path to. * @return constructed include path */ public static ConstructedIncludePath constructIncludePath(IModule from, IModule to) { IBuildPath fromBuildPath = from.getBuildPath(); IBuildPath toBuildPath = to.getBuildPath(); Set<IBuildPath> fromDependencies = fromBuildPath.getDependencies(); if (fromDependencies.equals(toBuildPath)) { String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, null, null); } // if "from" build-path directly depends from "to" build-path if (fromDependencies.contains(toBuildPath)) { String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, null, null); } else { // for local modules using its project-based build-path instead of native module build-path if (to instanceof LocalModule) { IFile file = ((LocalModule) to).getFile(); if (!file.isSynchronized(1)) { try { file.refreshLocal(1, new NullProgressMonitor()); if (file.exists()) { IProject project = file.getProject(); IBuildPath projectBuildPath = BuildPathManager.getInstance().getBuildPathByResource(project); if (projectBuildPath != null) { IModule alternativeToModule = projectBuildPath.getModule(file); if (alternativeToModule != null) { String includePath = constructPathFromRoot(alternativeToModule); return new ConstructedIncludePath(includePath, fromBuildPath, projectBuildPath); } } } } catch (CoreException e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "PHP Refactoring - Error while constructing an include-path (constructIncludePath)", //$NON-NLS-1$ e, PHPEditorPlugin.DEBUG_SCOPE); } } } // in other case, using original build-paths for reporting unsatisfied state String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, fromBuildPath, toBuildPath); } }
/** * Opens the internal HelpView and address it to the given doc url. * * @param url */ public static void openHelp(String url) { IWorkbenchPage page = getActivePage(); if (page != null) { try { IViewPart part = page.showView(HELP_VIEW_ID); if (part != null) { HelpView view = (HelpView) part; view.showHelp(url); } } catch (PartInitException e) { IdeLog.logError(UIPlugin.getDefault(), e); } } else { IdeLog.logWarning( UIPlugin.getDefault(), "Could not open the help view. Active page was null."); //$NON-NLS-1$ } }
/** * 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; }
/** * logWarning * * @deprecated Use IdeLog instead * @param message * @param e */ public static void logWarning(String message, Throwable e) { IdeLog.logWarning(getDefault(), message, e, null); }
/** * readProfiles * * @param file * @return File[] */ protected static File[] readProfiles(File dir) { List<File> list = new ArrayList<File>(); File profilesIni = new File(dir, "profiles.ini"); // $NON-NLS-1$ if (profilesIni.exists()) { LineNumberReader r = null; try { r = new LineNumberReader(new FileReader(profilesIni)); String line; Map<String, Map<String, String>> sections = new LinkedHashMap<String, Map<String, String>>(); Map<String, String> last = null; Pattern sectionPattern = Pattern.compile(SECTION_PATTERN); Pattern valuePattern = Pattern.compile(VALUE_PATTERN); while ((line = r.readLine()) != null) { Matcher matcher = sectionPattern.matcher(line); if (matcher.find()) { last = new HashMap<String, String>(); sections.put(matcher.group(1), last); continue; } else if (last == null) { continue; } matcher = valuePattern.matcher(line); if (matcher.find()) { last.put(matcher.group(1), matcher.group(2)); } } for (Entry<String, Map<String, String>> entry : sections.entrySet()) { if (entry.getKey().startsWith("Profile")) { // $NON-NLS-1$ Map<String, String> properties = entry.getValue(); String path = (String) properties.get("Path"); // $NON-NLS-1$ String isRelative = (String) properties.get("IsRelative"); // $NON-NLS-1$ File profile; if (isRelative != null && "1".equals(isRelative)) { // $NON-NLS-1$ profile = new File(dir, path); } else { profile = new File(path); // TODO: base64 decode ? } boolean def = properties.containsKey("Default"); // $NON-NLS-1$ if (def) { list.add(0, profile); } else { list.add(profile); } } } } catch (IOException e) { IdeLog.logWarning( CorePlugin.getDefault(), MessageFormat.format("Reading '{0}' fails", profilesIni.getAbsolutePath()), e, null); //$NON-NLS-1$ } finally { if (r != null) { try { r.close(); } catch (IOException ignore) { } } } } return list.toArray(new File[list.size()]); }