protected DfaMemoryStateImpl(DfaMemoryStateImpl toCopy) { myFactory = toCopy.myFactory; myEphemeral = toCopy.myEphemeral; myDefaultVariableStates = toCopy.myDefaultVariableStates; // shared between all states myStack = new Stack<DfaValue>(toCopy.myStack); myDistinctClasses = new TLongHashSet(toCopy.myDistinctClasses.toArray()); myUnknownVariables = ContainerUtil.newLinkedHashSet(toCopy.myUnknownVariables); myEqClasses = ContainerUtil.newArrayList(toCopy.myEqClasses); myIdToEqClassesIndices = new MyIdMap(toCopy.myIdToEqClassesIndices.size()); toCopy.myIdToEqClassesIndices.forEachEntry(new TIntObjectProcedure<int[]>() { @Override public boolean execute(int id, int[] set) { myIdToEqClassesIndices.put(id, set); return true; } }); myVariableStates = ContainerUtil.newLinkedHashMap(toCopy.myVariableStates); myCachedDistinctClassPairs = toCopy.myCachedDistinctClassPairs; myCachedNonTrivialEqClasses = toCopy.myCachedNonTrivialEqClasses; myCachedHash = toCopy.myCachedHash; }
@Nullable public ControlFlow buildControlFlow() { myCatchStack = new Stack<CatchDescriptor>(); myCurrentFlow = new ControlFlow(myFactory); try { myCodeFragment.accept(this); } catch (CannotAnalyzeException e) { return null; } PsiElement parent = myCodeFragment.getParent(); if (parent instanceof PsiLambdaExpression && myCodeFragment instanceof PsiExpression) { generateBoxingUnboxingInstructionFor((PsiExpression)myCodeFragment, LambdaUtil.getFunctionalInterfaceReturnType((PsiLambdaExpression)parent)); addInstruction(new CheckReturnValueInstruction(myCodeFragment)); } addInstruction(new ReturnInstruction(false, null)); if (Registry.is("idea.dfa.live.variables.analysis")) { new LiveVariablesAnalyzer(myCurrentFlow, myFactory).flushDeadVariablesOnStatementFinish(); } return myCurrentFlow; }
public static boolean allOperandsAreLiterals(@Nullable final PsiExpression expression) { if (expression == null) return false; if (expression instanceof PsiLiteralExpression) return true; if (expression instanceof PsiPolyadicExpression) { Stack<PsiExpression> stack = new Stack<PsiExpression>(); stack.add(expression); while (!stack.isEmpty()) { PsiExpression psiExpression = stack.pop(); if (psiExpression instanceof PsiPolyadicExpression) { PsiPolyadicExpression binaryExpression = (PsiPolyadicExpression)psiExpression; for (PsiExpression op : binaryExpression.getOperands()) { stack.push(op); } } else if (!(psiExpression instanceof PsiLiteralExpression)) { return false; } } return true; } return false; }
public static Set<PsiMethod> calculateSiblingMethods(PsiMethod method) { final Set<PsiMethod> siblingMethods = new HashSet<PsiMethod>(); final Stack<PsiMethod> pendingMethods = new Stack<PsiMethod>(); pendingMethods.add(method); while(!pendingMethods.isEmpty()) { final PsiMethod methodToAnalyze = pendingMethods.pop(); siblingMethods.add(methodToAnalyze); final Iterable<PsiMethod> overridingMethods = OverridingMethodsSearch.search(methodToAnalyze, false); for (PsiMethod overridingMethod : overridingMethods) { if (!siblingMethods.contains(overridingMethod) && !pendingMethods.contains(overridingMethod)) { pendingMethods.add(overridingMethod); } } final PsiMethod[] superMethods = methodToAnalyze.findSuperMethods(); for (PsiMethod superMethod : superMethods) { if (!siblingMethods.contains(superMethod) && !pendingMethods.contains(superMethod)) { pendingMethods.add(superMethod); } } } return siblingMethods; }
@Override public synchronized void initStateFrom(@NotNull final ProgressIndicator indicator) { myRunning = indicator.isRunning(); myCanceled = indicator.isCanceled(); myFraction = indicator.getFraction(); myIndeterminate = indicator.isIndeterminate(); myText = indicator.getText(); myText2 = indicator.getText2(); myFraction = indicator.getFraction(); if (indicator instanceof ProgressIndicatorStacked) { ProgressIndicatorStacked stacked = (ProgressIndicatorStacked)indicator; myNonCancelableCount = stacked.getNonCancelableCount(); myTextStack = new Stack<String>(stacked.getTextStack()); myText2Stack = new Stack<String>(stacked.getText2Stack()); myFractionStack = new DoubleArrayList(stacked.getFractionStack()); } myShouldStartActivity = false; }
@Override public void visitPyParenthesizedExpression(final PyParenthesizedExpression expression) { final Stack<PsiElement> stack = new Stack<PsiElement>(); stack.push(expression); while (!stack.isEmpty()) { PsiElement element = stack.pop(); if (!(element instanceof PyTupleExpression)) { findProblem(element); if (element != null) { for (PsiElement psiElement : element.getChildren()) { stack.push(psiElement); } } } } }
private static boolean isExceptionUsed(PyExceptPart node, String text) { Stack<PsiElement> stack = new Stack<PsiElement>(); PyStatementList statementList = node.getStatementList(); if (statementList != null) { for (PyStatement st : statementList.getStatements()) { stack.push(st); while (!stack.isEmpty()) { PsiElement e = stack.pop(); if (e instanceof PyReferenceExpression) { PsiReference reference = e.getReference(); if (reference != null) { PsiElement resolved = reference.resolve(); if (resolved != null) { if (resolved.getText().equals(text)) return true; } } } for (PsiElement psiElement : e.getChildren()) { stack.push(psiElement); } } } } return false; }
public static void removeBackSlash(PsiElement parent) { if (parent != null) { Stack<PsiElement> stack = new Stack<PsiElement>(); if (parent instanceof PyParenthesizedExpression) stack.push(((PyParenthesizedExpression)parent).getContainedExpression()); else stack.push(parent); while (!stack.isEmpty()) { PsiElement el = stack.pop(); PsiWhiteSpace[] children = PsiTreeUtil.getChildrenOfType(el, PsiWhiteSpace.class); if (children != null) { for (PsiWhiteSpace ws : children) { if (ws.getText().contains("\\")) { ws.delete(); } } } for (PsiElement psiElement : el.getChildren()) { stack.push(psiElement); } } } }
private static boolean hasAssertOrYield(PyStatementList list) { Stack<PsiElement> stack = new Stack<PsiElement>(); if (list != null) { for (PyStatement st : list.getStatements()) { stack.push(st); while (!stack.isEmpty()) { PsiElement e = stack.pop(); if (e instanceof PyAssertStatement || e instanceof PyYieldExpression) return true; for (PsiElement psiElement : e.getChildren()) { stack.push(psiElement); } } } } return false; }
@NotNull @Override protected List<RedmineProjectItem> fetch(@NotNull ProgressIndicator indicator) throws Exception { // Seems that Redmine always return its project hierarchy in DFS order. // So it's easy to find level of each project using stack of parents. Stack<RedmineProject> parents = new Stack<RedmineProject>(); List<RedmineProjectItem> items = new ArrayList<RedmineProjectItem>(); for (RedmineProject project : myRepository.fetchProjects()) { RedmineProject parentProject = project.getParent(); if (parentProject == null) { items.add(new RedmineProjectItem(project, 0)); parents.clear(); } else { while (!parents.isEmpty() && !parents.peek().equals(parentProject)) { parents.pop(); } items.add(new RedmineProjectItem(project, parents.size())); } parents.push(project); } return items; }
@SuppressWarnings("unchecked") private <T> void ensureTheDataIsReadyToUse(@NotNull Collection<DataNode<T>> nodes) { Map<Key<?>, List<ProjectDataService<?, ?>>> servicesByKey = myServices.getValue(); Stack<DataNode<T>> toProcess = ContainerUtil.newStack(nodes); while (!toProcess.isEmpty()) { DataNode<T> node = toProcess.pop(); List<ProjectDataService<?, ?>> services = servicesByKey.get(node.getKey()); if (services != null) { for (ProjectDataService<?, ?> service : services) { node.prepareData(service.getClass().getClassLoader()); } } for (DataNode<?> dataNode : node.getChildren()) { toProcess.push((DataNode<T>)dataNode); } } }
@Override public synchronized void initStateFrom(@NotNull final ProgressIndicator indicator) { myRunning = indicator.isRunning(); myCanceled = indicator.isCanceled(); myFraction = indicator.getFraction(); myIndeterminate = indicator.isIndeterminate(); myText = indicator.getText(); myText2 = indicator.getText2(); myFraction = indicator.getFraction(); if (indicator instanceof ProgressIndicatorStacked) { ProgressIndicatorStacked stacked = (ProgressIndicatorStacked)indicator; myNonCancelableCount = stacked.getNonCancelableCount(); myTextStack = new Stack<String>(stacked.getTextStack()); myText2Stack = new Stack<String>(stacked.getText2Stack()); myFractionStack = new DoubleArrayList(stacked.getFractionStack()); } }
private boolean reevaluate(Project context) { this.context = context; boolean ret = false; if (isComplete()) { try { Stack<ASTNode> rpn = infixToRPN(); String rpnString = LOG.isDebugEnabled() ? tokensToString(rpn) : null; ret = objectIsTrue(calculateRPN(rpn)); if (LOG.isDebugEnabled()) { // Don't create the strings unless we are debugging them... LOG.debug(toString() + " --> " + rpnString + " ==> " + (ret ? "true" : "false")); } if (!rpn.isEmpty()) { throw new CalculationException("Invalid Expression: Tokens left after calculating: " + rpn.toString()); } } catch (CalculationException e) { String msg = "Error calculating conditional compiler expression '" + toString() + "'"; // Add stack info if in debug mode. LOG.info( msg, LOG.isDebugEnabled() ? e : null ); } } return ret; }
@SuppressWarnings("unchecked") private <T> void ensureTheDataIsReadyToUse(@Nonnull Collection<DataNode<T>> nodes) { Map<Key<?>, List<ProjectDataService<?, ?>>> servicesByKey = myServices.getValue(); Stack<DataNode<T>> toProcess = ContainerUtil.newStack(nodes); while (!toProcess.isEmpty()) { DataNode<T> node = toProcess.pop(); List<ProjectDataService<?, ?>> services = servicesByKey.get(node.getKey()); if (services != null) { for (ProjectDataService<?, ?> service : services) { node.prepareData(service.getClass().getClassLoader()); } } for (DataNode<?> dataNode : node.getChildren()) { toProcess.push((DataNode<T>)dataNode); } } }
public static void enterModal(Project project, Dialog dialog) { LOG.assertTrue(isDispatchThread(), "enterModal() should be invoked in event-dispatch thread"); if (LOG.isDebugEnabled()) { LOG.debug("enterModal:" + dialog.getName() + " ; for project: " + project.getName()); } if (project == null) { enterModal(dialog); return; } ourModalityStateMulticaster.getMulticaster().beforeModalityStateChanged(true); List<Dialog> modalEntitiesList = projectToModalEntities.getOrDefault(project, ContainerUtil.createLockFreeCopyOnWriteList()); projectToModalEntities.put(project, modalEntitiesList); modalEntitiesList.add(dialog); Stack<ModalityState> modalEntitiesStack = projectToModalEntitiesStack.getOrDefault(project, new Stack<>(ModalityState.NON_MODAL)); projectToModalEntitiesStack.put(project, modalEntitiesStack); modalEntitiesStack.push(new ModalityStateEx(ArrayUtil.toObjectArray(ourModalEntities))); }
@Nullable private Pair<PomModelAspect,PomTransaction> getBlockingTransaction(final PomModelAspect aspect, PomTransaction transaction) { final List<PomModelAspect> allDependants = getAllDependants(aspect); for (final PomModelAspect pomModelAspect : allDependants) { Stack<Pair<PomModelAspect, PomTransaction>> blockedAspects = myBlockedAspects.get(); ListIterator<Pair<PomModelAspect, PomTransaction>> blocksIterator = blockedAspects.listIterator(blockedAspects.size()); while (blocksIterator.hasPrevious()) { final Pair<PomModelAspect, PomTransaction> pair = blocksIterator.previous(); if (pomModelAspect == pair.getFirst() && // aspect dependence PsiTreeUtil.isAncestor(getContainingFileByTree(pair.getSecond().getChangeScope()), transaction.getChangeScope(), false) // same file ) { return pair; } } } return null; }
@Override public synchronized void initStateFrom(@Nonnull final ProgressIndicator indicator) { myRunning = indicator.isRunning(); myCanceled = indicator.isCanceled(); myFraction = indicator.getFraction(); myIndeterminate = indicator.isIndeterminate(); myText = indicator.getText(); myText2 = indicator.getText2(); myFraction = indicator.getFraction(); if (indicator instanceof ProgressIndicatorStacked) { ProgressIndicatorStacked stacked = (ProgressIndicatorStacked)indicator; myNonCancelableCount = stacked.getNonCancelableCount(); myTextStack = new Stack<>(stacked.getTextStack()); myText2Stack = new Stack<>(stacked.getText2Stack()); myFractionStack = new DoubleArrayList(stacked.getFractionStack()); } myShouldStartActivity = false; }
protected DfaMemoryStateImpl(DfaMemoryStateImpl toCopy) { myFactory = toCopy.myFactory; myEphemeral = toCopy.myEphemeral; myDefaultVariableStates = toCopy.myDefaultVariableStates; // shared between all states myStack = new Stack<>(toCopy.myStack); myDistinctClasses = new TLongHashSet(toCopy.myDistinctClasses.size()); toCopy.myDistinctClasses.forEach(myDistinctClasses::add); myUnknownVariables = ContainerUtil.newLinkedHashSet(toCopy.myUnknownVariables); myEqClasses = ContainerUtil.newArrayList(toCopy.myEqClasses); myIdToEqClassesIndices = new MyIdMap(toCopy.myIdToEqClassesIndices.size()); toCopy.myIdToEqClassesIndices.forEachEntry((id, set) -> { myIdToEqClassesIndices.put(id, set); return true; }); myVariableStates = ContainerUtil.newLinkedHashMap(toCopy.myVariableStates); myCachedDistinctClassPairs = toCopy.myCachedDistinctClassPairs; myCachedNonTrivialEqClasses = toCopy.myCachedNonTrivialEqClasses; myCachedHash = toCopy.myCachedHash; }
public DfaMemoryStateImpl(final DfaValueFactory factory) { myFactory = factory; myDefaultVariableStates = ContainerUtil.newTroveMap(); myEqClasses = ContainerUtil.newArrayList(); myUnknownVariables = ContainerUtil.newLinkedHashSet(); myVariableStates = ContainerUtil.newLinkedHashMap(); myDistinctClasses = new TLongHashSet(); myStack = new Stack<DfaValue>(); myIdToEqClassesIndices = new MyIdMap(20); }
private boolean isCalledOnlyFrom(RefJavaElement refElement, Stack<RefJavaElement> callStack) { if (callStack.contains(this)) return refElement == this; if (getInReferences().isEmpty()) return false; if (refElement instanceof RefMethod) { RefMethod refMethod = (RefMethod) refElement; for (RefMethod refSuper : refMethod.getSuperMethods()) { if (!refSuper.getInReferences().isEmpty()) return false; } if (refMethod.isConstructor()){ boolean unreachable = true; for (RefElement refOut : refMethod.getOutReferences()){ unreachable &= !refOut.isReachable(); } if (unreachable) return true; } } callStack.push(this); for (RefElement refCaller : getInReferences()) { if (!((RefElementImpl)refCaller).isSuspicious() || !((RefJavaElementImpl)refCaller).isCalledOnlyFrom(refElement, callStack)) { callStack.pop(); return false; } } callStack.pop(); return true; }
public static void processAllSuperTypes(@NotNull PsiType type, @NotNull PsiTypeVisitor<PsiType> visitor, @NotNull Project project, @NotNull Set<PsiType> set) { if (type instanceof PsiPrimitiveType) { if (type.equals(PsiType.BOOLEAN) || type.equals(PsiType.VOID) || type.equals(PsiType.NULL)) return; Stack<PsiType> stack = new Stack<PsiType>(); for (int i = PRIMITIVE_TYPES.length - 1; !PRIMITIVE_TYPES[i].equals(type); i--) { stack.push(PRIMITIVE_TYPES[i]); } while(!stack.empty()) { processType(stack.pop(), visitor, set); } } else{ PsiManager manager = PsiManager.getInstance(project); GlobalSearchScope resolveScope = type.getResolveScope(); if (resolveScope == null) resolveScope = GlobalSearchScope.allScope(project); PsiClassType objectType = PsiType.getJavaLangObject(manager, resolveScope); processType(objectType, visitor, set); if (type instanceof PsiClassType) { PsiType[] superTypes = type.getSuperTypes(); for (PsiType superType : superTypes) { processType(superType, visitor, set); processAllSuperTypes(superType, visitor, project, set); } } } }
@Nullable private ArrangementEntryDependencyInfo buildMethodDependencyInfo(@NotNull final PsiMethod method, @NotNull Map<PsiMethod, ArrangementEntryDependencyInfo> cache) { JavaElementArrangementEntry entry = myMethodEntriesMap.get(method); if (entry == null) { return null; } ArrangementEntryDependencyInfo result = new ArrangementEntryDependencyInfo(entry); Stack<Pair<PsiMethod, ArrangementEntryDependencyInfo>> toProcess = new Stack<Pair<PsiMethod, ArrangementEntryDependencyInfo>>(); toProcess.push(Pair.create(method, result)); Set<PsiMethod> usedMethods = ContainerUtilRt.newHashSet(); while (!toProcess.isEmpty()) { Pair<PsiMethod, ArrangementEntryDependencyInfo> pair = toProcess.pop(); Set<PsiMethod> dependentMethods = myMethodDependencies.get(pair.first); if (dependentMethods == null) { continue; } usedMethods.add(pair.first); for (PsiMethod dependentMethod : dependentMethods) { if (usedMethods.contains(dependentMethod)) { // Prevent cyclic dependencies. return null; } JavaElementArrangementEntry dependentEntry = myMethodEntriesMap.get(dependentMethod); if (dependentEntry == null) { continue; } ArrangementEntryDependencyInfo dependentMethodInfo = cache.get(dependentMethod); if (dependentMethodInfo == null) { cache.put(dependentMethod, dependentMethodInfo = new ArrangementEntryDependencyInfo(dependentEntry)); } Pair<PsiMethod, ArrangementEntryDependencyInfo> dependentPair = Pair.create(dependentMethod, dependentMethodInfo); pair.second.addDependentEntryInfo(dependentPair.second); toProcess.push(dependentPair); } } return result; }
public static void visit(@Nullable DataNode node, @NotNull Consumer<DataNode<?>> consumer) { if(node == null) return; Stack<DataNode> toProcess = ContainerUtil.newStack(node); while (!toProcess.isEmpty()) { DataNode<?> node0 = toProcess.pop(); consumer.consume(node0); for (DataNode<?> child : node0.getChildren()) { toProcess.push(child); } } }
@NotNull protected StubElement buildStubTreeFor(@NotNull ASTNode root, @NotNull StubElement parentStub) { Stack<StubElement> parentStubs = new Stack<StubElement>(); Stack<ASTNode> parentNodes = new Stack<ASTNode>(); parentNodes.push(root); parentStubs.push(parentStub); while (!parentStubs.isEmpty()) { StubElement stub = parentStubs.pop(); ASTNode node = parentNodes.pop(); IElementType nodeType = node.getElementType(); if (nodeType instanceof IStubElementType) { final IStubElementType type = (IStubElementType)nodeType; if (type.shouldCreateStub(node)) { PsiElement element = node.getPsi(); if (!(element instanceof StubBasedPsiElement)) { LOG.error("Non-StubBasedPsiElement requests stub creation. Stub type: " + type + ", PSI: " + element); } @SuppressWarnings("unchecked") StubElement s = type.createStub(element, stub); stub = s; LOG.assertTrue(stub != null, element); } } for (ASTNode childNode = node.getLastChildNode(); childNode != null; childNode = childNode.getTreePrev()) { if (!skipChildProcessingWhenBuildingStubs(node, childNode)) { parentNodes.push(childNode); parentStubs.push(stub); } } } return parentStub; }
public static int findLeftmostLParen(HighlighterIterator iterator, IElementType lparenTokenType, CharSequence fileText, FileType fileType) { int lastLbraceOffset = -1; Stack<IElementType> braceStack = new Stack<IElementType>(); for (; !iterator.atEnd(); iterator.retreat()) { final IElementType tokenType = iterator.getTokenType(); if (isLBraceToken(iterator, fileText, fileType)) { if (!braceStack.isEmpty()) { IElementType topToken = braceStack.pop(); if (!isPairBraces(tokenType, topToken, fileType)) { break; // unmatched braces } } else { if (tokenType == lparenTokenType) { lastLbraceOffset = iterator.getStart(); } else { break; } } } else if (isRBraceToken(iterator, fileText, fileType)) { braceStack.push(iterator.getTokenType()); } } return lastLbraceOffset; }
public static int findLeftLParen(HighlighterIterator iterator, IElementType lparenTokenType, CharSequence fileText, FileType fileType) { int lastLbraceOffset = -1; Stack<IElementType> braceStack = new Stack<IElementType>(); for (; !iterator.atEnd(); iterator.retreat()) { final IElementType tokenType = iterator.getTokenType(); if (isLBraceToken(iterator, fileText, fileType)) { if (!braceStack.isEmpty()) { IElementType topToken = braceStack.pop(); if (!isPairBraces(tokenType, topToken, fileType)) { break; // unmatched braces } } else { if (tokenType == lparenTokenType) { return iterator.getStart(); } else { break; } } } else if (isRBraceToken(iterator, fileText, fileType)) { braceStack.push(iterator.getTokenType()); } } return lastLbraceOffset; }
public static int findRightmostRParen(HighlighterIterator iterator, IElementType rparenTokenType, CharSequence fileText, FileType fileType) { int lastRbraceOffset = -1; Stack<IElementType> braceStack = new Stack<IElementType>(); for (; !iterator.atEnd(); iterator.advance()) { final IElementType tokenType = iterator.getTokenType(); if (isRBraceToken(iterator, fileText, fileType)) { if (!braceStack.isEmpty()) { IElementType topToken = braceStack.pop(); if (!isPairBraces(tokenType, topToken, fileType)) { break; // unmatched braces } } else { if (tokenType == rparenTokenType) { lastRbraceOffset = iterator.getStart(); } else { break; } } } else if (isLBraceToken(iterator, fileText, fileType)) { braceStack.push(iterator.getTokenType()); } } return lastRbraceOffset; }
/** * finds subscriptions of keyword container, adds them to mySubscriptions * @param function */ private static List<PySubscriptionExpression> fillSubscriptions(PyFunction function) { List<PySubscriptionExpression> subscriptions = new ArrayList<PySubscriptionExpression>(); PyStatementList statementList = function.getStatementList(); Stack<PsiElement> stack = new Stack<PsiElement>(); PyParameter keywordContainer = getKeywordContainer(function); if (keywordContainer != null) { String keywordContainerName = keywordContainer.getName(); for (PyStatement st : statementList.getStatements()) { stack.push(st); while (!stack.isEmpty()) { PsiElement e = stack.pop(); if (e instanceof PySubscriptionExpression) { if (((PySubscriptionExpression)e).getOperand().getText().equals(keywordContainerName)) { subscriptions.add((PySubscriptionExpression)e); } } else { for (PsiElement psiElement : e.getChildren()) { stack.push(psiElement); } } } } } return subscriptions; }
private static List<PyCallExpression> fillCallExpressions(PyFunction function) { List<PyCallExpression> callElements = new ArrayList<PyCallExpression>(); PyStatementList statementList = function.getStatementList(); Stack<PsiElement> stack = new Stack<PsiElement>(); PyParameter keywordContainer = getKeywordContainer(function); if (keywordContainer != null) { String keywordContainerName = keywordContainer.getName(); for (PyStatement st : statementList.getStatements()) { stack.push(st); while (!stack.isEmpty()) { PsiElement e = stack.pop(); if (!(e instanceof PySubscriptionExpression)) { if (e instanceof PyCallExpression && ((PyCallExpression)e).getCallee() instanceof PyQualifiedExpression && isCallElement(((PyCallExpression)e).getCallee(), keywordContainerName)) { callElements.add((PyCallExpression)e); } else { for (PsiElement psiElement : e.getChildren()) { stack.push(psiElement); } } } } } } return callElements; }
/** * Allows to build file system path to the target gradle sub-project given the root project path. * * @param subProject target sub-project which config path we're interested in * @param rootProjectPath path to root project's directory which contains 'build.gradle' * @return path to the given sub-project's directory which contains 'build.gradle' */ @NotNull public static String getConfigPath(@NotNull GradleProject subProject, @NotNull String rootProjectPath) { try { GradleScript script = subProject.getBuildScript(); if (script != null) { File file = script.getSourceFile(); if (file != null) { if (file.isFile()) { // The file points to 'build.gradle' at the moment but we keep it's parent dir path instead. file = file.getParentFile(); } return ExternalSystemApiUtil.toCanonicalPath(file.getCanonicalPath()); } } } catch (Exception e) { // As said by gradle team: 'One thing I'm interested in is whether you have any thoughts about how the tooling API should // deal with missing details from the model - for example, when asking for details about the build scripts when using // a version of Gradle that does not supply that information. Currently, you'll get a `UnsupportedOperationException` // when you call the `getBuildScript()` method'. // // So, just ignore it and assume that the user didn't define any custom build file name. } File rootProjectParent = new File(rootProjectPath); StringBuilder buffer = new StringBuilder(FileUtil.toCanonicalPath(rootProjectParent.getAbsolutePath())); Stack<String> stack = ContainerUtilRt.newStack(); for (GradleProject p = subProject; p != null; p = p.getParent()) { stack.push(p.getName()); } // pop root project stack.pop(); while (!stack.isEmpty()) { buffer.append(ExternalSystemConstants.PATH_SEPARATOR).append(stack.pop()); } return buffer.toString(); }
private void update(Collection<VirtualFile> files, boolean recursive, boolean force, MavenExplicitProfiles explicitProfiles, MavenProjectReader projectReader, MavenGeneralSettings generalSettings, MavenProgressIndicator process) { if (files.isEmpty()) return; UpdateContext updateContext = new UpdateContext(); Stack<MavenProject> updateStack = new Stack<MavenProject>(); for (VirtualFile each : files) { MavenProject mavenProject = findProject(each); if (mavenProject == null) { doAdd(each, recursive, explicitProfiles, updateContext, updateStack, projectReader, generalSettings, process); } else { doUpdate(mavenProject, findAggregator(mavenProject), false, recursive, force, explicitProfiles, updateContext, updateStack, projectReader, generalSettings, process); } } updateExplicitProfiles(); updateContext.fireUpdatedIfNecessary(); }
private void doAdd(final VirtualFile f, boolean recursuve, MavenExplicitProfiles explicitProfiles, UpdateContext updateContext, Stack<MavenProject> updateStack, MavenProjectReader reader, MavenGeneralSettings generalSettings, MavenProgressIndicator process) { MavenProject newMavenProject = new MavenProject(f); MavenProject intendedAggregator = null; for (MavenProject each : getProjects()) { if (each.getExistingModuleFiles().contains(f)) { intendedAggregator = each; break; } } doUpdate(newMavenProject, intendedAggregator, true, recursuve, false, explicitProfiles, updateContext, updateStack, reader, generalSettings, process); }
private void endScope(@NotNull PsiBuilder builder, Ref<Integer> tokenIndex, Stack<MarkerScope> scopes, boolean advance) { if(scopes.isEmpty()) { // unbalanced scope, e.g. missing opening '{' return; } MarkerScope endedScope = scopes.pop(); if(advance) { builder.advanceLexer(); tokenIndex.set(tokenIndex.get() + 1); } endedScope.marker.done(endedScope.tokenType); }
private boolean isPropertyScopeDefinition(String text, int tokenIndex, List<JSGraphQLToken> astTokens, Stack<PropertyScope> scopes) { switch(text) { case JSGraphQLKeywords.TYPE: // type after extend is not a new scope if(tokenIndex > 0) { final JSGraphQLToken prevToken = astTokens.get(tokenIndex - 1); if(JSGraphQLKeywords.EXTEND.equals(prevToken.sourceToken.getText())) { return false; } } return true; case JSGraphQLKeywords.INTERFACE: case JSGraphQLKeywords.ENUM: case JSGraphQLKeywords.INPUT: case JSGraphQLKeywords.EXTEND: case JSGraphQLKeywords.SCHEMA: return true; } if(!schema) { switch (text) { case JSGraphQLKeywords.QUERY: case JSGraphQLKeywords.MUTATION: case JSGraphQLKeywords.SUBSCRIPTION: // not property scopes inside "schema {}" return scopes.isEmpty(); case JSGraphQLKeywords.FRAGMENT: return true; } if (JSGraphQLKeywords.FRAGMENT_DOTS.equals(text)) { // possible anonymous fragment if no def of the fragment name right after if (tokenIndex + 1 < astTokens.size()) { final JSGraphQLToken nextToken = astTokens.get(tokenIndex + 1); return nextToken.tokenType != JSGraphQLTokenTypes.DEF; } } } return false; }
public ControlFlow buildControlFlow(@NotNull PsiElement codeFragment, boolean ignoreAssertions) { myIgnoreAssertions = ignoreAssertions; PsiManager manager = codeFragment.getManager(); GlobalSearchScope scope = codeFragment.getResolveScope(); myRuntimeException = myFactory.getNotNullFactory().create(PsiType.getJavaLangRuntimeException(manager, scope)); myError = myFactory.getNotNullFactory().create(PsiType.getJavaLangError(manager, scope)); myNpe = JavaPsiFacade.getElementFactory(manager.getProject()).createTypeByFQClassName(JAVA_LANG_NULL_POINTER_EXCEPTION, scope); myFields = new HashSet<DfaVariableValue>(); myCatchStack = new Stack<CatchDescriptor>(); myPassNumber = 1; myPass1Flow = new ControlFlow(myFactory); myCurrentFlow = myPass1Flow; try { codeFragment.accept(this); } catch (CannotAnalyzeException e) { return null; } myPassNumber = 2; final ControlFlow pass2Flow = new ControlFlow(myFactory); myCurrentFlow = pass2Flow; codeFragment.accept(this); pass2Flow.setFields(myFields.toArray(new DfaVariableValue[myFields.size()])); if (myPass1Flow.getInstructionCount() != pass2Flow.getInstructionCount()) { LOG.error(Arrays.toString(myPass1Flow.getInstructions()) + "!=\n" + Arrays.toString(pass2Flow.getInstructions())); } addInstruction(new ReturnInstruction()); return pass2Flow; }